| 4211 | }; |
| 4212 | |
| 4213 | void SubVerifyUint64Int16() |
| 4214 | { |
| 4215 | size_t i; |
| 4216 | |
| 4217 | for( i = 0; i < COUNTOF(uint64_int16); ++i ) |
| 4218 | { |
| 4219 | std::uint64_t ret; |
| 4220 | if( SafeSubtract(uint64_int16[i].x, uint64_int16[i].y, ret) != uint64_int16[i].fExpected ) |
| 4221 | { |
| 4222 | cerr << "Error in case uint64_int16: "; |
| 4223 | cerr << hex << setw(16) << setfill('0') << uint64_int16[i].x << ", "; |
| 4224 | cerr << hex << setw(4) << setfill('0') << uint64_int16[i].y << ", "; |
| 4225 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 4226 | } |
| 4227 | |
| 4228 | // Now test throwing version |
| 4229 | bool fSuccess = true; |
| 4230 | try |
| 4231 | { |
| 4232 | SafeInt<std::uint64_t> si(uint64_int16[i].x); |
| 4233 | si -= (std::int16_t)uint64_int16[i].y; |
| 4234 | } |
| 4235 | catch(...) |
| 4236 | { |
| 4237 | fSuccess = false; |
| 4238 | } |
| 4239 | |
| 4240 | if( fSuccess != uint64_int16[i].fExpected ) |
| 4241 | { |
| 4242 | cerr << "Error in case uint64_int16 throw (1): "; |
| 4243 | cerr << hex << setw(16) << setfill('0') << uint64_int16[i].x << ", "; |
| 4244 | cerr << hex << setw(4) << setfill('0') << uint64_int16[i].y << ", "; |
| 4245 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 4246 | } |
| 4247 | |
| 4248 | // Also need to test the version that assigns back out |
| 4249 | // to a plain int, as it has different logic |
| 4250 | fSuccess = true; |
| 4251 | try |
| 4252 | { |
| 4253 | std::uint64_t x(uint64_int16[i].x); |
| 4254 | x -= SafeInt<std::int16_t>(uint64_int16[i].y); |
| 4255 | } |
| 4256 | catch(...) |
| 4257 | { |
| 4258 | fSuccess = false; |
| 4259 | } |
| 4260 | |
| 4261 | if( fSuccess != uint64_int16[i].fExpected ) |
| 4262 | { |
| 4263 | cerr << "Error in case uint64_int16 throw (2): "; |
| 4264 | cerr << hex << setw(16) << setfill('0') << uint64_int16[i].x << ", "; |
| 4265 | cerr << hex << setw(4) << setfill('0') << uint64_int16[i].y << ", "; |
| 4266 | cerr << "expected = " << uint64_int16[i].fExpected << endl; |
| 4267 | } |
| 4268 | } |
| 4269 | } |
| 4270 |
no test coverage detected