| 3765 | }; |
| 3766 | |
| 3767 | void SubVerifyUint64Int64() |
| 3768 | { |
| 3769 | size_t i; |
| 3770 | |
| 3771 | for( i = 0; i < COUNTOF(uint64_int64); ++i ) |
| 3772 | { |
| 3773 | std::uint64_t ret; |
| 3774 | if( SafeSubtract(uint64_int64[i].x, uint64_int64[i].y, ret) != uint64_int64[i].fExpected ) |
| 3775 | { |
| 3776 | cerr << "Error in case uint64_int64: "; |
| 3777 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].x << ", "; |
| 3778 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].y << ", "; |
| 3779 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 3780 | } |
| 3781 | |
| 3782 | // Now test throwing version |
| 3783 | bool fSuccess = true; |
| 3784 | try |
| 3785 | { |
| 3786 | SafeInt<std::uint64_t> si(uint64_int64[i].x); |
| 3787 | si -= (std::int64_t)uint64_int64[i].y; |
| 3788 | } |
| 3789 | catch(...) |
| 3790 | { |
| 3791 | fSuccess = false; |
| 3792 | } |
| 3793 | |
| 3794 | if( fSuccess != uint64_int64[i].fExpected ) |
| 3795 | { |
| 3796 | cerr << "Error in case uint64_int64 throw (1): "; |
| 3797 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].x << ", "; |
| 3798 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].y << ", "; |
| 3799 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 3800 | } |
| 3801 | |
| 3802 | // Also need to test the version that assigns back out |
| 3803 | // to a plain int, as it has different logic |
| 3804 | fSuccess = true; |
| 3805 | try |
| 3806 | { |
| 3807 | std::uint64_t x(uint64_int64[i].x); |
| 3808 | x -= SafeInt<std::int64_t>(uint64_int64[i].y); |
| 3809 | } |
| 3810 | catch(...) |
| 3811 | { |
| 3812 | fSuccess = false; |
| 3813 | } |
| 3814 | |
| 3815 | if( fSuccess != uint64_int64[i].fExpected ) |
| 3816 | { |
| 3817 | cerr << "Error in case uint64_int64 throw (2): "; |
| 3818 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].x << ", "; |
| 3819 | cerr << hex << setw(16) << setfill('0') << uint64_int64[i].y << ", "; |
| 3820 | cerr << "expected = " << uint64_int64[i].fExpected << endl; |
| 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 |
no test coverage detected