MCPcopy Create free account
hub / github.com/dcleblanc/SafeInt / AddVerifyUint64Uint8

Function AddVerifyUint64Uint8

Test/AddVerify.cpp:995–1051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

993};
994
995void AddVerifyUint64Uint8()
996{
997 size_t i;
998
999 for( i = 0; i < COUNTOF(uint64_uint8); ++i )
1000 {
1001 std::uint64_t ret;
1002 if( SafeAdd(uint64_uint8[i].x, uint64_uint8[i].y, ret) != uint64_uint8[i].fExpected )
1003 {
1004 cerr << "Error in case uint64_uint8: ";
1005 cerr << HEX(16) << uint64_uint8[i].x << ", ";
1006 cerr << HEX(2) << (0xFF & (unsigned int)uint64_uint8[i].y) << ", ";
1007 cerr << "expected = " << uint64_uint8[i].fExpected << endl;
1008 }
1009
1010 // Now test throwing version
1011 bool fSuccess = true;
1012 try
1013 {
1014 SafeInt<std::uint64_t> si(uint64_uint8[i].x);
1015 si += uint64_uint8[i].y;
1016 }
1017 catch(...)
1018 {
1019 fSuccess = false;
1020 }
1021
1022 if( fSuccess != uint64_uint8[i].fExpected )
1023 {
1024 cerr << "Error in case uint64_uint8 throw (1): ";
1025 cerr << HEX(16) << uint64_uint8[i].x << ", ";
1026 cerr << HEX(2) << (0xFF & (unsigned int)uint64_uint8[i].y) << ", ";
1027 cerr << "expected = " << uint64_uint8[i].fExpected << endl;
1028 }
1029
1030 // Also need to test the version that assigns back out
1031 // to a plain int, as it has different logic
1032 fSuccess = true;
1033 try
1034 {
1035 std::uint64_t x(uint64_uint8[i].x);
1036 x += SafeInt<std::uint8_t>(uint64_uint8[i].y);
1037 }
1038 catch(...)
1039 {
1040 fSuccess = false;
1041 }
1042
1043 if( fSuccess != uint64_uint8[i].fExpected )
1044 {
1045 cerr << "Error in case uint64_uint8 throw (2): ";
1046 cerr << HEX(16) << uint64_uint8[i].x << ", ";
1047 cerr << HEX(2) << (0xFF & (unsigned int)uint64_uint8[i].y) << ", ";
1048 cerr << "expected = " << uint64_uint8[i].fExpected << endl;
1049 }
1050 }
1051}
1052

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected