9#ifndef GOOGLE_TEST_LIB_H_
10#define GOOGLE_TEST_LIB_H_
12#include <gtest/gtest.h>
13#include <gmock/gmock.h>
16using ::testing::Throws;
17using ::testing::ThrowsMessage;
18using ::testing::HasSubstr;
25#define EXPECT_THROW_MESSAGE(statement, description) \
27 []() { statement; }, \
28 ThrowsMessage<std::runtime_error>(HasSubstr (description)) \
30#define ASSERT_THROW_MESSAGE(statement, description) \
32 []() { statement; }, \
33 ThrowsMessage<std::runtime_error>(HasSubstr (description)) \
49 HAS_1_TEMPLATE_PARAMS (
size_t, ArgNum),
50 AND_2_VALUE_PARAMS (Buffer, ByteSize)
52 auto ArgBuffer = std::get<ArgNum>(args);
54 std::memcpy (ArgBuffer, Buffer, ByteSize);
72 std::string (
"buffer data to ") + (negation ?
"not " :
"") +
"be the same"
74 UINT8 *Actual = (UINT8 *)arg;
75 UINT8 *Expected = (UINT8 *)Buffer;
77 for (
size_t i = 0; i < ByteSize; i++) {
78 if (Actual[i] != Expected[i]) {
79 *result_listener <<
"byte at offset " << i
80 <<
" does not match expected. [" << std::hex
81 <<
"Actual: 0x" << std::setw (2) << std::setfill (
'0')
82 << (
unsigned int)Actual[i] <<
", "
83 <<
"Expected: 0x" << std::setw (2) << std::setfill (
'0')
84 << (
unsigned int)Expected[i] <<
"]";
89 *result_listener <<
"all bytes match";
97 std::string (
"strings to ") + (negation ?
"not " :
"") +
"be the same"
99 CHAR16 *Actual = (CHAR16 *)arg;
100 CHAR16 *Expected = (CHAR16 *)String;
102 for (
size_t i = 0; Actual[i] != 0; i++) {
103 if (Actual[i] != Expected[i]) {
104 *result_listener <<
"character at offset " << i
105 <<
" does not match expected. [" << std::hex
106 <<
"Actual: 0x" << std::setw (4) << std::setfill (
'0')
109 if (std::isprint (Actual[i])) {
110 *result_listener <<
" ('" << (char)Actual[i] <<
"')";
113 *result_listener <<
", Expected: 0x" << std::setw (4) << std::setfill (
'0')
116 if (std::isprint (Expected[i])) {
117 *result_listener <<
" ('" << (char)Expected[i] <<
"')";
120 *result_listener <<
"]";
126 *result_listener <<
"strings match";