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

Function AddVerifyUint64Uint32

Test/AddVerify.cpp:549–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

547};
548
549void AddVerifyUint64Uint32()
550{
551 size_t i;
552
553 for( i = 0; i < COUNTOF(uint64_uint32); ++i )
554 {
555 std::uint64_t ret;
556 if( SafeAdd(uint64_uint32[i].x, uint64_uint32[i].y, ret) != uint64_uint32[i].fExpected )
557 {
558 cerr << "Error in case uint64_uint32: ";
559 cerr << HEX(16) << uint64_uint32[i].x << ", ";
560 cerr << HEX(8) << uint64_uint32[i].y << ", ";
561 cerr << "expected = " << uint64_uint32[i].fExpected << endl;
562 }
563
564 // Now test throwing version
565 bool fSuccess = true;
566 try
567 {
568 SafeInt<std::uint64_t> si(uint64_uint32[i].x);
569 si += uint64_uint32[i].y;
570 }
571 catch(...)
572 {
573 fSuccess = false;
574 }
575
576 if( fSuccess != uint64_uint32[i].fExpected )
577 {
578 cerr << "Error in case uint64_uint32 throw (1): ";
579 cerr << HEX(16) << uint64_uint32[i].x << ", ";
580 cerr << HEX(8) << uint64_uint32[i].y << ", ";
581 cerr << "expected = " << uint64_uint32[i].fExpected << endl;
582 }
583
584 // Also need to test the version that assigns back out
585 // to a plain int, as it has different logic
586 fSuccess = true;
587 try
588 {
589 std::uint64_t x(uint64_uint32[i].x);
590 x += SafeInt<std::uint32_t>(uint64_uint32[i].y);
591 }
592 catch(...)
593 {
594 fSuccess = false;
595 }
596
597 if( fSuccess != uint64_uint32[i].fExpected )
598 {
599 cerr << "Error in case uint64_uint32 throw (2): ";
600 cerr << HEX(16) << uint64_uint32[i].x << ", ";
601 cerr << HEX(8) << uint64_uint32[i].y << ", ";
602 cerr << "expected = " << uint64_uint32[i].fExpected << endl;
603 }
604 }
605}
606

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected