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

Function SubVerifyInt64Uint8

Test/SubVerify.cpp:6156–6212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6154};
6155
6156void SubVerifyInt64Uint8()
6157{
6158 size_t i;
6159
6160 for( i = 0; i < COUNTOF(int64_uint8); ++i )
6161 {
6162 std::int64_t ret;
6163 if( SafeSubtract(int64_uint8[i].x, int64_uint8[i].y, ret) != int64_uint8[i].fExpected )
6164 {
6165 cerr << "Error in case int64_uint8: ";
6166 cerr << hex << setw(16) << setfill('0') << int64_uint8[i].x << ", ";
6167 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_uint8[i].y) << ", ";
6168 cerr << "expected = " << int64_uint8[i].fExpected << endl;
6169 }
6170
6171 // Now test throwing version
6172 bool fSuccess = true;
6173 try
6174 {
6175 SafeInt<std::int64_t> si(int64_uint8[i].x);
6176 si -= int64_uint8[i].y;
6177 }
6178 catch(...)
6179 {
6180 fSuccess = false;
6181 }
6182
6183 if( fSuccess != int64_uint8[i].fExpected )
6184 {
6185 cerr << "Error in case int64_uint8 throw (1): ";
6186 cerr << hex << setw(16) << setfill('0') << int64_uint8[i].x << ", ";
6187 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_uint8[i].y) << ", ";
6188 cerr << "expected = " << int64_uint8[i].fExpected << endl;
6189 }
6190
6191 // Also need to test the version that assigns back out
6192 // to a plain int, as it has different logic
6193 fSuccess = true;
6194 try
6195 {
6196 std::int64_t x(int64_uint8[i].x);
6197 x -= SafeInt<std::uint8_t>(int64_uint8[i].y);
6198 }
6199 catch(...)
6200 {
6201 fSuccess = false;
6202 }
6203
6204 if( fSuccess != int64_uint8[i].fExpected )
6205 {
6206 cerr << "Error in case int64_uint8 throw (2): ";
6207 cerr << hex << setw(16) << setfill('0') << int64_uint8[i].x << ", ";
6208 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_uint8[i].y) << ", ";
6209 cerr << "expected = " << int64_uint8[i].fExpected << endl;
6210 }
6211 }
6212}
6213

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected