#include #include #include #include #include #include #include #include #include #include #if !zp_std_cxx17 #error At least C++17 is required for this test! #endif static_assert(::zp::isptr::val == false); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::isptr::val == true); static_assert(::zp::typequ::val == true); static_assert(::zp::typequ::val == false); static_assert(::zp::typequ<::zp::i8, ::std::uint8_t>::val == true); static_assert(::zp::typequ<::zp::i8s, ::std::int8_t>::val == true); static_assert(::zp::typequ<::zp::i01, ::std::uint16_t>::val == true); static_assert(::zp::typequ<::zp::i01s,::std::int16_t>::val == true); static_assert(::zp::typequ<::zp::i02, ::std::uint32_t>::val == true); static_assert(::zp::typequ<::zp::i02s,::std::int32_t>::val == true); static_assert(::zp::typequ<::zp::i04, ::std::uint64_t>::val == true); static_assert(::zp::typequ<::zp::i04s,::std::int64_t>::val == true); static_assert(::zp::typequ<::zp::ptr, ::std::uintptr_t>::val == true); static_assert(::zp::typequ<::zp::ptrdif,::std::ptrdiff_t>::val == true); static_assert(::zp::typequ<::zp::siz, ::std::size_t>::val == true); static_assert(::zp::typequ<::zp::remref::typ, int>::val == true); static_assert(::zp::typequ<::zp::remref::typ,int>::val == true); static_assert(::zp::typequ<::zp::remptr::typ, int>::val == true); static_assert(::zp::typequ<::zp::remptr::typ, int>::val == true); static_assert(::zp::typequ<::zp::remptr::typ, int>::val == true); static_assert(::zp::typequ<::zp::remptr::typ, int>::val == true); static_assert(::zp::typequ<::zp::remptr::typ,int>::val == true); static_assert(::zp::typequ<::zp::remqual::typ, int>::val == true); static_assert(::zp::typequ<::zp::remqual::typ, int>::val == true); static_assert(::zp::typequ<::zp::remqual::typ, int>::val == true); static_assert(::zp::typequ<::zp::remqual::typ,int>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int const>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int volatile>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int const volatile>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int const>::val == true); static_assert(::zp::typequ<::zp::sgn::typ, int volatile>::val == true); static_assert(::zp::typequ<::zp::sgn::typ,int const volatile>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned const>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned volatile>::val == true); static_assert(::zp::typequ<::zp::usgn::typ,int unsigned const volatile>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned const>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned volatile>::val == true); static_assert(::zp::typequ<::zp::usgn::typ, int unsigned const volatile>::val == true); static_assert(::zp::typequ<::zp::nulptrtyp,::std::nullptr_t>::val == true); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn<::zp::c8>::val == ::std::is_unsigned<::zp::c8>::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::isusgn::val == ::std::is_unsigned::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::issgn::val == ::std::is_signed::value); static_assert(::zp::bytelen == CHAR_BIT); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval<::zp::c8>::val == ::std::numeric_limits<::zp::c8>::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::minval::val == ::std::numeric_limits::lowest()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval<::zp::c8>::val == ::std::numeric_limits<::zp::c8>::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); static_assert(::zp::maxval::val == ::std::numeric_limits::max()); template static auto cmp(int unsigned & numerr,int long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept { char const* const ltypnm = typeid (ltyp).name(); char const* const rtypnm = typeid (rtyp).name(); auto const getval = [](auto const & valref) { using typ = typename ::zp::remqual::typ>::typ; if constexpr (::zp::ischrtyp::val) {return static_cast<::zp::i02>(valref);} else if constexpr (::zp::isptr::val) {return reinterpret_cast(valref);} else {return valref;} }; auto const lval = getval(lvalref); auto const rval = getval(rvalref); ::std::cout << " " << ln << ". comparing " << ltypnm << " (" << lval << ") vs. " << rtypnm << " (" << rval << ")... "; if (lval != rval) { ::std::cout << "\x1B[38;5;161munequal\x1B[0m\n"; //throw ::std::exception {}; ++numerr; return; } ::std::cout <<"\x1B[38;5;77mequal\x1B[0m\n"; } #define cmp(lval,rval) (::cmp(numerr,__LINE__,(lval),(rval))) int main() { int unsigned numerr = 0x0u; auto const tst = [](char const* const tst) noexcept { ::std::cout <<"\n\x1B[38;5;75mtesting\x1B[0m " << tst <<"\n\n"; }; ::std::cout <<"zp " <<::zp::ver.api <<"." <<::zp::ver.ext <<", run-time test\n"; try { #if false [&] { tst("optionals"); ::zp::opt<::zp::i8s> opt = ::zp::nulopt; cmp(opt.chk(),false); auto const fun = [](char const* msg) -> void { ::std::cout << msg << ::std::endl; ::std::abort(); }; opt = -0x45; cmp(opt.chk(),true); cmp(opt.exp(fun,"expectation failed"),-0x45); }(); #endif [&] { tst("special numbers"); ::zp::f02 f02; ::zp::f04 f04; cmp(sizeof (f02),0x4u); cmp(sizeof (f04),0x8u); f02 = ::zp::nan<::zp::f02>::val; f04 = ::zp::nan<::zp::f04>::val; cmp(::zp::isnan(f02),true); cmp(::zp::isnan(f04),true); f02 = ::zp::inf<::zp::f02>::val; f04 = ::zp::inf<::zp::f04>::val; cmp(f02 > ::zp::maxval<::zp::f02>::val,true); cmp(f04 > ::zp::maxval<::zp::f04>::val,true); }(); [&] { tst("mathematics"); }(); /*[&] { tst("vectors"); ::zp::vec2 const lvec2 = { .x = +0x1, .y = -0x3, }; ::zp::vec2 const rvec2 = { .x = +0x2, .y = -0x4, }; cmp(::zp::dot(lvec2,rvec2),0xE); ::zp::vec3 const lvec3 = { .x = +0x1, .y = -0x3, .z = +0x5, }; ::zp::vec3 const rvec3 = { .x = +0x2, .y = -0x4, .z = +0x6, }; cmp(::zp::dot(lvec3,rvec3),0x2C); ::zp::vec4 const lvec4 = { .x = +0x1, .y = -0x3, .z = +0x5, .w = -0x7, }; ::zp::vec4 const rvec4 = { .x = +0x2, .y = -0x4, .z = +0x6, .w = -0x8, }; cmp(::zp::dot(lvec4,rvec4),0x64); auto const avec2 = ::zp::vadd(lvec2,rvec2); auto const svec2 = ::zp::vsub(lvec2,rvec2); cmp(avec2.x,+0x3); cmp(avec2.y,-0x7); cmp(svec2.x,-0x1); cmp(svec2.y,+0x1); }();*/ [&] { tst("memory sequences"); ::zp::i04 filbuf; cmp(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast(&filbuf)+0x8u); cmp(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast(&filbuf)+0x4u); cmp(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast(&filbuf)+0x2u); cmp(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast(&filbuf)+0x1u); cmp(filbuf,0xFFFFFFFF7F7F3F1Fu); ::zp::i04 cpybuf; ::zp::memcpy(&cpybuf,&filbuf,0x8u); cmp(cpybuf,filbuf); cmp(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast(&cpybuf)); }(); [&] { tst("strings"); char str[] = "Hello there!"; wchar_t wstr[] = L"Hello there!"; char32_t str02[] = U"Hello there!"; ::zp::siz const len = ::zp_strlen( str); ::zp::siz const wlen = ::zp_wstrlen( wstr); ::zp::siz const len02 = ::zp_utf32len(str02); cmp(len, 0xCu); cmp(wlen, 0xCu); cmp(len02,0xCu); auto const buf = new char[ len]; auto const wbuf = new wchar_t[ wlen]; auto const buf02 = new char32_t[len02]; cmp(::zp_strcpy( buf, str), len); cmp(::zp_wstrcpy( wbuf, wstr), wlen); cmp(::zp_utf32cpy(buf02,str02),len02); delete[] buf; delete[] wbuf; delete[] buf02; }(); [&] { tst("UTF-8"); char32_t const src[] = U"\U0001F480"; ::zp::siz const buf8len = ::zp_utf8enclen(src); cmp(buf8len,0x4u); ::zp::c8 * buf8 = new ::zp::c8[buf8len+0x1]; ::zp_utf8enc(buf8,src); cmp(buf8[0x0],0xF0u); cmp(buf8[0x1],0x9Fu); cmp(buf8[0x2],0x92u); cmp(buf8[0x3],0x80u); cmp(buf8[0x4],0x00u); ::zp::siz const buf02len = ::zp_utf8declen(buf8); cmp(buf02len,0x1u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf8dec(buf02,buf8); cmp(buf02[0x0],0x1F480u); cmp(buf02[0x1],0x0u); delete[] buf8; delete[] buf02; }(); [&] { tst("UTF-16"); char32_t const src[] = U"\U0001F480\u00F0"; ::zp::siz const buf01len = ::zp_utf16enclen(src); cmp(buf01len,0x3u); char16_t * buf01 = new char16_t[buf01len+0x1]; ::zp_utf16enc(buf01,src); cmp(buf01[0x0],0xD83Du); cmp(buf01[0x1],0xDC80u); cmp(buf01[0x2],0x00F0u); cmp(buf01[0x3],0x0000u); ::zp::siz const buf02len = ::zp_utf16declen(buf01); cmp(buf02len,0x2u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf16dec(buf02,buf01); cmp(buf02[0x0],0x1F480u); cmp(buf02[0x1],0xF0u); cmp(buf02[0x2],0x0u); delete[] buf01; delete[] buf02; }(); } catch (::std::exception const &) { return EXIT_FAILURE; } ::std::cout <<"\nDone \u2212 " <