| 3655 | }; |
| 3656 | |
| 3657 | void AddVerifyInt64Int32() |
| 3658 | { |
| 3659 | size_t i; |
| 3660 | |
| 3661 | for( i = 0; i < COUNTOF(int64_int32); ++i ) |
| 3662 | { |
| 3663 | std::int64_t ret; |
| 3664 | if( SafeAdd(int64_int32[i].x, int64_int32[i].y, ret) != int64_int32[i].fExpected ) |
| 3665 | { |
| 3666 | cerr << "Error in case int64_int32: "; |
| 3667 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3668 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3669 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3670 | } |
| 3671 | |
| 3672 | // Now test throwing version |
| 3673 | bool fSuccess = true; |
| 3674 | try |
| 3675 | { |
| 3676 | SafeInt<std::int64_t> si(int64_int32[i].x); |
| 3677 | si += int64_int32[i].y; |
| 3678 | } |
| 3679 | catch(...) |
| 3680 | { |
| 3681 | fSuccess = false; |
| 3682 | } |
| 3683 | |
| 3684 | if( fSuccess != int64_int32[i].fExpected ) |
| 3685 | { |
| 3686 | cerr << "Error in case int64_int32 throw (1): "; |
| 3687 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3688 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3689 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3690 | } |
| 3691 | |
| 3692 | // Also need to test the version that assigns back out |
| 3693 | // to a plain int, as it has different logic |
| 3694 | fSuccess = true; |
| 3695 | try |
| 3696 | { |
| 3697 | std::int64_t x(int64_int32[i].x); |
| 3698 | x += SafeInt<std::int32_t>(int64_int32[i].y); |
| 3699 | } |
| 3700 | catch(...) |
| 3701 | { |
| 3702 | fSuccess = false; |
| 3703 | } |
| 3704 | |
| 3705 | if( fSuccess != int64_int32[i].fExpected ) |
| 3706 | { |
| 3707 | cerr << "Error in case int64_int32 throw (2): "; |
| 3708 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3709 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3710 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3711 | } |
| 3712 | } |
| 3713 | } |
| 3714 | |