Helper function for IsHRESULT{SuccessFailure} predicates
| 2638 | |
| 2639 | // Helper function for IsHRESULT{SuccessFailure} predicates |
| 2640 | AssertionResult HRESULTFailureHelper(const char* expr, |
| 2641 | const char* expected, |
| 2642 | long hr) { // NOLINT |
| 2643 | # if GTEST_OS_WINDOWS_MOBILE |
| 2644 | |
| 2645 | // Windows CE doesn't support FormatMessage. |
| 2646 | const char error_text[] = ""; |
| 2647 | |
| 2648 | # else |
| 2649 | |
| 2650 | // Looks up the human-readable system message for the HRESULT code |
| 2651 | // and since we're not passing any params to FormatMessage, we don't |
| 2652 | // want inserts expanded. |
| 2653 | const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM | |
| 2654 | FORMAT_MESSAGE_IGNORE_INSERTS; |
| 2655 | const DWORD kBufSize = 4096; // String::Format can't exceed this length. |
| 2656 | // Gets the system's human readable message string for this HRESULT. |
| 2657 | char error_text[kBufSize] = { '\0' }; |
| 2658 | DWORD message_length = ::FormatMessageA(kFlags, |
| 2659 | 0, // no source, we're asking system |
| 2660 | hr, // the error |
| 2661 | 0, // no line width restrictions |
| 2662 | error_text, // output buffer |
| 2663 | kBufSize, // buf size |
| 2664 | NULL); // no arguments for inserts |
| 2665 | // Trims tailing white space (FormatMessage leaves a trailing cr-lf) |
| 2666 | for (; message_length && IsSpace(error_text[message_length - 1]); |
| 2667 | --message_length) { |
| 2668 | error_text[message_length - 1] = '\0'; |
| 2669 | } |
| 2670 | |
| 2671 | # endif // GTEST_OS_WINDOWS_MOBILE |
| 2672 | |
| 2673 | const String error_hex(String::Format("0x%08X ", hr)); |
| 2674 | return ::testing::AssertionFailure() |
| 2675 | << "Expected: " << expr << " " << expected << ".\n" |
| 2676 | << " Actual: " << error_hex << error_text << "\n"; |
| 2677 | } |
| 2678 | |
| 2679 | } // namespace |
| 2680 |
no test coverage detected