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

Function AddVerifyInt8Uint64

Test/AddVerify.cpp:5702–5758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5700};
5701
5702void AddVerifyInt8Uint64()
5703{
5704 size_t i;
5705
5706 for( i = 0; i < COUNTOF(int8_uint64); ++i )
5707 {
5708 std::int8_t ret;
5709 if( SafeAdd(int8_uint64[i].x, int8_uint64[i].y, ret) != int8_uint64[i].fExpected )
5710 {
5711 cerr << "Error in case int8_uint64: ";
5712 cerr << HEX(2) << (0xFF & (int)int8_uint64[i].x) << ", ";
5713 cerr << HEX(16) << int8_uint64[i].y << ", ";
5714 cerr << "expected = " << int8_uint64[i].fExpected << endl;
5715 }
5716
5717 // Now test throwing version
5718 bool fSuccess = true;
5719 try
5720 {
5721 SafeInt<std::int8_t> si(int8_uint64[i].x);
5722 si += int8_uint64[i].y;
5723 }
5724 catch(...)
5725 {
5726 fSuccess = false;
5727 }
5728
5729 if( fSuccess != int8_uint64[i].fExpected )
5730 {
5731 cerr << "Error in case int8_uint64 throw (1): ";
5732 cerr << HEX(2) << (0xFF & (int)int8_uint64[i].x) << ", ";
5733 cerr << HEX(16) << int8_uint64[i].y << ", ";
5734 cerr << "expected = " << int8_uint64[i].fExpected << endl;
5735 }
5736
5737 // Also need to test the version that assigns back out
5738 // to a plain int, as it has different logic
5739 fSuccess = true;
5740 try
5741 {
5742 std::int8_t x(int8_uint64[i].x);
5743 x += SafeInt<std::uint64_t>(int8_uint64[i].y);
5744 }
5745 catch(...)
5746 {
5747 fSuccess = false;
5748 }
5749
5750 if( fSuccess != int8_uint64[i].fExpected )
5751 {
5752 cerr << "Error in case int8_uint64 throw (2): ";
5753 cerr << HEX(2) << (0xFF & (int)int8_uint64[i].x) << ", ";
5754 cerr << HEX(16) << int8_uint64[i].y << ", ";
5755 cerr << "expected = " << int8_uint64[i].fExpected << endl;
5756 }
5757 }
5758}
5759

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected