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

Function AddVerifyInt64Uint32

Test/AddVerify.cpp:2621–2677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2619};
2620
2621void AddVerifyInt64Uint32()
2622{
2623 size_t i;
2624
2625 for( i = 0; i < COUNTOF(int64_uint32); ++i )
2626 {
2627 std::int64_t ret;
2628 if( SafeAdd(int64_uint32[i].x, int64_uint32[i].y, ret) != int64_uint32[i].fExpected )
2629 {
2630 cerr << "Error in case int64_uint32: ";
2631 cerr << HEX(16) << int64_uint32[i].x << ", ";
2632 cerr << HEX(8) << int64_uint32[i].y << ", ";
2633 cerr << "expected = " << int64_uint32[i].fExpected << endl;
2634 }
2635
2636 // Now test throwing version
2637 bool fSuccess = true;
2638 try
2639 {
2640 SafeInt<std::int64_t> si(int64_uint32[i].x);
2641 si += int64_uint32[i].y;
2642 }
2643 catch(...)
2644 {
2645 fSuccess = false;
2646 }
2647
2648 if( fSuccess != int64_uint32[i].fExpected )
2649 {
2650 cerr << "Error in case int64_uint32 throw (1): ";
2651 cerr << HEX(16) << int64_uint32[i].x << ", ";
2652 cerr << HEX(8) << int64_uint32[i].y << ", ";
2653 cerr << "expected = " << int64_uint32[i].fExpected << endl;
2654 }
2655
2656 // Also need to test the version that assigns back out
2657 // to a plain int, as it has different logic
2658 fSuccess = true;
2659 try
2660 {
2661 std::int64_t x(int64_uint32[i].x);
2662 x += SafeInt<std::uint32_t>(int64_uint32[i].y);
2663 }
2664 catch(...)
2665 {
2666 fSuccess = false;
2667 }
2668
2669 if( fSuccess != int64_uint32[i].fExpected )
2670 {
2671 cerr << "Error in case int64_uint32 throw (2): ";
2672 cerr << HEX(16) << int64_uint32[i].x << ", ";
2673 cerr << HEX(8) << int64_uint32[i].y << ", ";
2674 cerr << "expected = " << int64_uint32[i].fExpected << endl;
2675 }
2676 }
2677}
2678

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected