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

Function AddVerifyUint8Uint16

Test/AddVerify.cpp:4636–4692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4634};
4635
4636void AddVerifyUint8Uint16()
4637{
4638 size_t i;
4639
4640 for( i = 0; i < COUNTOF(uint8_uint16); ++i )
4641 {
4642 std::uint8_t ret;
4643 if( SafeAdd(uint8_uint16[i].x, uint8_uint16[i].y, ret) != uint8_uint16[i].fExpected )
4644 {
4645 cerr << "Error in case uint8_uint16: ";
4646 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint16[i].x) << ", ";
4647 cerr << HEX(4) << uint8_uint16[i].y << ", ";
4648 cerr << "expected = " << uint8_uint16[i].fExpected << endl;
4649 }
4650
4651 // Now test throwing version
4652 bool fSuccess = true;
4653 try
4654 {
4655 SafeInt<std::uint8_t> si(uint8_uint16[i].x);
4656 si += uint8_uint16[i].y;
4657 }
4658 catch(...)
4659 {
4660 fSuccess = false;
4661 }
4662
4663 if( fSuccess != uint8_uint16[i].fExpected )
4664 {
4665 cerr << "Error in case uint8_uint16 throw (1): ";
4666 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint16[i].x) << ", ";
4667 cerr << HEX(4) << uint8_uint16[i].y << ", ";
4668 cerr << "expected = " << uint8_uint16[i].fExpected << endl;
4669 }
4670
4671 // Also need to test the version that assigns back out
4672 // to a plain int, as it has different logic
4673 fSuccess = true;
4674 try
4675 {
4676 std::uint8_t x(uint8_uint16[i].x);
4677 x += SafeInt<std::uint16_t>(uint8_uint16[i].y);
4678 }
4679 catch(...)
4680 {
4681 fSuccess = false;
4682 }
4683
4684 if( fSuccess != uint8_uint16[i].fExpected )
4685 {
4686 cerr << "Error in case uint8_uint16 throw (2): ";
4687 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint16[i].x) << ", ";
4688 cerr << HEX(4) << uint8_uint16[i].y << ", ";
4689 cerr << "expected = " << uint8_uint16[i].fExpected << endl;
4690 }
4691 }
4692}
4693

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected