| 3988 | }; |
| 3989 | |
| 3990 | void SubVerifyUint64Int32() |
| 3991 | { |
| 3992 | size_t i; |
| 3993 | |
| 3994 | for( i = 0; i < COUNTOF(uint64_int32); ++i ) |
| 3995 | { |
| 3996 | std::uint64_t ret; |
| 3997 | if( SafeSubtract(uint64_int32[i].x, uint64_int32[i].y, ret) != uint64_int32[i].fExpected ) |
| 3998 | { |
| 3999 | cerr << "Error in case uint64_int32: "; |
| 4000 | cerr << hex << setw(16) << setfill('0') << uint64_int32[i].x << ", "; |
| 4001 | cerr << hex << setw(8) << setfill('0') << uint64_int32[i].y << ", "; |
| 4002 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 4003 | } |
| 4004 | |
| 4005 | // Now test throwing version |
| 4006 | bool fSuccess = true; |
| 4007 | try |
| 4008 | { |
| 4009 | SafeInt<std::uint64_t> si(uint64_int32[i].x); |
| 4010 | si -= (std::int32_t)uint64_int32[i].y; |
| 4011 | } |
| 4012 | catch(...) |
| 4013 | { |
| 4014 | fSuccess = false; |
| 4015 | } |
| 4016 | |
| 4017 | if( fSuccess != uint64_int32[i].fExpected ) |
| 4018 | { |
| 4019 | cerr << "Error in case uint64_int32 throw (1): "; |
| 4020 | cerr << hex << setw(16) << setfill('0') << uint64_int32[i].x << ", "; |
| 4021 | cerr << hex << setw(8) << setfill('0') << uint64_int32[i].y << ", "; |
| 4022 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 4023 | } |
| 4024 | |
| 4025 | // Also need to test the version that assigns back out |
| 4026 | // to a plain int, as it has different logic |
| 4027 | fSuccess = true; |
| 4028 | try |
| 4029 | { |
| 4030 | std::uint64_t x(uint64_int32[i].x); |
| 4031 | x -= SafeInt<std::int32_t>(uint64_int32[i].y); |
| 4032 | } |
| 4033 | catch(...) |
| 4034 | { |
| 4035 | fSuccess = false; |
| 4036 | } |
| 4037 | |
| 4038 | if( fSuccess != uint64_int32[i].fExpected ) |
| 4039 | { |
| 4040 | cerr << "Error in case uint64_int32 throw (2): "; |
| 4041 | cerr << hex << setw(16) << setfill('0') << uint64_int32[i].x << ", "; |
| 4042 | cerr << hex << setw(8) << setfill('0') << uint64_int32[i].y << ", "; |
| 4043 | cerr << "expected = " << uint64_int32[i].fExpected << endl; |
| 4044 | } |
| 4045 | } |
| 4046 | } |
| 4047 |
no test coverage detected