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

Function AddVerifyUint64Int32

Test/AddVerify.cpp:1585–1641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1583};
1584
1585void AddVerifyUint64Int32()
1586{
1587 size_t i;
1588
1589 for( i = 0; i < COUNTOF(uint64_int32); ++i )
1590 {
1591 std::uint64_t ret;
1592 if( SafeAdd(uint64_int32[i].x, uint64_int32[i].y, ret) != uint64_int32[i].fExpected )
1593 {
1594 cerr << "Error in case uint64_int32: ";
1595 cerr << HEX(16) << uint64_int32[i].x << ", ";
1596 cerr << HEX(8) << uint64_int32[i].y << ", ";
1597 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1598 }
1599
1600 // Now test throwing version
1601 bool fSuccess = true;
1602 try
1603 {
1604 SafeInt<std::uint64_t> si(uint64_int32[i].x);
1605 si += uint64_int32[i].y;
1606 }
1607 catch(...)
1608 {
1609 fSuccess = false;
1610 }
1611
1612 if( fSuccess != uint64_int32[i].fExpected )
1613 {
1614 cerr << "Error in case uint64_int32 throw (1): ";
1615 cerr << HEX(16) << uint64_int32[i].x << ", ";
1616 cerr << HEX(8) << uint64_int32[i].y << ", ";
1617 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1618 }
1619
1620 // Also need to test the version that assigns back out
1621 // to a plain int, as it has different logic
1622 fSuccess = true;
1623 try
1624 {
1625 std::uint64_t x(uint64_int32[i].x);
1626 x += SafeInt<std::int32_t>(uint64_int32[i].y);
1627 }
1628 catch(...)
1629 {
1630 fSuccess = false;
1631 }
1632
1633 if( fSuccess != uint64_int32[i].fExpected )
1634 {
1635 cerr << "Error in case uint64_int32 throw (2): ";
1636 cerr << HEX(16) << uint64_int32[i].x << ", ";
1637 cerr << HEX(8) << uint64_int32[i].y << ", ";
1638 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1639 }
1640 }
1641}
1642

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected