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

Function AddVerifyUint64Int8

Test/AddVerify.cpp:2031–2087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2029};
2030
2031void AddVerifyUint64Int8()
2032{
2033 size_t i;
2034
2035 for( i = 0; i < COUNTOF(uint64_int8); ++i )
2036 {
2037 std::uint64_t ret;
2038 if( SafeAdd(uint64_int8[i].x, uint64_int8[i].y, ret) != uint64_int8[i].fExpected )
2039 {
2040 cerr << "Error in case uint64_int8: ";
2041 cerr << HEX(16) << uint64_int8[i].x << ", ";
2042 cerr << HEX(2) << (0xFF & (int)uint64_int8[i].y) << ", ";
2043 cerr << "expected = " << uint64_int8[i].fExpected << endl;
2044 }
2045
2046 // Now test throwing version
2047 bool fSuccess = true;
2048 try
2049 {
2050 SafeInt<std::uint64_t> si(uint64_int8[i].x);
2051 si += uint64_int8[i].y;
2052 }
2053 catch(...)
2054 {
2055 fSuccess = false;
2056 }
2057
2058 if( fSuccess != uint64_int8[i].fExpected )
2059 {
2060 cerr << "Error in case uint64_int8 throw (1): ";
2061 cerr << HEX(16) << uint64_int8[i].x << ", ";
2062 cerr << HEX(2) << (0xFF & (int)uint64_int8[i].y) << ", ";
2063 cerr << "expected = " << uint64_int8[i].fExpected << endl;
2064 }
2065
2066 // Also need to test the version that assigns back out
2067 // to a plain int, as it has different logic
2068 fSuccess = true;
2069 try
2070 {
2071 std::uint64_t x(uint64_int8[i].x);
2072 x += SafeInt<std::int8_t>(uint64_int8[i].y);
2073 }
2074 catch(...)
2075 {
2076 fSuccess = false;
2077 }
2078
2079 if( fSuccess != uint64_int8[i].fExpected )
2080 {
2081 cerr << "Error in case uint64_int8 throw (2): ";
2082 cerr << HEX(16) << uint64_int8[i].x << ", ";
2083 cerr << HEX(2) << (0xFF & (int)uint64_int8[i].y) << ", ";
2084 cerr << "expected = " << uint64_int8[i].fExpected << endl;
2085 }
2086 }
2087}
2088

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected