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

Function AddVerifyInt8Uint16

Test/AddVerify.cpp:6004–6060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6002};
6003
6004void AddVerifyInt8Uint16()
6005{
6006 size_t i;
6007
6008 for( i = 0; i < COUNTOF(int8_uint16); ++i )
6009 {
6010 std::int8_t ret;
6011 if( SafeAdd(int8_uint16[i].x, int8_uint16[i].y, ret) != int8_uint16[i].fExpected )
6012 {
6013 cerr << "Error in case int8_uint16: ";
6014 cerr << HEX(2) << (0xFF & (int)int8_uint16[i].x) << ", ";
6015 cerr << HEX(4) << int8_uint16[i].y << ", ";
6016 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6017 }
6018
6019 // Now test throwing version
6020 bool fSuccess = true;
6021 try
6022 {
6023 SafeInt<std::int8_t> si(int8_uint16[i].x);
6024 si += int8_uint16[i].y;
6025 }
6026 catch(...)
6027 {
6028 fSuccess = false;
6029 }
6030
6031 if( fSuccess != int8_uint16[i].fExpected )
6032 {
6033 cerr << "Error in case int8_uint16 throw (1): ";
6034 cerr << HEX(2) << (0xFF & (int)int8_uint16[i].x) << ", ";
6035 cerr << HEX(4) << int8_uint16[i].y << ", ";
6036 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6037 }
6038
6039 // Also need to test the version that assigns back out
6040 // to a plain int, as it has different logic
6041 fSuccess = true;
6042 try
6043 {
6044 std::int8_t x(int8_uint16[i].x);
6045 x += SafeInt<std::uint16_t>(int8_uint16[i].y);
6046 }
6047 catch(...)
6048 {
6049 fSuccess = false;
6050 }
6051
6052 if( fSuccess != int8_uint16[i].fExpected )
6053 {
6054 cerr << "Error in case int8_uint16 throw (2): ";
6055 cerr << HEX(2) << (0xFF & (int)int8_uint16[i].x) << ", ";
6056 cerr << HEX(4) << int8_uint16[i].y << ", ";
6057 cerr << "expected = " << int8_uint16[i].fExpected << endl;
6058 }
6059 }
6060}
6061

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected