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

Function SubVerifyInt8Uint16

Test/SubVerify.cpp:6689–6745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6687};
6688
6689void SubVerifyInt8Uint16()
6690{
6691 size_t i;
6692
6693 for( i = 0; i < COUNTOF(int8_uint16); ++i )
6694 {
6695 std::int8_t ret;
6696 if( SafeSubtract(int8_uint16[i].x, int8_uint16[i].y, ret) != int8_uint16[i].fExpected )
6697 {
6698 cerr << "Error in case int8_uint16: ";
6699 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint16[i].x) << ", ";
6700 cerr << hex << setw(4) << setfill('0') << int8_uint16[i].y << ", ";
6701 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6702 }
6703
6704 // Now test throwing version
6705 bool fSuccess = true;
6706 try
6707 {
6708 SafeInt<std::int8_t> si(int8_uint16[i].x);
6709 si -= int8_uint16[i].y;
6710 }
6711 catch(...)
6712 {
6713 fSuccess = false;
6714 }
6715
6716 if( fSuccess != int8_uint16[i].fExpected )
6717 {
6718 cerr << "Error in case int8_uint16 throw (1): ";
6719 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint16[i].x) << ", ";
6720 cerr << hex << setw(4) << setfill('0') << int8_uint16[i].y << ", ";
6721 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6722 }
6723
6724 // Also need to test the version that assigns back out
6725 // to a plain int, as it has different logic
6726 fSuccess = true;
6727 try
6728 {
6729 std::int8_t x(int8_uint16[i].x);
6730 x -= SafeInt<std::uint16_t>(int8_uint16[i].y);
6731 }
6732 catch(...)
6733 {
6734 fSuccess = false;
6735 }
6736
6737 if( fSuccess != int8_uint16[i].fExpected )
6738 {
6739 cerr << "Error in case int8_uint16 throw (2): ";
6740 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_uint16[i].x) << ", ";
6741 cerr << hex << setw(4) << setfill('0') << int8_uint16[i].y << ", ";
6742 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6743 }
6744 }
6745}
6746

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected