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

Function AddVerifyUint8Uint32

Test/AddVerify.cpp:4485–4541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4483};
4484
4485void AddVerifyUint8Uint32()
4486{
4487 size_t i;
4488
4489 for( i = 0; i < COUNTOF(uint8_uint32); ++i )
4490 {
4491 std::uint8_t ret;
4492 if( SafeAdd(uint8_uint32[i].x, uint8_uint32[i].y, ret) != uint8_uint32[i].fExpected )
4493 {
4494 cerr << "Error in case uint8_uint32: ";
4495 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint32[i].x) << ", ";
4496 cerr << HEX(8) << uint8_uint32[i].y << ", ";
4497 cerr << "expected = " << uint8_uint32[i].fExpected << endl;
4498 }
4499
4500 // Now test throwing version
4501 bool fSuccess = true;
4502 try
4503 {
4504 SafeInt<std::uint8_t> si(uint8_uint32[i].x);
4505 si += uint8_uint32[i].y;
4506 }
4507 catch(...)
4508 {
4509 fSuccess = false;
4510 }
4511
4512 if( fSuccess != uint8_uint32[i].fExpected )
4513 {
4514 cerr << "Error in case uint8_uint32 throw (1): ";
4515 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint32[i].x) << ", ";
4516 cerr << HEX(8) << uint8_uint32[i].y << ", ";
4517 cerr << "expected = " << uint8_uint32[i].fExpected << endl;
4518 }
4519
4520 // Also need to test the version that assigns back out
4521 // to a plain int, as it has different logic
4522 fSuccess = true;
4523 try
4524 {
4525 std::uint8_t x(uint8_uint32[i].x);
4526 x += SafeInt<std::uint32_t>(uint8_uint32[i].y);
4527 }
4528 catch(...)
4529 {
4530 fSuccess = false;
4531 }
4532
4533 if( fSuccess != uint8_uint32[i].fExpected )
4534 {
4535 cerr << "Error in case uint8_uint32 throw (2): ";
4536 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint32[i].x) << ", ";
4537 cerr << HEX(8) << uint8_uint32[i].y << ", ";
4538 cerr << "expected = " << uint8_uint32[i].fExpected << endl;
4539 }
4540 }
4541}
4542

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected