| 1360 | }; |
| 1361 | |
| 1362 | void AddVerifyUint64Int64() |
| 1363 | { |
| 1364 | size_t i; |
| 1365 | |
| 1366 | for( i = 0; i < COUNTOF(uint64_int64); ++i ) |
| 1367 | { |
| 1368 | std::uint64_t ret; |
| 1369 | if( SafeAdd(uint64_int64[i].x, uint64_int64[i].y, ret) != uint64_int64[i].fExpected ) |
| 1370 | { |
| 1371 | cerr << "Error in case uint64_int64: "; |
| 1372 | cerr << HEX(16) << uint64_int64[i].x << ", "; |
| 1373 | cerr << HEX(16) << uint64_int64[i].y << ", "; |
| 1374 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 1375 | } |
| 1376 | |
| 1377 | // Now test throwing version |
| 1378 | bool fSuccess = true; |
| 1379 | try |
| 1380 | { |
| 1381 | SafeInt<std::uint64_t> si(uint64_int64[i].x); |
| 1382 | si += uint64_int64[i].y; |
| 1383 | } |
| 1384 | catch(...) |
| 1385 | { |
| 1386 | fSuccess = false; |
| 1387 | } |
| 1388 | |
| 1389 | if( fSuccess != uint64_int64[i].fExpected ) |
| 1390 | { |
| 1391 | cerr << "Error in case uint64_int64 throw (1): "; |
| 1392 | cerr << HEX(16) << uint64_int64[i].x << ", "; |
| 1393 | cerr << HEX(16) << uint64_int64[i].y << ", "; |
| 1394 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 1395 | } |
| 1396 | |
| 1397 | // Also need to test the version that assigns back out |
| 1398 | // to a plain int, as it has different logic |
| 1399 | fSuccess = true; |
| 1400 | try |
| 1401 | { |
| 1402 | std::uint64_t x(uint64_int64[i].x); |
| 1403 | x += SafeInt<std::int64_t>(uint64_int64[i].y); |
| 1404 | } |
| 1405 | catch(...) |
| 1406 | { |
| 1407 | fSuccess = false; |
| 1408 | } |
| 1409 | |
| 1410 | if( fSuccess != uint64_int64[i].fExpected ) |
| 1411 | { |
| 1412 | cerr << "Error in case uint64_int64 throw (2): "; |
| 1413 | cerr << HEX(16) << uint64_int64[i].x << ", "; |
| 1414 | cerr << HEX(16) << uint64_int64[i].y << ", "; |
| 1415 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | |