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

Function SubVerifyInt8Uint64

Test/SubVerify.cpp:6387–6443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6385};
6386
6387void SubVerifyInt8Uint64()
6388{
6389 size_t i;
6390
6391 for( i = 0; i < COUNTOF(int8_uint64); ++i )
6392 {
6393 std::int8_t ret;
6394 if( SafeSubtract(int8_uint64[i].x, int8_uint64[i].y, ret) != int8_uint64[i].fExpected )
6395 {
6396 cerr << "Error in case int8_uint64: ";
6397 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint64[i].x) << ", ";
6398 cerr << hex << setw(16) << setfill('0') << int8_uint64[i].y << ", ";
6399 cerr << "expected = " << int8_uint64[i].fExpected << endl;
6400 }
6401
6402 // Now test throwing version
6403 bool fSuccess = true;
6404 try
6405 {
6406 SafeInt<std::int8_t> si(int8_uint64[i].x);
6407 si -= int8_uint64[i].y;
6408 }
6409 catch(...)
6410 {
6411 fSuccess = false;
6412 }
6413
6414 if( fSuccess != int8_uint64[i].fExpected )
6415 {
6416 cerr << "Error in case int8_uint64 throw (1): ";
6417 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint64[i].x) << ", ";
6418 cerr << hex << setw(16) << setfill('0') << int8_uint64[i].y << ", ";
6419 cerr << "expected = " << int8_uint64[i].fExpected << endl;
6420 }
6421
6422 // Also need to test the version that assigns back out
6423 // to a plain int, as it has different logic
6424 fSuccess = true;
6425 try
6426 {
6427 std::int8_t x(int8_uint64[i].x);
6428 x -= SafeInt<std::uint64_t>(int8_uint64[i].y);
6429 }
6430 catch(...)
6431 {
6432 fSuccess = false;
6433 }
6434
6435 if( fSuccess != int8_uint64[i].fExpected )
6436 {
6437 cerr << "Error in case int8_uint64 throw (2): ";
6438 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint64[i].x) << ", ";
6439 cerr << hex << setw(16) << setfill('0') << int8_uint64[i].y << ", ";
6440 cerr << "expected = " << int8_uint64[i].fExpected << endl;
6441 }
6442 }
6443}
6444

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected