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

Function AddVerifyUint8Uint8

Test/AddVerify.cpp:4787–4843  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4785};
4786
4787void AddVerifyUint8Uint8()
4788{
4789 size_t i;
4790
4791 for( i = 0; i < COUNTOF(uint8_uint8); ++i )
4792 {
4793 std::uint8_t ret;
4794 if( SafeAdd(uint8_uint8[i].x, uint8_uint8[i].y, ret) != uint8_uint8[i].fExpected )
4795 {
4796 cerr << "Error in case uint8_uint8: ";
4797 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].x) << ", ";
4798 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].y) << ", ";
4799 cerr << "expected = " << uint8_uint8[i].fExpected << endl;
4800 }
4801
4802 // Now test throwing version
4803 bool fSuccess = true;
4804 try
4805 {
4806 SafeInt<std::uint8_t> si(uint8_uint8[i].x);
4807 si += uint8_uint8[i].y;
4808 }
4809 catch(...)
4810 {
4811 fSuccess = false;
4812 }
4813
4814 if( fSuccess != uint8_uint8[i].fExpected )
4815 {
4816 cerr << "Error in case uint8_uint8 throw (1): ";
4817 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].x) << ", ";
4818 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].y) << ", ";
4819 cerr << "expected = " << uint8_uint8[i].fExpected << endl;
4820 }
4821
4822 // Also need to test the version that assigns back out
4823 // to a plain int, as it has different logic
4824 fSuccess = true;
4825 try
4826 {
4827 std::uint8_t x(uint8_uint8[i].x);
4828 x += SafeInt<std::uint8_t>(uint8_uint8[i].y);
4829 }
4830 catch(...)
4831 {
4832 fSuccess = false;
4833 }
4834
4835 if( fSuccess != uint8_uint8[i].fExpected )
4836 {
4837 cerr << "Error in case uint8_uint8 throw (2): ";
4838 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].x) << ", ";
4839 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint8[i].y) << ", ";
4840 cerr << "expected = " << uint8_uint8[i].fExpected << endl;
4841 }
4842 }
4843}
4844

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected