| 6424 | }; |
| 6425 | |
| 6426 | void AddVerifyInt8Int64() |
| 6427 | { |
| 6428 | size_t i; |
| 6429 | |
| 6430 | for( i = 0; i < COUNTOF(int8_int64); ++i ) |
| 6431 | { |
| 6432 | __int8 ret; |
| 6433 | if( SafeAdd(int8_int64[i].x, int8_int64[i].y, ret) != int8_int64[i].fExpected ) |
| 6434 | { |
| 6435 | cerr << "Error in case int8_int64: "; |
| 6436 | cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", "; |
| 6437 | cerr << HEX(16) << int8_int64[i].y << ", "; |
| 6438 | cerr << "expected = " << int8_int64[i].fExpected << endl; |
| 6439 | } |
| 6440 | |
| 6441 | // Now test throwing version |
| 6442 | bool fSuccess = true; |
| 6443 | try |
| 6444 | { |
| 6445 | SafeInt<__int8> si(int8_int64[i].x); |
| 6446 | si += int8_int64[i].y; |
| 6447 | } |
| 6448 | catch(...) |
| 6449 | { |
| 6450 | fSuccess = false; |
| 6451 | } |
| 6452 | |
| 6453 | if( fSuccess != int8_int64[i].fExpected ) |
| 6454 | { |
| 6455 | cerr << "Error in case int8_int64 throw (1): "; |
| 6456 | cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", "; |
| 6457 | cerr << HEX(16) << int8_int64[i].y << ", "; |
| 6458 | cerr << "expected = " << int8_int64[i].fExpected << endl; |
| 6459 | } |
| 6460 | |
| 6461 | // Also need to test the version that assigns back out |
| 6462 | // to a plain int, as it has different logic |
| 6463 | fSuccess = true; |
| 6464 | try |
| 6465 | { |
| 6466 | __int8 x(int8_int64[i].x); |
| 6467 | x += SafeInt<__int64>(int8_int64[i].y); |
| 6468 | } |
| 6469 | catch(...) |
| 6470 | { |
| 6471 | fSuccess = false; |
| 6472 | } |
| 6473 | |
| 6474 | if( fSuccess != int8_int64[i].fExpected ) |
| 6475 | { |
| 6476 | cerr << "Error in case int8_int64 throw (2): "; |
| 6477 | cerr << HEX(2) << (0xFF & (int)int8_int64[i].x) << ", "; |
| 6478 | cerr << HEX(16) << int8_int64[i].y << ", "; |
| 6479 | cerr << "expected = " << int8_int64[i].fExpected << endl; |
| 6480 | } |
| 6481 | } |
| 6482 | } |
| 6483 | |