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

Function SubVerifyInt8Uint32

Test/SubVerify.cpp:6538–6594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6536};
6537
6538void SubVerifyInt8Uint32()
6539{
6540 size_t i;
6541
6542 for( i = 0; i < COUNTOF(int8_uint32); ++i )
6543 {
6544 std::int8_t ret;
6545 if( SafeSubtract(int8_uint32[i].x, int8_uint32[i].y, ret) != int8_uint32[i].fExpected )
6546 {
6547 cerr << "Error in case int8_uint32: ";
6548 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint32[i].x) << ", ";
6549 cerr << hex << setw(8) << setfill('0') << int8_uint32[i].y << ", ";
6550 cerr << "expected = " << int8_uint32[i].fExpected << endl;
6551 }
6552
6553 // Now test throwing version
6554 bool fSuccess = true;
6555 try
6556 {
6557 SafeInt<std::int8_t> si(int8_uint32[i].x);
6558 si -= int8_uint32[i].y;
6559 }
6560 catch(...)
6561 {
6562 fSuccess = false;
6563 }
6564
6565 if( fSuccess != int8_uint32[i].fExpected )
6566 {
6567 cerr << "Error in case int8_uint32 throw (1): ";
6568 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint32[i].x) << ", ";
6569 cerr << hex << setw(8) << setfill('0') << int8_uint32[i].y << ", ";
6570 cerr << "expected = " << int8_uint32[i].fExpected << endl;
6571 }
6572
6573 // Also need to test the version that assigns back out
6574 // to a plain int, as it has different logic
6575 fSuccess = true;
6576 try
6577 {
6578 std::int8_t x(int8_uint32[i].x);
6579 x -= SafeInt<std::uint32_t>(int8_uint32[i].y);
6580 }
6581 catch(...)
6582 {
6583 fSuccess = false;
6584 }
6585
6586 if( fSuccess != int8_uint32[i].fExpected )
6587 {
6588 cerr << "Error in case int8_uint32 throw (2): ";
6589 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint32[i].x) << ", ";
6590 cerr << hex << setw(8) << setfill('0') << int8_uint32[i].y << ", ";
6591 cerr << "expected = " << int8_uint32[i].fExpected << endl;
6592 }
6593 }
6594}
6595

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected