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

Function AddVerifyUint64Uint16

Test/AddVerify.cpp:772–828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

770};
771
772void AddVerifyUint64Uint16()
773{
774 size_t i;
775
776 for( i = 0; i < COUNTOF(uint64_uint16); ++i )
777 {
778 std::uint64_t ret;
779 if( SafeAdd(uint64_uint16[i].x, uint64_uint16[i].y, ret) != uint64_uint16[i].fExpected )
780 {
781 cerr << "Error in case uint64_uint16: ";
782 cerr << HEX(16) << uint64_uint16[i].x << ", ";
783 cerr << HEX(4) << uint64_uint16[i].y << ", ";
784 cerr << "expected = " << uint64_uint16[i].fExpected << endl;
785 }
786
787 // Now test throwing version
788 bool fSuccess = true;
789 try
790 {
791 SafeInt<std::uint64_t> si(uint64_uint16[i].x);
792 si += uint64_uint16[i].y;
793 }
794 catch(...)
795 {
796 fSuccess = false;
797 }
798
799 if( fSuccess != uint64_uint16[i].fExpected )
800 {
801 cerr << "Error in case uint64_uint16 throw (1): ";
802 cerr << HEX(16) << uint64_uint16[i].x << ", ";
803 cerr << HEX(4) << uint64_uint16[i].y << ", ";
804 cerr << "expected = " << uint64_uint16[i].fExpected << endl;
805 }
806
807 // Also need to test the version that assigns back out
808 // to a plain int, as it has different logic
809 fSuccess = true;
810 try
811 {
812 std::uint64_t x(uint64_uint16[i].x);
813 x += SafeInt<std::uint16_t>(uint64_uint16[i].y);
814 }
815 catch(...)
816 {
817 fSuccess = false;
818 }
819
820 if( fSuccess != uint64_uint16[i].fExpected )
821 {
822 cerr << "Error in case uint64_uint16 throw (2): ";
823 cerr << HEX(16) << uint64_uint16[i].x << ", ";
824 cerr << HEX(4) << uint64_uint16[i].y << ", ";
825 cerr << "expected = " << uint64_uint16[i].fExpected << endl;
826 }
827 }
828}
829

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected