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

Function SubVerifyInt64Uint32

Test/SubVerify.cpp:5710–5766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5708};
5709
5710void SubVerifyInt64Uint32()
5711{
5712 size_t i;
5713
5714 for( i = 0; i < COUNTOF(int64_uint32); ++i )
5715 {
5716 std::int64_t ret;
5717 if( SafeSubtract(int64_uint32[i].x, int64_uint32[i].y, ret) != int64_uint32[i].fExpected )
5718 {
5719 cerr << "Error in case int64_uint32: ";
5720 cerr << hex << setw(16) << setfill('0') << int64_uint32[i].x << ", ";
5721 cerr << hex << setw(8) << setfill('0') << int64_uint32[i].y << ", ";
5722 cerr << "expected = " << int64_uint32[i].fExpected << endl;
5723 }
5724
5725 // Now test throwing version
5726 bool fSuccess = true;
5727 try
5728 {
5729 SafeInt<std::int64_t> si(int64_uint32[i].x);
5730 si -= int64_uint32[i].y;
5731 }
5732 catch(...)
5733 {
5734 fSuccess = false;
5735 }
5736
5737 if( fSuccess != int64_uint32[i].fExpected )
5738 {
5739 cerr << "Error in case int64_uint32 throw (1): ";
5740 cerr << hex << setw(16) << setfill('0') << int64_uint32[i].x << ", ";
5741 cerr << hex << setw(8) << setfill('0') << int64_uint32[i].y << ", ";
5742 cerr << "expected = " << int64_uint32[i].fExpected << endl;
5743 }
5744
5745 // Also need to test the version that assigns back out
5746 // to a plain int, as it has different logic
5747 fSuccess = true;
5748 try
5749 {
5750 std::int64_t x(int64_uint32[i].x);
5751 x -= SafeInt<std::uint32_t>(int64_uint32[i].y);
5752 }
5753 catch(...)
5754 {
5755 fSuccess = false;
5756 }
5757
5758 if( fSuccess != int64_uint32[i].fExpected )
5759 {
5760 cerr << "Error in case int64_uint32 throw (2): ";
5761 cerr << hex << setw(16) << setfill('0') << int64_uint32[i].x << ", ";
5762 cerr << hex << setw(8) << setfill('0') << int64_uint32[i].y << ", ";
5763 cerr << "expected = " << int64_uint32[i].fExpected << endl;
5764 }
5765 }
5766}
5767

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected