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

Function AddVerifyUint64Uint64

Test/AddVerify.cpp:326–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324};
325
326void AddVerifyUint64Uint64()
327{
328 size_t i;
329
330 for( i = 0; i < COUNTOF(uint64_uint64); ++i )
331 {
332 std::uint64_t ret;
333 if( SafeAdd(uint64_uint64[i].x, uint64_uint64[i].y, ret) != uint64_uint64[i].fExpected )
334 {
335 cerr << "Error in case uint64_uint64: ";
336 cerr << HEX(16) << uint64_uint64[i].x << ", ";
337 cerr << HEX(16) << uint64_uint64[i].y << ", ";
338 cerr << "expected = " << uint64_uint64[i].fExpected << endl;
339 }
340
341 // Now test throwing version
342 bool fSuccess = true;
343 try
344 {
345 SafeInt<std::uint64_t> si(uint64_uint64[i].x);
346 si += uint64_uint64[i].y;
347 }
348 catch(...)
349 {
350 fSuccess = false;
351 }
352
353 if( fSuccess != uint64_uint64[i].fExpected )
354 {
355 cerr << "Error in case uint64_uint64 throw (1): ";
356 cerr << HEX(16) << uint64_uint64[i].x << ", ";
357 cerr << HEX(16) << uint64_uint64[i].y << ", ";
358 cerr << "expected = " << uint64_uint64[i].fExpected << endl;
359 }
360
361 // Also need to test the version that assigns back out
362 // to a plain int, as it has different logic
363 fSuccess = true;
364 try
365 {
366 std::uint64_t x(uint64_uint64[i].x);
367 x += SafeInt<std::uint64_t>(uint64_uint64[i].y);
368 }
369 catch(...)
370 {
371 fSuccess = false;
372 }
373
374 if( fSuccess != uint64_uint64[i].fExpected )
375 {
376 cerr << "Error in case uint64_uint64 throw (2): ";
377 cerr << HEX(16) << uint64_uint64[i].x << ", ";
378 cerr << HEX(16) << uint64_uint64[i].y << ", ";
379 cerr << "expected = " << uint64_uint64[i].fExpected << endl;
380 }
381 }
382}
383

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected