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

Function SubVerifyInt64Int8

Test/SubVerify.cpp:2716–2772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2714};
2715
2716void SubVerifyInt64Int8()
2717{
2718 size_t i;
2719
2720 for( i = 0; i < COUNTOF(int64_int8); ++i )
2721 {
2722 std::int64_t ret;
2723 if( SafeSubtract(int64_int8[i].x, int64_int8[i].y, ret) != int64_int8[i].fExpected )
2724 {
2725 cerr << "Error in case int64_int8: ";
2726 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2727 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2728 cerr << "expected = " << int64_int8[i].fExpected << endl;
2729 }
2730
2731 // Now test throwing version
2732 bool fSuccess = true;
2733 try
2734 {
2735 SafeInt<std::int64_t> si(int64_int8[i].x);
2736 si -= int64_int8[i].y;
2737 }
2738 catch(...)
2739 {
2740 fSuccess = false;
2741 }
2742
2743 if( fSuccess != int64_int8[i].fExpected )
2744 {
2745 cerr << "Error in case int64_int8 throw (1): ";
2746 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2747 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2748 cerr << "expected = " << int64_int8[i].fExpected << endl;
2749 }
2750
2751 // Also need to test the version that assigns back out
2752 // to a plain int, as it has different logic
2753 fSuccess = true;
2754 try
2755 {
2756 std::int64_t x(int64_int8[i].x);
2757 x -= SafeInt<std::int64_t>(int64_int8[i].y);
2758 }
2759 catch(...)
2760 {
2761 fSuccess = false;
2762 }
2763
2764 if( fSuccess != int64_int8[i].fExpected )
2765 {
2766 cerr << "Error in case int64_int8 throw (2): ";
2767 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2768 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2769 cerr << "expected = " << int64_int8[i].fExpected << endl;
2770 }
2771 }
2772}
2773

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected