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

Function AddVerifyInt64Uint64

Test/AddVerify.cpp:2398–2454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2396};
2397
2398void AddVerifyInt64Uint64()
2399{
2400 size_t i;
2401
2402 for( i = 0; i < COUNTOF(int64_uint64); ++i )
2403 {
2404 std::int64_t ret;
2405 if( SafeAdd(int64_uint64[i].x, int64_uint64[i].y, ret) != int64_uint64[i].fExpected )
2406 {
2407 cerr << "Error in case int64_uint64: ";
2408 cerr << HEX(16) << int64_uint64[i].x << ", ";
2409 cerr << HEX(16) << int64_uint64[i].y << ", ";
2410 cerr << "expected = " << int64_uint64[i].fExpected << endl;
2411 }
2412
2413 // Now test throwing version
2414 bool fSuccess = true;
2415 try
2416 {
2417 SafeInt<std::int64_t> si(int64_uint64[i].x);
2418 si += int64_uint64[i].y;
2419 }
2420 catch(...)
2421 {
2422 fSuccess = false;
2423 }
2424
2425 if( fSuccess != int64_uint64[i].fExpected )
2426 {
2427 cerr << "Error in case int64_uint64 throw (1): ";
2428 cerr << HEX(16) << int64_uint64[i].x << ", ";
2429 cerr << HEX(16) << int64_uint64[i].y << ", ";
2430 cerr << "expected = " << int64_uint64[i].fExpected << endl;
2431 }
2432
2433 // Also need to test the version that assigns back out
2434 // to a plain int, as it has different logic
2435 fSuccess = true;
2436 try
2437 {
2438 std::int64_t x(int64_uint64[i].x);
2439 x += SafeInt<std::uint64_t>(int64_uint64[i].y);
2440 }
2441 catch(...)
2442 {
2443 fSuccess = false;
2444 }
2445
2446 if( fSuccess != int64_uint64[i].fExpected )
2447 {
2448 cerr << "Error in case int64_uint64 throw (2): ";
2449 cerr << HEX(16) << int64_uint64[i].x << ", ";
2450 cerr << HEX(16) << int64_uint64[i].y << ", ";
2451 cerr << "expected = " << int64_uint64[i].fExpected << endl;
2452 }
2453 }
2454}
2455

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected