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

Function DivVerifyInt64Uint32

Archive/releases/2/DivVerify.cpp:2292–2340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2290};
2291
2292void DivVerifyInt64Uint32()
2293{
2294 size_t i;
2295
2296 for( i = 0; i < sizeof(int64_uint32)/sizeof(int64_uint32[0]); ++i )
2297 {
2298 __int64 ret;
2299 if( SafeDivide(int64_uint32[i].x, int64_uint32[i].y, ret) != int64_uint32[i].fExpected )
2300 {
2301 //assert(false);
2302 printf("Error in case int64_uint32: %I64X, %I64X, expected = %s\n", int64_uint32[i].x, int64_uint32[i].y, int64_uint32[i].fExpected ? "true" : "false");
2303 }
2304
2305 // Now test throwing version
2306 bool fSuccess = true;
2307 try
2308 {
2309 SafeInt<__int64> si(int64_uint32[i].x);
2310 si /= int64_uint32[i].y;
2311 }
2312 catch(...)
2313 {
2314 fSuccess = false;
2315 }
2316
2317 if( fSuccess != int64_uint32[i].fExpected )
2318 {
2319 printf("Error in case int64_uint32 throw: %I64X, %I64X, expected = %s\n", int64_uint32[i].x, int64_uint32[i].y, int64_uint32[i].fExpected ? "true" : "false");
2320 }
2321
2322 // Also need to test the version that assigns back out
2323 // to a plain int, as it has different logic
2324 fSuccess = true;
2325 try
2326 {
2327 __int64 x(int64_uint32[i].x);
2328 x /= SafeInt<unsigned __int32>(int64_uint32[i].y);
2329 }
2330 catch(...)
2331 {
2332 fSuccess = false;
2333 }
2334
2335 if( fSuccess != int64_uint32[i].fExpected )
2336 {
2337 printf("Error in case int64_uint32 throw: %I64X, %I64X, expected = %s\n", int64_uint32[i].x, int64_uint32[i].y, int64_uint32[i].fExpected ? "true" : "false");
2338 }
2339 }
2340}
2341
2342DivTest< __int64, unsigned __int32 > int64_uint32_2[] =
2343{

Callers 1

DivVerifyFunction · 0.70

Calls 1

SafeDivideFunction · 0.50

Tested by

no test coverage detected