| 3878 | }; |
| 3879 | |
| 3880 | void AddVerifyInt64Int16() |
| 3881 | { |
| 3882 | size_t i; |
| 3883 | |
| 3884 | for( i = 0; i < COUNTOF(int64_int16); ++i ) |
| 3885 | { |
| 3886 | std::int64_t ret; |
| 3887 | if( SafeAdd(int64_int16[i].x, int64_int16[i].y, ret) != int64_int16[i].fExpected ) |
| 3888 | { |
| 3889 | cerr << "Error in case int64_int16: "; |
| 3890 | cerr << HEX(16) << int64_int16[i].x << ", "; |
| 3891 | cerr << HEX(4) << int64_int16[i].y << ", "; |
| 3892 | cerr << "expected = " << int64_int16[i].fExpected << endl; |
| 3893 | } |
| 3894 | |
| 3895 | // Now test throwing version |
| 3896 | bool fSuccess = true; |
| 3897 | try |
| 3898 | { |
| 3899 | SafeInt<std::int64_t> si(int64_int16[i].x); |
| 3900 | si += int64_int16[i].y; |
| 3901 | } |
| 3902 | catch(...) |
| 3903 | { |
| 3904 | fSuccess = false; |
| 3905 | } |
| 3906 | |
| 3907 | if( fSuccess != int64_int16[i].fExpected ) |
| 3908 | { |
| 3909 | cerr << "Error in case int64_int16 throw (1): "; |
| 3910 | cerr << HEX(16) << int64_int16[i].x << ", "; |
| 3911 | cerr << HEX(4) << int64_int16[i].y << ", "; |
| 3912 | cerr << "expected = " << int64_int16[i].fExpected << endl; |
| 3913 | } |
| 3914 | |
| 3915 | // Also need to test the version that assigns back out |
| 3916 | // to a plain int, as it has different logic |
| 3917 | fSuccess = true; |
| 3918 | try |
| 3919 | { |
| 3920 | std::int64_t x(int64_int16[i].x); |
| 3921 | x += SafeInt<std::int16_t>(int64_int16[i].y); |
| 3922 | } |
| 3923 | catch(...) |
| 3924 | { |
| 3925 | fSuccess = false; |
| 3926 | } |
| 3927 | |
| 3928 | if( fSuccess != int64_int16[i].fExpected ) |
| 3929 | { |
| 3930 | cerr << "Error in case int64_int16 throw (2): "; |
| 3931 | cerr << HEX(16) << int64_int16[i].x << ", "; |
| 3932 | cerr << HEX(4) << int64_int16[i].y << ", "; |
| 3933 | cerr << "expected = " << int64_int16[i].fExpected << endl; |
| 3934 | } |
| 3935 | } |
| 3936 | } |
| 3937 | |