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

Function AddVerifyInt64Int64

Test/AddVerify.cpp:3434–3490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3432};
3433
3434void AddVerifyInt64Int64()
3435{
3436 size_t i;
3437
3438 for( i = 0; i < COUNTOF(int64_int64); ++i )
3439 {
3440 std::int64_t ret;
3441 if( SafeAdd(int64_int64[i].x, int64_int64[i].y, ret) != int64_int64[i].fExpected )
3442 {
3443 cerr << "Error in case int64_int64: ";
3444 cerr << HEX(16) << int64_int64[i].x << ", ";
3445 cerr << HEX(16) << int64_int64[i].y << ", ";
3446 cerr << "expected = " << int64_int64[i].fExpected << endl;
3447 }
3448
3449 // Now test throwing version
3450 bool fSuccess = true;
3451 try
3452 {
3453 SafeInt<std::int64_t> si(int64_int64[i].x);
3454 si += int64_int64[i].y;
3455 }
3456 catch(...)
3457 {
3458 fSuccess = false;
3459 }
3460
3461 if( fSuccess != int64_int64[i].fExpected )
3462 {
3463 cerr << "Error in case int64_int64 throw (1): ";
3464 cerr << HEX(16) << int64_int64[i].x << ", ";
3465 cerr << HEX(16) << int64_int64[i].y << ", ";
3466 cerr << "expected = " << int64_int64[i].fExpected << endl;
3467 }
3468
3469 // Also need to test the version that assigns back out
3470 // to a plain int, as it has different logic
3471 fSuccess = true;
3472 try
3473 {
3474 std::int64_t x(int64_int64[i].x);
3475 x += SafeInt<std::int64_t>(int64_int64[i].y);
3476 }
3477 catch(...)
3478 {
3479 fSuccess = false;
3480 }
3481
3482 if( fSuccess != int64_int64[i].fExpected )
3483 {
3484 cerr << "Error in case int64_int64 throw (2): ";
3485 cerr << HEX(16) << int64_int64[i].x << ", ";
3486 cerr << HEX(16) << int64_int64[i].y << ", ";
3487 cerr << "expected = " << int64_int64[i].fExpected << endl;
3488 }
3489 }
3490}
3491

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected