| 1806 | }; |
| 1807 | |
| 1808 | void AddVerifyUint64Int16() |
| 1809 | { |
| 1810 | size_t i; |
| 1811 | |
| 1812 | for( i = 0; i < COUNTOF(uint64_int16); ++i ) |
| 1813 | { |
| 1814 | std::uint64_t ret; |
| 1815 | if( SafeAdd(uint64_int16[i].x, uint64_int16[i].y, ret) != uint64_int16[i].fExpected ) |
| 1816 | { |
| 1817 | cerr << "Error in case uint64_int16: "; |
| 1818 | cerr << HEX(16) << uint64_int16[i].x << ", "; |
| 1819 | cerr << HEX(4) << uint64_int16[i].y << ", "; |
| 1820 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 1821 | } |
| 1822 | |
| 1823 | // Now test throwing version |
| 1824 | bool fSuccess = true; |
| 1825 | try |
| 1826 | { |
| 1827 | SafeInt<std::uint64_t> si(uint64_int16[i].x); |
| 1828 | si += uint64_int16[i].y; |
| 1829 | } |
| 1830 | catch(...) |
| 1831 | { |
| 1832 | fSuccess = false; |
| 1833 | } |
| 1834 | |
| 1835 | if( fSuccess != uint64_int16[i].fExpected ) |
| 1836 | { |
| 1837 | cerr << "Error in case uint64_int16 throw (1): "; |
| 1838 | cerr << HEX(16) << uint64_int16[i].x << ", "; |
| 1839 | cerr << HEX(4) << uint64_int16[i].y << ", "; |
| 1840 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 1841 | } |
| 1842 | |
| 1843 | // Also need to test the version that assigns back out |
| 1844 | // to a plain int, as it has different logic |
| 1845 | fSuccess = true; |
| 1846 | try |
| 1847 | { |
| 1848 | std::uint64_t x(uint64_int16[i].x); |
| 1849 | x += SafeInt<std::int16_t>(uint64_int16[i].y); |
| 1850 | } |
| 1851 | catch(...) |
| 1852 | { |
| 1853 | fSuccess = false; |
| 1854 | } |
| 1855 | |
| 1856 | if( fSuccess != uint64_int16[i].fExpected ) |
| 1857 | { |
| 1858 | cerr << "Error in case uint64_int16 throw (2): "; |
| 1859 | cerr << HEX(16) << uint64_int16[i].x << ", "; |
| 1860 | cerr << HEX(4) << uint64_int16[i].y << ", "; |
| 1861 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | |