| 4101 | }; |
| 4102 | |
| 4103 | void AddVerifyInt64Int8() |
| 4104 | { |
| 4105 | size_t i; |
| 4106 | |
| 4107 | for( i = 0; i < COUNTOF(int64_int8); ++i ) |
| 4108 | { |
| 4109 | std::int64_t ret; |
| 4110 | if( SafeAdd(int64_int8[i].x, int64_int8[i].y, ret) != int64_int8[i].fExpected ) |
| 4111 | { |
| 4112 | cerr << "Error in case int64_int8: "; |
| 4113 | cerr << HEX(16) << int64_int8[i].x << ", "; |
| 4114 | cerr << HEX(2) << (0xFF & (int)int64_int8[i].y) << ", "; |
| 4115 | cerr << "expected = " << int64_int8[i].fExpected << endl; |
| 4116 | } |
| 4117 | |
| 4118 | // Now test throwing version |
| 4119 | bool fSuccess = true; |
| 4120 | try |
| 4121 | { |
| 4122 | SafeInt<std::int64_t> si(int64_int8[i].x); |
| 4123 | si += int64_int8[i].y; |
| 4124 | } |
| 4125 | catch(...) |
| 4126 | { |
| 4127 | fSuccess = false; |
| 4128 | } |
| 4129 | |
| 4130 | if( fSuccess != int64_int8[i].fExpected ) |
| 4131 | { |
| 4132 | cerr << "Error in case int64_int8 throw (1): "; |
| 4133 | cerr << HEX(16) << int64_int8[i].x << ", "; |
| 4134 | cerr << HEX(2) << (0xFF & (int)int64_int8[i].y) << ", "; |
| 4135 | cerr << "expected = " << int64_int8[i].fExpected << endl; |
| 4136 | } |
| 4137 | |
| 4138 | // Also need to test the version that assigns back out |
| 4139 | // to a plain int, as it has different logic |
| 4140 | fSuccess = true; |
| 4141 | try |
| 4142 | { |
| 4143 | std::int64_t x(int64_int8[i].x); |
| 4144 | x += SafeInt<std::int8_t>(int64_int8[i].y); |
| 4145 | } |
| 4146 | catch(...) |
| 4147 | { |
| 4148 | fSuccess = false; |
| 4149 | } |
| 4150 | |
| 4151 | if( fSuccess != int64_int8[i].fExpected ) |
| 4152 | { |
| 4153 | cerr << "Error in case int64_int8 throw (2): "; |
| 4154 | cerr << HEX(16) << int64_int8[i].x << ", "; |
| 4155 | cerr << HEX(2) << (0xFF & (int)int64_int8[i].y) << ", "; |
| 4156 | cerr << "expected = " << int64_int8[i].fExpected << endl; |
| 4157 | } |
| 4158 | } |
| 4159 | } |
| 4160 | |