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

Function SubVerifyInt64Int64

Test/SubVerify.cpp:2047–2103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2045};
2046
2047void SubVerifyInt64Int64()
2048{
2049 size_t i;
2050
2051 for( i = 0; i < COUNTOF(int64_int64); ++i )
2052 {
2053 std::int64_t ret;
2054 if( SafeSubtract(int64_int64[i].x, int64_int64[i].y, ret) != int64_int64[i].fExpected )
2055 {
2056 cerr << "Error in case int64_int64: ";
2057 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2058 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2059 cerr << "expected = " << int64_int64[i].fExpected << endl;
2060 }
2061
2062 // Now test throwing version
2063 bool fSuccess = true;
2064 try
2065 {
2066 SafeInt<std::int64_t> si(int64_int64[i].x);
2067 si -= int64_int64[i].y;
2068 }
2069 catch(...)
2070 {
2071 fSuccess = false;
2072 }
2073
2074 if( fSuccess != int64_int64[i].fExpected )
2075 {
2076 cerr << "Error in case int64_int64 throw (1): ";
2077 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2078 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2079 cerr << "expected = " << int64_int64[i].fExpected << endl;
2080 }
2081
2082 // Also need to test the version that assigns back out
2083 // to a plain int, as it has different logic
2084 fSuccess = true;
2085 try
2086 {
2087 std::int64_t x(int64_int64[i].x);
2088 x -= SafeInt<std::int64_t>(int64_int64[i].y);
2089 }
2090 catch(...)
2091 {
2092 fSuccess = false;
2093 }
2094
2095 if( fSuccess != int64_int64[i].fExpected )
2096 {
2097 cerr << "Error in case int64_int64 throw (2): ";
2098 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2099 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2100 cerr << "expected = " << int64_int64[i].fExpected << endl;
2101 }
2102 }
2103}
2104

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected