| 6877 | }; |
| 6878 | |
| 6879 | void AddVerifyInt8Int8() |
| 6880 | { |
| 6881 | size_t i; |
| 6882 | |
| 6883 | for( i = 0; i < COUNTOF(int8_int8); ++i ) |
| 6884 | { |
| 6885 | __int8 ret; |
| 6886 | if( SafeAdd(int8_int8[i].x, int8_int8[i].y, ret) != int8_int8[i].fExpected ) |
| 6887 | { |
| 6888 | cerr << "Error in case int8_int8: "; |
| 6889 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6890 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6891 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6892 | } |
| 6893 | |
| 6894 | // Now test throwing version |
| 6895 | bool fSuccess = true; |
| 6896 | try |
| 6897 | { |
| 6898 | SafeInt<__int8> si(int8_int8[i].x); |
| 6899 | si += int8_int8[i].y; |
| 6900 | } |
| 6901 | catch(...) |
| 6902 | { |
| 6903 | fSuccess = false; |
| 6904 | } |
| 6905 | |
| 6906 | if( fSuccess != int8_int8[i].fExpected ) |
| 6907 | { |
| 6908 | cerr << "Error in case int8_int8 throw (1): "; |
| 6909 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6910 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6911 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6912 | } |
| 6913 | |
| 6914 | // Also need to test the version that assigns back out |
| 6915 | // to a plain int, as it has different logic |
| 6916 | fSuccess = true; |
| 6917 | try |
| 6918 | { |
| 6919 | __int8 x(int8_int8[i].x); |
| 6920 | x += SafeInt<__int8>(int8_int8[i].y); |
| 6921 | } |
| 6922 | catch(...) |
| 6923 | { |
| 6924 | fSuccess = false; |
| 6925 | } |
| 6926 | |
| 6927 | if( fSuccess != int8_int8[i].fExpected ) |
| 6928 | { |
| 6929 | cerr << "Error in case int8_int8 throw (2): "; |
| 6930 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].x) << ", "; |
| 6931 | cerr << HEX(2) << (0xFF & (int)int8_int8[i].y) << ", "; |
| 6932 | cerr << "expected = " << int8_int8[i].fExpected << endl; |
| 6933 | } |
| 6934 | } |
| 6935 | } |
| 6936 | |