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

Function SubVerifyInt64Int16

Test/SubVerify.cpp:2493–2549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2491};
2492
2493void SubVerifyInt64Int16()
2494{
2495 size_t i;
2496
2497 for( i = 0; i < COUNTOF(int64_int16); ++i )
2498 {
2499 std::int64_t ret;
2500 if( SafeSubtract(int64_int16[i].x, int64_int16[i].y, ret) != int64_int16[i].fExpected )
2501 {
2502 cerr << "Error in case int64_int16: ";
2503 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2504 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2505 cerr << "expected = " << int64_int16[i].fExpected << endl;
2506 }
2507
2508 // Now test throwing version
2509 bool fSuccess = true;
2510 try
2511 {
2512 SafeInt<std::int64_t> si(int64_int16[i].x);
2513 si -= int64_int16[i].y;
2514 }
2515 catch(...)
2516 {
2517 fSuccess = false;
2518 }
2519
2520 if( fSuccess != int64_int16[i].fExpected )
2521 {
2522 cerr << "Error in case int64_int16 throw (1): ";
2523 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2524 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2525 cerr << "expected = " << int64_int16[i].fExpected << endl;
2526 }
2527
2528 // Also need to test the version that assigns back out
2529 // to a plain int, as it has different logic
2530 fSuccess = true;
2531 try
2532 {
2533 std::int64_t x(int64_int16[i].x);
2534 x -= SafeInt<std::int64_t>(int64_int16[i].y);
2535 }
2536 catch(...)
2537 {
2538 fSuccess = false;
2539 }
2540
2541 if( fSuccess != int64_int16[i].fExpected )
2542 {
2543 cerr << "Error in case int64_int16 throw (2): ";
2544 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2545 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2546 cerr << "expected = " << int64_int16[i].fExpected << endl;
2547 }
2548 }
2549}
2550

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected