33 #include "gtest/gtest.h"
53 #include <unordered_set>
57 #include "gtest/gtest-spi.h"
58 #include "gtest/internal/custom/gtest.h"
67 # include <sys/mman.h>
68 # include <sys/time.h>
73 # include <sys/time.h>
78 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
83 #elif GTEST_OS_WINDOWS // We are on Windows proper.
93 # include <sys/timeb.h>
94 # include <sys/types.h>
95 # include <sys/stat.h>
97 # if GTEST_OS_WINDOWS_MINGW
98 # include <sys/time.h>
99 # endif // GTEST_OS_WINDOWS_MINGW
105 # include <sys/time.h>
108 #endif // GTEST_OS_LINUX
110 #if GTEST_HAS_EXCEPTIONS
111 # include <stdexcept>
114 #if GTEST_CAN_STREAM_RESULTS_
115 # include <arpa/inet.h>
117 # include <sys/socket.h>
118 # include <sys/types.h>
121 #include "src/gtest-internal-inl.h"
124 # define vsnprintf _vsnprintf
125 #endif // GTEST_OS_WINDOWS
129 #include <crt_externs.h>
134 #include "absl/debugging/failure_signal_handler.h"
135 #include "absl/debugging/stacktrace.h"
136 #include "absl/debugging/symbolize.h"
137 #include "absl/strings/str_cat.h"
138 #endif // GTEST_HAS_ABSL
185 FILE* fileout =
nullptr;
186 FilePath output_file_path(output_file);
189 if (
output_dir.CreateDirectoriesRecursively()) {
192 if (fileout ==
nullptr) {
203 const char*
const testbridge_test_only =
205 if (testbridge_test_only !=
nullptr) {
206 return testbridge_test_only;
214 const char*
const testbridge_test_runner_fail_fast =
216 if (testbridge_test_runner_fail_fast !=
nullptr) {
217 return strcmp(testbridge_test_runner_fail_fast,
"1") == 0;
228 "True if and only if a test failure should stop further test execution.");
231 also_run_disabled_tests,
233 "Run disabled tests too, in addition to the tests normally being run.");
238 "True if and only if a failed assertion should be a debugger "
245 " should catch exceptions and treat them as test failures.");
249 "Whether to use colors in the output. Valid values: yes, no, "
250 "and auto. 'auto' means to use colors if the output is "
251 "being sent to a terminal and the TERM environment variable "
252 "is set to a terminal type that supports colors.");
258 "A colon-separated list of glob (not regex) patterns "
259 "for filtering the tests to run, optionally followed by a "
260 "'-' and a : separated list of negative patterns (tests to "
261 "exclude). A test is run if it matches one of the positive "
262 "patterns and does not match any of the negative patterns.");
265 install_failure_signal_handler,
268 "If true and supported on the current platform, " GTEST_NAME_
270 "install a signal handler that dumps debugging information when fatal "
271 "signals are raised.");
274 "List all tests without running them.");
285 "A format (defaults to \"xml\" but can be specified to be \"json\"), "
286 "optionally followed by a colon and an output file name or directory. "
287 "A directory is indicated by a trailing pathname separator. "
288 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
289 "If a directory is specified, output files will be created "
290 "within that directory, with file-names based on the test "
291 "executable's name and, if necessary, made unique by adding "
296 "True if only test failures should be displayed in text output.");
301 " should display elapsed time in text output.");
306 " prints UTF8 characters as text.");
310 "Random number seed to use when shuffling test orders. Must be in range "
311 "[1, 99999], or 0 to use a seed based on the current time.");
315 "How many times to repeat each test. Specify a negative number "
316 "for repeating forever. Useful for shaking out flaky tests.");
319 recreate_environments_when_repeating,
322 "Controls whether global test environments are recreated for each repeat "
323 "of the tests. If set to false the global test environments are only set "
324 "up once, for the first iteration, and only torn down once, for the last. "
325 "Useful for shaking out flaky tests with stable, expensive test "
326 "environments. If --gtest_repeat is set to a negative number, meaning "
327 "there is no last run, the environments will always be recreated to avoid "
332 " should include internal stack frames when "
333 "printing test failure stack traces.");
338 " should randomize tests' order on every run.");
344 "The maximum number of stack frames to print when an "
345 "assertion fails. The valid range is 0 through 100, inclusive.");
350 "This flag specifies the host name and the port number on which to stream "
351 "test results. Example: \"localhost:555\". The flag is effective only on "
357 "When this flag is specified, a failed assertion will throw an exception "
358 "if exceptions are enabled or exit the program with a non-zero code "
359 "otherwise. For use with an external test framework.");
361 #if GTEST_USE_OWN_FLAGFILE_FLAG_
364 "This flag specifies the flagfile to read command-line flags from.");
365 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
379 <<
"Cannot generate a number in the range [0, 0).";
381 <<
"Generation of a number in [0, " <<
range <<
") was requested, "
382 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
401 for (
size_t i = 0;
i < case_list.size();
i++) {
431 AssertHelper::~AssertHelper() {
453 constexpr
bool kErrorOnUninstantiatedParameterizedTest =
true;
454 constexpr
bool kErrorOnUninstantiatedTypeParameterizedTest =
true;
457 class FailureTest :
public Test {
459 explicit FailureTest(
const CodeLocation&
loc,
std::string error_message,
465 void TestBody()
override {
488 MarkAsIgnored::MarkAsIgnored(
const char*
test_suite) {
497 if (ignored.find(
name) != ignored.end())
return;
499 const char kMissingInstantiation[] =
500 " is defined via TEST_P, but never instantiated. None of the test cases "
501 "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only "
502 "ones provided expand to nothing."
504 "Ideally, TEST_P definitions should only ever be included as part of "
505 "binaries that intend to use them. (As opposed to, for example, being "
506 "placed in a library that may be linked in to get other utilities.)";
508 const char kMissingTestCase[] =
509 " is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are "
510 "defined via TEST_P . No test cases will run."
512 "Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from "
513 "code that always depend on code that provides TEST_P. Failing to do "
514 "so is often an indication of dead code, e.g. the last TEST_P was "
515 "removed but the rest got left behind.";
518 "Parameterized test suite " +
name +
519 (has_test_p ? kMissingInstantiation : kMissingTestCase) +
521 "To suppress this error for this test suite, insert the following line "
522 "(in a non-header) in the namespace it is defined in:"
524 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" +
name +
");";
526 std::string full_name =
"UninstantiatedParameterizedTestSuite<" +
name +
">";
528 "GoogleTestVerification", full_name.c_str(),
531 location.file.c_str(), location.line, [
message, location] {
532 return new FailureTest(location, message,
533 kErrorOnUninstantiatedParameterizedTest);
538 CodeLocation code_location) {
540 test_suite_name, code_location);
549 void TypeParameterizedTestSuiteRegistry::RegisterTestSuite(
550 const char* test_suite_name, CodeLocation code_location) {
552 TypeParameterizedTestSuiteInfo(code_location));
555 void TypeParameterizedTestSuiteRegistry::RegisterInstantiation(
556 const char* test_suite_name) {
558 if (
it != suites_.end()) {
559 it->second.instantiated =
true;
562 << test_suite_name <<
"'";
566 void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() {
568 for (
const auto& testcase : suites_) {
569 if (testcase.second.instantiated)
continue;
570 if (ignored.find(testcase.first) != ignored.end())
continue;
573 "Type parameterized test suite " + testcase.first +
574 " is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated "
575 "via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run."
577 "Ideally, TYPED_TEST_P definitions should only ever be included as "
578 "part of binaries that intend to use them. (As opposed to, for "
579 "example, being placed in a library that may be linked in to get other "
582 "To suppress this error for this test suite, insert the following line "
583 "(in a non-header) in the namespace it is defined in:"
585 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" +
586 testcase.first +
");";
589 "UninstantiatedTypeParameterizedTestSuite<" + testcase.first +
">";
591 "GoogleTestVerification", full_name.c_str(),
594 testcase.second.code_location.file.c_str(),
595 testcase.second.code_location.line, [
message, testcase] {
596 return new FailureTest(testcase.second.code_location, message,
597 kErrorOnUninstantiatedTypeParameterizedTest);
603 static ::std::vector<std::string>
g_argvs;
605 ::std::vector<std::string>
GetArgvs() {
606 #if defined(GTEST_CUSTOM_GET_ARGVS_)
609 const auto&
custom = GTEST_CUSTOM_GET_ARGVS_();
610 return ::std::vector<std::string>(
custom.begin(),
custom.end());
611 #else // defined(GTEST_CUSTOM_GET_ARGVS_)
613 #endif // defined(GTEST_CUSTOM_GET_ARGVS_)
621 #if GTEST_OS_WINDOWS || GTEST_OS_OS2
625 #endif // GTEST_OS_WINDOWS
627 return result.RemoveDirectoryName();
635 const char*
const gtest_output_flag =
s.c_str();
636 const char*
const colon = strchr(gtest_output_flag,
':');
637 return (colon ==
nullptr)
640 static_cast<size_t>(colon - gtest_output_flag));
645 std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
647 const char*
const gtest_output_flag =
s.c_str();
653 const char*
const colon = strchr(gtest_output_flag,
':');
654 if (colon ==
nullptr)
662 if (!output_name.IsAbsolutePath())
667 if (!output_name.IsDirectory())
668 return output_name.string();
672 GetOutputFormat().
c_str()));
683 const char*
pattern,
const char* pattern_end) {
684 const char*
name = name_str.c_str();
685 const char*
const name_begin =
name;
686 const char*
const name_end =
name + name_str.size();
688 const char* pattern_next =
pattern;
689 const char* name_next =
name;
702 if (
name < name_end) {
713 name_next =
name + 1;
719 if (name_begin < name_next && name_next <= name_end) {
733 [](
const char c) { return c ==
'?' || c ==
'*'; });
736 class UnitTestFilter {
738 UnitTestFilter() =
default;
741 explicit UnitTestFilter(
const std::string& filter) {
743 std::vector<std::string> all_patterns;
745 const auto exact_match_patterns_begin = std::partition(
746 all_patterns.begin(), all_patterns.end(), &IsGlobPattern);
748 glob_patterns_.reserve(exact_match_patterns_begin - all_patterns.begin());
749 std::move(all_patterns.begin(), exact_match_patterns_begin,
752 exact_match_patterns_begin, all_patterns.end(),
762 return PatternMatchesString(
763 name, pattern.c_str(),
764 pattern.c_str() + pattern.size());
773 class PositiveAndNegativeUnitTestFilter {
780 explicit PositiveAndNegativeUnitTestFilter(
const std::string& filter) {
781 std::vector<std::string> positive_and_negative_filters;
784 SplitString(filter,
'-', &positive_and_negative_filters);
785 const auto& positive_filter = positive_and_negative_filters.front();
787 if (positive_and_negative_filters.size() > 1) {
794 auto negative_filter_string = positive_and_negative_filters[1];
795 for (std::size_t
i = 2;
i < positive_and_negative_filters.size();
i++)
796 negative_filter_string =
797 negative_filter_string +
'-' + positive_and_negative_filters[
i];
810 bool MatchesTest(
const std::string& test_suite_name,
812 return MatchesName(test_suite_name +
"." + test_name);
828 bool UnitTestOptions::MatchesFilter(
const std::string& name_str,
829 const char* filter) {
830 return UnitTestFilter(filter).MatchesName(name_str);
835 bool UnitTestOptions::FilterMatchesTest(
const std::string& test_suite_name,
840 .MatchesTest(test_suite_name, test_name);
847 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
856 const DWORD kCxxExceptionCode = 0xe06d7363;
858 bool should_handle =
true;
861 should_handle =
false;
862 else if (exception_code == EXCEPTION_BREAKPOINT)
863 should_handle =
false;
864 else if (exception_code == kCxxExceptionCode)
865 should_handle =
false;
867 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
869 #endif // GTEST_HAS_SEH
876 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
877 TestPartResultArray*
result)
878 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
886 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
887 InterceptMode intercept_mode, TestPartResultArray*
result)
888 : intercept_mode_(intercept_mode),
895 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
896 old_reporter_ = impl->GetGlobalTestPartResultReporter();
897 impl->SetGlobalTestPartResultReporter(
this);
899 old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
900 impl->SetTestPartResultReporterForCurrentThread(
this);
906 ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
908 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
909 impl->SetGlobalTestPartResultReporter(old_reporter_);
911 impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
917 void ScopedFakeTestPartResultReporter::ReportTestPartResult(
918 const TestPartResult&
result) {
934 return GetTypeId<Test>();
952 "1 non-fatal failure");
955 msg <<
"Expected: " << expected <<
"\n"
956 <<
" Actual: " <<
results.size() <<
" failures";
964 if (
r.type() !=
type) {
970 if (strstr(
r.message(), substr.c_str()) ==
nullptr) {
992 SingleFailureChecker::~SingleFailureChecker() {
996 DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
997 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
999 void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
1000 const TestPartResult&
result) {
1001 unit_test_->current_test_result()->AddTestPartResult(
result);
1002 unit_test_->listeners()->repeater()->OnTestPartResult(
result);
1005 DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
1006 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
1008 void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
1009 const TestPartResult&
result) {
1010 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(
result);
1014 TestPartResultReporterInterface*
1015 UnitTestImpl::GetGlobalTestPartResultReporter() {
1017 return global_test_part_result_repoter_;
1021 void UnitTestImpl::SetGlobalTestPartResultReporter(
1022 TestPartResultReporterInterface* reporter) {
1024 global_test_part_result_repoter_ = reporter;
1028 TestPartResultReporterInterface*
1029 UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
1030 return per_thread_test_part_result_reporter_.get();
1034 void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
1035 TestPartResultReporterInterface* reporter) {
1036 per_thread_test_part_result_reporter_.set(reporter);
1040 int UnitTestImpl::successful_test_suite_count()
const {
1045 int UnitTestImpl::failed_test_suite_count()
const {
1050 int UnitTestImpl::total_test_suite_count()
const {
1051 return static_cast<int>(test_suites_.size());
1056 int UnitTestImpl::test_suite_to_run_count()
const {
1061 int UnitTestImpl::successful_test_count()
const {
1066 int UnitTestImpl::skipped_test_count()
const {
1071 int UnitTestImpl::failed_test_count()
const {
1076 int UnitTestImpl::reportable_disabled_test_count()
const {
1082 int UnitTestImpl::disabled_test_count()
const {
1087 int UnitTestImpl::reportable_test_count()
const {
1092 int UnitTestImpl::total_test_count()
const {
1097 int UnitTestImpl::test_to_run_count()
const {
1111 std::string UnitTestImpl::CurrentOsStackTraceExceptTop(
int skip_count) {
1112 return os_stack_trace_getter()->CurrentStackTrace(
1113 static_cast<int>(
GTEST_FLAG_GET(stack_trace_depth)), skip_count + 1
1126 return std::chrono::duration_cast<std::chrono::milliseconds>(
1139 return std::chrono::duration_cast<std::chrono::milliseconds>(
1141 std::chrono::system_clock::from_time_t(0))
1149 #if GTEST_OS_WINDOWS_MOBILE
1154 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
1155 if (!ansi)
return nullptr;
1156 const int length = strlen(ansi);
1157 const int unicode_length =
1158 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
nullptr, 0);
1159 WCHAR*
unicode =
new WCHAR[unicode_length + 1];
1160 MultiByteToWideChar(CP_ACP, 0, ansi,
length,
1170 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
1171 if (!utf16_str)
return nullptr;
1172 const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
nullptr,
1173 0,
nullptr,
nullptr);
1174 char* ansi =
new char[ansi_length + 1];
1175 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length,
nullptr,
1177 ansi[ansi_length] = 0;
1181 #endif // GTEST_OS_WINDOWS_MOBILE
1189 bool String::CStringEquals(
const char * lhs,
const char * rhs) {
1190 if (lhs ==
nullptr)
return rhs ==
nullptr;
1192 if (rhs ==
nullptr)
return false;
1194 return strcmp(lhs, rhs) == 0;
1197 #if GTEST_HAS_STD_WSTRING
1203 for (
size_t i = 0;
i !=
length; ) {
1204 if (wstr[i] != L
'\0') {
1205 *msg << WideStringToUtf8(wstr + i, static_cast<int>(
length - i));
1206 while (i !=
length && wstr[i] != L
'\0')
1215 #endif // GTEST_HAS_STD_WSTRING
1218 ::std::vector< ::std::string>*
dest) {
1219 ::std::vector< ::std::string> parsed;
1220 ::std::string::size_type
pos = 0;
1222 const ::std::string::size_type colon =
str.find(delimiter,
pos);
1223 if (colon == ::std::string::npos) {
1224 parsed.push_back(
str.substr(
pos));
1227 parsed.push_back(
str.substr(
pos, colon -
pos));
1244 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
1256 #if GTEST_HAS_STD_WSTRING
1263 #endif // GTEST_HAS_STD_WSTRING
1273 namespace edit_distance {
1275 const std::vector<size_t>& right) {
1276 std::vector<std::vector<double> > costs(
1277 left.size() + 1, std::vector<double>(right.size() + 1));
1278 std::vector<std::vector<EditType> > best_move(
1279 left.size() + 1, std::vector<EditType>(right.size() + 1));
1282 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1283 costs[l_i][0] =
static_cast<double>(l_i);
1287 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1288 costs[0][r_i] =
static_cast<double>(r_i);
1289 best_move[0][r_i] =
kAdd;
1292 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1293 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1294 if (left[l_i] == right[r_i]) {
1296 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1297 best_move[l_i + 1][r_i + 1] =
kMatch;
1301 const double add = costs[l_i + 1][r_i];
1302 const double remove = costs[l_i][r_i + 1];
1303 const double replace = costs[l_i][r_i];
1304 if (
add < remove &&
add < replace) {
1305 costs[l_i + 1][r_i + 1] =
add + 1;
1306 best_move[l_i + 1][r_i + 1] =
kAdd;
1307 }
else if (remove <
add && remove < replace) {
1308 costs[l_i + 1][r_i + 1] = remove + 1;
1309 best_move[l_i + 1][r_i + 1] =
kRemove;
1313 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1314 best_move[l_i + 1][r_i + 1] =
kReplace;
1320 std::vector<EditType> best_path;
1321 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1323 best_path.push_back(
move);
1334 class InternalStrings {
1338 if (
it !=
ids_.end())
return it->second;
1339 size_t id =
ids_.size();
1344 typedef std::map<std::string, size_t>
IdMap;
1351 const std::vector<std::string>& left,
1352 const std::vector<std::string>& right) {
1353 std::vector<size_t> left_ids, right_ids;
1355 InternalStrings intern_table;
1356 for (
size_t i = 0;
i < left.size(); ++
i) {
1357 left_ids.push_back(intern_table.GetId(left[
i]));
1359 for (
size_t i = 0;
i < right.size(); ++
i) {
1360 right_ids.push_back(intern_table.GetId(right[i]));
1374 Hunk(
size_t left_start,
size_t right_start)
1381 void PushLine(
char edit,
const char*
line) {
1386 hunk_.push_back(std::make_pair(
' ',
line));
1399 void PrintTo(std::ostream* os) {
1402 for (std::list<std::pair<char, const char*> >::const_iterator
it =
1405 *os <<
it->first <<
it->second <<
"\n";
1421 void PrintHeader(std::ostream* ss)
const {
1450 const std::vector<std::string>& right,
1454 size_t l_i = 0, r_i = 0, edit_i = 0;
1455 std::stringstream ss;
1456 while (edit_i < edits.size()) {
1458 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1466 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1467 for (
size_t i = prefix_context;
i > 0; --
i) {
1468 hunk.PushLine(
' ', left[l_i - i].
c_str());
1473 size_t n_suffix = 0;
1474 for (; edit_i < edits.size(); ++edit_i) {
1477 auto it = edits.begin() +
static_cast<int>(edit_i);
1479 if (
it == edits.end() ||
1480 static_cast<size_t>(
it - edits.begin()) - edit_i >=
context) {
1488 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1491 hunk.PushLine(edit == kMatch ?
' ' :
'-', left[l_i].
c_str());
1494 hunk.PushLine(
'+', right[r_i].
c_str());
1498 l_i += edit !=
kAdd;
1502 if (!hunk.has_edits()) {
1519 std::vector<std::string> SplitEscapedString(
const std::string&
str) {
1520 std::vector<std::string>
lines;
1526 bool escaped =
false;
1530 if (
str[i] ==
'n') {
1535 escaped =
str[
i] ==
'\\';
1559 AssertionResult
EqFailure(
const char* lhs_expression,
1560 const char* rhs_expression,
1563 bool ignoring_case) {
1565 msg <<
"Expected equality of these values:";
1566 msg <<
"\n " << lhs_expression;
1567 if (lhs_value != lhs_expression) {
1568 msg <<
"\n Which is: " << lhs_value;
1570 msg <<
"\n " << rhs_expression;
1571 if (rhs_value != rhs_expression) {
1572 msg <<
"\n Which is: " << rhs_value;
1575 if (ignoring_case) {
1576 msg <<
"\nIgnoring case";
1579 if (!lhs_value.empty() && !rhs_value.empty()) {
1580 const std::vector<std::string> lhs_lines =
1581 SplitEscapedString(lhs_value);
1582 const std::vector<std::string> rhs_lines =
1583 SplitEscapedString(rhs_value);
1584 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1585 msg <<
"\nWith diff:\n"
1595 const AssertionResult& assertion_result,
1596 const char* expression_text,
1597 const char* actual_predicate_value,
1598 const char* expected_predicate_value) {
1599 const char* actual_message = assertion_result.message();
1601 msg <<
"Value of: " << expression_text
1602 <<
"\n Actual: " << actual_predicate_value;
1603 if (actual_message[0] !=
'\0')
1604 msg <<
" (" << actual_message <<
")";
1605 msg <<
"\nExpected: " << expected_predicate_value;
1606 return msg.GetString();
1612 const char* abs_error_expr,
1622 const double epsilon =
1623 nextafter(min_abs, std::numeric_limits<double>::infinity()) - min_abs;
1631 abs_error < epsilon) {
1633 <<
"The difference between " << expr1 <<
" and " << expr2 <<
" is "
1634 <<
diff <<
", where\n"
1635 << expr1 <<
" evaluates to " <<
val1 <<
",\n"
1636 << expr2 <<
" evaluates to " <<
val2 <<
".\nThe abs_error parameter "
1637 << abs_error_expr <<
" evaluates to " << abs_error
1638 <<
" which is smaller than the minimum distance between doubles for "
1639 "numbers of this magnitude which is "
1641 <<
", thus making this EXPECT_NEAR check equivalent to "
1642 "EXPECT_EQUAL. Consider using EXPECT_DOUBLE_EQ instead.";
1645 <<
"The difference between " << expr1 <<
" and " << expr2
1646 <<
" is " <<
diff <<
", which exceeds " << abs_error_expr <<
", where\n"
1647 << expr1 <<
" evaluates to " <<
val1 <<
",\n"
1648 << expr2 <<
" evaluates to " <<
val2 <<
", and\n"
1649 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1654 template <
typename RawType>
1665 const FloatingPoint<RawType> lhs(
val1), rhs(
val2);
1666 if (lhs.AlmostEquals(rhs)) {
1674 ::std::stringstream val1_ss;
1675 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1678 ::std::stringstream val2_ss;
1679 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1683 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n"
1692 AssertionResult
FloatLE(
const char* expr1,
const char* expr2,
1694 return internal::FloatingPointLE<float>(expr1, expr2,
val1,
val2);
1699 AssertionResult
DoubleLE(
const char* expr1,
const char* expr2,
1701 return internal::FloatingPointLE<double>(expr1, expr2,
val1,
val2);
1708 const char* rhs_expression,
1724 const char* rhs_expression,
1740 const char* s2_expression,
1747 << s2_expression <<
"), actual: \""
1748 << s1 <<
"\" vs \"" << s2 <<
"\"";
1754 const char* s2_expression,
1761 <<
"Expected: (" << s1_expression <<
") != ("
1762 << s2_expression <<
") (ignoring case), actual: \""
1763 << s1 <<
"\" vs \"" << s2 <<
"\"";
1777 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1778 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1780 return strstr(haystack, needle) !=
nullptr;
1783 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1784 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1786 return wcsstr(haystack, needle) !=
nullptr;
1790 template <
typename StringType>
1791 bool IsSubstringPred(
const StringType& needle,
1793 return haystack.find(needle) != StringType::npos;
1800 template <
typename StringType>
1801 AssertionResult IsSubstringImpl(
1802 bool expected_to_be_substring,
1803 const char* needle_expr,
const char* haystack_expr,
1805 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1808 const bool is_wide_string =
sizeof(needle[0]) > 1;
1809 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1811 <<
"Value of: " << needle_expr <<
"\n"
1812 <<
" Actual: " << begin_string_quote << needle <<
"\"\n"
1813 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1814 <<
"a substring of " << haystack_expr <<
"\n"
1815 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1825 const char* needle_expr,
const char* haystack_expr,
1826 const char* needle,
const char* haystack) {
1827 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1831 const char* needle_expr,
const char* haystack_expr,
1832 const wchar_t* needle,
const wchar_t* haystack) {
1833 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1837 const char* needle_expr,
const char* haystack_expr,
1838 const char* needle,
const char* haystack) {
1839 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1843 const char* needle_expr,
const char* haystack_expr,
1844 const wchar_t* needle,
const wchar_t* haystack) {
1845 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1849 const char* needle_expr,
const char* haystack_expr,
1851 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1855 const char* needle_expr,
const char* haystack_expr,
1857 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1860 #if GTEST_HAS_STD_WSTRING
1862 const char* needle_expr,
const char* haystack_expr,
1864 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1868 const char* needle_expr,
const char* haystack_expr,
1870 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1872 #endif // GTEST_HAS_STD_WSTRING
1876 #if GTEST_OS_WINDOWS
1881 AssertionResult HRESULTFailureHelper(
const char* expr,
1882 const char* expected,
1884 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
1887 const char error_text[] =
"";
1894 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1895 FORMAT_MESSAGE_IGNORE_INSERTS;
1896 const DWORD kBufSize = 4096;
1898 char error_text[kBufSize] = {
'\0' };
1899 DWORD message_length = ::FormatMessageA(kFlags,
1901 static_cast<DWORD
>(hr),
1907 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1909 error_text[message_length - 1] =
'\0';
1912 # endif // GTEST_OS_WINDOWS_MOBILE
1916 <<
"Expected: " << expr <<
" " << expected <<
".\n"
1917 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1922 AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1923 if (SUCCEEDED(hr)) {
1926 return HRESULTFailureHelper(expr,
"succeeds", hr);
1929 AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1933 return HRESULTFailureHelper(expr,
"fails", hr);
1936 #endif // GTEST_OS_WINDOWS
1985 str[0] =
static_cast<char>(code_point);
1989 str[0] =
static_cast<char>(0xC0 | code_point);
1994 str[0] =
static_cast<char>(0xE0 | code_point);
2000 str[0] =
static_cast<char>(0xF0 | code_point);
2013 return sizeof(wchar_t) == 2 &&
2014 (
first & 0xFC00) == 0xD800 && (
second & 0xFC00) == 0xDC00;
2022 const uint32_t mask = (1 << 10) - 1;
2023 return (
sizeof(
wchar_t) == 2)
2024 ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
2045 if (num_chars == -1)
2046 num_chars =
static_cast<int>(wcslen(
str));
2048 ::std::stringstream
stream;
2049 for (
int i = 0;
i < num_chars; ++
i) {
2052 if (
str[i] == L
'\0') {
2070 if (wide_c_str ==
nullptr)
return "(null)";
2082 if (lhs ==
nullptr)
return rhs ==
nullptr;
2084 if (rhs ==
nullptr)
return false;
2086 return wcscmp(lhs, rhs) == 0;
2091 const char* rhs_expression,
2093 const wchar_t* rhs) {
2107 const char* s2_expression,
2109 const wchar_t* s2) {
2115 << s2_expression <<
"), actual: "
2127 if (lhs ==
nullptr)
return rhs ==
nullptr;
2128 if (rhs ==
nullptr)
return false;
2145 const wchar_t* rhs) {
2146 if (lhs ==
nullptr)
return rhs ==
nullptr;
2148 if (rhs ==
nullptr)
return false;
2150 #if GTEST_OS_WINDOWS
2151 return _wcsicmp(lhs, rhs) == 0;
2152 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
2153 return wcscasecmp(lhs, rhs) == 0;
2159 left = towlower(
static_cast<wint_t
>(*lhs++));
2160 right = towlower(
static_cast<wint_t
>(*rhs++));
2161 }
while (left && left == right);
2162 return left == right;
2163 #endif // OS selector
2170 const size_t str_len =
str.length();
2171 const size_t suffix_len =
suffix.length();
2172 return (str_len >= suffix_len) &&
2179 return FormatIntWidthN(
value, 2);
2184 std::stringstream ss;
2185 ss << std::setfill(
'0') << std::setw(
width) <<
value;
2191 std::stringstream ss;
2192 ss << std::hex << std::uppercase <<
value;
2203 std::stringstream ss;
2204 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
2205 <<
static_cast<unsigned int>(
value);
2213 const char*
const start =
str.c_str();
2233 const std::string user_msg_string = user_msg.GetString();
2234 if (user_msg_string.empty()) {
2237 if (gtest_msg.empty()) {
2238 return user_msg_string;
2240 return gtest_msg +
"\n" + user_msg_string;
2249 : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
2252 TestResult::~TestResult() {
2258 const TestPartResult& TestResult::GetTestPartResult(
int i)
const {
2259 if (i < 0 || i >= total_part_count())
2261 return test_part_results_.at(
static_cast<size_t>(
i));
2267 const TestProperty& TestResult::GetTestProperty(
int i)
const {
2268 if (i < 0 || i >= test_property_count())
2270 return test_properties_.at(
static_cast<size_t>(
i));
2274 void TestResult::ClearTestPartResults() {
2275 test_part_results_.clear();
2279 void TestResult::AddTestPartResult(
const TestPartResult& test_part_result) {
2280 test_part_results_.push_back(test_part_result);
2286 void TestResult::RecordProperty(
const std::string& xml_element,
2287 const TestProperty& test_property) {
2288 if (!ValidateTestProperty(xml_element, test_property)) {
2293 std::find_if(test_properties_.begin(), test_properties_.end(),
2294 internal::TestPropertyKeyIs(test_property.key()));
2295 if (property_with_matching_key == test_properties_.end()) {
2296 test_properties_.push_back(test_property);
2299 property_with_matching_key->SetValue(test_property.value());
2318 "disabled",
"errors",
"failures",
"name",
2319 "tests",
"time",
"timestamp",
"skipped"};
2323 "classname",
"name",
"status",
"time",
"type_param",
2324 "value_param",
"file",
"line"};
2329 "classname",
"name",
"status",
"time",
"type_param",
2330 "value_param",
"file",
"line",
"result",
"timestamp"};
2332 template <
size_t kSize>
2339 if (xml_element ==
"testsuites") {
2341 }
else if (xml_element ==
"testsuite") {
2343 }
else if (xml_element ==
"testcase") {
2346 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2349 return std::vector<std::string>();
2355 if (xml_element ==
"testsuites") {
2357 }
else if (xml_element ==
"testsuite") {
2359 }
else if (xml_element ==
"testcase") {
2362 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2365 return std::vector<std::string>();
2370 for (
size_t i = 0;
i <
words.size(); ++
i) {
2371 if (
i > 0 &&
words.size() > 2) {
2374 if (
i ==
words.size() - 1) {
2375 word_list <<
"and ";
2377 word_list <<
"'" <<
words[
i] <<
"'";
2387 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2397 bool TestResult::ValidateTestProperty(
const std::string& xml_element,
2398 const TestProperty& test_property) {
2405 test_part_results_.clear();
2406 test_properties_.clear();
2407 death_test_count_ = 0;
2417 bool TestResult::Skipped()
const {
2422 bool TestResult::Failed()
const {
2423 for (
int i = 0;
i < total_part_count(); ++
i) {
2424 if (GetTestPartResult(
i).failed())
2432 return result.fatally_failed();
2436 bool TestResult::HasFatalFailure()
const {
2442 return result.nonfatally_failed();
2446 bool TestResult::HasNonfatalFailure()
const {
2452 int TestResult::total_part_count()
const {
2453 return static_cast<int>(test_part_results_.size());
2457 int TestResult::test_property_count()
const {
2458 return static_cast<int>(test_properties_.size());
2479 void Test::SetUp() {
2485 void Test::TearDown() {
2490 UnitTest::GetInstance()->RecordProperty(
key,
value);
2496 value_message <<
value;
2497 RecordProperty(
key, value_message.GetString().c_str());
2506 UnitTest::GetInstance()->AddTestPartResult(
2521 bool Test::HasSameFixtureClass() {
2526 const TestInfo*
const first_test_info =
test_suite->test_info_list()[0];
2527 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
2528 const char*
const first_test_name = first_test_info->name();
2531 const TestInfo*
const this_test_info = impl->current_test_info();
2532 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
2533 const char*
const this_test_name = this_test_info->name();
2535 if (this_fixture_id != first_fixture_id) {
2541 if (first_is_TEST || this_is_TEST) {
2548 const char*
const TEST_name =
2549 first_is_TEST ? first_test_name : this_test_name;
2550 const char*
const TEST_F_name =
2551 first_is_TEST ? this_test_name : first_test_name;
2554 <<
"All tests in the same test suite must use the same test fixture\n"
2555 <<
"class, so mixing TEST_F and TEST in the same test suite is\n"
2556 <<
"illegal. In test suite " << this_test_info->test_suite_name()
2558 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n"
2559 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n"
2560 <<
"want to change the TEST to TEST_F or move it to another test\n"
2566 <<
"All tests in the same test suite must use the same test fixture\n"
2567 <<
"class. However, in test suite "
2568 << this_test_info->test_suite_name() <<
",\n"
2569 <<
"you defined test " << first_test_name <<
" and test "
2570 << this_test_name <<
"\n"
2571 <<
"using two different test fixture classes. This can happen if\n"
2572 <<
"the two classes are from different namespaces or translation\n"
2573 <<
"units and have the same name. You should probably rename one\n"
2574 <<
"of the classes to put the tests into different test suites.";
2588 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2589 const char* location) {
2591 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2592 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2597 #endif // GTEST_HAS_SEH
2601 #if GTEST_HAS_EXCEPTIONS
2605 const char* location) {
2610 message <<
"Unknown C++ exception";
2612 message <<
" thrown in " << location <<
".";
2618 const TestPartResult& test_part_result);
2620 GoogleTestFailureException::GoogleTestFailureException(
2621 const TestPartResult& failure)
2624 #endif // GTEST_HAS_EXCEPTIONS
2634 template <
class T,
typename Result>
2639 return (object->*
method)();
2640 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2641 GetExceptionCode())) {
2645 std::string* exception_message = FormatSehExceptionMessage(
2646 GetExceptionCode(), location);
2648 *exception_message);
2649 delete exception_message;
2650 return static_cast<Result>(0);
2654 return (object->*
method)();
2655 #endif // GTEST_HAS_SEH
2661 template <
class T,
typename Result>
2688 #if GTEST_HAS_EXCEPTIONS
2691 }
catch (
const AssertionException&) {
2693 }
catch (
const internal::GoogleTestFailureException&) {
2698 }
catch (
const std::exception& e) {
2700 TestPartResult::kFatalFailure,
2701 FormatCxxExceptionMessage(
e.what(), location));
2704 TestPartResult::kFatalFailure,
2705 FormatCxxExceptionMessage(
nullptr, location));
2707 return static_cast<Result>(0);
2710 #endif // GTEST_HAS_EXCEPTIONS
2712 return (object->*
method)();
2720 if (!HasSameFixtureClass())
return;
2723 impl->os_stack_trace_getter()->UponLeavingGTest();
2727 if (!HasFatalFailure() && !IsSkipped()) {
2728 impl->os_stack_trace_getter()->UponLeavingGTest();
2730 this, &Test::TestBody,
"the test body");
2736 impl->os_stack_trace_getter()->UponLeavingGTest();
2738 this, &Test::TearDown,
"TearDown()");
2742 bool Test::HasFatalFailure() {
2747 bool Test::HasNonfatalFailure() {
2749 HasNonfatalFailure();
2753 bool Test::IsSkipped() {
2761 TestInfo::TestInfo(
const std::string& a_test_suite_name,
2762 const std::string& a_name,
const char* a_type_param,
2763 const char* a_value_param,
2764 internal::CodeLocation a_code_location,
2766 internal::TestFactoryBase* factory)
2767 : test_suite_name_(a_test_suite_name),
2769 type_param_(a_type_param ?
new std::
string(a_type_param) : nullptr),
2770 value_param_(a_value_param ?
new std::
string(a_value_param) : nullptr),
2771 location_(a_code_location),
2772 fixture_class_id_(fixture_class_id),
2774 is_disabled_(
false),
2775 matches_filter_(
false),
2776 is_in_another_shard_(
false),
2781 TestInfo::~TestInfo() {
delete factory_; }
2804 const char* test_suite_name,
const char*
name,
const char* type_param,
2805 const char* value_param, CodeLocation code_location,
2808 TestInfo*
const test_info =
2809 new TestInfo(test_suite_name,
name, type_param, value_param,
2810 code_location, fixture_class_id, factory);
2816 CodeLocation code_location) {
2819 <<
"Attempted redefinition of test suite " << test_suite_name <<
".\n"
2820 <<
"All tests in the same test suite must use the same test fixture\n"
2821 <<
"class. However, in test suite " << test_suite_name <<
", you tried\n"
2822 <<
"to define a test using a fixture class different from the one\n"
2823 <<
"used earlier. This can happen if the two fixture classes are\n"
2824 <<
"from different namespaces and have the same name. You should\n"
2825 <<
"probably rename one of the classes to put the tests into different\n"
2830 <<
" " <<
errors.GetString();
2849 explicit TestNameIs(
const char*
name)
2853 bool operator()(
const TestInfo * test_info)
const {
2854 return test_info && test_info->name() ==
name_;
2868 void UnitTestImpl::RegisterParameterizedTests() {
2869 if (!parameterized_tests_registered_) {
2870 parameterized_test_registry_.RegisterTests();
2871 type_parameterized_test_registry_.CheckForInstantiations();
2872 parameterized_tests_registered_ =
true;
2881 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
2883 if (is_disabled_) repeater->OnTestDisabled(*
this);
2889 impl->set_current_test_info(
this);
2892 repeater->OnTestStart(*
this);
2894 internal::Timer
timer;
2895 impl->os_stack_trace_getter()->UponLeavingGTest();
2899 factory_, &internal::TestFactoryBase::CreateTest,
2900 "the test fixture's constructor");
2905 if (!Test::HasFatalFailure() && !Test::IsSkipped()) {
2911 if (
test !=
nullptr) {
2913 impl->os_stack_trace_getter()->UponLeavingGTest();
2915 test, &Test::DeleteSelf_,
"the test fixture's destructor");
2918 result_.set_elapsed_time(
timer.Elapsed());
2921 repeater->OnTestEnd(*
this);
2925 impl->set_current_test_info(
nullptr);
2930 if (!should_run_)
return;
2933 impl->set_current_test_info(
this);
2935 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
2938 repeater->OnTestStart(*
this);
2940 const TestPartResult test_part_result =
2941 TestPartResult(TestPartResult::kSkip, this->
file(), this->
line(),
"");
2942 impl->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult(
2946 repeater->OnTestEnd(*
this);
2947 impl->set_current_test_info(
nullptr);
2953 int TestSuite::successful_test_count()
const {
2954 return CountIf(test_info_list_, TestPassed);
2958 int TestSuite::skipped_test_count()
const {
2959 return CountIf(test_info_list_, TestSkipped);
2963 int TestSuite::failed_test_count()
const {
2964 return CountIf(test_info_list_, TestFailed);
2968 int TestSuite::reportable_disabled_test_count()
const {
2969 return CountIf(test_info_list_, TestReportableDisabled);
2973 int TestSuite::disabled_test_count()
const {
2974 return CountIf(test_info_list_, TestDisabled);
2978 int TestSuite::reportable_test_count()
const {
2979 return CountIf(test_info_list_, TestReportable);
2983 int TestSuite::test_to_run_count()
const {
2984 return CountIf(test_info_list_, ShouldRunTest);
2988 int TestSuite::total_test_count()
const {
2989 return static_cast<int>(test_info_list_.size());
3001 TestSuite::TestSuite(
const char* a_name,
const char* a_type_param,
3005 type_param_(a_type_param ?
new std::
string(a_type_param) : nullptr),
3006 set_up_tc_(set_up_tc),
3007 tear_down_tc_(tear_down_tc),
3009 start_timestamp_(0),
3013 TestSuite::~TestSuite() {
3015 ForEach(test_info_list_, internal::Delete<TestInfo>);
3020 const TestInfo* TestSuite::GetTestInfo(
int i)
const {
3022 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(
index)];
3027 TestInfo* TestSuite::GetMutableTestInfo(
int i) {
3029 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(
index)];
3034 void TestSuite::AddTestInfo(TestInfo* test_info) {
3035 test_info_list_.push_back(test_info);
3036 test_indices_.push_back(
static_cast<int>(test_indices_.size()));
3041 if (!should_run_)
return;
3044 impl->set_current_test_suite(
this);
3046 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
3049 repeater->OnTestSuiteStart(*
this);
3051 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3052 repeater->OnTestCaseStart(*
this);
3053 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3055 impl->os_stack_trace_getter()->UponLeavingGTest();
3057 this, &TestSuite::RunSetUpTestSuite,
"SetUpTestSuite()");
3059 const bool skip_all = ad_hoc_test_result().Failed();
3062 internal::Timer
timer;
3063 for (
int i = 0;
i < total_test_count();
i++) {
3065 GetMutableTestInfo(
i)->Skip();
3067 GetMutableTestInfo(
i)->Run();
3070 GetMutableTestInfo(
i)->
result()->Failed()) {
3071 for (
int j =
i + 1;
j < total_test_count();
j++) {
3072 GetMutableTestInfo(j)->Skip();
3077 elapsed_time_ =
timer.Elapsed();
3079 impl->os_stack_trace_getter()->UponLeavingGTest();
3081 this, &TestSuite::RunTearDownTestSuite,
"TearDownTestSuite()");
3084 repeater->OnTestSuiteEnd(*
this);
3086 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3087 repeater->OnTestCaseEnd(*
this);
3088 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3090 impl->set_current_test_suite(
nullptr);
3095 if (!should_run_)
return;
3098 impl->set_current_test_suite(
this);
3100 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
3103 repeater->OnTestSuiteStart(*
this);
3105 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3106 repeater->OnTestCaseStart(*
this);
3107 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3109 for (
int i = 0;
i < total_test_count();
i++) {
3110 GetMutableTestInfo(
i)->Skip();
3114 repeater->OnTestSuiteEnd(*
this);
3116 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3117 repeater->OnTestCaseEnd(*
this);
3118 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3120 impl->set_current_test_suite(
nullptr);
3124 void TestSuite::ClearResult() {
3125 ad_hoc_test_result_.Clear();
3126 ForEach(test_info_list_, TestInfo::ClearTestResult);
3131 Shuffle(random, &test_indices_);
3135 void TestSuite::UnshuffleTests() {
3136 for (
size_t i = 0;
i < test_indices_.size();
i++) {
3137 test_indices_[
i] =
static_cast<int>(
i);
3147 const char * singular_form,
3148 const char * plural_form) {
3150 (
count == 1 ? singular_form : plural_form);
3169 case TestPartResult::kSkip:
3171 case TestPartResult::kSuccess:
3174 case TestPartResult::kNonFatalFailure:
3175 case TestPartResult::kFatalFailure:
3182 return "Unknown result type";
3188 enum class GTestColor { kDefault, kRed, kGreen, kYellow };
3198 << test_part_result.
message()).GetString();
3211 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3215 ::OutputDebugStringA(
result.c_str());
3216 ::OutputDebugStringA(
"\n");
3221 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3222 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3225 static WORD GetColorAttribute(
GTestColor color) {
3227 case GTestColor::kRed:
3228 return FOREGROUND_RED;
3229 case GTestColor::kGreen:
3230 return FOREGROUND_GREEN;
3231 case GTestColor::kYellow:
3232 return FOREGROUND_RED | FOREGROUND_GREEN;
3237 static int GetBitOffset(WORD color_mask) {
3238 if (color_mask == 0)
return 0;
3241 while ((color_mask & 1) == 0) {
3248 static WORD GetNewColor(
GTestColor color, WORD old_color_attrs) {
3250 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
3251 BACKGROUND_RED | BACKGROUND_INTENSITY;
3252 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
3253 FOREGROUND_RED | FOREGROUND_INTENSITY;
3254 const WORD existing_bg = old_color_attrs & background_mask;
3257 GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
3258 static const int bg_bitOffset = GetBitOffset(background_mask);
3259 static const int fg_bitOffset = GetBitOffset(foreground_mask);
3261 if (((new_color & background_mask) >> bg_bitOffset) ==
3262 ((new_color & foreground_mask) >> fg_bitOffset)) {
3263 new_color ^= FOREGROUND_INTENSITY;
3274 case GTestColor::kRed:
3276 case GTestColor::kGreen:
3278 case GTestColor::kYellow:
3285 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3290 const char*
const gtest_color = c.c_str();
3293 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
3296 return stdout_is_tty;
3300 const bool term_supports_color =
3301 String::CStringEquals(term,
"xterm") ||
3302 String::CStringEquals(term,
"xterm-color") ||
3303 String::CStringEquals(term,
"xterm-256color") ||
3304 String::CStringEquals(term,
"screen") ||
3305 String::CStringEquals(term,
"screen-256color") ||
3306 String::CStringEquals(term,
"tmux") ||
3307 String::CStringEquals(term,
"tmux-256color") ||
3308 String::CStringEquals(term,
"rxvt-unicode") ||
3309 String::CStringEquals(term,
"rxvt-unicode-256color") ||
3310 String::CStringEquals(term,
"linux") ||
3311 String::CStringEquals(term,
"cygwin");
3312 return stdout_is_tty && term_supports_color;
3313 #endif // GTEST_OS_WINDOWS
3319 String::CStringEquals(gtest_color,
"1");
3335 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
3336 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM)
3339 static const bool in_color_mode =
3342 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS
3350 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3351 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3352 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3355 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3356 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3357 const WORD old_color_attrs = buffer_info.wAttributes;
3358 const WORD new_color = GetNewColor(color, old_color_attrs);
3364 SetConsoleTextAttribute(stdout_handle, new_color);
3370 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3375 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
3385 const char*
const type_param = test_info.
type_param();
3386 const char*
const value_param = test_info.
value_param();
3388 if (type_param !=
nullptr || value_param !=
nullptr) {
3390 if (type_param !=
nullptr) {
3392 if (value_param !=
nullptr)
printf(
" and ");
3394 if (value_param !=
nullptr) {
3412 void OnTestIterationStart(
const UnitTest& unit_test,
int iteration)
override;
3413 void OnEnvironmentsSetUpStart(
const UnitTest& unit_test)
override;
3415 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3416 void OnTestCaseStart(
const TestCase& test_case)
override;
3419 #endif // OnTestCaseStart
3421 void OnTestStart(
const TestInfo& test_info)
override;
3422 void OnTestDisabled(
const TestInfo& test_info)
override;
3425 void OnTestEnd(
const TestInfo& test_info)
override;
3426 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3427 void OnTestCaseEnd(
const TestCase& test_case)
override;
3430 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3432 void OnEnvironmentsTearDownStart(
const UnitTest& unit_test)
override;
3434 void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration)
override;
3438 static void PrintFailedTests(
const UnitTest& unit_test);
3439 static void PrintFailedTestSuites(
const UnitTest& unit_test);
3440 static void PrintSkippedTests(
const UnitTest& unit_test);
3444 void PrettyUnitTestResultPrinter::OnTestIterationStart(
3445 const UnitTest& unit_test,
int iteration) {
3447 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3450 const char*
const filter = f.c_str();
3461 ColoredPrintf(GTestColor::kYellow,
"Note: This is test shard %d of %s.\n",
3462 static_cast<int>(shard_index) + 1,
3468 "Note: Randomizing tests' orders with a seed of %d .\n",
3473 printf(
"Running %s from %s.\n",
3479 void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
3482 printf(
"Global test environment set-up.\n");
3486 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3487 void PrettyUnitTestResultPrinter::OnTestCaseStart(
const TestCase& test_case) {
3491 printf(
"%s from %s", counts.c_str(), test_case.name());
3492 if (test_case.type_param() ==
nullptr) {
3500 void PrettyUnitTestResultPrinter::OnTestSuiteStart(
3513 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3515 void PrettyUnitTestResultPrinter::OnTestStart(
const TestInfo& test_info) {
3517 PrintTestName(test_info.test_suite_name(), test_info.name());
3522 void PrettyUnitTestResultPrinter::OnTestDisabled(
const TestInfo& test_info) {
3530 void PrettyUnitTestResultPrinter::OnTestPartResult(
3534 case TestPartResult::kSuccess:
3544 void PrettyUnitTestResultPrinter::OnTestEnd(
const TestInfo& test_info) {
3545 if (test_info.result()->Passed()) {
3547 }
else if (test_info.result()->Skipped()) {
3552 PrintTestName(test_info.test_suite_name(), test_info.name());
3553 if (test_info.result()->Failed())
3558 test_info.result()->elapsed_time()).c_str());
3565 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3566 void PrettyUnitTestResultPrinter::OnTestCaseEnd(
const TestCase& test_case) {
3572 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_case.name(),
3587 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3589 void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
3592 printf(
"Global test environment tear-down\n");
3597 void PrettyUnitTestResultPrinter::PrintFailedTests(
const UnitTest& unit_test) {
3598 const int failed_test_count = unit_test.failed_test_count();
3602 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3607 for (
int j = 0;
j <
test_suite.total_test_count(); ++
j) {
3608 const TestInfo& test_info = *
test_suite.GetTestInfo(j);
3609 if (!test_info.should_run() || !test_info.result()->Failed()) {
3618 printf(
"\n%2d FAILED %s\n", failed_test_count,
3619 failed_test_count == 1 ?
"TEST" :
"TESTS");
3624 void PrettyUnitTestResultPrinter::PrintFailedTestSuites(
3625 const UnitTest& unit_test) {
3626 int suite_failure_count = 0;
3627 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3632 if (
test_suite.ad_hoc_test_result().Failed()) {
3635 ++suite_failure_count;
3638 if (suite_failure_count > 0) {
3639 printf(
"\n%2d FAILED TEST %s\n", suite_failure_count,
3640 suite_failure_count == 1 ?
"SUITE" :
"SUITES");
3645 void PrettyUnitTestResultPrinter::PrintSkippedTests(
const UnitTest& unit_test) {
3646 const int skipped_test_count = unit_test.skipped_test_count();
3647 if (skipped_test_count == 0) {
3651 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
3656 for (
int j = 0;
j <
test_suite.total_test_count(); ++
j) {
3657 const TestInfo& test_info = *
test_suite.GetTestInfo(j);
3658 if (!test_info.should_run() || !test_info.result()->Skipped()) {
3668 void PrettyUnitTestResultPrinter::OnTestIterationEnd(
const UnitTest& unit_test,
3671 printf(
"%s from %s ran.",
3682 const int skipped_test_count = unit_test.skipped_test_count();
3683 if (skipped_test_count > 0) {
3686 PrintSkippedTests(unit_test);
3689 if (!unit_test.Passed()) {
3690 PrintFailedTests(unit_test);
3691 PrintFailedTestSuites(unit_test);
3694 int num_disabled = unit_test.reportable_disabled_test_count();
3696 if (unit_test.Passed()) {
3699 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3700 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3711 class BriefUnitTestResultPrinter :
public TestEventListener {
3724 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3727 void OnTestSuiteStart(
const TestSuite& )
override {}
3728 #endif // OnTestCaseStart
3734 void OnTestEnd(
const TestInfo& test_info)
override;
3735 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3738 void OnTestSuiteEnd(
const TestSuite& )
override {}
3739 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3743 void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration)
override;
3748 void BriefUnitTestResultPrinter::OnTestPartResult(
3752 case TestPartResult::kSuccess:
3762 void BriefUnitTestResultPrinter::OnTestEnd(
const TestInfo& test_info) {
3763 if (test_info.result()->Failed()) {
3765 PrintTestName(test_info.test_suite_name(), test_info.name());
3779 void BriefUnitTestResultPrinter::OnTestIterationEnd(
const UnitTest& unit_test,
3782 printf(
"%s from %s ran.",
3793 const int skipped_test_count = unit_test.skipped_test_count();
3794 if (skipped_test_count > 0) {
3799 int num_disabled = unit_test.reportable_disabled_test_count();
3801 if (unit_test.Passed()) {
3804 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3805 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3816 class TestEventRepeater :
public TestEventListener {
3828 void OnTestProgramStart(
const UnitTest& unit_test)
override;
3829 void OnTestIterationStart(
const UnitTest& unit_test,
int iteration)
override;
3830 void OnEnvironmentsSetUpStart(
const UnitTest& unit_test)
override;
3831 void OnEnvironmentsSetUpEnd(
const UnitTest& unit_test)
override;
3833 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3834 void OnTestCaseStart(
const TestSuite& parameter)
override;
3835 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3836 void OnTestSuiteStart(
const TestSuite& parameter)
override;
3837 void OnTestStart(
const TestInfo& test_info)
override;
3838 void OnTestDisabled(
const TestInfo& test_info)
override;
3840 void OnTestEnd(
const TestInfo& test_info)
override;
3842 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3843 void OnTestCaseEnd(
const TestCase& parameter)
override;
3844 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3845 void OnTestSuiteEnd(
const TestSuite& parameter)
override;
3846 void OnEnvironmentsTearDownStart(
const UnitTest& unit_test)
override;
3847 void OnEnvironmentsTearDownEnd(
const UnitTest& unit_test)
override;
3848 void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration)
override;
3849 void OnTestProgramEnd(
const UnitTest& unit_test)
override;
3854 bool forwarding_enabled_;
3856 std::vector<TestEventListener*> listeners_;
3861 TestEventRepeater::~TestEventRepeater() {
3862 ForEach(listeners_, Delete<TestEventListener>);
3866 listeners_.push_back(listener);
3869 TestEventListener* TestEventRepeater::Release(TestEventListener *listener) {
3870 for (
size_t i = 0;
i < listeners_.size(); ++
i) {
3871 if (listeners_[i] == listener) {
3872 listeners_.erase(listeners_.begin() +
static_cast<int>(i));
3882 #define GTEST_REPEATER_METHOD_(Name, Type) \
3883 void TestEventRepeater::Name(const Type& parameter) { \
3884 if (forwarding_enabled_) { \
3885 for (size_t i = 0; i < listeners_.size(); i++) { \
3886 listeners_[i]->Name(parameter); \
3892 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
3893 void TestEventRepeater::Name(const Type& parameter) { \
3894 if (forwarding_enabled_) { \
3895 for (size_t i = listeners_.size(); i != 0; i--) { \
3896 listeners_[i - 1]->Name(parameter); \
3904 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3906 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3916 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3918 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
3922 #undef GTEST_REPEATER_METHOD_
3923 #undef GTEST_REVERSE_REPEATER_METHOD_
3925 void TestEventRepeater::OnTestIterationStart(
const UnitTest& unit_test,
3927 if (forwarding_enabled_) {
3928 for (
size_t i = 0;
i < listeners_.size();
i++) {
3929 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3934 void TestEventRepeater::OnTestIterationEnd(
const UnitTest& unit_test,
3936 if (forwarding_enabled_) {
3937 for (
size_t i = listeners_.size(); i > 0; i--) {
3938 listeners_[
i - 1]->OnTestIterationEnd(unit_test, iteration);
3946 class XmlUnitTestResultPrinter :
public EmptyTestEventListener {
3948 explicit XmlUnitTestResultPrinter(
const char* output_file);
3950 void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration)
override;
3951 void ListTestsMatchingFilter(
const std::vector<TestSuite*>& test_suites);
3954 static void PrintXmlTestsList(std::ostream*
stream,
3955 const std::vector<TestSuite*>& test_suites);
3961 return c ==
'\t' || c ==
'\n' || c ==
'\r';
3967 return IsNormalizableWhitespace(c) || c >= 0x20;
3981 return EscapeXml(
str,
true);
3986 return EscapeXml(
str,
false);
3991 static void OutputXmlAttribute(std::ostream*
stream,
3997 static void OutputXmlCDataSection(::std::ostream*
stream,
const char*
data);
4002 static void OutputXmlTestSuiteForTestResult(::std::ostream*
stream,
4006 static void OutputXmlTestResult(::std::ostream*
stream,
4010 static void OutputXmlTestInfo(::std::ostream*
stream,
4011 const char* test_suite_name,
4015 static void PrintXmlTestSuite(::std::ostream*
stream,
4019 static void PrintXmlUnitTest(::std::ostream*
stream,
4030 static void OutputXmlTestProperties(std::ostream*
stream,
4040 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(
const char* output_file)
4041 : output_file_(output_file) {
4051 std::stringstream
stream;
4058 const std::vector<TestSuite*>& test_suites) {
4060 std::stringstream
stream;
4080 for (
size_t i = 0;
i <
str.size(); ++
i) {
4117 return m.GetString();
4127 for (std::string::const_iterator
it =
str.begin();
it !=
str.end(); ++
it)
4152 ::std::stringstream ss;
4153 ss << (static_cast<double>(ms) * 1
e-3);
4158 #if defined(_MSC_VER)
4160 #elif defined(__MINGW32__) || defined(__MINGW64__)
4163 struct tm* tm_ptr = localtime(&
seconds);
4164 if (tm_ptr ==
nullptr)
return false;
4167 #elif defined(__STDC_LIB_EXT1__)
4170 return localtime_s(&
seconds,
out) !=
nullptr;
4172 return localtime_r(&
seconds,
out) !=
nullptr;
4179 struct tm time_struct;
4195 const char* segment =
data;
4198 const char*
const next_segment = strstr(segment,
"]]>");
4199 if (next_segment !=
nullptr) {
4201 segment,
static_cast<std::streamsize
>(next_segment - segment));
4202 *
stream <<
"]]>]]><![CDATA[";
4203 segment = next_segment + strlen(
"]]>");
4217 const std::vector<std::string>& allowed_names =
4221 allowed_names.end())
4232 *
stream <<
" <testsuite";
4242 stream,
"testsuite",
"timestamp",
4255 stream,
"testcase",
"timestamp",
4262 *
stream <<
" </testsuite>\n";
4267 const char* test_suite_name,
4299 ? (
result.Skipped() ?
"skipped" :
"completed")
4304 stream, kTestsuite,
"timestamp",
4315 for (
int i = 0;
i <
result.total_part_count(); ++
i) {
4318 if (++
failures == 1 && skips == 0) {
4325 *
stream <<
" <failure message=\""
4330 *
stream <<
"</failure>\n";
4331 }
else if (part.skipped()) {
4332 if (++skips == 1 &&
failures == 0) {
4339 *
stream <<
" <skipped message=\""
4343 *
stream <<
"</skipped>\n";
4347 if (
failures == 0 && skips == 0 &&
result.test_property_count() == 0) {
4354 *
stream <<
" </testcase>\n";
4362 *
stream <<
" <" << kTestsuite;
4370 stream, kTestsuite,
"disabled",
4380 stream, kTestsuite,
"timestamp",
4389 *
stream <<
" </" << kTestsuite <<
">\n";
4394 const UnitTest& unit_test) {
4397 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4398 *
stream <<
"<" << kTestsuites;
4405 stream, kTestsuites,
"disabled",
4411 stream, kTestsuites,
"timestamp",
4423 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
4424 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0)
4430 if (unit_test.ad_hoc_test_result().Failed()) {
4434 *
stream <<
"</" << kTestsuites <<
">\n";
4438 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
4441 *
stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4442 *
stream <<
"<" << kTestsuites;
4444 int total_tests = 0;
4446 total_tests +=
test_suite->total_test_count();
4456 *
stream <<
"</" << kTestsuites <<
">\n";
4462 const TestResult&
result) {
4464 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
4465 const TestProperty&
property =
result.GetTestProperty(
i);
4466 attributes <<
" " <<
property.key() <<
"="
4469 return attributes.GetString();
4477 if (
result.test_property_count() <= 0) {
4481 *
stream <<
" <" << kProperties <<
">\n";
4482 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
4483 const TestProperty&
property =
result.GetTestProperty(
i);
4484 *
stream <<
" <" << kProperty;
4489 *
stream <<
" </" << kProperties <<
">\n";
4495 class JsonUnitTestResultPrinter :
public EmptyTestEventListener {
4503 const std::vector<TestSuite*>& test_suites);
4528 const TestResult&
result);
4532 const TestResult&
result);
4536 const char* test_suite_name,
4537 const TestInfo& test_info);
4545 const UnitTest& unit_test);
4560 : output_file_(output_file) {
4569 std::stringstream
stream;
4579 for (
size_t i = 0;
i <
str.size(); ++
i) {
4612 return m.GetString();
4620 ::std::stringstream ss;
4621 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
4628 struct tm time_struct;
4651 const std::vector<std::string>& allowed_names =
4655 allowed_names.end())
4671 const std::vector<std::string>& allowed_names =
4675 allowed_names.end())
4728 const char* test_suite_name,
4753 test_info.
should_run() ?
"RUN" :
"NOTRUN", kIndent);
4756 ? (
result.Skipped() ?
"SKIPPED" :
"COMPLETED")
4776 for (
int i = 0;
i <
result.total_part_count(); ++
i) {
4781 *
stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4787 *
stream << kIndent <<
" {\n"
4788 << kIndent <<
" \"failure\": \"" <<
message <<
"\",\n"
4789 << kIndent <<
" \"type\": \"\"\n"
4795 *
stream <<
"\n" << kIndent <<
"]";
4813 test_suite.reportable_disabled_test_count(), kIndent);
4816 stream, kTestsuite,
"timestamp",
4826 *
stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4839 *
stream <<
"\n" << kIndent <<
"]\n" <<
Indent(4) <<
"}";
4844 const UnitTest& unit_test) {
4854 unit_test.reportable_disabled_test_count(), kIndent);
4871 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4874 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
4875 if (unit_test.GetTestSuite(
i)->reportable_test_count() > 0) {
4887 if (unit_test.ad_hoc_test_result().Failed()) {
4891 *
stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4895 std::ostream*
stream,
const std::vector<TestSuite*>& test_suites) {
4899 int total_tests = 0;
4901 total_tests +=
test_suite->total_test_count();
4906 *
stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4908 for (
size_t i = 0;
i < test_suites.size(); ++
i) {
4924 for (
int i = 0;
i <
result.test_property_count(); ++
i) {
4925 const TestProperty&
property =
result.GetTestProperty(
i);
4926 attributes <<
",\n" <<
indent <<
"\"" <<
property.key() <<
"\": "
4927 <<
"\"" <<
EscapeJson(property.value()) <<
"\"";
4929 return attributes.GetString();
4934 #if GTEST_CAN_STREAM_RESULTS_
4960 void StreamingListener::SocketWriter::MakeConnection() {
4962 <<
"MakeConnection() can't be called when there is already a connection.";
4965 memset(&hints, 0,
sizeof(hints));
4972 const int error_num = getaddrinfo(
4973 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4974 if (error_num != 0) {
4976 << gai_strerror(error_num);
4980 for (
addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr !=
nullptr;
4981 cur_addr = cur_addr->
ai_next) {
4983 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4984 if (sockfd_ != -1) {
4986 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4993 freeaddrinfo(servinfo);
4995 if (sockfd_ == -1) {
4997 << host_name_ <<
":" << port_num_;
5002 #endif // GTEST_CAN_STREAM_RESULTS__
5014 if (max_depth <= 0) {
5020 std::vector<void*> raw_stack(max_depth);
5022 const int raw_stack_size =
5025 void* caller_frame =
nullptr;
5028 caller_frame = caller_frame_;
5031 for (
int i = 0;
i < raw_stack_size; ++
i) {
5032 if (raw_stack[
i] == caller_frame &&
5040 const char* symbol =
"(unknown)";
5046 snprintf(
line,
sizeof(
line),
" %p: %s\n", raw_stack[
i], symbol);
5052 #else // !GTEST_HAS_ABSL
5053 static_cast<void>(max_depth);
5054 static_cast<void>(skip_count);
5056 #endif // GTEST_HAS_ABSL
5061 void* caller_frame =
nullptr;
5063 caller_frame =
nullptr;
5067 caller_frame_ = caller_frame;
5068 #endif // GTEST_HAS_ABSL
5073 class ScopedPrematureExitFile {
5077 premature_exit_filepath :
"") {
5084 fwrite(
"0", 1, 1, pfile);
5090 #if !defined GTEST_OS_ESP8266
5114 default_result_printer_(nullptr),
5115 default_xml_generator_(nullptr) {}
5124 repeater_->Append(listener);
5131 if (listener == default_result_printer_)
5132 default_result_printer_ =
nullptr;
5133 else if (listener == default_xml_generator_)
5134 default_xml_generator_ =
nullptr;
5135 return repeater_->Release(listener);
5148 if (default_result_printer_ != listener) {
5151 delete Release(default_result_printer_);
5152 default_result_printer_ = listener;
5153 if (listener !=
nullptr)
Append(listener);
5163 if (default_xml_generator_ != listener) {
5166 delete Release(default_xml_generator_);
5167 default_xml_generator_ = listener;
5168 if (listener !=
nullptr)
Append(listener);
5175 return repeater_->forwarding_enabled();
5179 repeater_->set_forwarding_enabled(
false);
5196 #if defined(__BORLANDC__)
5197 static UnitTest*
const instance =
new UnitTest;
5202 #endif // defined(__BORLANDC__)
5207 return impl()->successful_test_suite_count();
5212 return impl()->failed_test_suite_count();
5217 return impl()->total_test_suite_count();
5223 return impl()->test_suite_to_run_count();
5227 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5229 return impl()->successful_test_suite_count();
5232 return impl()->failed_test_suite_count();
5235 return impl()->total_test_suite_count();
5238 return impl()->test_suite_to_run_count();
5240 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5244 return impl()->successful_test_count();
5249 return impl()->skipped_test_count();
5257 return impl()->reportable_disabled_test_count();
5262 return impl()->disabled_test_count();
5267 return impl()->reportable_test_count();
5279 return impl()->start_timestamp();
5284 return impl()->elapsed_time();
5298 return impl()->GetTestSuite(i);
5302 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5304 return impl()->GetTestCase(i);
5306 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5311 return *impl()->ad_hoc_test_result();
5317 return impl()->GetMutableSuiteCase(i);
5323 return *impl()->listeners();
5337 if (
env ==
nullptr) {
5341 impl_->environments().push_back(
env);
5351 const char* file_name,
5359 if (
impl_->gtest_trace_stack().size() > 0) {
5362 for (
size_t i =
impl_->gtest_trace_stack().size(); i > 0; --i) {
5363 const internal::TraceInfo& trace =
impl_->gtest_trace_stack()[
i - 1];
5365 <<
" " << trace.message;
5369 if (os_stack_trace.c_str() !=
nullptr && !os_stack_trace.empty()) {
5373 const TestPartResult
result = TestPartResult(
5375 impl_->GetTestPartResultReporterForCurrentThread()->
5376 ReportTestPartResult(
result);
5386 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
5391 #elif (!defined(__native_client__)) && \
5392 ((defined(__clang__) || defined(__GNUC__)) && \
5393 (defined(__x86_64__) || defined(__i386__)))
5400 *
static_cast<volatile int*
>(
nullptr) = 1;
5401 #endif // GTEST_OS_WINDOWS
5403 #if GTEST_HAS_EXCEPTIONS
5404 throw internal::GoogleTestFailureException(
result);
5430 const bool in_death_test_child_process =
5454 const internal::ScopedPrematureExitFile premature_exit_file(
5455 in_death_test_child_process
5463 #if GTEST_OS_WINDOWS
5468 if (impl()->catch_exceptions() || in_death_test_child_process) {
5469 # if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
5471 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
5472 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
5473 # endif // !GTEST_OS_WINDOWS_MOBILE
5475 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
5479 _set_error_mode(_OUT_TO_STDERR);
5482 # if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
5489 _set_abort_behavior(
5491 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
5497 if (!IsDebuggerPresent()) {
5498 (void)_CrtSetReportMode(_CRT_ASSERT,
5499 _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
5500 (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
5504 #endif // GTEST_OS_WINDOWS
5509 "auxiliary test code (environments or event listeners)") ? 0 : 1;
5515 return impl_->original_working_dir_.c_str();
5523 return impl_->current_test_suite();
5527 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
5531 return impl_->current_test_suite();
5540 return impl_->current_test_info();
5548 internal::ParameterizedTestSuiteRegistry&
5550 return impl_->parameterized_test_registry();
5555 impl_ =
new internal::UnitTestImpl(
this);
5568 impl_->gtest_trace_stack().push_back(trace);
5575 impl_->gtest_trace_stack().pop_back();
5583 default_global_test_part_result_reporter_(this),
5584 default_per_thread_test_part_result_reporter_(this),
5586 &default_global_test_part_result_reporter_),
5587 per_thread_test_part_result_reporter_(
5588 &default_per_thread_test_part_result_reporter_),
5589 parameterized_test_registry_(),
5590 parameterized_tests_registered_(
false),
5591 last_death_test_suite_(-1),
5592 current_test_suite_(nullptr),
5593 current_test_info_(nullptr),
5594 ad_hoc_test_result_(),
5595 os_stack_trace_getter_(nullptr),
5596 post_flag_parse_init_performed_(
false),
5599 start_timestamp_(0),
5601 #
if GTEST_HAS_DEATH_TEST
5602 death_test_factory_(
new DefaultDeathTestFactory),
5605 catch_exceptions_(
false) {
5606 listeners()->SetDefaultResultPrinter(
new PrettyUnitTestResultPrinter);
5629 xml_element =
"testcase";
5632 xml_element =
"testsuite";
5635 xml_element =
"testsuites";
5638 test_result->RecordProperty(xml_element, test_property);
5641 #if GTEST_HAS_DEATH_TEST
5644 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
5645 if (internal_run_death_test_flag_.get() !=
nullptr)
5648 #endif // GTEST_HAS_DEATH_TEST
5654 if (output_format ==
"xml") {
5657 }
else if (output_format ==
"json") {
5660 }
else if (output_format !=
"") {
5662 << output_format <<
"\" ignored.";
5666 #if GTEST_CAN_STREAM_RESULTS_
5669 void UnitTestImpl::ConfigureStreamingOutput() {
5673 if (
pos != std::string::npos) {
5682 #endif // GTEST_CAN_STREAM_RESULTS_
5694 #if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5697 #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
5699 #if GTEST_HAS_DEATH_TEST
5700 InitDeathTestSubprocessControlInfo();
5701 SuppressTestEventsIfInSubprocess();
5702 #endif // GTEST_HAS_DEATH_TEST
5717 #if GTEST_CAN_STREAM_RESULTS_
5719 ConfigureStreamingOutput();
5720 #endif // GTEST_CAN_STREAM_RESULTS_
5727 #endif // GTEST_HAS_ABSL
5739 class TestSuiteNameIs {
5767 const char* test_suite_name,
const char* type_param,
5773 TestSuiteNameIs(test_suite_name));
5778 auto*
const new_test_suite =
5779 new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
5783 if (death_test_suite_filter.MatchesName(test_suite_name)) {
5797 return new_test_suite;
5834 bool in_subprocess_for_death_test =
false;
5836 #if GTEST_HAS_DEATH_TEST
5837 in_subprocess_for_death_test =
5838 (internal_run_death_test_flag_.get() !=
nullptr);
5839 # if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5840 if (in_subprocess_for_death_test) {
5841 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
5843 # endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
5844 #endif // GTEST_HAS_DEATH_TEST
5847 in_subprocess_for_death_test);
5851 const bool has_tests_to_run =
FilterTests(should_shard
5865 bool failed =
false;
5870 repeater->OnTestProgramStart(*
parent_);
5874 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG_GET(repeat);
5877 const bool gtest_repeat_forever = repeat < 0;
5885 const bool recreate_environments_when_repeating =
5887 gtest_repeat_forever;
5889 for (
int i = 0; gtest_repeat_forever ||
i != repeat;
i++) {
5906 repeater->OnTestIterationStart(*
parent_, i);
5909 if (has_tests_to_run) {
5912 if (i == 0 || recreate_environments_when_repeating) {
5913 repeater->OnEnvironmentsSetUpStart(*
parent_);
5915 repeater->OnEnvironmentsSetUpEnd(*
parent_);
5926 const TestPartResult& test_part_result =
5928 if (test_part_result.type() == TestPartResult::kSkip) {
5959 if (i == repeat - 1 || recreate_environments_when_repeating) {
5960 repeater->OnEnvironmentsTearDownStart(*
parent_);
5963 repeater->OnEnvironmentsTearDownEnd(*
parent_);
5970 repeater->OnTestIterationEnd(*
parent_, i);
5991 repeater->OnTestProgramEnd(*
parent_);
5993 if (!gtest_is_initialized_before_run_all_tests) {
5996 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
5998 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
5999 " will start to enforce the valid usage. "
6000 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
6001 #if GTEST_FOR_GOOGLE_
6003 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
6004 #endif // GTEST_FOR_GOOGLE_
6016 if (test_shard_file !=
nullptr) {
6018 if (
file ==
nullptr) {
6020 "Could not write to the test shard status file \"%s\" "
6021 "specified by the %s environment variable.\n",
6037 const char* shard_index_env,
6038 bool in_subprocess_for_death_test) {
6039 if (in_subprocess_for_death_test) {
6046 if (total_shards == -1 && shard_index == -1) {
6048 }
else if (total_shards == -1 && shard_index != -1) {
6050 <<
"Invalid environment variables: you have "
6056 }
else if (total_shards != -1 && shard_index == -1) {
6058 <<
"Invalid environment variables: you have "
6064 }
else if (shard_index < 0 || shard_index >= total_shards) {
6066 <<
"Invalid environment variables: we require 0 <= "
6075 return total_shards > 1;
6083 if (str_val ==
nullptr) {
6100 return (test_id % total_shards) == shard_index;
6116 const PositiveAndNegativeUnitTestFilter gtest_flag_filter(
6123 int num_runnable_tests = 0;
6124 int num_selected_tests = 0;
6130 TestInfo*
const test_info =
test_suite->test_info_list()[
j];
6134 const bool is_disabled =
6135 disable_test_filter.MatchesName(test_suite_name) ||
6136 disable_test_filter.MatchesName(test_name);
6137 test_info->is_disabled_ = is_disabled;
6139 const bool matches_filter =
6140 gtest_flag_filter.MatchesTest(test_suite_name, test_name);
6141 test_info->matches_filter_ = matches_filter;
6143 const bool is_runnable =
6147 const bool is_in_another_shard =
6150 test_info->is_in_another_shard_ = is_in_another_shard;
6151 const bool is_selected = is_runnable && !is_in_another_shard;
6153 num_runnable_tests += is_runnable;
6154 num_selected_tests += is_selected;
6156 test_info->should_run_ = is_selected;
6160 return num_selected_tests;
6168 if (
str !=
nullptr) {
6169 for (
int i = 0; *
str !=
'\0'; ++
str) {
6170 if (
i >= max_length) {
6188 const int kMaxParamLength = 250;
6191 bool printed_test_suite_name =
false;
6193 for (
size_t j = 0; j <
test_suite->test_info_list().
size(); j++) {
6196 if (!printed_test_suite_name) {
6197 printed_test_suite_name =
true;
6220 if (output_format ==
"xml" || output_format ==
"json") {
6223 std::stringstream
stream;
6224 if (output_format ==
"xml") {
6225 XmlUnitTestResultPrinter(
6228 }
else if (output_format ==
"json") {
6229 JsonUnitTestResultPrinter(
6244 OsStackTraceGetterInterface* getter) {
6256 #ifdef GTEST_OS_STACK_TRACE_GETTER_
6260 #endif // GTEST_OS_STACK_TRACE_GETTER_
6323 class ClassUniqueToAlwaysTrue {};
6326 bool IsTrue(
bool condition) {
return condition; }
6329 #if GTEST_HAS_EXCEPTIONS
6333 throw ClassUniqueToAlwaysTrue();
6334 #endif // GTEST_HAS_EXCEPTIONS
6342 const size_t prefix_len = strlen(
prefix);
6343 if (strncmp(*pstr,
prefix, prefix_len) == 0) {
6344 *pstr += prefix_len;
6356 bool def_optional) {
6358 if (
str ==
nullptr || flag_name ==
nullptr)
return nullptr;
6363 const size_t flag_len = flag_str.length();
6364 if (strncmp(
str, flag_str.c_str(), flag_len) != 0)
return nullptr;
6367 const char* flag_end =
str + flag_len;
6370 if (def_optional && (flag_end[0] ==
'\0')) {
6377 if (flag_end[0] !=
'=')
return nullptr;
6380 return flag_end + 1;
6398 if (value_str ==
nullptr)
return false;
6401 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
6414 if (value_str ==
nullptr)
return false;
6425 template <
typename String>
6431 if (value_str ==
nullptr)
return false;
6470 const char* p = strchr(
str,
'@');
6478 const char ch = p[1];
6482 }
else if (
ch ==
'D') {
6484 }
else if (
ch ==
'R') {
6485 color = GTestColor::kRed;
6486 }
else if (
ch ==
'G') {
6487 color = GTestColor::kGreen;
6488 }
else if (
ch ==
'Y') {
6489 color = GTestColor::kYellow;
6497 "This program contains tests written using " GTEST_NAME_
6498 ". You can use the\n"
6499 "following command line flags to control its behavior:\n"
6504 " List the names of all tests instead of running them. The name of\n"
6505 " TEST(Foo, Bar) is \"Foo.Bar\".\n"
6507 "filter=@YPOSITIVE_PATTERNS"
6508 "[@G-@YNEGATIVE_PATTERNS]@D\n"
6509 " Run only the tests whose name matches one of the positive patterns "
6511 " none of the negative patterns. '?' matches any single character; "
6513 " matches any substring; ':' separates two patterns.\n"
6515 "also_run_disabled_tests@D\n"
6516 " Run all disabled tests too.\n"
6520 "repeat=@Y[COUNT]@D\n"
6521 " Run the tests repeatedly; use a negative count to repeat forever.\n"
6524 " Randomize tests' orders on every iteration.\n"
6526 "random_seed=@Y[NUMBER]@D\n"
6527 " Random number seed to use for shuffling test orders (between 1 and\n"
6528 " 99999, or 0 to use a seed based on the current time).\n"
6530 "recreate_environments_when_repeating@D\n"
6531 " Sets up and tears down the global test environment on each repeat\n"
6536 "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
6537 " Enable/disable colored output. The default is @Gauto@D.\n"
6540 " Only print test failures.\n"
6543 " Don't print the elapsed time of each test.\n"
6546 "@Y|@G:@YFILE_PATH]@D\n"
6547 " Generate a JSON or XML report in the given directory or with the "
6549 " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n"
6550 # if GTEST_CAN_STREAM_RESULTS_
6552 "stream_result_to=@YHOST@G:@YPORT@D\n"
6553 " Stream test results to the given server.\n"
6554 # endif // GTEST_CAN_STREAM_RESULTS_
6556 "Assertion Behavior:\n"
6557 # if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
6559 "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
6560 " Set the default death test style.\n"
6561 # endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
6563 "break_on_failure@D\n"
6564 " Turn assertion failures into debugger break-points.\n"
6566 "throw_on_failure@D\n"
6567 " Turn assertion failures into C++ exceptions for use by an external\n"
6568 " test framework.\n"
6570 "catch_exceptions=0@D\n"
6571 " Do not report exceptions as test failures. Instead, allow them\n"
6572 " to crash the program or throw a pop-up (on Windows).\n"
6575 "list_tests@D, you can alternatively set "
6576 "the corresponding\n"
6577 "environment variable of a flag (all letters in upper-case). For example, "
6579 "disable colored text output, you can either specify "
6581 "color=no@D or set\n"
6583 "COLOR@D environment variable to @Gno@D.\n"
6585 "For more information, please read the " GTEST_NAME_
6586 " documentation at\n"
6589 "(not one in your own code or tests), please report it to\n"
6593 #define GTEST_INTERNAL_PARSE_FLAG(flag_name) \
6595 auto value = GTEST_FLAG_GET(flag_name); \
6596 if (ParseFlag(arg, #flag_name, &value)) { \
6597 GTEST_FLAG_SET(flag_name, value); \
6626 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6635 std::vector<std::string>
lines;
6637 for (
size_t i = 0;
i <
lines.size(); ++
i) {
6644 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6649 template <
typename CharType>
6652 for (
int i = 1;
i < *argc;
i++) {
6654 const char*
const arg = arg_string.c_str();
6658 bool remove_flag =
false;
6661 #if GTEST_USE_OWN_FLAGFILE_FLAG_
6662 }
else if (
ParseFlag(
arg,
"flagfile", &flagfile_value)) {
6666 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_
6667 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
6668 arg_string ==
"-?" || arg_string ==
"/?" ||
6680 for (
int j = i;
j != *argc;
j++) {
6681 argv[
j] = argv[
j + 1];
6710 #ifndef GTEST_OS_IOS
6711 if (*_NSGetArgv() == argv) {
6712 *_NSGetArgc() = *argc;
6725 template <
typename CharType>
6730 if (*argc <= 0)
return;
6733 for (
int i = 0;
i != *argc;
i++) {
6739 #endif // GTEST_HAS_ABSL
6757 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6758 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6759 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6761 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6767 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6768 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6769 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6771 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6779 const auto arg0 =
"dummy";
6780 char* argv0 =
const_cast<char*
>(arg0);
6781 char** argv = &argv0;
6783 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6784 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
6785 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6787 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
6791 #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
6792 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
6793 #elif GTEST_OS_WINDOWS_MOBILE
6795 #elif GTEST_OS_WINDOWS
6797 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6799 }
else if (temp_dir[strlen(temp_dir) - 1] ==
'\\') {
6804 #elif GTEST_OS_LINUX_ANDROID
6806 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6807 return "/data/local/tmp/";
6811 #elif GTEST_OS_LINUX
6813 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0') {
6820 #endif // GTEST_OS_WINDOWS_MOBILE
6828 internal::TraceInfo trace;