| 1623 | }; |
| 1624 | |
| 1625 | void AddVerifyUint64Int32() |
| 1626 | { |
| 1627 | size_t i; |
| 1628 | |
| 1629 | for( i = 0; i < COUNTOF(uint64_int32); ++i ) |
| 1630 | { |
| 1631 | unsigned __int64 ret; |
| 1632 | if( SafeAdd(uint64_int32[i].x, uint64_int32[i].y, ret) != uint64_int32[i].fExpected ) |
| 1633 | { |
| 1634 | cerr << "Error in case uint64_int32: "; |
| 1635 | cerr << HEX(16) << uint64_int32[i].x << ", "; |
| 1636 | cerr << HEX(8) << uint64_int32[i].y << ", "; |
| 1637 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 1638 | } |
| 1639 | |
| 1640 | // Now test throwing version |
| 1641 | bool fSuccess = true; |
| 1642 | try |
| 1643 | { |
| 1644 | SafeInt<unsigned __int64> si(uint64_int32[i].x); |
| 1645 | si += uint64_int32[i].y; |
| 1646 | } |
| 1647 | catch(...) |
| 1648 | { |
| 1649 | fSuccess = false; |
| 1650 | } |
| 1651 | |
| 1652 | if( fSuccess != uint64_int32[i].fExpected ) |
| 1653 | { |
| 1654 | cerr << "Error in case uint64_int32 throw (1): "; |
| 1655 | cerr << HEX(16) << uint64_int32[i].x << ", "; |
| 1656 | cerr << HEX(8) << uint64_int32[i].y << ", "; |
| 1657 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 1658 | } |
| 1659 | |
| 1660 | // Also need to test the version that assigns back out |
| 1661 | // to a plain int, as it has different logic |
| 1662 | fSuccess = true; |
| 1663 | try |
| 1664 | { |
| 1665 | unsigned __int64 x(uint64_int32[i].x); |
| 1666 | x += SafeInt<__int32>(uint64_int32[i].y); |
| 1667 | } |
| 1668 | catch(...) |
| 1669 | { |
| 1670 | fSuccess = false; |
| 1671 | } |
| 1672 | |
| 1673 | if( fSuccess != uint64_int32[i].fExpected ) |
| 1674 | { |
| 1675 | cerr << "Error in case uint64_int32 throw (2): "; |
| 1676 | cerr << HEX(16) << uint64_int32[i].x << ", "; |
| 1677 | cerr << HEX(8) << uint64_int32[i].y << ", "; |
| 1678 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |