| 6837 | }; |
| 6838 | |
| 6839 | void AddVerifyInt8Int8() |
| 6840 | { |
| 6841 | size_t i; |
| 6842 | |
| 6843 | for( i = 0; i < COUNTOF(int8_int8); ++i ) |
| 6844 | { |
| 6845 | std::int8_t ret; |
| 6846 | if( SafeAdd(int8_int8[i].x, int8_int8[i].y, ret) != int8_int8[i].fExpected ) |
| 6847 | { |
| 6848 | cerr << "Error in case int8_int8: "; |
| 6849 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6850 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6851 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6852 | } |
| 6853 | |
| 6854 | // Now test throwing version |
| 6855 | bool fSuccess = true; |
| 6856 | try |
| 6857 | { |
| 6858 | SafeInt<std::int8_t> si(int8_int8[i].x); |
| 6859 | si += int8_int8[i].y; |
| 6860 | } |
| 6861 | catch(...) |
| 6862 | { |
| 6863 | fSuccess = false; |
| 6864 | } |
| 6865 | |
| 6866 | if( fSuccess != int8_int8[i].fExpected ) |
| 6867 | { |
| 6868 | cerr << "Error in case int8_int8 throw (1): "; |
| 6869 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6870 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6871 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6872 | } |
| 6873 | |
| 6874 | // Also need to test the version that assigns back out |
| 6875 | // to a plain int, as it has different logic |
| 6876 | fSuccess = true; |
| 6877 | try |
| 6878 | { |
| 6879 | std::int8_t x(int8_int8[i].x); |
| 6880 | x += SafeInt<std::int8_t>(int8_int8[i].y); |
| 6881 | } |
| 6882 | catch(...) |
| 6883 | { |
| 6884 | fSuccess = false; |
| 6885 | } |
| 6886 | |
| 6887 | if( fSuccess != int8_int8[i].fExpected ) |
| 6888 | { |
| 6889 | cerr << "Error in case int8_int8 throw (2): "; |
| 6890 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6891 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6892 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6893 | } |
| 6894 | } |
| 6895 | } |
| 6896 | |