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

Function SubVerifyInt64Int32

Test/SubVerify.cpp:2270–2326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2268};
2269
2270void SubVerifyInt64Int32()
2271{
2272 size_t i;
2273
2274 for( i = 0; i < COUNTOF(int64_int32); ++i )
2275 {
2276 std::int64_t ret;
2277 if( SafeSubtract(int64_int32[i].x, int64_int32[i].y, ret) != int64_int32[i].fExpected )
2278 {
2279 cerr << "Error in case int64_int32: ";
2280 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2281 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2282 cerr << "expected = " << int64_int32[i].fExpected << endl;
2283 }
2284
2285 // Now test throwing version
2286 bool fSuccess = true;
2287 try
2288 {
2289 SafeInt<std::int64_t> si(int64_int32[i].x);
2290 si -= int64_int32[i].y;
2291 }
2292 catch(...)
2293 {
2294 fSuccess = false;
2295 }
2296
2297 if( fSuccess != int64_int32[i].fExpected )
2298 {
2299 cerr << "Error in case int64_int32 throw (1): ";
2300 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2301 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2302 cerr << "expected = " << int64_int32[i].fExpected << endl;
2303 }
2304
2305 // Also need to test the version that assigns back out
2306 // to a plain int, as it has different logic
2307 fSuccess = true;
2308 try
2309 {
2310 std::int64_t x(int64_int32[i].x);
2311 x -= SafeInt<std::int64_t>(int64_int32[i].y);
2312 }
2313 catch(...)
2314 {
2315 fSuccess = false;
2316 }
2317
2318 if( fSuccess != int64_int32[i].fExpected )
2319 {
2320 cerr << "Error in case int64_int32 throw (2): ";
2321 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2322 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2323 cerr << "expected = " << int64_int32[i].fExpected << endl;
2324 }
2325 }
2326}
2327

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected