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

Function SubVerifyInt64Uint64

Test/SubVerify.cpp:5487–5543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5485};
5486
5487void SubVerifyInt64Uint64()
5488{
5489 size_t i;
5490
5491 for( i = 0; i < COUNTOF(int64_uint64); ++i )
5492 {
5493 std::int64_t ret;
5494 if( SafeSubtract(int64_uint64[i].x, int64_uint64[i].y, ret) != int64_uint64[i].fExpected )
5495 {
5496 cerr << "Error in case int64_uint64: ";
5497 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].x << ", ";
5498 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].y << ", ";
5499 cerr << "expected = " << int64_uint64[i].fExpected << endl;
5500 }
5501
5502 // Now test throwing version
5503 bool fSuccess = true;
5504 try
5505 {
5506 SafeInt<std::int64_t> si(int64_uint64[i].x);
5507 si -= int64_uint64[i].y;
5508 }
5509 catch(...)
5510 {
5511 fSuccess = false;
5512 }
5513
5514 if( fSuccess != int64_uint64[i].fExpected )
5515 {
5516 cerr << "Error in case int64_uint64 throw (1): ";
5517 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].x << ", ";
5518 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].y << ", ";
5519 cerr << "expected = " << int64_uint64[i].fExpected << endl;
5520 }
5521
5522 // Also need to test the version that assigns back out
5523 // to a plain int, as it has different logic
5524 fSuccess = true;
5525 try
5526 {
5527 std::int64_t x(int64_uint64[i].x);
5528 x -= SafeInt<std::uint64_t>(int64_uint64[i].y);
5529 }
5530 catch(...)
5531 {
5532 fSuccess = false;
5533 }
5534
5535 if( fSuccess != int64_uint64[i].fExpected )
5536 {
5537 cerr << "Error in case int64_uint64 throw (2): ";
5538 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].x << ", ";
5539 cerr << hex << setw(16) << setfill('0') << int64_uint64[i].y << ", ";
5540 cerr << "expected = " << int64_uint64[i].fExpected << endl;
5541 }
5542 }
5543}
5544

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected