Go to the documentation of this file.
33 #include "gtest/gtest.h"
34 #include "gtest/internal/custom/gtest.h"
35 #include "gtest/gtest-spi.h"
57 # define GTEST_HAS_GETTIMEOFDAY_ 1
64 # include <sys/mman.h>
65 # include <sys/time.h>
70 # define GTEST_HAS_GETTIMEOFDAY_ 1
71 # include <sys/time.h>
76 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
81 #elif GTEST_OS_WINDOWS // We are on Windows proper.
87 # include <debugapi.h>
89 # include <sys/timeb.h>
90 # include <sys/types.h>
91 # include <sys/stat.h>
93 # if GTEST_OS_WINDOWS_MINGW
95 # define GTEST_HAS_GETTIMEOFDAY_ 1
96 # include <sys/time.h>
97 # endif // GTEST_OS_WINDOWS_MINGW
102 # define GTEST_HAS_GETTIMEOFDAY_ 1
106 # include <sys/time.h>
109 #endif // GTEST_OS_LINUX
111 #if GTEST_HAS_EXCEPTIONS
112 # include <stdexcept>
115 #if GTEST_CAN_STREAM_RESULTS_
116 # include <arpa/inet.h>
118 # include <sys/socket.h>
119 # include <sys/types.h>
122 #include "src/gtest-internal-inl.h"
125 # define vsnprintf _vsnprintf
126 #endif // GTEST_OS_WINDOWS
130 #include <crt_externs.h>
135 #include "absl/debugging/failure_signal_handler.h"
136 #include "absl/debugging/stacktrace.h"
137 #include "absl/debugging/symbolize.h"
138 #include "absl/strings/str_cat.h"
139 #endif // GTEST_HAS_ABSL
186 FILE* fileout =
nullptr;
187 FilePath output_file_path(output_file);
190 if (
output_dir.CreateDirectoriesRecursively()) {
193 if (fileout ==
nullptr) {
204 const char*
const testbridge_test_only =
206 if (testbridge_test_only !=
nullptr) {
207 return testbridge_test_only;
213 also_run_disabled_tests,
215 "Run disabled tests too, in addition to the tests normally being run.");
220 "True if a failed assertion should be a debugger break-point.");
226 " should catch exceptions and treat them as test failures.");
231 "Whether to use colors in the output. Valid values: yes, no, "
232 "and auto. 'auto' means to use colors if the output is "
233 "being sent to a terminal and the TERM environment variable "
234 "is set to a terminal type that supports colors.");
239 "A colon-separated list of glob (not regex) patterns "
240 "for filtering the tests to run, optionally followed by a "
241 "'-' and a : separated list of negative patterns (tests to "
242 "exclude). A test is run if it matches one of the positive "
243 "patterns and does not match any of the negative patterns.");
246 install_failure_signal_handler,
248 "If true and supported on the current platform, " GTEST_NAME_ " should "
249 "install a signal handler that dumps debugging information when fatal "
250 "signals are raised.");
253 "List all tests without running them.");
264 "A format (defaults to \"xml\" but can be specified to be \"json\"), "
265 "optionally followed by a colon and an output file name or directory. "
266 "A directory is indicated by a trailing pathname separator. "
267 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
268 "If a directory is specified, output files will be created "
269 "within that directory, with file-names based on the test "
270 "executable's name and, if necessary, made unique by adding "
277 " should display elapsed time in text output.");
283 " prints UTF8 characters as text.");
288 "Random number seed to use when shuffling test orders. Must be in range "
289 "[1, 99999], or 0 to use a seed based on the current time.");
294 "How many times to repeat each test. Specify a negative number "
295 "for repeating forever. Useful for shaking out flaky tests.");
298 show_internal_stack_frames,
false,
299 "True if " GTEST_NAME_ " should include internal stack frames when "
300 "printing test failure stack traces.");
306 " should randomize tests' order on every run.");
311 "The maximum number of stack frames to print when an "
312 "assertion fails. The valid range is 0 through 100, inclusive.");
317 "This flag specifies the host name and the port number on which to stream "
318 "test results. Example: \"localhost:555\". The flag is effective only on "
324 "When this flag is specified, a failed assertion will throw an exception "
325 "if exceptions are enabled or exit the program with a non-zero code "
326 "otherwise. For use with an external test framework.");
328 #if GTEST_USE_OWN_FLAGFILE_FLAG_
332 "This flag specifies the flagfile to read command-line flags from.");
333 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
346 <<
"Cannot generate a number in the range [0, 0).";
348 <<
"Generation of a number in [0, " <<
range <<
") was requested, "
349 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
368 for (
size_t i = 0;
i < case_list.size();
i++) {
417 #if defined(GTEST_CUSTOM_GET_ARGVS_)
420 const auto&
custom = GTEST_CUSTOM_GET_ARGVS_();
421 return ::std::vector<std::string>(
custom.begin(),
custom.end());
422 #else // defined(GTEST_CUSTOM_GET_ARGVS_)
424 #endif // defined(GTEST_CUSTOM_GET_ARGVS_)
432 #if GTEST_OS_WINDOWS || GTEST_OS_OS2
436 #endif // GTEST_OS_WINDOWS
438 return result.RemoveDirectoryName();
446 const char*
const colon = strchr(gtest_output_flag,
':');
447 return (colon ==
nullptr)
450 static_cast<size_t>(colon - gtest_output_flag));
462 const char*
const colon = strchr(gtest_output_flag,
':');
463 if (colon ==
nullptr)
477 return output_name.
string();
509 const char *cur_pattern = filter;
516 cur_pattern = strchr(cur_pattern,
':');
519 if (cur_pattern ==
nullptr) {
532 const std::string& full_name = test_suite_name +
"." + test_name.c_str();
536 const char*
const p =
GTEST_FLAG(filter).c_str();
537 const char*
const dash = strchr(p,
'-');
540 if (dash ==
nullptr) {
546 if (positive.empty()) {
562 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
571 const DWORD kCxxExceptionCode = 0xe06d7363;
573 bool should_handle =
true;
576 should_handle =
false;
577 else if (exception_code == EXCEPTION_BREAKPOINT)
578 should_handle =
false;
579 else if (exception_code == kCxxExceptionCode)
580 should_handle =
false;
582 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
584 #endif // GTEST_HAS_SEH
593 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
603 : intercept_mode_(intercept_mode),
649 return GetTypeId<Test>();
667 "1 non-fatal failure");
670 msg <<
"Expected: " << expected <<
"\n"
671 <<
" Actual: " <<
results.size() <<
" failures";
679 if (
r.type() !=
type) {
685 if (strstr(
r.message(), substr.c_str()) ==
nullptr) {
828 static_cast<int>(
GTEST_FLAG(stack_trace_depth)),
837 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
842 const DWORD kTenthMicrosInMilliSecond = 10000;
844 SYSTEMTIME now_systime;
845 FILETIME now_filetime;
846 ULARGE_INTEGER now_int64;
847 GetSystemTime(&now_systime);
848 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
849 now_int64.LowPart = now_filetime.dwLowDateTime;
850 now_int64.HighPart = now_filetime.dwHighDateTime;
851 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
852 kJavaEpochToWinFileTimeDelta;
853 return now_int64.QuadPart;
856 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
868 gettimeofday(&
now,
nullptr);
871 #
error "Don't know how to get the current time on your system."
879 #if GTEST_OS_WINDOWS_MOBILE
884 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
885 if (!ansi)
return nullptr;
886 const int length = strlen(ansi);
887 const int unicode_length =
888 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
nullptr, 0);
889 WCHAR*
unicode =
new WCHAR[unicode_length + 1];
890 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
900 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
901 if (!utf16_str)
return nullptr;
902 const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
nullptr,
903 0,
nullptr,
nullptr);
904 char* ansi =
new char[ansi_length + 1];
905 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length,
nullptr,
907 ansi[ansi_length] = 0;
911 #endif // GTEST_OS_WINDOWS_MOBILE
919 if (lhs ==
nullptr)
return rhs ==
nullptr;
921 if (rhs ==
nullptr)
return false;
923 return strcmp(lhs, rhs) == 0;
926 #if GTEST_HAS_STD_WSTRING
932 for (
size_t i = 0;
i !=
length; ) {
933 if (wstr[i] != L
'\0') {
934 *msg << WideStringToUtf8(wstr + i, static_cast<int>(
length - i));
935 while (i !=
length && wstr[i] != L
'\0')
944 #endif // GTEST_HAS_STD_WSTRING
947 ::std::vector< ::std::string>*
dest) {
948 ::std::vector< ::std::string> parsed;
949 ::std::string::size_type
pos = 0;
951 const ::std::string::size_type colon =
str.find(delimiter,
pos);
952 if (colon == ::std::string::npos) {
953 parsed.push_back(
str.substr(
pos));
956 parsed.push_back(
str.substr(
pos, colon -
pos));
973 *
ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
985 #if GTEST_HAS_STD_WSTRING
992 #endif // GTEST_HAS_STD_WSTRING
1003 : success_(other.success_),
1004 message_(other.message_.
get() != nullptr
1006 : static_cast< ::
std::
string*>(nullptr)) {}
1040 namespace edit_distance {
1042 const std::vector<size_t>& right) {
1043 std::vector<std::vector<double> > costs(
1044 left.size() + 1, std::vector<double>(right.size() + 1));
1045 std::vector<std::vector<EditType> > best_move(
1046 left.size() + 1, std::vector<EditType>(right.size() + 1));
1049 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1050 costs[l_i][0] =
static_cast<double>(l_i);
1054 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1055 costs[0][r_i] =
static_cast<double>(r_i);
1056 best_move[0][r_i] =
kAdd;
1059 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1060 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1061 if (left[l_i] == right[r_i]) {
1063 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1064 best_move[l_i + 1][r_i + 1] =
kMatch;
1068 const double add = costs[l_i + 1][r_i];
1069 const double remove = costs[l_i][r_i + 1];
1070 const double replace = costs[l_i][r_i];
1071 if (
add < remove &&
add < replace) {
1072 costs[l_i + 1][r_i + 1] =
add + 1;
1073 best_move[l_i + 1][r_i + 1] =
kAdd;
1074 }
else if (remove <
add && remove < replace) {
1075 costs[l_i + 1][r_i + 1] = remove + 1;
1076 best_move[l_i + 1][r_i + 1] =
kRemove;
1080 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1081 best_move[l_i + 1][r_i + 1] =
kReplace;
1087 std::vector<EditType> best_path;
1088 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1090 best_path.push_back(
move);
1101 class InternalStrings {
1105 if (
it !=
ids_.end())
return it->second;
1106 size_t id =
ids_.size();
1111 typedef std::map<std::string, size_t>
IdMap;
1118 const std::vector<std::string>& left,
1119 const std::vector<std::string>& right) {
1120 std::vector<size_t> left_ids, right_ids;
1122 InternalStrings intern_table;
1123 for (
size_t i = 0;
i < left.size(); ++
i) {
1124 left_ids.push_back(intern_table.GetId(left[
i]));
1126 for (
size_t i = 0;
i < right.size(); ++
i) {
1127 right_ids.push_back(intern_table.GetId(right[
i]));
1141 Hunk(
size_t left_start,
size_t right_start)
1148 void PushLine(
char edit,
const char*
line) {
1153 hunk_.push_back(std::make_pair(
' ',
line));
1166 void PrintTo(std::ostream* os) {
1169 for (std::list<std::pair<char, const char*> >::const_iterator
it =
1172 *os <<
it->first <<
it->second <<
"\n";
1188 void PrintHeader(std::ostream* ss)
const {
1217 const std::vector<std::string>& right,
1221 size_t l_i = 0, r_i = 0, edit_i = 0;
1222 std::stringstream ss;
1223 while (edit_i < edits.size()) {
1225 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1233 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1234 for (
size_t i = prefix_context;
i > 0; --
i) {
1235 hunk.PushLine(
' ', left[l_i -
i].
c_str());
1240 size_t n_suffix = 0;
1241 for (; edit_i < edits.size(); ++edit_i) {
1244 auto it = edits.begin() +
static_cast<int>(edit_i);
1246 if (
it == edits.end() ||
1247 static_cast<size_t>(
it - edits.begin()) - edit_i >=
context) {
1255 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1258 hunk.PushLine(edit ==
kMatch ?
' ' :
'-', left[l_i].
c_str());
1261 hunk.PushLine(
'+', right[r_i].
c_str());
1265 l_i += edit !=
kAdd;
1269 if (!hunk.has_edits()) {
1286 std::vector<std::string> SplitEscapedString(
const std::string&
str) {
1287 std::vector<std::string>
lines;
1293 bool escaped =
false;
1297 if (
str[i] ==
'n') {
1302 escaped =
str[
i] ==
'\\';
1327 const char* rhs_expression,
1330 bool ignoring_case) {
1332 msg <<
"Expected equality of these values:";
1333 msg <<
"\n " << lhs_expression;
1334 if (lhs_value != lhs_expression) {
1335 msg <<
"\n Which is: " << lhs_value;
1337 msg <<
"\n " << rhs_expression;
1338 if (rhs_value != rhs_expression) {
1339 msg <<
"\n Which is: " << rhs_value;
1342 if (ignoring_case) {
1343 msg <<
"\nIgnoring case";
1346 if (!lhs_value.empty() && !rhs_value.empty()) {
1347 const std::vector<std::string> lhs_lines =
1348 SplitEscapedString(lhs_value);
1349 const std::vector<std::string> rhs_lines =
1350 SplitEscapedString(rhs_value);
1351 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1352 msg <<
"\nWith diff:\n"
1363 const char* expression_text,
1364 const char* actual_predicate_value,
1365 const char* expected_predicate_value) {
1366 const char* actual_message = assertion_result.
message();
1368 msg <<
"Value of: " << expression_text
1369 <<
"\n Actual: " << actual_predicate_value;
1370 if (actual_message[0] !=
'\0')
1371 msg <<
" (" << actual_message <<
")";
1372 msg <<
"\nExpected: " << expected_predicate_value;
1373 return msg.GetString();
1379 const char* abs_error_expr,
1387 <<
"The difference between " << expr1 <<
" and " << expr2
1388 <<
" is " <<
diff <<
", which exceeds " << abs_error_expr <<
", where\n"
1389 << expr1 <<
" evaluates to " <<
val1 <<
",\n"
1390 << expr2 <<
" evaluates to " <<
val2 <<
", and\n"
1391 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1396 template <
typename RawType>
1408 if (lhs.AlmostEquals(rhs)) {
1416 ::std::stringstream val1_ss;
1417 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1420 ::std::stringstream val2_ss;
1421 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1425 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n"
1436 return internal::FloatingPointLE<float>(expr1, expr2,
val1,
val2);
1443 return internal::FloatingPointLE<double>(expr1, expr2,
val1,
val2);
1451 const char* rhs_expression,
1468 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1469 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1470 BiggestInt val1, BiggestInt val2) {\
1471 if (val1 op val2) {\
1472 return AssertionSuccess();\
1474 return AssertionFailure() \
1475 << "Expected: (" << expr1 << ") " #op " (" << expr2\
1476 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1477 << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1497 #undef GTEST_IMPL_CMP_HELPER_
1501 const char* rhs_expression,
1517 const char* rhs_expression,
1533 const char* s2_expression,
1540 << s2_expression <<
"), actual: \""
1541 << s1 <<
"\" vs \"" << s2 <<
"\"";
1547 const char* s2_expression,
1554 <<
"Expected: (" << s1_expression <<
") != ("
1555 << s2_expression <<
") (ignoring case), actual: \""
1556 << s1 <<
"\" vs \"" << s2 <<
"\"";
1570 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1571 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1573 return strstr(haystack, needle) !=
nullptr;
1576 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1577 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1579 return wcsstr(haystack, needle) !=
nullptr;
1583 template <
typename StringType>
1584 bool IsSubstringPred(
const StringType& needle,
1586 return haystack.find(needle) != StringType::npos;
1593 template <
typename StringType>
1594 AssertionResult IsSubstringImpl(
1595 bool expected_to_be_substring,
1596 const char* needle_expr,
const char* haystack_expr,
1598 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1601 const bool is_wide_string =
sizeof(needle[0]) > 1;
1602 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1604 <<
"Value of: " << needle_expr <<
"\n"
1605 <<
" Actual: " << begin_string_quote << needle <<
"\"\n"
1606 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1607 <<
"a substring of " << haystack_expr <<
"\n"
1608 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1618 const char* needle_expr,
const char* haystack_expr,
1619 const char* needle,
const char* haystack) {
1620 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1624 const char* needle_expr,
const char* haystack_expr,
1625 const wchar_t* needle,
const wchar_t* haystack) {
1626 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1630 const char* needle_expr,
const char* haystack_expr,
1631 const char* needle,
const char* haystack) {
1632 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1636 const char* needle_expr,
const char* haystack_expr,
1637 const wchar_t* needle,
const wchar_t* haystack) {
1638 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1642 const char* needle_expr,
const char* haystack_expr,
1644 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1648 const char* needle_expr,
const char* haystack_expr,
1650 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1653 #if GTEST_HAS_STD_WSTRING
1655 const char* needle_expr,
const char* haystack_expr,
1657 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1661 const char* needle_expr,
const char* haystack_expr,
1663 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1665 #endif // GTEST_HAS_STD_WSTRING
1669 #if GTEST_OS_WINDOWS
1674 AssertionResult HRESULTFailureHelper(
const char* expr,
1675 const char* expected,
1677 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
1680 const char error_text[] =
"";
1687 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1688 FORMAT_MESSAGE_IGNORE_INSERTS;
1689 const DWORD kBufSize = 4096;
1691 char error_text[kBufSize] = {
'\0' };
1692 DWORD message_length = ::FormatMessageA(kFlags,
1694 static_cast<DWORD
>(hr),
1700 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1702 error_text[message_length - 1] =
'\0';
1705 # endif // GTEST_OS_WINDOWS_MOBILE
1709 <<
"Expected: " << expr <<
" " << expected <<
".\n"
1710 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1715 AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1716 if (SUCCEEDED(hr)) {
1719 return HRESULTFailureHelper(expr,
"succeeds", hr);
1722 AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1726 return HRESULTFailureHelper(expr,
"fails", hr);
1729 #endif // GTEST_OS_WINDOWS
1778 str[0] =
static_cast<char>(code_point);
1782 str[0] =
static_cast<char>(0xC0 | code_point);
1787 str[0] =
static_cast<char>(0xE0 | code_point);
1793 str[0] =
static_cast<char>(0xF0 | code_point);
1806 return sizeof(wchar_t) == 2 &&
1807 (
first & 0xFC00) == 0xD800 && (
second & 0xFC00) == 0xDC00;
1815 const UInt32 mask = (1 << 10) - 1;
1816 return (
sizeof(
wchar_t) == 2)
1817 ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
1838 if (num_chars == -1)
1839 num_chars =
static_cast<int>(wcslen(
str));
1841 ::std::stringstream
stream;
1842 for (
int i = 0;
i < num_chars; ++
i) {
1843 UInt32 unicode_code_point;
1845 if (
str[
i] ==
L'\0') {
1852 unicode_code_point =
static_cast<UInt32>(
str[
i]);
1863 if (wide_c_str ==
nullptr)
return "(null)";
1875 if (lhs ==
nullptr)
return rhs ==
nullptr;
1877 if (rhs ==
nullptr)
return false;
1879 return wcscmp(lhs, rhs) == 0;
1884 const char* rhs_expression,
1886 const wchar_t* rhs) {
1900 const char* s2_expression,
1902 const wchar_t* s2) {
1908 << s2_expression <<
"), actual: "
1920 if (lhs ==
nullptr)
return rhs ==
nullptr;
1921 if (rhs ==
nullptr)
return false;
1938 const wchar_t* rhs) {
1939 if (lhs ==
nullptr)
return rhs ==
nullptr;
1941 if (rhs ==
nullptr)
return false;
1943 #if GTEST_OS_WINDOWS
1944 return _wcsicmp(lhs, rhs) == 0;
1945 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
1946 return wcscasecmp(lhs, rhs) == 0;
1952 left = towlower(
static_cast<wint_t
>(*lhs++));
1953 right = towlower(
static_cast<wint_t
>(*rhs++));
1954 }
while (left && left == right);
1955 return left == right;
1956 #endif // OS selector
1963 const size_t str_len =
str.length();
1964 const size_t suffix_len =
suffix.length();
1965 return (str_len >= suffix_len) &&
1972 std::stringstream ss;
1973 ss << std::setfill(
'0') << std::setw(2) <<
value;
1979 std::stringstream ss;
1980 ss << std::hex << std::uppercase <<
value;
1991 std::stringstream ss;
1992 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
1993 <<
static_cast<unsigned int>(
value);
2001 const char*
const start =
str.c_str();
2022 if (user_msg_string.empty()) {
2026 return gtest_msg +
"\n" + user_msg_string;
2035 : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
2085 property_with_matching_key->SetValue(test_property.
value());
2104 "disabled",
"errors",
"failures",
"name",
"tests",
"time",
"timestamp"};
2108 "classname",
"name",
"status",
"time",
"type_param",
2109 "value_param",
"file",
"line"};
2114 "classname",
"name",
"status",
"time",
"type_param",
2115 "value_param",
"file",
"line",
"result",
"timestamp"};
2117 template <
int kSize>
2119 return std::vector<std::string>(
array,
array + kSize);
2124 if (xml_element ==
"testsuites") {
2126 }
else if (xml_element ==
"testsuite") {
2128 }
else if (xml_element ==
"testcase") {
2131 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2134 return std::vector<std::string>();
2140 if (xml_element ==
"testsuites") {
2142 }
else if (xml_element ==
"testsuite") {
2144 }
else if (xml_element ==
"testcase") {
2147 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2150 return std::vector<std::string>();
2155 for (
size_t i = 0;
i <
words.size(); ++
i) {
2156 if (
i > 0 &&
words.size() > 2) {
2159 if (
i ==
words.size() - 1) {
2160 word_list <<
"and ";
2162 word_list <<
"'" <<
words[
i] <<
"'";
2172 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2217 return result.fatally_failed();
2227 return result.nonfatally_failed();
2281 value_message <<
value;
2313 const char*
const first_test_name = first_test_info->
name();
2318 const char*
const this_test_name = this_test_info->
name();
2320 if (this_fixture_id != first_fixture_id) {
2326 if (first_is_TEST || this_is_TEST) {
2333 const char*
const TEST_name =
2334 first_is_TEST ? first_test_name : this_test_name;
2335 const char*
const TEST_F_name =
2336 first_is_TEST ? this_test_name : first_test_name;
2339 <<
"All tests in the same test suite must use the same test fixture\n"
2340 <<
"class, so mixing TEST_F and TEST in the same test suite is\n"
2343 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n"
2344 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n"
2345 <<
"want to change the TEST to TEST_F or move it to another test\n"
2351 <<
"All tests in the same test suite must use the same test fixture\n"
2352 <<
"class. However, in test suite "
2354 <<
"you defined test " << first_test_name <<
" and test "
2355 << this_test_name <<
"\n"
2356 <<
"using two different test fixture classes. This can happen if\n"
2357 <<
"the two classes are from different namespaces or translation\n"
2358 <<
"units and have the same name. You should probably rename one\n"
2359 <<
"of the classes to put the tests into different test suites.";
2373 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2374 const char* location) {
2376 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2377 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2382 #endif // GTEST_HAS_SEH
2386 #if GTEST_HAS_EXCEPTIONS
2390 const char* location) {
2395 message <<
"Unknown C++ exception";
2397 message <<
" thrown in " << location <<
".";
2403 const TestPartResult& test_part_result);
2405 GoogleTestFailureException::GoogleTestFailureException(
2406 const TestPartResult& failure)
2409 #endif // GTEST_HAS_EXCEPTIONS
2419 template <
class T,
typename Result>
2424 return (object->*
method)();
2425 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2426 GetExceptionCode())) {
2430 std::string* exception_message = FormatSehExceptionMessage(
2431 GetExceptionCode(), location);
2433 *exception_message);
2434 delete exception_message;
2435 return static_cast<Result>(0);
2439 return (object->*
method)();
2440 #endif // GTEST_HAS_SEH
2446 template <
class T,
typename Result>
2473 #if GTEST_HAS_EXCEPTIONS
2476 }
catch (
const AssertionException&) {
2478 }
catch (
const internal::GoogleTestFailureException&) {
2483 }
catch (
const std::exception& e) {
2486 FormatCxxExceptionMessage(e.what(), location));
2490 FormatCxxExceptionMessage(
nullptr, location));
2492 return static_cast<Result>(0);
2495 #endif // GTEST_HAS_EXCEPTIONS
2497 return (object->*
method)();
2505 if (!HasSameFixtureClass())
return;
2512 if (!HasFatalFailure() && !IsSkipped()) {
2515 this, &Test::TestBody,
"the test body");
2523 this, &Test::TearDown,
"TearDown()");
2527 bool Test::HasFatalFailure() {
2532 bool Test::HasNonfatalFailure() {
2534 HasNonfatalFailure();
2538 bool Test::IsSkipped() {
2547 const std::string& a_name,
const char* a_type_param,
2548 const char* a_value_param,
2552 : test_suite_name_(a_test_suite_name),
2554 type_param_(a_type_param ?
new std::
string(a_type_param) : nullptr),
2555 value_param_(a_value_param ?
new std::
string(a_value_param) : nullptr),
2556 location_(a_code_location),
2557 fixture_class_id_(fixture_class_id),
2559 is_disabled_(
false),
2560 matches_filter_(
false),
2588 const char* test_suite_name,
const char*
name,
const char* type_param,
2593 new TestInfo(test_suite_name,
name, type_param, value_param,
2594 code_location, fixture_class_id, factory);
2603 <<
"Attempted redefinition of test suite " << test_suite_name <<
".\n"
2604 <<
"All tests in the same test suite must use the same test fixture\n"
2605 <<
"class. However, in test suite " << test_suite_name <<
", you tried\n"
2606 <<
"to define a test using a fixture class different from the one\n"
2607 <<
"used earlier. This can happen if the two fixture classes are\n"
2608 <<
"from different namespaces and have the same name. You should\n"
2609 <<
"probably rename one of the classes to put the tests into different\n"
2614 <<
" " <<
errors.GetString();
2633 explicit TestNameIs(
const char*
name)
2637 bool operator()(
const TestInfo * test_info)
const {
2638 return test_info && test_info->name() ==
name_;
2682 "the test fixture's constructor");
2693 if (
test !=
nullptr) {
2766 type_param_(a_type_param ?
new std::
string(a_type_param) : nullptr),
2767 set_up_tc_(set_up_tc),
2768 tear_down_tc_(tear_down_tc),
2770 start_timestamp_(0),
2783 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(
index)];
2790 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(
index)];
2812 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
2814 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
2833 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
2835 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
2864 const char * singular_form,
2865 const char * plural_form) {
2867 (
count == 1 ? singular_form : plural_form);
2886 case TestPartResult::kSkip:
2899 return "Unknown result type";
2912 << test_part_result.
message()).GetString();
2925 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2929 ::OutputDebugStringA(
result.c_str());
2930 ::OutputDebugStringA(
"\n");
2935 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
2936 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
2939 static WORD GetColorAttribute(
GTestColor color) {
2943 case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
2948 static int GetBitOffset(WORD color_mask) {
2949 if (color_mask == 0)
return 0;
2952 while ((color_mask & 1) == 0) {
2959 static WORD GetNewColor(
GTestColor color, WORD old_color_attrs) {
2961 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
2962 BACKGROUND_RED | BACKGROUND_INTENSITY;
2963 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
2964 FOREGROUND_RED | FOREGROUND_INTENSITY;
2965 const WORD existing_bg = old_color_attrs & background_mask;
2968 GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
2969 static const int bg_bitOffset = GetBitOffset(background_mask);
2970 static const int fg_bitOffset = GetBitOffset(foreground_mask);
2972 if (((new_color & background_mask) >> bg_bitOffset) ==
2973 ((new_color & foreground_mask) >> fg_bitOffset)) {
2974 new_color ^= FOREGROUND_INTENSITY;
2993 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2997 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
3000 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
3003 return stdout_is_tty;
3007 const bool term_supports_color =
3019 return stdout_is_tty && term_supports_color;
3020 #endif // GTEST_OS_WINDOWS
3040 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
3041 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
3044 static const bool in_color_mode =
3046 const bool use_color = in_color_mode && (color !=
COLOR_DEFAULT);
3047 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS
3055 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3056 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3057 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3060 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3061 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3062 const WORD old_color_attrs = buffer_info.wAttributes;
3063 const WORD new_color = GetNewColor(color, old_color_attrs);
3069 SetConsoleTextAttribute(stdout_handle, new_color);
3075 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3080 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3090 const char*
const type_param = test_info.
type_param();
3091 const char*
const value_param = test_info.
value_param();
3093 if (type_param !=
nullptr || value_param !=
nullptr) {
3095 if (type_param !=
nullptr) {
3097 if (value_param !=
nullptr)
printf(
" and ");
3099 if (value_param !=
nullptr) {
3120 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3124 #endif // OnTestCaseStart
3130 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3134 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3148 const UnitTest& unit_test,
int iteration) {
3150 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3152 const char*
const filter =
GTEST_FLAG(filter).c_str();
3164 "Note: This is test shard %d of %s.\n",
3165 static_cast<int>(shard_index) + 1,
3171 "Note: Randomizing tests' orders with a seed of %d .\n",
3176 printf(
"Running %s from %s.\n",
3185 printf(
"Global test environment set-up.\n");
3189 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3194 printf(
"%s from %s", counts.c_str(), test_case.
name());
3216 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3231 case TestPartResult::kSkip:
3263 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3270 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_case.
name(),
3285 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3290 printf(
"Global test environment tear-down\n");
3297 if (failed_test_count == 0) {
3306 for (
int j = 0; j <
test_suite.total_test_count(); ++j) {
3322 if (skipped_test_count == 0) {
3331 for (
int j = 0; j <
test_suite.total_test_count(); ++j) {
3346 printf(
"%s from %s ran.",
3358 if (skipped_test_count > 0) {
3365 if (!unit_test.
Passed()) {
3375 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3380 " YOU HAVE %d DISABLED %s\n\n",
3382 num_disabled == 1 ?
"TEST" :
"TESTS");
3410 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3412 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3418 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3420 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3458 #define GTEST_REPEATER_METHOD_(Name, Type) \
3459 void TestEventRepeater::Name(const Type& parameter) { \
3460 if (forwarding_enabled_) { \
3461 for (size_t i = 0; i < listeners_.size(); i++) { \
3462 listeners_[i]->Name(parameter); \
3468 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
3469 void TestEventRepeater::Name(const Type& parameter) { \
3470 if (forwarding_enabled_) { \
3471 for (size_t i = listeners_.size(); i != 0; i--) { \
3472 listeners_[i - 1]->Name(parameter); \
3480 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3482 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3491 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3493 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3497 #undef GTEST_REPEATER_METHOD_
3498 #undef GTEST_REVERSE_REPEATER_METHOD_
3504 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3513 listeners_[
i - 1]->OnTestIterationEnd(unit_test, iteration);
3530 const std::vector<TestSuite*>& test_suites);
3536 return c == 0x9 || c == 0xA || c == 0xD;
3575 const char* test_suite_name,
3605 : output_file_(output_file) {
3615 std::stringstream
stream;
3622 const std::vector<TestSuite*>& test_suites) {
3624 std::stringstream
stream;
3644 for (
size_t i = 0;
i <
str.size(); ++
i) {
3680 return m.GetString();
3690 for (std::string::const_iterator
it =
str.begin();
it !=
str.end(); ++
it)
3716 ::std::stringstream ss;
3717 ss << (static_cast<double>(ms) * 1e-3);
3722 #if defined(_MSC_VER)
3724 #elif defined(__MINGW32__) || defined(__MINGW64__)
3727 struct tm* tm_ptr = localtime(&
seconds);
3728 if (tm_ptr ==
nullptr)
return false;
3732 return localtime_r(&
seconds,
out) !=
nullptr;
3739 struct tm time_struct;
3754 const char* segment =
data;
3757 const char*
const next_segment = strstr(segment,
"]]>");
3758 if (next_segment !=
nullptr) {
3760 segment,
static_cast<std::streamsize
>(next_segment - segment));
3761 *
stream <<
"]]>]]><![CDATA[";
3762 segment = next_segment + strlen(
"]]>");
3776 const std::vector<std::string>& allowed_names =
3780 allowed_names.end())
3789 const char* test_suite_name,
3821 ? (
result.Skipped() ?
"skipped" :
"completed")
3826 stream, kTestsuite,
"timestamp",
3831 for (
int i = 0;
i <
result.total_part_count(); ++
i) {
3841 *
stream <<
" <failure message=\""
3846 *
stream <<
"</failure>\n";
3857 *
stream <<
" </testcase>\n";
3865 *
stream <<
" <" << kTestsuite;
3873 stream, kTestsuite,
"disabled",
3879 stream, kTestsuite,
"timestamp",
3888 *
stream <<
" </" << kTestsuite <<
">\n";
3893 const UnitTest& unit_test) {
3896 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3897 *
stream <<
"<" << kTestsuites;
3904 stream, kTestsuites,
"disabled",
3910 stream, kTestsuites,
"timestamp",
3922 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3923 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0)
3926 *
stream <<
"</" << kTestsuites <<
">\n";
3930 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
3933 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3934 *
stream <<
"<" << kTestsuites;
3936 int total_tests = 0;
3938 total_tests +=
test_suite->total_test_count();
3948 *
stream <<
"</" << kTestsuites <<
">\n";
3956 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
3958 attributes <<
" " <<
property.key() <<
"="
3969 if (
result.test_property_count() <= 0) {
3973 *
stream <<
"<" << kProperties <<
">\n";
3974 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
3976 *
stream <<
"<" << kProperty;
3981 *
stream <<
"</" << kProperties <<
">\n";
3995 const std::vector<TestSuite*>& test_suites);
4018 const char* test_suite_name,
4042 : output_file_(output_file) {
4051 std::stringstream
stream;
4061 for (
size_t i = 0;
i <
str.size(); ++
i) {
4094 return m.GetString();
4102 ::std::stringstream ss;
4103 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
4110 struct tm time_struct;
4133 const std::vector<std::string>& allowed_names =
4137 allowed_names.end())
4153 const std::vector<std::string>& allowed_names =
4157 allowed_names.end())
4168 const char* test_suite_name,
4193 test_info.
should_run() ?
"RUN" :
"NOTRUN", kIndent);
4196 ? (
result.Skipped() ?
"SKIPPED" :
"COMPLETED")
4209 for (
int i = 0;
i <
result.total_part_count(); ++
i) {
4214 *
stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4220 *
stream << kIndent <<
" {\n"
4221 << kIndent <<
" \"failure\": \"" <<
message <<
"\",\n"
4222 << kIndent <<
" \"type\": \"\"\n"
4228 *
stream <<
"\n" << kIndent <<
"]";
4246 test_suite.reportable_disabled_test_count(), kIndent);
4249 stream, kTestsuite,
"timestamp",
4259 *
stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4272 *
stream <<
"\n" << kIndent <<
"]\n" <<
Indent(4) <<
"}";
4277 const UnitTest& unit_test) {
4287 unit_test.reportable_disabled_test_count(), kIndent);
4304 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4307 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
4308 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0) {
4318 *
stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4322 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
4326 int total_tests = 0;
4328 total_tests +=
test_suite->total_test_count();
4333 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4335 for (
size_t i = 0;
i < test_suites.size(); ++
i) {
4351 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
4353 attributes <<
",\n" <<
indent <<
"\"" <<
property.key() <<
"\": "
4354 <<
"\"" <<
EscapeJson(property.value()) <<
"\"";
4361 #if GTEST_CAN_STREAM_RESULTS_
4387 void StreamingListener::SocketWriter::MakeConnection() {
4389 <<
"MakeConnection() can't be called when there is already a connection.";
4392 memset(&hints, 0,
sizeof(hints));
4399 const int error_num = getaddrinfo(
4400 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4401 if (error_num != 0) {
4403 << gai_strerror(error_num);
4407 for (
addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr !=
nullptr;
4408 cur_addr = cur_addr->
ai_next) {
4410 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4411 if (sockfd_ != -1) {
4413 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4420 freeaddrinfo(servinfo);
4422 if (sockfd_ == -1) {
4424 << host_name_ <<
":" << port_num_;
4429 #endif // GTEST_CAN_STREAM_RESULTS__
4441 if (max_depth <= 0) {
4447 std::vector<void*> raw_stack(max_depth);
4449 const int raw_stack_size =
4452 void* caller_frame =
nullptr;
4455 caller_frame = caller_frame_;
4458 for (
int i = 0;
i < raw_stack_size; ++
i) {
4459 if (raw_stack[
i] == caller_frame &&
4467 const char* symbol =
"(unknown)";
4473 snprintf(
line,
sizeof(
line),
" %p: %s\n", raw_stack[
i], symbol);
4479 #else // !GTEST_HAS_ABSL
4480 static_cast<void>(max_depth);
4481 static_cast<void>(skip_count);
4483 #endif // GTEST_HAS_ABSL
4488 void* caller_frame =
nullptr;
4490 caller_frame =
nullptr;
4494 caller_frame_ = caller_frame;
4495 #endif // GTEST_HAS_ABSL
4504 premature_exit_filepath :
"") {
4511 fwrite(
"0", 1, 1, pfile);
4539 default_result_printer_(nullptr),
4540 default_xml_generator_(nullptr) {}
4578 if (listener !=
nullptr)
Append(listener);
4593 if (listener !=
nullptr)
Append(listener);
4621 #if defined(__BORLANDC__)
4627 #endif // defined(__BORLANDC__)
4652 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4665 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4726 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4730 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4761 if (
env ==
nullptr) {
4775 const char* file_name,
4783 if (
impl_->gtest_trace_stack().size() > 0) {
4786 for (
size_t i =
impl_->gtest_trace_stack().size();
i > 0; --
i) {
4793 if (os_stack_trace.c_str() !=
nullptr && !os_stack_trace.empty()) {
4799 impl_->GetTestPartResultReporterForCurrentThread()->
4800 ReportTestPartResult(
result);
4810 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4815 #elif (!defined(__native_client__)) && \
4816 ((defined(__clang__) || defined(__GNUC__)) && \
4817 (defined(__x86_64__) || defined(__i386__)))
4824 *
static_cast<volatile int*
>(
nullptr) = 1;
4825 #endif // GTEST_OS_WINDOWS
4827 #if GTEST_HAS_EXCEPTIONS
4828 throw internal::GoogleTestFailureException(
result);
4854 const bool in_death_test_child_process =
4879 in_death_test_child_process
4887 #if GTEST_OS_WINDOWS
4892 if (
impl()->catch_exceptions() || in_death_test_child_process) {
4893 # if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4895 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
4896 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
4897 # endif // !GTEST_OS_WINDOWS_MOBILE
4899 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
4903 _set_error_mode(_OUT_TO_STDERR);
4906 # if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
4913 _set_abort_behavior(
4915 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
4922 if (!IsDebuggerPresent()) {
4923 (void)_CrtSetReportMode(_CRT_ASSERT,
4924 _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
4925 (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
4928 #endif // GTEST_OS_WINDOWS
4933 "auxiliary test code (environments or event listeners)") ? 0 : 1;
4951 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
4992 impl_->gtest_trace_stack().push_back(trace);
5007 default_global_test_part_result_reporter_(this),
5008 default_per_thread_test_part_result_reporter_(this),
5010 &default_global_test_part_result_reporter_),
5011 per_thread_test_part_result_reporter_(
5012 &default_per_thread_test_part_result_reporter_),
5013 parameterized_test_registry_(),
5014 parameterized_tests_registered_(
false),
5015 last_death_test_suite_(-1),
5016 current_test_suite_(nullptr),
5017 current_test_info_(nullptr),
5018 ad_hoc_test_result_(),
5019 os_stack_trace_getter_(nullptr),
5020 post_flag_parse_init_performed_(
false),
5023 start_timestamp_(0),
5025 #
if GTEST_HAS_DEATH_TEST
5026 death_test_factory_(
new DefaultDeathTestFactory),
5029 catch_exceptions_(
false) {
5053 xml_element =
"testcase";
5056 xml_element =
"testsuite";
5059 xml_element =
"testsuites";
5062 test_result->RecordProperty(xml_element, test_property);
5065 #if GTEST_HAS_DEATH_TEST
5068 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
5069 if (internal_run_death_test_flag_.get() !=
nullptr)
5072 #endif // GTEST_HAS_DEATH_TEST
5078 if (output_format ==
"xml") {
5081 }
else if (output_format ==
"json") {
5084 }
else if (output_format !=
"") {
5086 << output_format <<
"\" ignored.";
5090 #if GTEST_CAN_STREAM_RESULTS_
5093 void UnitTestImpl::ConfigureStreamingOutput() {
5097 if (
pos != std::string::npos) {
5106 #endif // GTEST_CAN_STREAM_RESULTS_
5118 #if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5121 #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5123 #if GTEST_HAS_DEATH_TEST
5124 InitDeathTestSubprocessControlInfo();
5125 SuppressTestEventsIfInSubprocess();
5126 #endif // GTEST_HAS_DEATH_TEST
5137 #if GTEST_CAN_STREAM_RESULTS_
5139 ConfigureStreamingOutput();
5140 #endif // GTEST_CAN_STREAM_RESULTS_
5143 if (
GTEST_FLAG(install_failure_signal_handler)) {
5147 #endif // GTEST_HAS_ABSL
5187 const char* test_suite_name,
const char* type_param,
5198 auto*
const new_test_suite =
5199 new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
5217 return new_test_suite;
5253 bool in_subprocess_for_death_test =
false;
5255 #if GTEST_HAS_DEATH_TEST
5256 in_subprocess_for_death_test =
5257 (internal_run_death_test_flag_.get() !=
nullptr);
5258 # if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5259 if (in_subprocess_for_death_test) {
5260 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
5262 # endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5263 #endif // GTEST_HAS_DEATH_TEST
5266 in_subprocess_for_death_test);
5270 const bool has_tests_to_run =
FilterTests(should_shard
5285 bool failed =
false;
5294 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
5296 const bool gtest_repeat_forever = repeat < 0;
5297 for (
int i = 0; gtest_repeat_forever ||
i != repeat;
i++) {
5305 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
5317 if (has_tests_to_run) {
5330 for (
int j = 0; j <
test_result.total_part_count(); ++j) {
5333 if (test_part_result.
type() == TestPartResult::kSkip) {
5379 if (!gtest_is_initialized_before_run_all_tests) {
5382 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
5384 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
5385 " will start to enforce the valid usage. "
5386 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
5387 #if GTEST_FOR_GOOGLE_
5389 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
5390 #endif // GTEST_FOR_GOOGLE_
5402 if (test_shard_file !=
nullptr) {
5404 if (
file ==
nullptr) {
5406 "Could not write to the test shard status file \"%s\" "
5407 "specified by the %s environment variable.\n",
5423 const char* shard_index_env,
5424 bool in_subprocess_for_death_test) {
5425 if (in_subprocess_for_death_test) {
5432 if (total_shards == -1 && shard_index == -1) {
5434 }
else if (total_shards == -1 && shard_index != -1) {
5436 <<
"Invalid environment variables: you have "
5442 }
else if (total_shards != -1 && shard_index == -1) {
5444 <<
"Invalid environment variables: you have "
5450 }
else if (shard_index < 0 || shard_index >= total_shards) {
5452 <<
"Invalid environment variables: we require 0 <= "
5461 return total_shards > 1;
5469 if (str_val ==
nullptr) {
5486 return (test_id % total_shards) == shard_index;
5506 int num_runnable_tests = 0;
5507 int num_selected_tests = 0;
5512 for (
size_t j = 0; j <
test_suite->test_info_list().
size(); j++) {
5524 test_suite_name, test_name);
5527 const bool is_runnable =
5528 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
5531 const bool is_in_another_shard =
5535 const bool is_selected = is_runnable && !is_in_another_shard;
5537 num_runnable_tests += is_runnable;
5538 num_selected_tests += is_selected;
5544 return num_selected_tests;
5552 if (
str !=
nullptr) {
5553 for (
int i = 0; *
str !=
'\0'; ++
str) {
5554 if (
i >= max_length) {
5572 const int kMaxParamLength = 250;
5575 bool printed_test_suite_name =
false;
5577 for (
size_t j = 0; j <
test_suite->test_info_list().
size(); j++) {
5580 if (!printed_test_suite_name) {
5581 printed_test_suite_name =
true;
5604 if (output_format ==
"xml" || output_format ==
"json") {
5607 std::stringstream
stream;
5608 if (output_format ==
"xml") {
5612 }
else if (output_format ==
"json") {
5640 #ifdef GTEST_OS_STACK_TRACE_GETTER_
5644 #endif // GTEST_OS_STACK_TRACE_GETTER_
5707 class ClassUniqueToAlwaysTrue {};
5710 bool IsTrue(
bool condition) {
return condition; }
5713 #if GTEST_HAS_EXCEPTIONS
5717 throw ClassUniqueToAlwaysTrue();
5718 #endif // GTEST_HAS_EXCEPTIONS
5726 const size_t prefix_len = strlen(
prefix);
5727 if (strncmp(*pstr,
prefix, prefix_len) == 0) {
5728 *pstr += prefix_len;
5740 bool def_optional) {
5742 if (
str ==
nullptr ||
flag ==
nullptr)
return nullptr;
5746 const size_t flag_len = flag_str.length();
5747 if (strncmp(
str, flag_str.c_str(), flag_len) != 0)
return nullptr;
5750 const char* flag_end =
str + flag_len;
5753 if (def_optional && (flag_end[0] ==
'\0')) {
5760 if (flag_end[0] !=
'=')
return nullptr;
5763 return flag_end + 1;
5781 if (value_str ==
nullptr)
return false;
5784 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
5798 if (value_str ==
nullptr)
return false;
5810 template <
typename String>
5816 if (value_str ==
nullptr)
return false;
5855 const char* p = strchr(
str,
'@');
5863 const char ch = p[1];
5867 }
else if (
ch ==
'D') {
5869 }
else if (
ch ==
'R') {
5871 }
else if (
ch ==
'G') {
5873 }
else if (
ch ==
'Y') {
5882 "This program contains tests written using " GTEST_NAME_ ". You can use the\n"
5883 "following command line flags to control its behavior:\n"
5887 " List the names of all tests instead of running them. The name of\n"
5888 " TEST(Foo, Bar) is \"Foo.Bar\".\n"
5890 "[@G-@YNEGATIVE_PATTERNS]@D\n"
5891 " Run only the tests whose name matches one of the positive patterns but\n"
5892 " none of the negative patterns. '?' matches any single character; '*'\n"
5893 " matches any substring; ':' separates two patterns.\n"
5895 " Run all disabled tests too.\n"
5899 " Run the tests repeatedly; use a negative count to repeat forever.\n"
5901 " Randomize tests' orders on every iteration.\n"
5903 " Random number seed to use for shuffling test orders (between 1 and\n"
5904 " 99999, or 0 to use a seed based on the current time).\n"
5908 " Enable/disable colored output. The default is @Gauto@D.\n"
5910 " Don't print the elapsed time of each test.\n"
5913 " Generate a JSON or XML report in the given directory or with the given\n"
5914 " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
5915 # if GTEST_CAN_STREAM_RESULTS_
5917 " Stream test results to the given server.\n"
5918 # endif // GTEST_CAN_STREAM_RESULTS_
5920 "Assertion Behavior:\n"
5921 # if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
5923 " Set the default death test style.\n"
5924 # endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
5926 " Turn assertion failures into debugger break-points.\n"
5928 " Turn assertion failures into C++ exceptions for use by an external\n"
5929 " test framework.\n"
5931 " Do not report exceptions as test failures. Instead, allow them\n"
5932 " to crash the program or throw a pop-up (on Windows).\n"
5935 "the corresponding\n"
5936 "environment variable of a flag (all letters in upper-case). For example, to\n"
5938 "color=no@D or set\n"
5941 "For more information, please read the " GTEST_NAME_ " documentation at\n"
5943 "(not one in your own code or tests), please report it to\n"
5976 #if GTEST_USE_OWN_FLAGFILE_FLAG_
5985 std::vector<std::string>
lines;
5987 for (
size_t i = 0;
i <
lines.size(); ++
i) {
5994 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
5999 template <
typename CharType>
6001 for (
int i = 1;
i < *argc;
i++) {
6003 const char*
const arg = arg_string.c_str();
6009 bool remove_flag =
false;
6012 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6016 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6017 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
6018 arg_string ==
"-?" || arg_string ==
"/?" ||
6030 for (
int j =
i; j != *argc; j++) {
6031 argv[j] = argv[j + 1];
6060 #ifndef GTEST_OS_IOS
6061 if (*_NSGetArgv() == argv) {
6062 *_NSGetArgc() = *argc;
6075 template <
typename CharType>
6080 if (*argc <= 0)
return;
6083 for (
int i = 0;
i != *argc;
i++) {
6089 #endif // GTEST_HAS_ABSL
6107 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6108 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6109 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6111 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6117 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6118 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6119 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6121 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6129 const auto arg0 =
"dummy";
6130 char* argv0 =
const_cast<char*
>(arg0);
6131 char** argv = &argv0;
6133 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6134 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
6135 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6137 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6141 #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
6142 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
6145 #if GTEST_OS_WINDOWS_MOBILE
6147 #elif GTEST_OS_WINDOWS
6149 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0')
6151 else if (temp_dir[strlen(temp_dir) - 1] ==
'\\')
6155 #elif GTEST_OS_LINUX_ANDROID
6159 #endif // GTEST_OS_WINDOWS_MOBILE
TestEventListeners & listeners()
void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_)
static bool ParseStringFlag(const char *str, const char *flag, String *value)
int failed_test_count() const
static std::string ShowWideCString(const wchar_t *wide_c_str)
TestPartResultReporterInterface * global_test_part_result_repoter_
TestPartResultReporterInterface * old_reporter_
std::chrono::duration< std::int_fast64_t > seconds
#define GTEST_FLAG_PREFIX_DASH_
static void PrintXmlTestsList(std::ostream *stream, const std::vector< TestSuite * > &test_suites)
const std::string & string() const
int failed_test_suite_count() const
virtual string CurrentStackTrace(int max_depth, int skip_count)=0
TestResult * current_test_result()
AssertionResult operator!() const
void SplitString(const ::std::string &str, char delimiter, ::std::vector< ::std::string > *dest)
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
AssertionResult AssertionFailure()
const char kStreamResultToFlag[]
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
int total_test_count() const
bool parameterized_tests_registered_
void PostFlagParsingInit()
virtual void UponLeavingGTest()
void PushTrace(const char *file, int line, std::string message)
void ClearNonAdHocTestResult()
const std::string output_file_
void AddTestPartResult(const TestPartResult &test_part_result)
UInt32 ChopLowBits(UInt32 *bits, int n)
ABSL_ATTRIBUTE_NOINLINE ABSL_ATTRIBUTE_NO_TAIL_CALL int GetStackTrace(void **result, int max_depth, int skip_count)
GTEST_API_ std::string TempDir()
void OnTestSuiteStart(const TestSuite ¶meter) override
static const char *const kReservedTestSuiteAttributes[]
GTEST_API_ bool IsTrue(bool condition)
absl::string_view get(const Cont &c)
void set_current_test_suite(TestSuite *a_current_test_suite)
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
void StrAppend(std::string *dest, const AlphaNum &a)
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
int total_test_suite_count() const
UnitTestImpl *const unit_test_
bool IsAbsolutePath() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
TypeWithSize< 4 >::Int Int32
static void ** find(grpc_chttp2_stream_map *map, uint32_t key)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
return memset(p, 0, total)
TestEventListeners * listeners()
const grpc_generator::File * file
virtual void ReportTestPartResult(const TestPartResult &result)
const char kListTestsFlag[]
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
static bool TestDisabled(const TestInfo *test_info)
@ HONOR_SHARDING_PROTOCOL
virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test)=0
int test_to_run_count() const
GTEST_API_ AssertionResult CmpHelperSTREQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
static bool ParseBoolFlag(const char *str, const char *flag, bool *value)
int reportable_test_count() const
TestResult ad_hoc_test_result_
static std::string EscapeXmlAttribute(const std::string &str)
const std::string premature_exit_filepath_
static bool ShouldRunTestSuite(const TestSuite *test_suite)
static bool ParseGoogleTestFlag(const char *const arg)
void ShuffleTests(internal::Random *random)
virtual void OnTestCaseEnd(const TestCase &)
const std::string output_file_
internal::TestFactoryBase *const factory_
int total_test_suite_count() const
static std::string Indent(size_t width)
internal::UnitTestImpl * impl()
static const char kTypeParamLabel[]
const char * summary() const
const char * StringFromGTestEnv(const char *flag, const char *default_val)
int test_case_to_run_count() const
int total_part_count() const
void(*)() TearDownTestSuiteFunc
bool IsUtf16SurrogatePair(wchar_t first, wchar_t second)
void RecordProperty(const std::string &xml_element, const TestProperty &test_property)
UInt32 Generate(UInt32 range)
static bool TestSuitePassed(const TestSuite *test_suite)
double sum(const T &container, F functor)
static const char * TestPartResultTypeToString(TestPartResult::Type type)
SingleFailureChecker(const TestPartResultArray *results, TestPartResult::Type type, const string &substr)
int reportable_disabled_test_count() const
static AssertionResult HasOneFailure(const char *, const char *, const char *, const TestPartResultArray &results, TestPartResult::Type type, const std::string &substr)
const char kDeathTestUseFork[]
void set_start_timestamp(TimeInMillis start)
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line)
static void SetUpEnvironment(Environment *env)
virtual void OnTestSuiteEnd(const TestSuite &)
Result HandleSehExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
#define GTEST_HAS_GETTIMEOFDAY_
UnitTestImpl * GetUnitTestImpl()
DefaultPerThreadTestPartResultReporter(UnitTestImpl *unit_test)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
const typedef void * TypeId
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
internal::scoped_ptr< ::std::string > message_
int disabled_test_count() const
AssertionResult CmpHelperEQ(const char *lhs_expression, const char *rhs_expression, const T1 &lhs, const T2 &rhs)
static std::string FormatTestSuiteCount(int test_suite_count)
#define GTEST_FLAG_PREFIX_UPPER_
int successful_test_count() const
void set_forwarding_enabled(bool enable)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GRPC_CUSTOM_MESSAGE Message
int GetNextRandomSeed(int seed)
static bool MatchesFilter(const std::string &name, const char *filter)
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
virtual void OnTestEnd(const TestInfo &test_info)=0
TestSuite(const char *name, const char *a_type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc)
const char kAlsoRunDisabledTestsFlag[]
TimeInMillis elapsed_time() const
FilePath RemoveFileName() const
std::vector< TestPartResult > test_part_results_
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
void ListTestsMatchingFilter(const std::vector< TestSuite * > &test_suites)
RefCountedPtr< grpc_tls_certificate_provider > instance
static std::string EscapeJson(const std::string &str)
void OnTestStart(const TestInfo &test_info) override
void Append(TestEventListener *listener)
void ConfigureXmlOutput()
static bool HasGoogleTestFlagPrefix(const char *str)
GTEST_API_ void ReportInvalidTestSuiteType(const char *test_suite_name, CodeLocation code_location)
std::vector< std::string > words
static void PrintXmlTestSuite(::std::ostream *stream, const TestSuite &test_suite)
AssertHelper(TestPartResult::Type type, const char *file, int line, const char *message)
static std::string FormatHexInt(int value)
int successful_test_suite_count() const
const char * name() const
TestEventListener * Release(TestEventListener *listener)
for_each_detail::ForEach< Reader, Action > ForEach(Reader reader, Action action)
For each item acquired by calling Reader::Next, run the promise Action.
int successful_test_suite_count() const
static const char * GetAnsiColorCode(GTestColor color)
void SetDefaultResultPrinter(TestEventListener *listener)
bool is_in_another_shard_
int failed_test_suite_count() const
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
OsStackTraceGetterInterface * os_stack_trace_getter_
static bool CStringEquals(const char *lhs, const char *rhs)
#define GTEST_FLAG_SAVER_
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
static bool HasFatalFailure()
const char * type_param() const
TypeWithSize< 4 >::UInt UInt32
E GetElementOr(const std::vector< E > &v, int i, E default_value)
int FilterTests(ReactionToSharding shard_tests)
static const char kTestTotalShards[]
GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter)
const typedef MCPhysReg * iterator
bool is_in_another_shard() const
static bool TestPartNonfatallyFailed(const TestPartResult &result)
static std::string FormatCountableNoun(int count, const char *singular_form, const char *plural_form)
const InterceptMode intercept_mode_
static void ClearTestResult(TestInfo *test_info)
int skipped_test_count() const
virtual void ReportTestPartResult(const TestPartResult &result)=0
static std::vector< std::string > GetReservedAttributesForElement(const std::string &xml_element)
#define T(upbtypeconst, upbtype, ctype, default_value)
static bool HasSameFixtureClass()
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
const internal::TypeId fixture_class_id_
std::atomic< uint64_t > failures
virtual ~ScopedFakeTestPartResultReporter()
const char * type_param() const
internal::TestEventRepeater * repeater_
internal::ParameterizedTestCaseRegistry parameterized_test_registry_
static bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
const TestPartResult & GetTestPartResult(int i) const
void ColoredPrintf(GTestColor color, const char *fmt,...)
const UInt32 kMaxCodePoint3
virtual void OnTestPartResult(const TestPartResult &test_part_result)=0
int disabled_test_count() const
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
GTEST_API_ std::string ReadEntireFile(FILE *file)
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
void Append(TestEventListener *listener)
void PushGTestTrace(const internal::TraceInfo &trace) GTEST_LOCK_EXCLUDED_(mutex_)
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
bool ShouldUseColor(bool stdout_is_tty)
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
void set_elapsed_time(TimeInMillis elapsed)
#define GTEST_FLAG_PREFIX_
#define GTEST_LOG_(severity)
std::vector< TraceInfo > & gtest_trace_stack()
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
static bool IsNormalizableWhitespace(char c)
TestSuite * GetMutableTestSuite(int i)
std::string StreamableToString(const T &streamable)
const char * file() const
static bool ValidateTestProperty(const std::string &xml_element, const TestProperty &test_property)
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_
@ IGNORE_SHARDING_PROTOCOL
void ClearTestPartResults()
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
static std::string FormatTimeInMillisAsDuration(TimeInMillis ms)
void OnTestProgramStart(const UnitTest &unit_test) override
static const char * GetDefaultFilter()
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
int reportable_test_count() const
void OnTestCaseEnd(const TestCase ¶meter) override
void OnTestCaseEnd(const TestCase &test_case) override
const TestPartResultArray *const results_
GTEST_API_ std::vector< std::string > GetArgvs()
TestPartResultReporterInterface * GetTestPartResultReporterForCurrentThread()
static std::string FormatHexUInt32(UInt32 value)
void OnTestProgramStart(const UnitTest &) override
virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test)=0
std::vector< Environment * > & environments()
static bool TestPassed(const TestInfo *test_info)
TimeInMillis start_timestamp_
static std::string GetAbsolutePathToOutputFile()
AssertionResult FloatingPointLE(const char *expr1, const char *expr2, RawType val1, RawType val2)
std::list< std::pair< char, const char * > > hunk_adds_
int skipped_test_count() const
static const char kDeathTestSuiteFilter[]
const TypeId kTestTypeIdInGoogleTest
int Run() GTEST_MUST_USE_RESULT_
const TestSuite * current_test_suite() const
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
TestInstance::Result Result
def c_str(s, encoding='ascii')
internal::Random * random()
UnitTestImpl *const unit_test_
static const char kTestShardStatusFile[]
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
bool post_flag_parse_init_performed_
static bool PatternMatchesString(const char *pattern, const char *str)
void OnEnvironmentsTearDownEnd(const UnitTest &) override
std::shared_ptr< ExternalConnectionAcceptorImpl > impl_
int total_test_count() const
void OnTestEnd(const TestInfo &test_info) override
bool HasNonfatalFailure() const
const TestPartResult::Type type
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
static std::string GetOutputFormat()
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile)
void AddTestInfo(TestInfo *test_info)
static void OutputXmlTestInfo(::std::ostream *stream, const char *test_suite_name, const TestInfo &test_info)
std::string CodePointToUtf8(UInt32 code_point)
static const UInt32 kMaxRange
const typedef int * result_type
std::list< std::pair< char, const char * > > hunk_removes_
static void PrintJsonTestSuite(::std::ostream *stream, const TestSuite &test_suite)
XmlUnitTestResultPrinter(const char *output_file)
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
TestSuite * current_test_suite_
static const char * ParseFlagValue(const char *str, const char *flag, bool def_optional)
static void PrintFailedTests(const UnitTest &unit_test)
int test_to_run_count() const
static void PrintSkippedTests(const UnitTest &unit_test)
TestResult ad_hoc_test_result_
TimeInMillis elapsed_time_
void InstallFailureSignalHandler(const FailureSignalHandlerOptions &options)
FILE * FOpen(const char *path, const char *mode)
static const char kValueParamLabel[]
int test_to_run_count() const
OPENSSL_EXPORT ASN1_BIT_STRING * bits
void LoadFlagsFromFile(const std::string &path)
static std::string EscapeXmlText(const char *str)
TestPartResultReporterInterface * GetGlobalTestPartResultReporter()
void SetDefaultXmlGenerator(TestEventListener *listener)
AssertionResult(const AssertionResult &other)
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
static bool TestSkipped(const TestInfo *test_info)
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
bool EventForwardingEnabled() const
static bool GTestIsInitialized()
ScopedFakeTestPartResultReporter(TestPartResultArray *result)
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
GTEST_API_ bool AlwaysTrue()
void set_catch_exceptions(bool value)
const char kBreakOnFailureFlag[]
const TestCase * GetTestCase(int i) const
const std::unique_ptr< ::std::stringstream > ss_
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
GTEST_DISABLE_MSC_WARNINGS_POP_() inline const char *SkipComma(const char *str)
static void RecordProperty(const std::string &key, const std::string &value)
internal::TimeInMillis TimeInMillis
int test_suite_to_run_count() const
static uint8_t negative(signed char b)
static int SumOverTestSuiteList(const std::vector< TestSuite * > &case_list, int(TestSuite::*method)() const)
int successful_test_count() const
#define GTEST_LOCK_EXCLUDED_(locks)
static bool TestReportable(const TestInfo *test_info)
static FilePath MakeFileName(const FilePath &directory, const FilePath &base_name, int number, const char *extension)
AssertionResult AssertionSuccess()
static const char kDefaultOutputFile[]
void OnEnvironmentsTearDownEnd(const UnitTest &unit_test) override
Int32 Int32FromEnvOrDie(const char *var, Int32 default_val)
int StrCaseCmp(const char *s1, const char *s2)
static const LogLevel WARNING
int failed_test_count() const
const char kRandomSeedFlag[]
static std::string RemoveInvalidXmlCharacters(const std::string &str)
void OnTestCaseStart(const TestCase &test_case) override
AssertionResult AssertionFailure(const Message &message)
static void OutputXmlTestProperties(std::ostream *stream, const TestResult &result)
TestPartResultArray *const result_
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const UInt32 kMaxCodePoint1
int reportable_test_count() const
std::atomic< Unwinder > custom
std::vector< TestSuite * > test_suites_
~ScopedPrematureExitFile()
int failed_test_count() const
~TestEventRepeater() override
const char * message() const
std::vector< TestInfo * > test_info_list_
int skipped_test_count() const
int total_test_count() const
static bool ValidateTestPropertyName(const std::string &property_name, const std::vector< std::string > &reserved_names)
const TestResult * result() const
FilePath GetCurrentExecutableName()
UnitTestImpl(UnitTest *parent)
void OnEnvironmentsSetUpEnd(const UnitTest &unit_test) override
std::string GetString() const
void operator=(const Message &message) const
static const char *const kReservedTestSuitesAttributes[]
GTEST_API_ TypeId GetTestTypeId()
TimeInMillis GetTimeInMillis()
static void PrintJsonUnitTest(::std::ostream *stream, const UnitTest &unit_test)
void SuppressEventForwarding()
static void PrintOnOneLine(const char *str, int max_length)
int test_property_count() const
GTEST_DEFINE_int32_(random_seed, internal::Int32FromGTestEnv("random_seed", 0), "Random number seed to use when shuffling test orders. Must be in range " "[1, 99999], or 0 to use a seed based on the current time.")
void SetGlobalTestPartResultReporter(TestPartResultReporterInterface *reporter)
TestInfo * current_test_info()
TestInfo * GetMutableTestInfo(int i)
static const char *const kReservedTestCaseAttributes[]
static std::string FormatEpochTimeInMillisAsRFC3339(TimeInMillis ms)
static const LogLevel ERROR
DefaultGlobalTestPartResultReporter(UnitTestImpl *unit_test)
void Append(const TestPartResult &result)
static void PrintColorEncoded(const char *str)
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater)
static bool IsValidXmlCharacter(char c)
int total_test_case_count() const
UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
void RegisterParameterizedTests()
void ParseGoogleTestFlagsOnly(int *argc, char **argv)
static bool TestPartFatallyFailed(const TestPartResult &result)
std::vector< TestProperty > test_properties_
static void add(const char *beg, const char *end, char ***ss, size_t *ns)
TestInfo * current_test_info_
void OnTestSuiteEnd(const TestSuite ¶meter) override
static bool TestReportableDisabled(const TestInfo *test_info)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) class GTEST_API_ TypedTestSuitePState
std::map< int, GraphId > IdMap
const char * GetEnv(const char *name)
const char kDeathTestStyleFlag[]
bool Symbolize(const void *pc, char *out, int out_size)
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)=0
void AddTestPartResult(TestPartResult::Type result_type, const char *file_name, int line_number, const std::string &message, const std::string &os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_)
#define GTEST_INIT_GOOGLE_TEST_NAME_
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_suite_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase *factory)
internal::ParameterizedTestCaseRegistry & parameterized_test_registry()
const TestProperty & GetTestProperty(int i) const
GTEST_IMPL_CMP_HELPER_(NE, !=)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
GTEST_API_ const char * fmt
PrettyUnitTestResultPrinter()
struct addrinfo * ai_next
TestEventListener * default_xml_generator_
void OnTestPartResult(const TestPartResult &result) override
const int kMaxStackTraceDepth
int test_to_run_count() const
static void OutputJsonKey(std::ostream *stream, const std::string &element_name, const std::string &name, const std::string &value, const std::string &indent, bool comma=true)
const char * value_param() const
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
TimeInMillis elapsed_time() const
GTEST_API_ AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
const UInt32 kMaxCodePoint4
const char * original_working_dir() const
virtual void OnTestCaseStart(const TestCase &)
#define GTEST_CHECK_(condition)
const char * c_str() const
TestSuite * GetMutableSuiteCase(int i)
static void OutputXmlAttribute(std::ostream *stream, const std::string &element_name, const std::string &name, const std::string &value)
const TestSuite * GetTestSuite(int i) const
static HashTable * reserved_names
void OnTestProgramEnd(const UnitTest &unit_test) override
unsigned char suffix[65536]
const char * name() const
void Shuffle(internal::Random *random, std::vector< E > *v)
virtual Test * CreateTest()=0
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
static bool FilterMatchesTest(const std::string &test_case_name, const std::string &test_name)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
const UInt32 kMaxCodePoint2
static std::string TestPropertiesAsJson(const TestResult &result, const std::string &indent)
std::vector< int > test_suite_indices_
const std::string message
static const char kDefaultOutputFormat[]
std::vector< TestEventListener * > listeners_
static ::std::vector< std::string > g_argvs
TestSuiteNameIs(const std::string &name)
bool BoolFromGTestEnv(const char *flag, bool default_val)
static void PrintTestName(const char *test_suite, const char *test)
static void PrintTestPartResult(const TestPartResult &test_part_result)
TimeInMillis start_timestamp() const
virtual void UponLeavingGTest()=0
Environment * AddEnvironment(Environment *env)
static const char kTestShardIndex[]
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
static bool TestPartSkipped(const TestPartResult &result)
static std::string FormatWordList(const std::vector< std::string > &words)
static std::string EscapeXml(const std::string &str, bool is_attribute)
const char kStackTraceDepthFlag[]
GTEST_DEFINE_string_(death_test_style, internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle), "Indicates how to run a death test in a forked child process: " "\"threadsafe\" (child process re-executes the test binary " "from the beginning, running only the specific death test) or " "\"fast\" (child process runs the death test immediately " "after forking).")
static const char kColorEncodedHelpMessage[]
internal::ThreadLocal< TestPartResultReporterInterface * > per_thread_test_part_result_reporter_
void ListTestsMatchingFilter()
JsonUnitTestResultPrinter(const char *output_file)
void ForEach(const Container &c, Functor functor)
Message & operator<<(const T &val)
const TestPartResult::Type type_
void(*)() SetUpTestSuiteFunc
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
TestEventListener * repeater()
TestEventListener * default_result_printer_
static FILE * OpenFileForWriting(const std::string &output_file)
int test_suite_to_run_count() const
const char kShuffleFlag[]
ABSL_NAMESPACE_BEGIN void InitializeSymbolizer(const char *argv0)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static const char *const kReservedOutputTestCaseAttributes[]
void set_current_test_info(TestInfo *a_current_test_info)
static const char kUniversalFilter[]
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
void RunTearDownTestSuite()
static const char prefix[]
void InitGoogleTestImpl(int *argc, CharType **argv)
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)=0
TestEventListener * Release(TestEventListener *listener)
static std::string FormatTestCount(int test_count)
std::vector< Environment * > environments_
internal::UnitTestImpl * impl_
TimeInMillis elapsed_time() const
GTEST_DEFINE_bool_(death_test_use_fork, internal::BoolFromGTestEnv("death_test_use_fork", false), "Instructs to use fork()/_exit() instead of clone() in death tests. " "Ignored and always uses fork() on POSIX systems where clone() is not " "implemented. Useful when running under valgrind or similar tools if " "those do not support clone(). Valgrind 3.3.1 will just fail if " "it sees an unsupported combination of clone() flags. " "It is not recommended to use this flag w/o valgrind though it will " "work in 99% of the cases. Once valgrind is fixed, this flag will " "most likely be removed.")
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static bool WideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
const TestResult & ad_hoc_test_result() const
void OnTestEnd(const TestInfo &test_info) override
const char kInternalRunDeathTestFlag[]
static UnitTest * GetInstance()
int successful_test_count() const
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
static void PrintFullTestCommentIfPresent(const TestInfo &test_info)
static bool PortableLocaltime(time_t seconds, struct tm *out)
TimeInMillis elapsed_time_
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
#define GTEST_REPEATER_METHOD_(Name, Type)
virtual void ReportTestPartResult(const TestPartResult &result)
TypeWithSize< 8 >::Int TimeInMillis
int reportable_disabled_test_count() const
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
const char kCatchExceptionsFlag[]
const char kThrowOnFailureFlag[]
TimeInMillis elapsed_time() const
bool HasFatalFailure() const
static std::string FormatIntWidth2(int value)
static std::string TestPropertiesAsXmlAttributes(const TestResult &result)
const GTEST_API_ char kStackTraceMarker[]
bool operator()(const TestSuite *test_suite) const
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
void swap(AssertionResult &other)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
static bool TestSuiteFailed(const TestSuite *test_suite)
void OnTestProgramEnd(const UnitTest &) override
static void OutputJsonTestInfo(::std::ostream *stream, const char *test_suite_name, const TestInfo &test_info)
void OnEnvironmentsSetUpEnd(const UnitTest &) override
internal::ParameterizedTestSuiteRegistry & parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_)
int failed_test_case_count() const
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
void OnTestStart(const TestInfo &test_info) override
const char kFlagfileFlag[]
static void StreamWideCharsToMessage(const wchar_t *wstr, size_t length, Message *msg)
int CountIf(const Container &c, Predicate predicate)
void OnTestCaseStart(const TestSuite ¶meter) override
virtual void OnTestStart(const TestInfo &test_info)=0
std::vector< int > test_indices_
grpc::ClientContext context
TimeInMillis elapsed_time_
internal::Mutex test_properites_mutex_
internal::Mutex global_test_part_result_reporter_mutex_
int disabled_test_count() const
void RecordProperty(const std::string &key, const std::string &value)
internal::WrappedMutex mutex_
const char * value() const
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
bool forwarding_enabled() const
static bool ShouldRunTest(const TestInfo *test_info)
internal::FilePath original_working_dir_
void RecordProperty(const TestProperty &test_property)
static const char *const kElidedFramesMarker
std::list< std::pair< char, const char * > > hunk_
AssertHelperData *const data_
static void OutputXmlCDataSection(::std::ostream *stream, const char *data)
const T & move(const T &t)
const TestResult * ad_hoc_test_result() const
RefCountedPtr< GrpcLb > parent_
static std::vector< std::string > GetReservedOutputAttributesForElement(const std::string &xml_element)
std::string OutputFlagAlsoCheckEnvVar()
static std::string PrintTestPartResultToString(const TestPartResult &test_part_result)
int reportable_disabled_test_count() const
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
TimeInMillis start_timestamp_
const char * file_name() const
TimeInMillis start_timestamp() const
static void PrintJsonTestList(::std::ostream *stream, const std::vector< TestSuite * > &test_suites)
const char * test_suite_name() const
const TestCase * GetTestCase(int i) const
string FilePath(const FileDescriptor *file)
OsStackTraceGetterInterface * os_stack_trace_getter()
static const char kDisableTestFilter[]
const char kPrintTimeFlag[]
bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
void PrintTo(const T &value, ::std::ostream *os)
void WriteToShardStatusFileIfNeeded()
void OnTestPartResult(const TestPartResult &result) override
static void TearDownEnvironment(Environment *env)
virtual void ReportTestPartResult(const TestPartResult &result)
const char * message() const
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
int last_death_test_suite_
static void PrintXmlUnitTest(::std::ostream *stream, const UnitTest &unit_test)
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
if(p->owned &&p->wrapped !=NULL)
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
const TestInfo * GetTestInfo(int i) const
virtual string CurrentStackTrace(int max_depth, int skip_count)
void SetTestPartResultReporterForCurrentThread(TestPartResultReporterInterface *reporter)
GTEST_DISALLOW_COPY_AND_ASSIGN_(JsonUnitTestResultPrinter)
static bool TestFailed(const TestInfo *test_info)
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
int GetRandomSeedFromFlag(Int32 random_seed_flag)
int successful_test_case_count() const
ScopedPrematureExitFile(const char *premature_exit_filepath)
#define GTEST_PROJECT_URL_
static std::string FormatByte(unsigned char value)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
virtual void OnTestSuiteStart(const TestSuite &)
const TestSuite * GetTestSuite(int i) const
::std::string PrintToString(const T &value)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:50