| 6535 | }; |
| 6536 | |
| 6537 | void AddVerifyInt8Int32() |
| 6538 | { |
| 6539 | size_t i; |
| 6540 | |
| 6541 | for( i = 0; i < COUNTOF(int8_int32); ++i ) |
| 6542 | { |
| 6543 | std::int8_t ret; |
| 6544 | if( SafeAdd(int8_int32[i].x, int8_int32[i].y, ret) != int8_int32[i].fExpected ) |
| 6545 | { |
| 6546 | cerr << "Error in case int8_int32: "; |
| 6547 | cerr << HEX(2) << (0xFF & (int)int8_int32[i].x) << ", "; |
| 6548 | cerr << HEX(8) << int8_int32[i].y << ", "; |
| 6549 | cerr << "expected = " << int8_int32[i].fExpected << endl; |
| 6550 | } |
| 6551 | |
| 6552 | // Now test throwing version |
| 6553 | bool fSuccess = true; |
| 6554 | try |
| 6555 | { |
| 6556 | SafeInt<std::int8_t> si(int8_int32[i].x); |
| 6557 | si += int8_int32[i].y; |
| 6558 | } |
| 6559 | catch(...) |
| 6560 | { |
| 6561 | fSuccess = false; |
| 6562 | } |
| 6563 | |
| 6564 | if( fSuccess != int8_int32[i].fExpected ) |
| 6565 | { |
| 6566 | cerr << "Error in case int8_int32 throw (1): "; |
| 6567 | cerr << HEX(2) << (0xFF & (int)int8_int32[i].x) << ", "; |
| 6568 | cerr << HEX(8) << int8_int32[i].y << ", "; |
| 6569 | cerr << "expected = " << int8_int32[i].fExpected << endl; |
| 6570 | } |
| 6571 | |
| 6572 | // Also need to test the version that assigns back out |
| 6573 | // to a plain int, as it has different logic |
| 6574 | fSuccess = true; |
| 6575 | try |
| 6576 | { |
| 6577 | std::int8_t x(int8_int32[i].x); |
| 6578 | x += SafeInt<std::int32_t>(int8_int32[i].y); |
| 6579 | } |
| 6580 | catch(...) |
| 6581 | { |
| 6582 | fSuccess = false; |
| 6583 | } |
| 6584 | |
| 6585 | if( fSuccess != int8_int32[i].fExpected ) |
| 6586 | { |
| 6587 | cerr << "Error in case int8_int32 throw (2): "; |
| 6588 | cerr << HEX(2) << (0xFF & (int)int8_int32[i].x) << ", "; |
| 6589 | cerr << HEX(8) << int8_int32[i].y << ", "; |
| 6590 | cerr << "expected = " << int8_int32[i].fExpected << endl; |
| 6591 | } |
| 6592 | } |
| 6593 | } |
| 6594 | |