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

Function SubVerifyInt8Int64

Test/SubVerify.cpp:2947–3003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2945};
2946
2947void SubVerifyInt8Int64()
2948{
2949 size_t i;
2950
2951 for( i = 0; i < COUNTOF(int8_int64); ++i )
2952 {
2953 std::int8_t ret;
2954 if( SafeSubtract(int8_int64[i].x, int8_int64[i].y, ret) != int8_int64[i].fExpected )
2955 {
2956 cerr << "Error in case int8_int64: ";
2957 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
2958 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
2959 cerr << "expected = " << int8_int64[i].fExpected << endl;
2960 }
2961
2962 // Now test throwing version
2963 bool fSuccess = true;
2964 try
2965 {
2966 SafeInt<std::int8_t> si(int8_int64[i].x);
2967 si -= int8_int64[i].y;
2968 }
2969 catch(...)
2970 {
2971 fSuccess = false;
2972 }
2973
2974 if( fSuccess != int8_int64[i].fExpected )
2975 {
2976 cerr << "Error in case int8_int64 throw (1): ";
2977 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
2978 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
2979 cerr << "expected = " << int8_int64[i].fExpected << endl;
2980 }
2981
2982 // Also need to test the version that assigns back out
2983 // to a plain int, as it has different logic
2984 fSuccess = true;
2985 try
2986 {
2987 std::int8_t x(int8_int64[i].x);
2988 x -= SafeInt<std::int64_t>(int8_int64[i].y);
2989 }
2990 catch(...)
2991 {
2992 fSuccess = false;
2993 }
2994
2995 if( fSuccess != int8_int64[i].fExpected )
2996 {
2997 cerr << "Error in case int8_int64 throw (2): ";
2998 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
2999 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
3000 cerr << "expected = " << int8_int64[i].fExpected << endl;
3001 }
3002 }
3003}
3004

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected