| 3695 | }; |
| 3696 | |
| 3697 | void AddVerifyInt64Int32() |
| 3698 | { |
| 3699 | size_t i; |
| 3700 | |
| 3701 | for( i = 0; i < COUNTOF(int64_int32); ++i ) |
| 3702 | { |
| 3703 | __int64 ret; |
| 3704 | if( SafeAdd(int64_int32[i].x, int64_int32[i].y, ret) != int64_int32[i].fExpected ) |
| 3705 | { |
| 3706 | cerr << "Error in case int64_int32: "; |
| 3707 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3708 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3709 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3710 | } |
| 3711 | |
| 3712 | // Now test throwing version |
| 3713 | bool fSuccess = true; |
| 3714 | try |
| 3715 | { |
| 3716 | SafeInt<__int64> si(int64_int32[i].x); |
| 3717 | si += int64_int32[i].y; |
| 3718 | } |
| 3719 | catch(...) |
| 3720 | { |
| 3721 | fSuccess = false; |
| 3722 | } |
| 3723 | |
| 3724 | if( fSuccess != int64_int32[i].fExpected ) |
| 3725 | { |
| 3726 | cerr << "Error in case int64_int32 throw (1): "; |
| 3727 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3728 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3729 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3730 | } |
| 3731 | |
| 3732 | // Also need to test the version that assigns back out |
| 3733 | // to a plain int, as it has different logic |
| 3734 | fSuccess = true; |
| 3735 | try |
| 3736 | { |
| 3737 | __int64 x(int64_int32[i].x); |
| 3738 | x += SafeInt<__int32>(int64_int32[i].y); |
| 3739 | } |
| 3740 | catch(...) |
| 3741 | { |
| 3742 | fSuccess = false; |
| 3743 | } |
| 3744 | |
| 3745 | if( fSuccess != int64_int32[i].fExpected ) |
| 3746 | { |
| 3747 | cerr << "Error in case int64_int32 throw (2): "; |
| 3748 | cerr << HEX(16) << int64_int32[i].x << ", "; |
| 3749 | cerr << HEX(8) << int64_int32[i].y << ", "; |
| 3750 | cerr << "expected = " << int64_int32[i].fExpected << endl; |
| 3751 | } |
| 3752 | } |
| 3753 | } |
| 3754 | |