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

Function SubVerifyInt64Uint16

Test/SubVerify.cpp:5933–5989  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5931};
5932
5933void SubVerifyInt64Uint16()
5934{
5935 size_t i;
5936
5937 for( i = 0; i < COUNTOF(int64_uint16); ++i )
5938 {
5939 std::int64_t ret;
5940 if( SafeSubtract(int64_uint16[i].x, int64_uint16[i].y, ret) != int64_uint16[i].fExpected )
5941 {
5942 cerr << "Error in case int64_uint16: ";
5943 cerr << hex << setw(16) << setfill('0') << int64_uint16[i].x << ", ";
5944 cerr << hex << setw(4) << setfill('0') << int64_uint16[i].y << ", ";
5945 cerr << "expected = " << int64_uint16[i].fExpected << endl;
5946 }
5947
5948 // Now test throwing version
5949 bool fSuccess = true;
5950 try
5951 {
5952 SafeInt<std::int64_t> si(int64_uint16[i].x);
5953 si -= int64_uint16[i].y;
5954 }
5955 catch(...)
5956 {
5957 fSuccess = false;
5958 }
5959
5960 if( fSuccess != int64_uint16[i].fExpected )
5961 {
5962 cerr << "Error in case int64_uint16 throw (1): ";
5963 cerr << hex << setw(16) << setfill('0') << int64_uint16[i].x << ", ";
5964 cerr << hex << setw(4) << setfill('0') << int64_uint16[i].y << ", ";
5965 cerr << "expected = " << int64_uint16[i].fExpected << endl;
5966 }
5967
5968 // Also need to test the version that assigns back out
5969 // to a plain int, as it has different logic
5970 fSuccess = true;
5971 try
5972 {
5973 std::int64_t x(int64_uint16[i].x);
5974 x -= SafeInt<std::uint16_t>(int64_uint16[i].y);
5975 }
5976 catch(...)
5977 {
5978 fSuccess = false;
5979 }
5980
5981 if( fSuccess != int64_uint16[i].fExpected )
5982 {
5983 cerr << "Error in case int64_uint16 throw (2): ";
5984 cerr << hex << setw(16) << setfill('0') << int64_uint16[i].x << ", ";
5985 cerr << hex << setw(4) << setfill('0') << int64_uint16[i].y << ", ";
5986 cerr << "expected = " << int64_uint16[i].fExpected << endl;
5987 }
5988 }
5989}
5990

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected