MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / HRESULTFailureHelper

Function HRESULTFailureHelper

tests/gtest/gtest-all.cc:3154–3191  ·  view source on GitHub ↗

Helper function for IsHRESULT{SuccessFailure} predicates

Source from the content-addressed store, hash-verified

3152
3153// Helper function for IsHRESULT{SuccessFailure} predicates
3154AssertionResult HRESULTFailureHelper(const char* expr,
3155 const char* expected,
3156 long hr) { // NOLINT
3157# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
3158
3159 // Windows CE doesn't support FormatMessage.
3160 const char error_text[] = "";
3161
3162# else
3163
3164 // Looks up the human-readable system message for the HRESULT code
3165 // and since we're not passing any params to FormatMessage, we don't
3166 // want inserts expanded.
3167 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
3168 FORMAT_MESSAGE_IGNORE_INSERTS;
3169 const DWORD kBufSize = 4096;
3170 // Gets the system's human readable message string for this HRESULT.
3171 char error_text[kBufSize] = { '\0' };
3172 DWORD message_length = ::FormatMessageA(kFlags,
3173 0, // no source, we're asking system
3174 static_cast<DWORD>(hr), // the error
3175 0, // no line width restrictions
3176 error_text, // output buffer
3177 kBufSize, // buf size
3178 nullptr); // no arguments for inserts
3179 // Trims tailing white space (FormatMessage leaves a trailing CR-LF)
3180 for (; message_length && IsSpace(error_text[message_length - 1]);
3181 --message_length) {
3182 error_text[message_length - 1] = '\0';
3183 }
3184
3185# endif // GTEST_OS_WINDOWS_MOBILE
3186
3187 const std::string error_hex("0x" + String::FormatHexInt(hr));
3188 return ::testing::AssertionFailure()
3189 << "Expected: " << expr << " " << expected << ".\n"
3190 << " Actual: " << error_hex << " " << error_text << "\n";
3191}
3192
3193} // namespace
3194

Callers 2

IsHRESULTSuccessFunction · 0.85
IsHRESULTFailureFunction · 0.85

Calls 2

IsSpaceFunction · 0.85
AssertionFailureFunction · 0.85

Tested by

no test coverage detected