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

Function AddVerifyInt8Int64

Test/AddVerify.cpp:6386–6442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6384};
6385
6386void AddVerifyInt8Int64()
6387{
6388 size_t i;
6389
6390 for( i = 0; i < COUNTOF(int8_int64); ++i )
6391 {
6392 std::int8_t ret;
6393 if( SafeAdd(int8_int64[i].x, int8_int64[i].y, ret) != int8_int64[i].fExpected )
6394 {
6395 cerr << "Error in case int8_int64: ";
6396 cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", ";
6397 cerr << HEX(16) << int8_int64[i].y << ", ";
6398 cerr << "expected = " << int8_int64[i].fExpected << endl;
6399 }
6400
6401 // Now test throwing version
6402 bool fSuccess = true;
6403 try
6404 {
6405 SafeInt<std::int8_t> si(int8_int64[i].x);
6406 si += int8_int64[i].y;
6407 }
6408 catch(...)
6409 {
6410 fSuccess = false;
6411 }
6412
6413 if( fSuccess != int8_int64[i].fExpected )
6414 {
6415 cerr << "Error in case int8_int64 throw (1): ";
6416 cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", ";
6417 cerr << HEX(16) << int8_int64[i].y << ", ";
6418 cerr << "expected = " << int8_int64[i].fExpected << endl;
6419 }
6420
6421 // Also need to test the version that assigns back out
6422 // to a plain int, as it has different logic
6423 fSuccess = true;
6424 try
6425 {
6426 std::int8_t x(int8_int64[i].x);
6427 x += SafeInt<std::int64_t>(int8_int64[i].y);
6428 }
6429 catch(...)
6430 {
6431 fSuccess = false;
6432 }
6433
6434 if( fSuccess != int8_int64[i].fExpected )
6435 {
6436 cerr << "Error in case int8_int64 throw (2): ";
6437 cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", ";
6438 cerr << HEX(16) << int8_int64[i].y << ", ";
6439 cerr << "expected = " << int8_int64[i].fExpected << endl;
6440 }
6441 }
6442}
6443

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected