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

Function AddVerifyInt8Uint8

Test/AddVerify.cpp:6155–6211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6153};
6154
6155void AddVerifyInt8Uint8()
6156{
6157 size_t i;
6158
6159 for( i = 0; i < COUNTOF(int8_uint8); ++i )
6160 {
6161 std::int8_t ret;
6162 if( SafeAdd(int8_uint8[i].x, int8_uint8[i].y, ret) != int8_uint8[i].fExpected )
6163 {
6164 cerr << "Error in case int8_uint8: ";
6165 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].x) << ", ";
6166 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].y) << ", ";
6167 cerr << "expected = " << int8_uint8[i].fExpected << endl;
6168 }
6169
6170 // Now test throwing version
6171 bool fSuccess = true;
6172 try
6173 {
6174 SafeInt<std::int8_t> si(int8_uint8[i].x);
6175 si += int8_uint8[i].y;
6176 }
6177 catch(...)
6178 {
6179 fSuccess = false;
6180 }
6181
6182 if( fSuccess != int8_uint8[i].fExpected )
6183 {
6184 cerr << "Error in case int8_uint8 throw (1): ";
6185 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].x) << ", ";
6186 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].y) << ", ";
6187 cerr << "expected = " << int8_uint8[i].fExpected << endl;
6188 }
6189
6190 // Also need to test the version that assigns back out
6191 // to a plain int, as it has different logic
6192 fSuccess = true;
6193 try
6194 {
6195 std::int8_t x(int8_uint8[i].x);
6196 x += SafeInt<std::uint8_t>(int8_uint8[i].y);
6197 }
6198 catch(...)
6199 {
6200 fSuccess = false;
6201 }
6202
6203 if( fSuccess != int8_uint8[i].fExpected )
6204 {
6205 cerr << "Error in case int8_uint8 throw (2): ";
6206 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].x) << ", ";
6207 cerr << HEX(2) << (0xFF & (int)int8_uint8[i].y) << ", ";
6208 cerr << "expected = " << int8_uint8[i].fExpected << endl;
6209 }
6210 }
6211}
6212

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected