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

Function AddVerifyInt64Uint8

Test/AddVerify.cpp:3067–3123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3065};
3066
3067void AddVerifyInt64Uint8()
3068{
3069 size_t i;
3070
3071 for( i = 0; i < COUNTOF(int64_uint8); ++i )
3072 {
3073 std::int64_t ret;
3074 if( SafeAdd(int64_uint8[i].x, int64_uint8[i].y, ret) != int64_uint8[i].fExpected )
3075 {
3076 cerr << "Error in case int64_uint8: ";
3077 cerr << HEX(16) << int64_uint8[i].x << ", ";
3078 cerr << HEX(2) << (0xFF & (unsigned int)int64_uint8[i].y) << ", ";
3079 cerr << "expected = " << int64_uint8[i].fExpected << endl;
3080 }
3081
3082 // Now test throwing version
3083 bool fSuccess = true;
3084 try
3085 {
3086 SafeInt<std::int64_t> si(int64_uint8[i].x);
3087 si += int64_uint8[i].y;
3088 }
3089 catch(...)
3090 {
3091 fSuccess = false;
3092 }
3093
3094 if( fSuccess != int64_uint8[i].fExpected )
3095 {
3096 cerr << "Error in case int64_uint8 throw (1): ";
3097 cerr << HEX(16) << int64_uint8[i].x << ", ";
3098 cerr << HEX(2) << (0xFF & (unsigned int)int64_uint8[i].y) << ", ";
3099 cerr << "expected = " << int64_uint8[i].fExpected << endl;
3100 }
3101
3102 // Also need to test the version that assigns back out
3103 // to a plain int, as it has different logic
3104 fSuccess = true;
3105 try
3106 {
3107 std::int64_t x(int64_uint8[i].x);
3108 x += SafeInt<std::uint8_t>(int64_uint8[i].y);
3109 }
3110 catch(...)
3111 {
3112 fSuccess = false;
3113 }
3114
3115 if( fSuccess != int64_uint8[i].fExpected )
3116 {
3117 cerr << "Error in case int64_uint8 throw (2): ";
3118 cerr << HEX(16) << int64_uint8[i].x << ", ";
3119 cerr << HEX(2) << (0xFF & (unsigned int)int64_uint8[i].y) << ", ";
3120 cerr << "expected = " << int64_uint8[i].fExpected << endl;
3121 }
3122 }
3123}
3124

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected