58 # define GTEST_HAS_GETTIMEOFDAY_ 1 65 # include <sys/mman.h> 66 # include <sys/time.h> 71 # define GTEST_HAS_GETTIMEOFDAY_ 1 72 # include <sys/time.h> 77 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. 82 #elif GTEST_OS_WINDOWS // We are on Windows proper. 92 # include <sys/timeb.h> 93 # include <sys/types.h> 94 # include <sys/stat.h> 96 # if GTEST_OS_WINDOWS_MINGW 98 # define GTEST_HAS_GETTIMEOFDAY_ 1 99 # include <sys/time.h> 100 # endif // GTEST_OS_WINDOWS_MINGW 105 # define GTEST_HAS_GETTIMEOFDAY_ 1 109 # include <sys/time.h> 112 #endif // GTEST_OS_LINUX 114 #if GTEST_HAS_EXCEPTIONS 115 # include <stdexcept> 118 #if GTEST_CAN_STREAM_RESULTS_ 119 # include <arpa/inet.h> 121 # include <sys/socket.h> 122 # include <sys/types.h> 128 # define vsnprintf _vsnprintf 129 #endif // GTEST_OS_WINDOWS 133 #include <crt_externs.h> 138 #include "absl/debugging/failure_signal_handler.h" 139 #include "absl/debugging/stacktrace.h" 140 #include "absl/debugging/symbolize.h" 141 #include "absl/strings/str_cat.h" 142 #endif // GTEST_HAS_ABSL 146 using internal::CountIf;
147 using internal::ForEach;
148 using internal::GetElementOr;
149 using internal::Shuffle;
189 FILE* fileout =
nullptr;
190 FilePath output_file_path(output_file);
191 FilePath output_dir(output_file_path.RemoveFileName());
193 if (output_dir.CreateDirectoriesRecursively()) {
196 if (fileout ==
nullptr) {
197 GTEST_LOG_(FATAL) <<
"Unable to open file \"" << output_file <<
"\"";
207 const char*
const testbridge_test_only =
209 if (testbridge_test_only !=
nullptr) {
210 return testbridge_test_only;
218 const char*
const testbridge_test_runner_fail_fast =
220 if (testbridge_test_runner_fail_fast !=
nullptr) {
221 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.");
237 "True if and only if a failed assertion should be a debugger " 243 " should catch exceptions and treat them as test failures.");
248 "Whether to use colors in the output. Valid values: yes, no, " 249 "and auto. 'auto' means to use colors if the output is " 250 "being sent to a terminal and the TERM environment variable " 251 "is set to a terminal type that supports colors.");
256 "A colon-separated list of glob (not regex) patterns " 257 "for filtering the tests to run, optionally followed by a " 258 "'-' and a : separated list of negative patterns (tests to " 259 "exclude). A test is run if it matches one of the positive " 260 "patterns and does not match any of the negative patterns.");
263 install_failure_signal_handler,
265 "If true and supported on the current platform, " GTEST_NAME_ " should " 266 "install a signal handler that dumps debugging information when fatal " 267 "signals are raised.");
270 "List all tests without running them.");
281 "A format (defaults to \"xml\" but can be specified to be \"json\"), " 282 "optionally followed by a colon and an output file name or directory. " 283 "A directory is indicated by a trailing pathname separator. " 284 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". " 285 "If a directory is specified, output files will be created " 286 "within that directory, with file-names based on the test " 287 "executable's name and, if necessary, made unique by adding " 292 "True if only test failures should be displayed in text output.");
296 " should display elapsed time in text output.");
300 " prints UTF8 characters as text.");
305 "Random number seed to use when shuffling test orders. Must be in range " 306 "[1, 99999], or 0 to use a seed based on the current time.");
311 "How many times to repeat each test. Specify a negative number " 312 "for repeating forever. Useful for shaking out flaky tests.");
316 " should include internal stack frames when " 317 "printing test failure stack traces.");
321 " should randomize tests' order on every run.");
326 "The maximum number of stack frames to print when an " 327 "assertion fails. The valid range is 0 through 100, inclusive.");
332 "This flag specifies the host name and the port number on which to stream " 333 "test results. Example: \"localhost:555\". The flag is effective only on " 339 "When this flag is specified, a failed assertion will throw an exception " 340 "if exceptions are enabled or exit the program with a non-zero code " 341 "otherwise. For use with an external test framework.");
343 #if GTEST_USE_OWN_FLAGFILE_FLAG_ 347 "This flag specifies the flagfile to read command-line flags from.");
348 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ 361 <<
"Cannot generate a number in the range [0, 0).";
363 <<
"Generation of a number in [0, " << range <<
") was requested, " 364 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
383 for (
size_t i = 0;
i < case_list.size();
i++) {
384 sum += (case_list[
i]->*method)();
423 ->CurrentOsStackTraceExceptTop(1)
435 constexpr
bool kErrorOnUninstantiatedParameterizedTest =
true;
436 constexpr
bool kErrorOnUninstantiatedTypeParameterizedTest =
true;
439 class FailureTest :
public Test {
441 explicit FailureTest(
const CodeLocation& loc, std::string error_message,
447 void TestBody()
override {
449 AssertHelper(TestPartResult::kNonFatalFailure,
loc_.file.c_str(),
479 if (ignored.find(name) != ignored.end())
return;
481 const char kMissingInstantiation[] =
482 " is defined via TEST_P, but never instantiated. None of the test cases " 483 "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only " 484 "ones provided expand to nothing." 486 "Ideally, TEST_P definitions should only ever be included as part of " 487 "binaries that intend to use them. (As opposed to, for example, being " 488 "placed in a library that may be linked in to get other utilities.)";
490 const char kMissingTestCase[] =
491 " is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are " 492 "defined via TEST_P . No test cases will run." 494 "Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from " 495 "code that always depend on code that provides TEST_P. Failing to do " 496 "so is often an indication of dead code, e.g. the last TEST_P was " 497 "removed but the rest got left behind.";
499 std::string message =
500 "Parameterized test suite " + name +
501 (has_test_p ? kMissingInstantiation : kMissingTestCase) +
503 "To suppress this error for this test suite, insert the following line " 504 "(in a non-header) in the namespace it is defined in:" 506 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + name +
");";
508 std::string full_name =
"UninstantiatedParameterizedTestSuite<" + name +
">";
510 "GoogleTestVerification", full_name.c_str(),
513 location.
file.c_str(), location.
line, [message, location] {
514 return new FailureTest(location, message,
515 kErrorOnUninstantiatedParameterizedTest);
521 GetUnitTestImpl()->type_parameterized_test_registry().RegisterTestSuite(
522 test_suite_name, code_location);
527 ->type_parameterized_test_registry()
528 .RegisterInstantiation(case_name);
532 const char* test_suite_name,
CodeLocation code_location) {
533 suites_.emplace(std::string(test_suite_name),
538 const char* test_suite_name) {
539 auto it =
suites_.find(std::string(test_suite_name));
541 it->second.instantiated =
true;
543 GTEST_LOG_(ERROR) <<
"Unknown type parameterized test suit '" 544 << test_suite_name <<
"'";
550 for (
const auto& testcase :
suites_) {
551 if (testcase.second.instantiated)
continue;
552 if (ignored.find(testcase.first) != ignored.end())
continue;
554 std::string message =
555 "Type parameterized test suite " + testcase.first +
556 " is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated " 557 "via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run." 559 "Ideally, TYPED_TEST_P definitions should only ever be included as " 560 "part of binaries that intend to use them. (As opposed to, for " 561 "example, being placed in a library that may be linked in to get other " 564 "To suppress this error for this test suite, insert the following line " 565 "(in a non-header) in the namespace it is definedin in:" 567 "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" +
568 testcase.first +
");";
570 std::string full_name =
571 "UninstantiatedTypeParameterizedTestSuite<" + testcase.first +
">";
573 "GoogleTestVerification", full_name.c_str(),
576 testcase.second.code_location.file.c_str(),
577 testcase.second.code_location.line, [message, testcase] {
578 return new FailureTest(testcase.second.code_location, message,
579 kErrorOnUninstantiatedTypeParameterizedTest);
588 #if defined(GTEST_CUSTOM_GET_ARGVS_) 591 const auto& custom = GTEST_CUSTOM_GET_ARGVS_();
592 return ::std::vector<std::string>(custom.begin(), custom.end());
593 #else // defined(GTEST_CUSTOM_GET_ARGVS_) 595 #endif // defined(GTEST_CUSTOM_GET_ARGVS_) 603 #if GTEST_OS_WINDOWS || GTEST_OS_OS2 604 result.Set(FilePath(
GetArgvs()[0]).RemoveExtension(
"exe"));
606 result.Set(FilePath(
GetArgvs()[0]));
607 #endif // GTEST_OS_WINDOWS 609 return result.RemoveDirectoryName();
615 std::string UnitTestOptions::GetOutputFormat() {
616 const char*
const gtest_output_flag =
GTEST_FLAG(output).c_str();
617 const char*
const colon = strchr(gtest_output_flag,
':');
618 return (colon ==
nullptr)
619 ? std::string(gtest_output_flag)
620 :
std::string(gtest_output_flag,
621 static_cast<size_t>(colon - gtest_output_flag));
626 std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
627 const char*
const gtest_output_flag =
GTEST_FLAG(output).c_str();
629 std::string format = GetOutputFormat();
633 const char*
const colon = strchr(gtest_output_flag,
':');
634 if (colon ==
nullptr)
635 return internal::FilePath::MakeFileName(
639 format.c_str()).
string();
641 internal::FilePath output_name(colon + 1);
642 if (!output_name.IsAbsolutePath())
643 output_name = internal::FilePath::ConcatPaths(
645 internal::FilePath(colon + 1));
647 if (!output_name.IsDirectory())
648 return output_name.string();
650 internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
652 GetOutputFormat().c_str()));
653 return result.string();
661 bool UnitTestOptions::PatternMatchesString(
const char *pattern,
668 return *str !=
'\0' && PatternMatchesString(pattern + 1, str + 1);
670 return (*str !=
'\0' && PatternMatchesString(pattern, str + 1)) ||
671 PatternMatchesString(pattern + 1, str);
673 return *pattern == *str &&
674 PatternMatchesString(pattern + 1, str + 1);
678 bool UnitTestOptions::MatchesFilter(
679 const std::string& name,
const char* filter) {
680 const char *cur_pattern = filter;
682 if (PatternMatchesString(cur_pattern, name.c_str())) {
687 cur_pattern = strchr(cur_pattern,
':');
690 if (cur_pattern ==
nullptr) {
701 bool UnitTestOptions::FilterMatchesTest(
const std::string& test_suite_name,
702 const std::string& test_name) {
703 const std::string& full_name = test_suite_name +
"." + test_name.c_str();
708 const char*
const dash = strchr(
p,
'-');
709 std::string positive;
710 std::string negative;
711 if (dash ==
nullptr) {
715 positive = std::string(
p, dash);
716 negative = std::string(dash + 1);
717 if (positive.empty()) {
725 return (MatchesFilter(full_name, positive.c_str()) &&
726 !MatchesFilter(full_name, negative.c_str()));
733 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
742 const DWORD kCxxExceptionCode = 0xe06d7363;
744 bool should_handle =
true;
747 should_handle =
false;
748 else if (exception_code == EXCEPTION_BREAKPOINT)
749 should_handle =
false;
750 else if (exception_code == kCxxExceptionCode)
751 should_handle =
false;
753 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
755 #endif // GTEST_HAS_SEH 762 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
763 TestPartResultArray* result)
764 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
772 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
773 InterceptMode intercept_mode, TestPartResultArray* result)
774 : intercept_mode_(intercept_mode),
779 void ScopedFakeTestPartResultReporter::Init() {
780 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
781 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
782 old_reporter_ = impl->GetGlobalTestPartResultReporter();
783 impl->SetGlobalTestPartResultReporter(
this);
785 old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
786 impl->SetTestPartResultReporterForCurrentThread(
this);
792 ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
793 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
794 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
795 impl->SetGlobalTestPartResultReporter(old_reporter_);
797 impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
803 void ScopedFakeTestPartResultReporter::ReportTestPartResult(
804 const TestPartResult& result) {
805 result_->Append(result);
820 return GetTypeId<Test>();
833 const TestPartResultArray& results,
834 TestPartResult::Type type,
835 const std::string& substr) {
836 const std::string
expected(type == TestPartResult::kFatalFailure ?
838 "1 non-fatal failure");
840 if (results.size() != 1) {
841 msg <<
"Expected: " <<
expected <<
"\n" 842 <<
" Actual: " << results.size() <<
" failures";
843 for (
int i = 0;
i < results.size();
i++) {
844 msg <<
"\n" << results.GetTestPartResult(
i);
849 const TestPartResult& r = results.GetTestPartResult(0);
850 if (r.type() != type) {
856 if (strstr(r.message(), substr.c_str()) ==
nullptr) {
869 SingleFailureChecker::SingleFailureChecker(
const TestPartResultArray* results,
870 TestPartResult::Type type,
871 const std::string& substr)
872 : results_(results), type_(type), substr_(substr) {}
878 SingleFailureChecker::~SingleFailureChecker() {
882 DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
883 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
885 void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
886 const TestPartResult& result) {
887 unit_test_->current_test_result()->AddTestPartResult(result);
888 unit_test_->listeners()->repeater()->OnTestPartResult(result);
891 DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
892 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
894 void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
895 const TestPartResult& result) {
896 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
900 TestPartResultReporterInterface*
901 UnitTestImpl::GetGlobalTestPartResultReporter() {
903 return global_test_part_result_repoter_;
907 void UnitTestImpl::SetGlobalTestPartResultReporter(
908 TestPartResultReporterInterface* reporter) {
910 global_test_part_result_repoter_ = reporter;
914 TestPartResultReporterInterface*
915 UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
916 return per_thread_test_part_result_reporter_.get();
920 void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
921 TestPartResultReporterInterface* reporter) {
922 per_thread_test_part_result_reporter_.set(reporter);
926 int UnitTestImpl::successful_test_suite_count()
const {
931 int UnitTestImpl::failed_test_suite_count()
const {
936 int UnitTestImpl::total_test_suite_count()
const {
937 return static_cast<int>(test_suites_.size());
942 int UnitTestImpl::test_suite_to_run_count()
const {
947 int UnitTestImpl::successful_test_count()
const {
952 int UnitTestImpl::skipped_test_count()
const {
957 int UnitTestImpl::failed_test_count()
const {
962 int UnitTestImpl::reportable_disabled_test_count()
const {
968 int UnitTestImpl::disabled_test_count()
const {
973 int UnitTestImpl::reportable_test_count()
const {
978 int UnitTestImpl::total_test_count()
const {
983 int UnitTestImpl::test_to_run_count()
const {
997 std::string UnitTestImpl::CurrentOsStackTraceExceptTop(
int skip_count) {
998 return os_stack_trace_getter()->CurrentStackTrace(
999 static_cast<int>(
GTEST_FLAG(stack_trace_depth)),
1008 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) 1013 const DWORD kTenthMicrosInMilliSecond = 10000;
1015 SYSTEMTIME now_systime;
1016 FILETIME now_filetime;
1017 ULARGE_INTEGER now_int64;
1018 GetSystemTime(&now_systime);
1019 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
1020 now_int64.LowPart = now_filetime.dwLowDateTime;
1021 now_int64.HighPart = now_filetime.dwHighDateTime;
1022 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
1023 kJavaEpochToWinFileTimeDelta;
1024 return now_int64.QuadPart;
1027 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ 1036 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
1039 gettimeofday(&now,
nullptr);
1040 return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
1042 # error
"Don't know how to get the current time on your system." 1050 #if GTEST_OS_WINDOWS_MOBILE 1055 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
1056 if (!ansi)
return nullptr;
1057 const int length = strlen(ansi);
1058 const int unicode_length =
1059 MultiByteToWideChar(CP_ACP, 0, ansi, length,
nullptr, 0);
1060 WCHAR* unicode =
new WCHAR[unicode_length + 1];
1061 MultiByteToWideChar(CP_ACP, 0, ansi, length,
1062 unicode, unicode_length);
1063 unicode[unicode_length] = 0;
1071 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
1072 if (!utf16_str)
return nullptr;
1073 const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
nullptr,
1074 0,
nullptr,
nullptr);
1075 char* ansi =
new char[ansi_length + 1];
1076 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length,
nullptr,
1078 ansi[ansi_length] = 0;
1082 #endif // GTEST_OS_WINDOWS_MOBILE 1090 bool String::CStringEquals(
const char * lhs,
const char * rhs) {
1091 if (lhs ==
nullptr)
return rhs ==
nullptr;
1093 if (rhs ==
nullptr)
return false;
1095 return strcmp(lhs, rhs) == 0;
1098 #if GTEST_HAS_STD_WSTRING 1102 static void StreamWideCharsToMessage(
const wchar_t* wstr,
size_t length,
1104 for (
size_t i = 0;
i != length; ) {
1105 if (wstr[
i] != L
'\0') {
1106 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length -
i));
1107 while (
i != length && wstr[
i] != L
'\0')
1116 #endif // GTEST_HAS_STD_WSTRING 1119 ::std::vector< ::std::string>* dest) {
1120 ::std::vector< ::std::string> parsed;
1121 ::std::string::size_type pos = 0;
1123 const ::std::string::size_type colon = str.find(delimiter, pos);
1124 if (colon == ::std::string::npos) {
1125 parsed.push_back(str.substr(pos));
1128 parsed.push_back(str.substr(pos, colon - pos));
1142 Message::Message() : ss_(new ::
std::stringstream) {
1145 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
1157 #if GTEST_HAS_STD_WSTRING 1161 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
1164 #endif // GTEST_HAS_STD_WSTRING 1174 AssertionResult::AssertionResult(
const AssertionResult& other)
1175 : success_(other.success_),
1176 message_(other.message_.get() != nullptr
1177 ? new ::
std::string(*other.message_)
1178 : static_cast< ::
std::string*>(nullptr)) {}
1181 void AssertionResult::swap(AssertionResult& other) {
1183 swap(success_, other.success_);
1184 swap(message_, other.message_);
1189 AssertionResult negation(!success_);
1190 if (message_.get() !=
nullptr) negation << *message_;
1196 return AssertionResult(
true);
1201 return AssertionResult(
false);
1210 namespace internal {
1212 namespace edit_distance {
1214 const std::vector<size_t>& right) {
1215 std::vector<std::vector<double> > costs(
1216 left.size() + 1, std::vector<double>(right.size() + 1));
1217 std::vector<std::vector<EditType> > best_move(
1218 left.size() + 1, std::vector<EditType>(right.size() + 1));
1221 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1222 costs[l_i][0] =
static_cast<double>(l_i);
1226 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1227 costs[0][r_i] =
static_cast<double>(r_i);
1228 best_move[0][r_i] =
kAdd;
1231 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1232 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1233 if (left[l_i] == right[r_i]) {
1235 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1236 best_move[l_i + 1][r_i + 1] =
kMatch;
1240 const double add = costs[l_i + 1][r_i];
1241 const double remove = costs[l_i][r_i + 1];
1242 const double replace = costs[l_i][r_i];
1243 if (add <
remove && add < replace) {
1244 costs[l_i + 1][r_i + 1] = add + 1;
1245 best_move[l_i + 1][r_i + 1] =
kAdd;
1246 }
else if (
remove < add &&
remove < replace) {
1247 costs[l_i + 1][r_i + 1] =
remove + 1;
1248 best_move[l_i + 1][r_i + 1] =
kRemove;
1252 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1253 best_move[l_i + 1][r_i + 1] =
kReplace;
1259 std::vector<EditType> best_path;
1260 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1261 EditType move = best_move[l_i][r_i];
1262 best_path.push_back(move);
1263 l_i -= move !=
kAdd;
1266 std::reverse(best_path.begin(), best_path.end());
1273 class InternalStrings {
1275 size_t GetId(
const std::string& str) {
1276 IdMap::iterator it =
ids_.find(str);
1277 if (it !=
ids_.end())
return it->second;
1278 size_t id =
ids_.size();
1279 return ids_[str] = id;
1283 typedef std::map<std::string, size_t> IdMap;
1290 const std::vector<std::string>& left,
1291 const std::vector<std::string>& right) {
1292 std::vector<size_t> left_ids, right_ids;
1294 InternalStrings intern_table;
1295 for (
size_t i = 0;
i < left.size(); ++
i) {
1296 left_ids.push_back(intern_table.GetId(left[
i]));
1298 for (
size_t i = 0;
i < right.size(); ++
i) {
1299 right_ids.push_back(intern_table.GetId(right[
i]));
1313 Hunk(
size_t left_start,
size_t right_start)
1320 void PushLine(
char edit,
const char* line) {
1325 hunk_.push_back(std::make_pair(
' ', line));
1333 hunk_adds_.push_back(std::make_pair(
'+', line));
1338 void PrintTo(std::ostream* os) {
1341 for (std::list<std::pair<char, const char*> >::const_iterator it =
1343 it !=
hunk_.end(); ++it) {
1344 *os << it->first << it->second <<
"\n";
1360 void PrintHeader(std::ostream* ss)
const {
1389 const std::vector<std::string>& right,
1393 size_t l_i = 0, r_i = 0, edit_i = 0;
1394 std::stringstream ss;
1395 while (edit_i < edits.size()) {
1397 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1404 const size_t prefix_context =
std::min(l_i, context);
1405 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1406 for (
size_t i = prefix_context;
i > 0; --
i) {
1407 hunk.PushLine(
' ', left[l_i -
i].c_str());
1412 size_t n_suffix = 0;
1413 for (; edit_i < edits.size(); ++edit_i) {
1414 if (n_suffix >= context) {
1416 auto it = edits.begin() +
static_cast<int>(edit_i);
1417 while (it != edits.end() && *it ==
kMatch) ++it;
1418 if (it == edits.end() ||
1419 static_cast<size_t>(it - edits.begin()) - edit_i >= context) {
1427 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1430 hunk.PushLine(edit ==
kMatch ?
' ' :
'-', left[l_i].c_str());
1433 hunk.PushLine(
'+', right[r_i].c_str());
1437 l_i += edit !=
kAdd;
1441 if (!hunk.has_edits()) {
1458 std::vector<std::string> SplitEscapedString(
const std::string& str) {
1459 std::vector<std::string> lines;
1460 size_t start = 0, end = str.size();
1461 if (end > 2 && str[0] ==
'"' && str[end - 1] ==
'"') {
1465 bool escaped =
false;
1466 for (
size_t i = start;
i + 1 < end; ++
i) {
1469 if (str[
i] ==
'n') {
1470 lines.push_back(str.substr(start,
i - start - 1));
1474 escaped = str[
i] ==
'\\';
1477 lines.push_back(str.substr(start, end - start));
1499 const char* rhs_expression,
1500 const std::string& lhs_value,
1501 const std::string& rhs_value,
1502 bool ignoring_case) {
1504 msg <<
"Expected equality of these values:";
1505 msg <<
"\n " << lhs_expression;
1506 if (lhs_value != lhs_expression) {
1507 msg <<
"\n Which is: " << lhs_value;
1509 msg <<
"\n " << rhs_expression;
1510 if (rhs_value != rhs_expression) {
1511 msg <<
"\n Which is: " << rhs_value;
1514 if (ignoring_case) {
1515 msg <<
"\nIgnoring case";
1518 if (!lhs_value.empty() && !rhs_value.empty()) {
1519 const std::vector<std::string> lhs_lines =
1520 SplitEscapedString(lhs_value);
1521 const std::vector<std::string> rhs_lines =
1522 SplitEscapedString(rhs_value);
1523 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1524 msg <<
"\nWith diff:\n" 1534 const AssertionResult& assertion_result,
1535 const char* expression_text,
1536 const char* actual_predicate_value,
1537 const char* expected_predicate_value) {
1538 const char* actual_message = assertion_result.message();
1540 msg <<
"Value of: " << expression_text
1541 <<
"\n Actual: " << actual_predicate_value;
1542 if (actual_message[0] !=
'\0')
1543 msg <<
" (" << actual_message <<
")";
1544 msg <<
"\nExpected: " << expected_predicate_value;
1551 const char* abs_error_expr,
1555 const double diff =
fabs(val1 - val2);
1559 <<
"The difference between " << expr1 <<
" and " << expr2
1560 <<
" is " <<
diff <<
", which exceeds " << abs_error_expr <<
", where\n" 1561 << expr1 <<
" evaluates to " << val1 <<
",\n" 1562 << expr2 <<
" evaluates to " << val2 <<
", and\n" 1563 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1568 template <
typename RawType>
1580 if (lhs.AlmostEquals(rhs)) {
1588 ::std::stringstream val1_ss;
1589 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1592 ::std::stringstream val2_ss;
1593 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1597 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n" 1606 AssertionResult
FloatLE(
const char* expr1,
const char* expr2,
1607 float val1,
float val2) {
1608 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1613 AssertionResult
DoubleLE(
const char* expr1,
const char* expr2,
1614 double val1,
double val2) {
1615 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1618 namespace internal {
1623 const char* rhs_expression,
1640 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\ 1641 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ 1642 BiggestInt val1, BiggestInt val2) {\ 1643 if (val1 op val2) {\ 1644 return AssertionSuccess();\ 1646 return AssertionFailure() \ 1647 << "Expected: (" << expr1 << ") " #op " (" << expr2\ 1648 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ 1649 << " vs " << FormatForComparisonFailureMessage(val2, val1);\ 1669 #undef GTEST_IMPL_CMP_HELPER_ 1673 const char* rhs_expression,
1689 const char* rhs_expression,
1705 const char* s2_expression,
1712 << s2_expression <<
"), actual: \"" 1713 << s1 <<
"\" vs \"" << s2 <<
"\"";
1719 const char* s2_expression,
1726 <<
"Expected: (" << s1_expression <<
") != (" 1727 << s2_expression <<
") (ignoring case), actual: \"" 1728 << s1 <<
"\" vs \"" << s2 <<
"\"";
1742 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1743 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1745 return strstr(haystack, needle) !=
nullptr;
1748 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1749 if (needle ==
nullptr || haystack ==
nullptr)
return needle == haystack;
1751 return wcsstr(haystack, needle) !=
nullptr;
1755 template <
typename StringType>
1756 bool IsSubstringPred(
const StringType& needle,
1757 const StringType& haystack) {
1758 return haystack.find(needle) != StringType::npos;
1765 template <
typename StringType>
1766 AssertionResult IsSubstringImpl(
1767 bool expected_to_be_substring,
1768 const char* needle_expr,
const char* haystack_expr,
1769 const StringType& needle,
const StringType& haystack) {
1770 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1773 const bool is_wide_string =
sizeof(needle[0]) > 1;
1774 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1776 <<
"Value of: " << needle_expr <<
"\n" 1777 <<
" Actual: " << begin_string_quote << needle <<
"\"\n" 1778 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1779 <<
"a substring of " << haystack_expr <<
"\n" 1780 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1790 const char* needle_expr,
const char* haystack_expr,
1791 const char* needle,
const char* haystack) {
1792 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1796 const char* needle_expr,
const char* haystack_expr,
1797 const wchar_t* needle,
const wchar_t* haystack) {
1798 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1802 const char* needle_expr,
const char* haystack_expr,
1803 const char* needle,
const char* haystack) {
1804 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1808 const char* needle_expr,
const char* haystack_expr,
1809 const wchar_t* needle,
const wchar_t* haystack) {
1810 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1814 const char* needle_expr,
const char* haystack_expr,
1815 const ::std::string& needle, const ::std::string& haystack) {
1816 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1820 const char* needle_expr,
const char* haystack_expr,
1821 const ::std::string& needle, const ::std::string& haystack) {
1822 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1825 #if GTEST_HAS_STD_WSTRING 1827 const char* needle_expr,
const char* haystack_expr,
1828 const ::std::wstring& needle, const ::std::wstring& haystack) {
1829 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1833 const char* needle_expr,
const char* haystack_expr,
1834 const ::std::wstring& needle, const ::std::wstring& haystack) {
1835 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1837 #endif // GTEST_HAS_STD_WSTRING 1839 namespace internal {
1841 #if GTEST_OS_WINDOWS 1846 AssertionResult HRESULTFailureHelper(
const char* expr,
1849 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE 1852 const char error_text[] =
"";
1859 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1860 FORMAT_MESSAGE_IGNORE_INSERTS;
1861 const DWORD kBufSize = 4096;
1863 char error_text[kBufSize] = {
'\0' };
1864 DWORD message_length = ::FormatMessageA(kFlags,
1866 static_cast<DWORD>(hr),
1872 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1874 error_text[message_length - 1] =
'\0';
1877 # endif // GTEST_OS_WINDOWS_MOBILE 1881 <<
"Expected: " << expr <<
" " <<
expected <<
".\n" 1882 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1887 AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1888 if (SUCCEEDED(hr)) {
1891 return HRESULTFailureHelper(expr,
"succeeds", hr);
1894 AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1898 return HRESULTFailureHelper(expr,
"fails", hr);
1901 #endif // GTEST_OS_WINDOWS 1931 const uint32_t low_bits = *bits & ((
static_cast<uint32_t
>(1) << n) - 1);
1950 str[0] =
static_cast<char>(code_point);
1953 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1954 str[0] =
static_cast<char>(0xC0 | code_point);
1957 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1958 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1959 str[0] =
static_cast<char>(0xE0 | code_point);
1962 str[3] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1963 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1964 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1965 str[0] =
static_cast<char>(0xF0 | code_point);
1978 return sizeof(wchar_t) == 2 &&
1979 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1985 const auto first_u =
static_cast<uint32_t
>(first);
1986 const auto second_u =
static_cast<uint32_t
>(second);
1987 const uint32_t mask = (1 << 10) - 1;
1988 return (
sizeof(
wchar_t) == 2)
1989 ? (((first_u & mask) << 10) | (second_u & mask)) + 0x10000
2010 if (num_chars == -1)
2011 num_chars =
static_cast<int>(wcslen(str));
2013 ::std::stringstream stream;
2014 for (
int i = 0;
i < num_chars; ++
i) {
2015 uint32_t unicode_code_point;
2017 if (str[
i] == L
'\0') {
2024 unicode_code_point =
static_cast<uint32_t
>(str[
i]);
2035 if (wide_c_str ==
nullptr)
return "(null)";
2047 if (lhs ==
nullptr)
return rhs ==
nullptr;
2049 if (rhs ==
nullptr)
return false;
2051 return wcscmp(lhs, rhs) == 0;
2056 const char* rhs_expression,
2058 const wchar_t* rhs) {
2072 const char* s2_expression,
2074 const wchar_t* s2) {
2080 << s2_expression <<
"), actual: " 2092 if (lhs ==
nullptr)
return rhs ==
nullptr;
2093 if (rhs ==
nullptr)
return false;
2110 const wchar_t* rhs) {
2111 if (lhs ==
nullptr)
return rhs ==
nullptr;
2113 if (rhs ==
nullptr)
return false;
2115 #if GTEST_OS_WINDOWS 2116 return _wcsicmp(lhs, rhs) == 0;
2117 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID 2118 return wcscasecmp(lhs, rhs) == 0;
2124 left = towlower(static_cast<wint_t>(*lhs++));
2125 right = towlower(static_cast<wint_t>(*rhs++));
2126 }
while (left && left == right);
2127 return left == right;
2128 #endif // OS selector 2134 const std::string& str,
const std::string& suffix) {
2135 const size_t str_len = str.length();
2136 const size_t suffix_len = suffix.length();
2137 return (str_len >= suffix_len) &&
2144 std::stringstream ss;
2145 ss << std::setfill(
'0') << std::setw(2) <<
value;
2151 std::stringstream ss;
2152 ss << std::hex << std::uppercase <<
value;
2163 std::stringstream ss;
2164 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
2165 <<
static_cast<unsigned int>(
value);
2172 const ::std::string& str = ss->str();
2173 const char*
const start = str.c_str();
2174 const char*
const end = start + str.length();
2177 result.reserve(static_cast<size_t>(2 * (end - start)));
2178 for (
const char*
ch = start;
ch != end; ++
ch) {
2193 const std::string user_msg_string = user_msg.
GetString();
2194 if (user_msg_string.empty()) {
2197 if (gtest_msg.empty()) {
2198 return user_msg_string;
2200 return gtest_msg +
"\n" + user_msg_string;
2209 : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
2252 const std::vector<TestProperty>::iterator property_with_matching_key =
2254 internal::TestPropertyKeyIs(test_property.
key()));
2259 property_with_matching_key->SetValue(test_property.
value());
2278 "disabled",
"errors",
"failures",
"name",
2279 "tests",
"time",
"timestamp",
"skipped"};
2283 "classname",
"name",
"status",
"time",
"type_param",
2284 "value_param",
"file",
"line"};
2289 "classname",
"name",
"status",
"time",
"type_param",
2290 "value_param",
"file",
"line",
"result",
"timestamp"};
2292 template <
size_t kSize>
2294 return std::vector<std::string>(array, array + kSize);
2298 const std::string& xml_element) {
2299 if (xml_element ==
"testsuites") {
2301 }
else if (xml_element ==
"testsuite") {
2303 }
else if (xml_element ==
"testcase") {
2306 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2309 return std::vector<std::string>();
2314 const std::string& xml_element) {
2315 if (xml_element ==
"testsuites") {
2317 }
else if (xml_element ==
"testsuite") {
2319 }
else if (xml_element ==
"testcase") {
2322 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2325 return std::vector<std::string>();
2330 for (
size_t i = 0;
i < words.size(); ++
i) {
2331 if (
i > 0 && words.size() > 2) {
2334 if (
i == words.size() - 1) {
2335 word_list <<
"and ";
2337 word_list <<
"'" << words[
i] <<
"'";
2343 const std::string& property_name,
2344 const std::vector<std::string>& reserved_names) {
2345 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
2346 reserved_names.end()) {
2347 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2373 return result.skipped();
2392 return result.fatally_failed();
2402 return result.nonfatally_failed();
2456 value_message <<
value;
2460 namespace internal {
2463 const std::string& message) {
2482 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2483 const TestSuite*
const test_suite = impl->current_test_suite();
2488 const char*
const first_test_name = first_test_info->
name();
2491 const TestInfo*
const this_test_info = impl->current_test_info();
2493 const char*
const this_test_name = this_test_info->
name();
2495 if (this_fixture_id != first_fixture_id) {
2501 if (first_is_TEST || this_is_TEST) {
2508 const char*
const TEST_name =
2509 first_is_TEST ? first_test_name : this_test_name;
2510 const char*
const TEST_F_name =
2511 first_is_TEST ? this_test_name : first_test_name;
2514 <<
"All tests in the same test suite must use the same test fixture\n" 2515 <<
"class, so mixing TEST_F and TEST in the same test suite is\n" 2518 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n" 2519 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n" 2520 <<
"want to change the TEST to TEST_F or move it to another test\n" 2526 <<
"All tests in the same test suite must use the same test fixture\n" 2527 <<
"class. However, in test suite " 2529 <<
"you defined test " << first_test_name <<
" and test " 2530 << this_test_name <<
"\n" 2531 <<
"using two different test fixture classes. This can happen if\n" 2532 <<
"the two classes are from different namespaces or translation\n" 2533 <<
"units and have the same name. You should probably rename one\n" 2534 <<
"of the classes to put the tests into different test suites.";
2548 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2549 const char* location) {
2551 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2552 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2554 return new std::string(message.
GetString());
2557 #endif // GTEST_HAS_SEH 2559 namespace internal {
2561 #if GTEST_HAS_EXCEPTIONS 2564 static std::string FormatCxxExceptionMessage(
const char* description,
2565 const char* location) {
2567 if (description !=
nullptr) {
2568 message <<
"C++ exception with description \"" << description <<
"\"";
2570 message <<
"Unknown C++ exception";
2572 message <<
" thrown in " << location <<
".";
2578 const TestPartResult& test_part_result);
2580 GoogleTestFailureException::GoogleTestFailureException(
2581 const TestPartResult& failure)
2584 #endif // GTEST_HAS_EXCEPTIONS 2594 template <
class T,
typename Result>
2596 T*
object, Result (
T::*method)(),
const char* location) {
2599 return (object->*method)();
2600 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2601 GetExceptionCode())) {
2605 std::string* exception_message = FormatSehExceptionMessage(
2606 GetExceptionCode(), location);
2608 *exception_message);
2609 delete exception_message;
2610 return static_cast<Result
>(0);
2614 return (object->*method)();
2615 #endif // GTEST_HAS_SEH 2621 template <
class T,
typename Result>
2623 T*
object, Result (
T::*method)(),
const char* location) {
2647 if (internal::GetUnitTestImpl()->catch_exceptions()) {
2648 #if GTEST_HAS_EXCEPTIONS 2651 }
catch (
const AssertionException&) {
2653 }
catch (
const internal::GoogleTestFailureException&) {
2658 }
catch (
const std::exception& e) {
2660 TestPartResult::kFatalFailure,
2661 FormatCxxExceptionMessage(e.what(), location));
2664 TestPartResult::kFatalFailure,
2665 FormatCxxExceptionMessage(
nullptr, location));
2667 return static_cast<Result
>(0);
2670 #endif // GTEST_HAS_EXCEPTIONS 2672 return (object->*method)();
2680 if (!HasSameFixtureClass())
return;
2682 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2683 impl->os_stack_trace_getter()->UponLeavingGTest();
2687 if (!HasFatalFailure() && !IsSkipped()) {
2688 impl->os_stack_trace_getter()->UponLeavingGTest();
2690 this, &Test::TestBody,
"the test body");
2696 impl->os_stack_trace_getter()->UponLeavingGTest();
2698 this, &Test::TearDown,
"TearDown()");
2702 bool Test::HasFatalFailure() {
2703 return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
2707 bool Test::HasNonfatalFailure() {
2708 return internal::GetUnitTestImpl()->current_test_result()->
2709 HasNonfatalFailure();
2713 bool Test::IsSkipped() {
2714 return internal::GetUnitTestImpl()->current_test_result()->Skipped();
2721 TestInfo::TestInfo(
const std::string& a_test_suite_name,
2722 const std::string& a_name,
const char* a_type_param,
2723 const char* a_value_param,
2727 : test_suite_name_(a_test_suite_name),
2729 type_param_(a_type_param ? new
std::string(a_type_param) : nullptr),
2730 value_param_(a_value_param ? new
std::string(a_value_param) : nullptr),
2731 location_(a_code_location),
2732 fixture_class_id_(fixture_class_id),
2734 is_disabled_(
false),
2735 matches_filter_(
false),
2742 namespace internal {
2763 const char* test_suite_name,
const char* name,
const char* type_param,
2768 new TestInfo(test_suite_name, name, type_param, value_param,
2769 code_location, fixture_class_id, factory);
2770 GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
2778 <<
"Attempted redefinition of test suite " << test_suite_name <<
".\n" 2779 <<
"All tests in the same test suite must use the same test fixture\n" 2780 <<
"class. However, in test suite " << test_suite_name <<
", you tried\n" 2781 <<
"to define a test using a fixture class different from the one\n" 2782 <<
"used earlier. This can happen if the two fixture classes are\n" 2783 <<
"from different namespaces and have the same name. You should\n" 2784 <<
"probably rename one of the classes to put the tests into different\n" 2808 explicit TestNameIs(
const char* name)
2812 bool operator()(
const TestInfo * test_info)
const {
2813 return test_info && test_info->name() ==
name_;
2822 namespace internal {
2827 void UnitTestImpl::RegisterParameterizedTests() {
2828 if (!parameterized_tests_registered_) {
2829 parameterized_test_registry_.RegisterTests();
2830 type_parameterized_test_registry_.CheckForInstantiations();
2831 parameterized_tests_registered_ =
true;
2844 impl->set_current_test_info(
this);
2853 impl->os_stack_trace_getter()->UponLeavingGTest();
2858 "the test fixture's constructor");
2869 if (
test !=
nullptr) {
2871 impl->os_stack_trace_getter()->UponLeavingGTest();
2884 impl->set_current_test_info(
nullptr);
2892 impl->set_current_test_info(
this);
2899 const TestPartResult test_part_result =
2900 TestPartResult(TestPartResult::kSkip, this->
file(), this->
line(),
"");
2901 impl->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult(
2906 impl->set_current_test_info(
nullptr);
2964 type_param_(a_type_param ? new
std::string(a_type_param) : nullptr),
2965 set_up_tc_(set_up_tc),
2966 tear_down_tc_(tear_down_tc),
2968 start_timestamp_(0),
2981 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
2988 return index < 0 ? nullptr : test_info_list_[static_cast<size_t>(index)];
3003 impl->set_current_test_suite(
this);
3010 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI 3012 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI 3014 impl->os_stack_trace_getter()->UponLeavingGTest();
3030 impl->os_stack_trace_getter()->UponLeavingGTest();
3037 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI 3039 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI 3041 impl->set_current_test_suite(
nullptr);
3049 impl->set_current_test_suite(
this);
3056 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI 3058 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI 3067 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI 3069 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI 3071 impl->set_current_test_suite(
nullptr);
3098 const char * singular_form,
3099 const char * plural_form) {
3101 (
count == 1 ? singular_form : plural_form);
3120 case TestPartResult::kSkip:
3122 case TestPartResult::kSuccess:
3125 case TestPartResult::kNonFatalFailure:
3126 case TestPartResult::kFatalFailure:
3133 return "Unknown result type";
3137 namespace internal {
3144 const TestPartResult& test_part_result) {
3147 test_part_result.line_number())
3149 << test_part_result.message()).GetString();
3154 const std::string& result =
3156 printf(
"%s\n", result.c_str());
3162 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 3166 ::OutputDebugStringA(result.c_str());
3167 ::OutputDebugStringA(
"\n");
3172 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ 3173 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW 3176 static WORD GetColorAttribute(GTestColor color) {
3178 case GTestColor::kRed:
3179 return FOREGROUND_RED;
3180 case GTestColor::kGreen:
3181 return FOREGROUND_GREEN;
3182 case GTestColor::kYellow:
3183 return FOREGROUND_RED | FOREGROUND_GREEN;
3188 static int GetBitOffset(WORD color_mask) {
3189 if (color_mask == 0)
return 0;
3192 while ((color_mask & 1) == 0) {
3199 static WORD GetNewColor(GTestColor color, WORD old_color_attrs) {
3201 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
3202 BACKGROUND_RED | BACKGROUND_INTENSITY;
3203 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
3204 FOREGROUND_RED | FOREGROUND_INTENSITY;
3205 const WORD existing_bg = old_color_attrs & background_mask;
3208 GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
3209 static const int bg_bitOffset = GetBitOffset(background_mask);
3210 static const int fg_bitOffset = GetBitOffset(foreground_mask);
3212 if (((new_color & background_mask) >> bg_bitOffset) ==
3213 ((new_color & foreground_mask) >> fg_bitOffset)) {
3214 new_color ^= FOREGROUND_INTENSITY;
3225 case GTestColor::kRed:
3227 case GTestColor::kGreen:
3229 case GTestColor::kYellow:
3236 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 3240 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
3243 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW 3246 return stdout_is_tty;
3250 const bool term_supports_color =
3262 return stdout_is_tty && term_supports_color;
3263 #endif // GTEST_OS_WINDOWS 3282 va_start(args, fmt);
3284 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ 3285 GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) 3288 static const bool in_color_mode =
3290 const bool use_color = in_color_mode && (color != GTestColor::kDefault);
3291 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS 3299 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ 3300 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW 3301 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3304 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3305 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3306 const WORD old_color_attrs = buffer_info.wAttributes;
3307 const WORD new_color = GetNewColor(color, old_color_attrs);
3313 SetConsoleTextAttribute(stdout_handle, new_color);
3319 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3324 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 3334 const char*
const type_param = test_info.
type_param();
3335 const char*
const value_param = test_info.
value_param();
3337 if (type_param !=
nullptr || value_param !=
nullptr) {
3339 if (type_param !=
nullptr) {
3341 if (value_param !=
nullptr) printf(
" and ");
3343 if (value_param !=
nullptr) {
3356 printf(
"%s.%s", test_suite,
test);
3364 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3368 #endif // OnTestCaseStart 3374 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3378 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3393 const UnitTest& unit_test,
int iteration) {
3395 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3397 const char*
const filter =
GTEST_FLAG(filter).c_str();
3408 ColoredPrintf(GTestColor::kYellow,
"Note: This is test shard %d of %s.\n",
3409 static_cast<int>(shard_index) + 1,
3415 "Note: Randomizing tests' orders with a seed of %d .\n",
3420 printf(
"Running %s from %s.\n",
3429 printf(
"Global test environment set-up.\n");
3433 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3435 const std::string counts =
3438 printf(
"%s from %s", counts.c_str(), test_case.name());
3439 if (test_case.type_param() ==
nullptr) {
3449 const std::string counts =
3452 printf(
"%s from %s", counts.c_str(), test_suite.
name());
3460 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3471 const TestPartResult& result) {
3472 switch (result.type()) {
3474 case TestPartResult::kSuccess:
3505 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3509 const std::string counts =
3512 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_case.name(),
3520 const std::string counts =
3523 printf(
"%s from %s (%s ms total)\n\n", counts.c_str(), test_suite.
name(),
3527 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3532 printf(
"Global test environment tear-down\n");
3540 printf(
"%s, listed below:\n",
FormatTestCount(failed_test_count).c_str());
3553 printf(
"%s.%s", test_suite.
name(), test_info.
name());
3558 printf(
"\n%2d FAILED %s\n", failed_test_count,
3559 failed_test_count == 1 ?
"TEST" :
"TESTS");
3566 int suite_failure_count = 0;
3574 printf(
"%s: SetUpTestSuite or TearDownTestSuite\n", test_suite.
name());
3575 ++suite_failure_count;
3578 if (suite_failure_count > 0) {
3579 printf(
"\n%2d FAILED TEST %s\n", suite_failure_count,
3580 suite_failure_count == 1 ?
"SUITE" :
"SUITES");
3587 if (skipped_test_count == 0) {
3602 printf(
"%s.%s", test_suite.
name(), test_info.
name());
3611 printf(
"%s from %s ran.",
3615 printf(
" (%s ms total)",
3623 if (skipped_test_count > 0) {
3625 printf(
"%s, listed below:\n",
FormatTestCount(skipped_test_count).c_str());
3629 if (!unit_test.
Passed()) {
3635 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3636 if (unit_test.
Passed()) {
3639 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3640 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3655 printf(
"%s.%s", test_suite,
test);
3664 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3668 #endif // OnTestCaseStart 3674 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3678 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3688 const TestPartResult& result) {
3689 switch (result.type()) {
3691 case TestPartResult::kSuccess:
3708 printf(
" (%s ms)\n",
3721 printf(
"%s from %s ran.",
3725 printf(
" (%s ms total)",
3733 if (skipped_test_count > 0) {
3739 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3740 if (unit_test.
Passed()) {
3743 ColoredPrintf(GTestColor::kYellow,
" YOU HAVE %d DISABLED %s\n\n",
3744 num_disabled, num_disabled == 1 ?
"TEST" :
"TESTS");
3772 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3774 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3780 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3782 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3800 ForEach(
listeners_, Delete<TestEventListener>);
3820 #define GTEST_REPEATER_METHOD_(Name, Type) \ 3821 void TestEventRepeater::Name(const Type& parameter) { \ 3822 if (forwarding_enabled_) { \ 3823 for (size_t i = 0; i < listeners_.size(); i++) { \ 3824 listeners_[i]->Name(parameter); \ 3830 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \ 3831 void TestEventRepeater::Name(const Type& parameter) { \ 3832 if (forwarding_enabled_) { \ 3833 for (size_t i = listeners_.size(); i != 0; i--) { \ 3834 listeners_[i - 1]->Name(parameter); \ 3842 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3844 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3853 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3855 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 3859 #undef GTEST_REPEATER_METHOD_ 3860 #undef GTEST_REVERSE_REPEATER_METHOD_ 3866 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3875 listeners_[
i - 1]->OnTestIterationEnd(unit_test, iteration);
3892 const std::vector<TestSuite*>& test_suites);
3898 return c == 0x9 ||
c == 0xA ||
c == 0xD;
3910 static std::string
EscapeXml(
const std::string& str,
bool is_attribute);
3928 const std::string& element_name,
3929 const std::string& name,
3930 const std::string&
value);
3937 const char* test_suite_name,
3967 : output_file_(output_file) {
3969 GTEST_LOG_(FATAL) <<
"XML output file may not be null";
3977 std::stringstream stream;
3984 const std::vector<TestSuite*>& test_suites) {
3986 std::stringstream stream;
4003 const std::string& str,
bool is_attribute) {
4006 for (
size_t i = 0;
i < str.size(); ++
i) {
4007 const char ch = str[
i];
4049 const std::string& str) {
4051 output.reserve(str.size());
4052 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
4054 output.push_back(*it);
4078 ::std::stringstream ss;
4079 ss << (static_cast<double>(ms) * 1e-3);
4084 #if defined(_MSC_VER) 4085 return localtime_s(out, &seconds) == 0;
4086 #elif defined(__MINGW32__) || defined(__MINGW64__) 4089 struct tm* tm_ptr = localtime(&seconds);
4090 if (tm_ptr ==
nullptr)
return false;
4094 return localtime_r(&seconds, out) !=
nullptr;
4101 struct tm time_struct;
4116 const char* segment = data;
4117 *stream <<
"<![CDATA[";
4119 const char*
const next_segment = strstr(segment,
"]]>");
4120 if (next_segment !=
nullptr) {
4122 segment, static_cast<std::streamsize>(next_segment - segment));
4123 *stream <<
"]]>]]><![CDATA[";
4124 segment = next_segment + strlen(
"]]>");
4134 std::ostream* stream,
4135 const std::string& element_name,
4136 const std::string& name,
4137 const std::string&
value) {
4138 const std::vector<std::string>& allowed_names =
4141 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4142 allowed_names.end())
4143 <<
"Attribute " << name <<
" is not allowed for element <" << element_name
4151 const char* test_suite_name,
4154 const std::string kTestsuite =
"testcase";
4160 *stream <<
" <testcase";
4183 ? (result.
Skipped() ?
"skipped" :
"completed")
4188 stream, kTestsuite,
"timestamp",
4196 if (part.failed()) {
4197 if (++failures == 1 && skips == 0) {
4200 const std::string location =
4202 part.line_number());
4203 const std::string summary = location +
"\n" + part.summary();
4204 *stream <<
" <failure message=\"" 4207 const std::string detail = location +
"\n" + part.message();
4209 *stream <<
"</failure>\n";
4210 }
else if (part.skipped()) {
4211 if (++skips == 1 && failures == 0) {
4214 const std::string location =
4216 part.line_number());
4217 const std::string summary = location +
"\n" + part.summary();
4218 *stream <<
" <skipped message=\"" 4220 const std::string detail = location +
"\n" + part.message();
4222 *stream <<
"</skipped>\n";
4229 if (failures == 0 && skips == 0) {
4233 *stream <<
" </testcase>\n";
4240 const std::string kTestsuite =
"testsuite";
4241 *stream <<
" <" << kTestsuite;
4249 stream, kTestsuite,
"disabled",
4259 stream, kTestsuite,
"timestamp",
4268 *stream <<
" </" << kTestsuite <<
">\n";
4274 const std::string kTestsuites =
"testsuites";
4276 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4277 *stream <<
"<" << kTestsuites;
4284 stream, kTestsuites,
"disabled",
4290 stream, kTestsuites,
"timestamp",
4306 *stream <<
"</" << kTestsuites <<
">\n";
4310 std::ostream* stream,
const std::vector<TestSuite*>& test_suites) {
4311 const std::string kTestsuites =
"testsuites";
4313 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
4314 *stream <<
"<" << kTestsuites;
4316 int total_tests = 0;
4317 for (
auto test_suite : test_suites) {
4325 for (
auto test_suite : test_suites) {
4328 *stream <<
"</" << kTestsuites <<
">\n";
4338 attributes <<
" " <<
property.key() <<
"=" 4345 std::ostream* stream,
const TestResult& result) {
4346 const std::string kProperties =
"properties";
4347 const std::string kProperty =
"property";
4353 *stream <<
"<" << kProperties <<
">\n";
4356 *stream <<
"<" << kProperty;
4361 *stream <<
"</" << kProperties <<
">\n";
4375 const std::vector<TestSuite*>& test_suites);
4379 static std::string
EscapeJson(
const std::string& str);
4384 const std::string& element_name,
4385 const std::string& name,
4386 const std::string&
value,
4387 const std::string& indent,
4390 const std::string& element_name,
4391 const std::string& name,
4393 const std::string& indent,
4398 const char* test_suite_name,
4412 const std::string& indent);
4422 : output_file_(output_file) {
4424 GTEST_LOG_(FATAL) <<
"JSON output file may not be null";
4431 std::stringstream stream;
4441 for (
size_t i = 0;
i < str.size(); ++
i) {
4442 const char ch = str[
i];
4482 ::std::stringstream ss;
4483 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
4490 struct tm time_struct;
4502 static inline std::string
Indent(
size_t width) {
4503 return std::string(width,
' ');
4507 std::ostream* stream,
4508 const std::string& element_name,
4509 const std::string& name,
4510 const std::string&
value,
4511 const std::string& indent,
4513 const std::vector<std::string>& allowed_names =
4516 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4517 allowed_names.end())
4518 <<
"Key \"" << name <<
"\" is not allowed for value \"" << element_name
4521 *stream << indent <<
"\"" << name <<
"\": \"" <<
EscapeJson(
value) <<
"\"";
4527 std::ostream* stream,
4528 const std::string& element_name,
4529 const std::string& name,
4531 const std::string& indent,
4533 const std::vector<std::string>& allowed_names =
4536 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
4537 allowed_names.end())
4538 <<
"Key \"" << name <<
"\" is not allowed for value \"" << element_name
4548 const char* test_suite_name,
4551 const std::string kTestsuite =
"testcase";
4552 const std::string kIndent =
Indent(10);
4554 *stream <<
Indent(8) <<
"{\n";
4568 *stream <<
"\n" <<
Indent(8) <<
"}";
4573 test_info.
should_run() ?
"RUN" :
"NOTRUN", kIndent);
4576 ? (result.
Skipped() ?
"SKIPPED" :
"COMPLETED")
4584 OutputJsonKey(stream, kTestsuite,
"classname", test_suite_name, kIndent,
4591 if (part.failed()) {
4593 if (++failures == 1) {
4594 *stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4596 const std::string location =
4598 part.line_number());
4599 const std::string message =
EscapeJson(location +
"\n" + part.message());
4600 *stream << kIndent <<
" {\n" 4601 << kIndent <<
" \"failure\": \"" << message <<
"\",\n" 4602 << kIndent <<
" \"type\": \"\"\n" 4608 *stream <<
"\n" << kIndent <<
"]";
4609 *stream <<
"\n" <<
Indent(8) <<
"}";
4614 std::ostream* stream,
const TestSuite& test_suite) {
4615 const std::string kTestsuite =
"testsuite";
4616 const std::string kIndent =
Indent(6);
4618 *stream <<
Indent(4) <<
"{\n";
4629 stream, kTestsuite,
"timestamp",
4639 *stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4652 *stream <<
"\n" << kIndent <<
"]\n" <<
Indent(4) <<
"}";
4658 const std::string kTestsuites =
"testsuites";
4659 const std::string kIndent =
Indent(2);
4683 OutputJsonKey(stream, kTestsuites,
"name",
"AllTests", kIndent);
4684 *stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4698 *stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4702 std::ostream* stream,
const std::vector<TestSuite*>& test_suites) {
4703 const std::string kTestsuites =
"testsuites";
4704 const std::string kIndent =
Indent(2);
4706 int total_tests = 0;
4707 for (
auto test_suite : test_suites) {
4710 OutputJsonKey(stream, kTestsuites,
"tests", total_tests, kIndent);
4712 OutputJsonKey(stream, kTestsuites,
"name",
"AllTests", kIndent);
4713 *stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4715 for (
size_t i = 0;
i < test_suites.size(); ++
i) {
4729 const TestResult& result,
const std::string& indent) {
4733 attributes <<
",\n" << indent <<
"\"" <<
property.key() <<
"\": " 4734 <<
"\"" <<
EscapeJson(property.value()) <<
"\"";
4741 #if GTEST_CAN_STREAM_RESULTS_ 4748 std::string StreamingListener::UrlEncode(
const char* str) {
4750 result.reserve(strlen(str) + 1);
4751 for (
char ch = *str;
ch !=
'\0';
ch = *++str) {
4760 result.push_back(
ch);
4767 void StreamingListener::SocketWriter::MakeConnection() {
4769 <<
"MakeConnection() can't be called when there is already a connection.";
4772 memset(&hints, 0,
sizeof(hints));
4773 hints.ai_family = AF_UNSPEC;
4774 hints.ai_socktype = SOCK_STREAM;
4775 addrinfo* servinfo =
nullptr;
4779 const int error_num = getaddrinfo(
4780 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4781 if (error_num != 0) {
4782 GTEST_LOG_(WARNING) <<
"stream_result_to: getaddrinfo() failed: " 4783 << gai_strerror(error_num);
4787 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr !=
nullptr;
4788 cur_addr = cur_addr->ai_next) {
4790 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4791 if (sockfd_ != -1) {
4793 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4800 freeaddrinfo(servinfo);
4802 if (sockfd_ == -1) {
4803 GTEST_LOG_(WARNING) <<
"stream_result_to: failed to connect to " 4804 << host_name_ <<
":" << port_num_;
4809 #endif // GTEST_CAN_STREAM_RESULTS__ 4813 const char*
const OsStackTraceGetterInterface::kElidedFramesMarker =
4816 std::string OsStackTraceGetter::CurrentStackTrace(
int max_depth,
int skip_count)
4821 if (max_depth <= 0) {
4825 max_depth =
std::min(max_depth, kMaxStackTraceDepth);
4827 std::vector<void*> raw_stack(max_depth);
4829 const int raw_stack_size =
4830 absl::GetStackTrace(&raw_stack[0], max_depth, skip_count + 1);
4832 void* caller_frame =
nullptr;
4835 caller_frame = caller_frame_;
4838 for (
int i = 0;
i < raw_stack_size; ++
i) {
4839 if (raw_stack[
i] == caller_frame &&
4842 absl::StrAppend(&result, kElidedFramesMarker,
"\n");
4847 const char* symbol =
"(unknown)";
4848 if (absl::Symbolize(raw_stack[
i], tmp,
sizeof(tmp))) {
4853 snprintf(line,
sizeof(line),
" %p: %s\n", raw_stack[
i], symbol);
4859 #else // !GTEST_HAS_ABSL 4860 static_cast<void>(max_depth);
4861 static_cast<void>(skip_count);
4863 #endif // GTEST_HAS_ABSL 4868 void* caller_frame =
nullptr;
4869 if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) {
4870 caller_frame =
nullptr;
4874 caller_frame_ = caller_frame;
4875 #endif // GTEST_HAS_ABSL 4884 premature_exit_filepath :
"") {
4890 FILE* pfile =
posix::FOpen(premature_exit_filepath,
"w");
4891 fwrite(
"0", 1, 1, pfile);
4897 #if !defined GTEST_OS_ESP8266 4901 GTEST_LOG_(ERROR) <<
"Failed to remove premature exit filepath \"" 4920 : repeater_(new internal::TestEventRepeater()),
4921 default_result_printer_(nullptr),
4922 default_xml_generator_(nullptr) {}
4960 if (listener !=
nullptr)
Append(listener);
4975 if (listener !=
nullptr)
Append(listener);
5003 #if defined(__BORLANDC__) 5009 #endif // defined(__BORLANDC__) 5014 return impl()->successful_test_suite_count();
5019 return impl()->failed_test_suite_count();
5024 return impl()->total_test_suite_count();
5030 return impl()->test_suite_to_run_count();
5034 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 5036 return impl()->successful_test_suite_count();
5039 return impl()->failed_test_suite_count();
5042 return impl()->total_test_suite_count();
5045 return impl()->test_suite_to_run_count();
5047 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 5051 return impl()->successful_test_count();
5056 return impl()->skipped_test_count();
5064 return impl()->reportable_disabled_test_count();
5069 return impl()->disabled_test_count();
5074 return impl()->reportable_test_count();
5086 return impl()->start_timestamp();
5091 return impl()->elapsed_time();
5105 return impl()->GetTestSuite(
i);
5109 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 5111 return impl()->GetTestCase(
i);
5113 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 5118 return *
impl()->ad_hoc_test_result();
5124 return impl()->GetMutableSuiteCase(
i);
5130 return *
impl()->listeners();
5144 if (env ==
nullptr) {
5148 impl_->environments().push_back(env);
5157 TestPartResult::Type result_type,
5158 const char* file_name,
5160 const std::string& message,
5166 if (impl_->gtest_trace_stack().size() > 0) {
5169 for (
size_t i = impl_->gtest_trace_stack().size();
i > 0; --
i) {
5170 const internal::TraceInfo& trace = impl_->gtest_trace_stack()[
i - 1];
5172 <<
" " << trace.message;
5176 if (os_stack_trace.c_str() !=
nullptr && !os_stack_trace.empty()) {
5180 const TestPartResult result = TestPartResult(
5181 result_type, file_name, line_number, msg.
GetString().c_str());
5182 impl_->GetTestPartResultReporterForCurrentThread()->
5183 ReportTestPartResult(result);
5185 if (result_type != TestPartResult::kSuccess &&
5186 result_type != TestPartResult::kSkip) {
5193 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 5198 #elif (!defined(__native_client__)) && \ 5199 ((defined(__clang__) || defined(__GNUC__)) && \ 5200 (defined(__x86_64__) || defined(__i386__))) 5207 *
static_cast<volatile int*
>(
nullptr) = 1;
5208 #endif // GTEST_OS_WINDOWS 5210 #if GTEST_HAS_EXCEPTIONS 5211 throw internal::GoogleTestFailureException(result);
5227 const std::string&
value) {
5237 const bool in_death_test_child_process =
5262 in_death_test_child_process
5270 #if GTEST_OS_WINDOWS 5275 if (
impl()->catch_exceptions() || in_death_test_child_process) {
5276 # if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 5278 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
5279 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
5280 # endif // !GTEST_OS_WINDOWS_MOBILE 5282 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE 5286 _set_error_mode(_OUT_TO_STDERR);
5289 # if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE 5296 _set_abort_behavior(
5298 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
5304 if (!IsDebuggerPresent()) {
5305 (void)_CrtSetReportMode(_CRT_ASSERT,
5306 _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
5307 (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
5311 #endif // GTEST_OS_WINDOWS 5316 "auxiliary test code (environments or event listeners)") ? 0 : 1;
5322 return impl_->original_working_dir_.c_str();
5330 return impl_->current_test_suite();
5334 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 5338 return impl_->current_test_suite();
5347 return impl_->current_test_info();
5357 return impl_->parameterized_test_registry();
5362 impl_ =
new internal::UnitTestImpl(
this);
5375 impl_->gtest_trace_stack().push_back(trace);
5382 impl_->gtest_trace_stack().pop_back();
5385 namespace internal {
5387 UnitTestImpl::UnitTestImpl(
UnitTest* parent)
5390 default_global_test_part_result_reporter_(this),
5391 default_per_thread_test_part_result_reporter_(this),
5393 &default_global_test_part_result_reporter_),
5394 per_thread_test_part_result_reporter_(
5395 &default_per_thread_test_part_result_reporter_),
5396 parameterized_test_registry_(),
5397 parameterized_tests_registered_(
false),
5398 last_death_test_suite_(-1),
5399 current_test_suite_(nullptr),
5400 current_test_info_(nullptr),
5401 ad_hoc_test_result_(),
5402 os_stack_trace_getter_(nullptr),
5403 post_flag_parse_init_performed_(
false),
5406 start_timestamp_(0),
5408 #if GTEST_HAS_DEATH_TEST
5409 death_test_factory_(new DefaultDeathTestFactory),
5412 catch_exceptions_(
false) {
5416 UnitTestImpl::~UnitTestImpl() {
5418 ForEach(test_suites_, internal::Delete<TestSuite>);
5421 ForEach(environments_, internal::Delete<Environment>);
5423 delete os_stack_trace_getter_;
5431 void UnitTestImpl::RecordProperty(
const TestProperty& test_property) {
5432 std::string xml_element;
5433 TestResult* test_result;
5435 if (current_test_info_ !=
nullptr) {
5436 xml_element =
"testcase";
5437 test_result = &(current_test_info_->result_);
5438 }
else if (current_test_suite_ !=
nullptr) {
5439 xml_element =
"testsuite";
5440 test_result = &(current_test_suite_->ad_hoc_test_result_);
5442 xml_element =
"testsuites";
5443 test_result = &ad_hoc_test_result_;
5445 test_result->RecordProperty(xml_element, test_property);
5448 #if GTEST_HAS_DEATH_TEST 5451 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
5452 if (internal_run_death_test_flag_.get() !=
nullptr)
5453 listeners()->SuppressEventForwarding();
5455 #endif // GTEST_HAS_DEATH_TEST 5459 void UnitTestImpl::ConfigureXmlOutput() {
5460 const std::string& output_format = UnitTestOptions::GetOutputFormat();
5461 if (output_format ==
"xml") {
5462 listeners()->SetDefaultXmlGenerator(
new XmlUnitTestResultPrinter(
5463 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
5464 }
else if (output_format ==
"json") {
5465 listeners()->SetDefaultXmlGenerator(
new JsonUnitTestResultPrinter(
5466 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
5467 }
else if (output_format !=
"") {
5468 GTEST_LOG_(WARNING) <<
"WARNING: unrecognized output format \"" 5469 << output_format <<
"\" ignored.";
5473 #if GTEST_CAN_STREAM_RESULTS_ 5476 void UnitTestImpl::ConfigureStreamingOutput() {
5477 const std::string& target =
GTEST_FLAG(stream_result_to);
5478 if (!target.empty()) {
5479 const size_t pos = target.find(
':');
5480 if (pos != std::string::npos) {
5481 listeners()->Append(
new StreamingListener(target.substr(0, pos),
5482 target.substr(pos+1)));
5484 GTEST_LOG_(WARNING) <<
"unrecognized streaming target \"" << target
5489 #endif // GTEST_CAN_STREAM_RESULTS_ 5496 void UnitTestImpl::PostFlagParsingInit() {
5498 if (!post_flag_parse_init_performed_) {
5499 post_flag_parse_init_performed_ =
true;
5501 #if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) 5503 listeners()->Append(
new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
5504 #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) 5506 #if GTEST_HAS_DEATH_TEST 5507 InitDeathTestSubprocessControlInfo();
5508 SuppressTestEventsIfInSubprocess();
5509 #endif // GTEST_HAS_DEATH_TEST 5514 RegisterParameterizedTests();
5518 ConfigureXmlOutput();
5521 listeners()->SetDefaultResultPrinter(
new BriefUnitTestResultPrinter);
5524 #if GTEST_CAN_STREAM_RESULTS_ 5526 ConfigureStreamingOutput();
5527 #endif // GTEST_CAN_STREAM_RESULTS_ 5530 if (
GTEST_FLAG(install_failure_signal_handler)) {
5531 absl::FailureSignalHandlerOptions options;
5532 absl::InstallFailureSignalHandler(options);
5534 #endif // GTEST_HAS_ABSL 5553 return test_suite !=
nullptr &&
5554 strcmp(test_suite->
name(),
name_.c_str()) == 0;
5574 const char* test_suite_name,
const char* type_param,
5578 const auto test_suite =
5579 std::find_if(test_suites_.rbegin(), test_suites_.rend(),
5582 if (test_suite != test_suites_.rend())
return *test_suite;
5585 auto*
const new_test_suite =
5586 new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
5589 if (internal::UnitTestOptions::MatchesFilter(test_suite_name,
5595 ++last_death_test_suite_;
5596 test_suites_.insert(test_suites_.begin() + last_death_test_suite_,
5600 test_suites_.push_back(new_test_suite);
5603 test_suite_indices_.push_back(static_cast<int>(test_suite_indices_.size()));
5604 return new_test_suite;
5632 PostFlagParsingInit();
5641 bool in_subprocess_for_death_test =
false;
5643 #if GTEST_HAS_DEATH_TEST 5644 in_subprocess_for_death_test =
5645 (internal_run_death_test_flag_.get() !=
nullptr);
5646 # if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) 5647 if (in_subprocess_for_death_test) {
5648 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
5650 # endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) 5651 #endif // GTEST_HAS_DEATH_TEST 5654 in_subprocess_for_death_test);
5658 const bool has_tests_to_run = FilterTests(should_shard
5659 ? HONOR_SHARDING_PROTOCOL
5660 : IGNORE_SHARDING_PROTOCOL) > 0;
5665 ListTestsMatchingFilter();
5670 GetRandomSeedFromFlag(
GTEST_FLAG(random_seed)) : 0;
5673 bool failed =
false;
5675 TestEventListener* repeater = listeners()->repeater();
5678 repeater->OnTestProgramStart(*parent_);
5682 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
5684 const bool gtest_repeat_forever = repeat < 0;
5685 for (
int i = 0; gtest_repeat_forever ||
i != repeat;
i++) {
5688 ClearNonAdHocTestResult();
5693 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
5694 random()->Reseed(static_cast<uint32_t>(random_seed_));
5702 repeater->OnTestIterationStart(*parent_,
i);
5705 if (has_tests_to_run) {
5707 repeater->OnEnvironmentsSetUpStart(*parent_);
5709 repeater->OnEnvironmentsSetUpEnd(*parent_);
5716 TestResult& test_result =
5717 *internal::GetUnitTestImpl()->current_test_result();
5718 for (
int j = 0; j < test_result.total_part_count(); ++j) {
5719 const TestPartResult& test_part_result =
5720 test_result.GetTestPartResult(j);
5721 if (test_part_result.type() == TestPartResult::kSkip) {
5722 const std::string& result = test_part_result.message();
5723 printf(
"%s\n", result.c_str());
5728 for (
int test_index = 0; test_index < total_test_suite_count();
5730 GetMutableSuiteCase(test_index)->Run();
5732 GetMutableSuiteCase(test_index)->Failed()) {
5733 for (
int j = test_index + 1; j < total_test_suite_count(); j++) {
5734 GetMutableSuiteCase(j)->Skip();
5742 repeater->OnEnvironmentsTearDownStart(*parent_);
5743 std::for_each(environments_.rbegin(), environments_.rend(),
5745 repeater->OnEnvironmentsTearDownEnd(*parent_);
5751 repeater->OnTestIterationEnd(*parent_,
i);
5768 random_seed_ = GetNextRandomSeed(random_seed_);
5772 repeater->OnTestProgramEnd(*parent_);
5774 if (!gtest_is_initialized_before_run_all_tests) {
5777 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n" 5779 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_ 5780 " will start to enforce the valid usage. " 5781 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
5782 #if GTEST_FOR_GOOGLE_ 5784 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
5785 #endif // GTEST_FOR_GOOGLE_ 5797 if (test_shard_file !=
nullptr) {
5799 if (file ==
nullptr) {
5801 "Could not write to the test shard status file \"%s\" " 5802 "specified by the %s environment variable.\n",
5818 const char* shard_index_env,
5819 bool in_subprocess_for_death_test) {
5820 if (in_subprocess_for_death_test) {
5827 if (total_shards == -1 && shard_index == -1) {
5829 }
else if (total_shards == -1 && shard_index != -1) {
5831 <<
"Invalid environment variables: you have " 5837 }
else if (total_shards != -1 && shard_index == -1) {
5839 <<
"Invalid environment variables: you have " 5845 }
else if (shard_index < 0 || shard_index >= total_shards) {
5847 <<
"Invalid environment variables: we require 0 <= " 5856 return total_shards > 1;
5864 if (str_val ==
nullptr) {
5870 str_val, &result)) {
5881 return (test_id % total_shards) == shard_index;
5891 int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
5892 const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
5894 const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
5901 int num_runnable_tests = 0;
5902 int num_selected_tests = 0;
5903 for (
auto* test_suite : test_suites_) {
5904 const std::string& test_suite_name = test_suite->
name();
5907 for (
size_t j = 0; j < test_suite->
test_info_list().size(); j++) {
5909 const std::string test_name(test_info->
name());
5912 const bool is_disabled = internal::UnitTestOptions::MatchesFilter(
5914 internal::UnitTestOptions::MatchesFilter(
5918 const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest(
5919 test_suite_name, test_name);
5922 const bool is_runnable =
5923 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
5926 const bool is_in_another_shard =
5927 shard_tests != IGNORE_SHARDING_PROTOCOL &&
5930 const bool is_selected = is_runnable && !is_in_another_shard;
5932 num_runnable_tests += is_runnable;
5933 num_selected_tests += is_selected;
5939 return num_selected_tests;
5947 if (str !=
nullptr) {
5948 for (
int i = 0; *str !=
'\0'; ++str) {
5949 if (
i >= max_length) {
5965 void UnitTestImpl::ListTestsMatchingFilter() {
5967 const int kMaxParamLength = 250;
5969 for (
auto* test_suite : test_suites_) {
5970 bool printed_test_suite_name =
false;
5972 for (
size_t j = 0; j < test_suite->
test_info_list().size(); j++) {
5975 if (!printed_test_suite_name) {
5976 printed_test_suite_name =
true;
5977 printf(
"%s.", test_suite->
name());
5986 printf(
" %s", test_info->
name());
5998 const std::string& output_format = UnitTestOptions::GetOutputFormat();
5999 if (output_format ==
"xml" || output_format ==
"json") {
6001 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
6002 std::stringstream stream;
6003 if (output_format ==
"xml") {
6004 XmlUnitTestResultPrinter(
6005 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
6006 .PrintXmlTestsList(&stream, test_suites_);
6007 }
else if (output_format ==
"json") {
6008 JsonUnitTestResultPrinter(
6009 UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
6010 .PrintJsonTestList(&stream, test_suites_);
6022 void UnitTestImpl::set_os_stack_trace_getter(
6023 OsStackTraceGetterInterface* getter) {
6024 if (os_stack_trace_getter_ != getter) {
6025 delete os_stack_trace_getter_;
6026 os_stack_trace_getter_ = getter;
6033 OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
6034 if (os_stack_trace_getter_ ==
nullptr) {
6035 #ifdef GTEST_OS_STACK_TRACE_GETTER_ 6036 os_stack_trace_getter_ =
new GTEST_OS_STACK_TRACE_GETTER_;
6038 os_stack_trace_getter_ =
new OsStackTraceGetter;
6039 #endif // GTEST_OS_STACK_TRACE_GETTER_ 6042 return os_stack_trace_getter_;
6046 TestResult* UnitTestImpl::current_test_result() {
6047 if (current_test_info_ !=
nullptr) {
6048 return ¤t_test_info_->result_;
6050 if (current_test_suite_ !=
nullptr) {
6051 return ¤t_test_suite_->ad_hoc_test_result_;
6053 return &ad_hoc_test_result_;
6058 void UnitTestImpl::ShuffleTests() {
6060 ShuffleRange(random(), 0, last_death_test_suite_ + 1, &test_suite_indices_);
6063 ShuffleRange(random(), last_death_test_suite_ + 1,
6064 static_cast<int>(test_suites_.size()), &test_suite_indices_);
6067 for (
auto& test_suite : test_suites_) {
6073 void UnitTestImpl::UnshuffleTests() {
6074 for (
size_t i = 0;
i < test_suites_.size();
i++) {
6076 test_suites_[
i]->UnshuffleTests();
6078 test_suite_indices_[
i] =
static_cast<int>(
i);
6096 return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
6102 class ClassUniqueToAlwaysTrue {};
6105 bool IsTrue(
bool condition) {
return condition; }
6108 #if GTEST_HAS_EXCEPTIONS 6112 throw ClassUniqueToAlwaysTrue();
6113 #endif // GTEST_HAS_EXCEPTIONS 6121 const size_t prefix_len = strlen(prefix);
6122 if (strncmp(*pstr, prefix, prefix_len) == 0) {
6123 *pstr += prefix_len;
6135 bool def_optional) {
6137 if (str ==
nullptr || flag ==
nullptr)
return nullptr;
6141 const size_t flag_len = flag_str.length();
6142 if (strncmp(str, flag_str.c_str(), flag_len) != 0)
return nullptr;
6145 const char* flag_end = str + flag_len;
6148 if (def_optional && (flag_end[0] ==
'\0')) {
6155 if (flag_end[0] !=
'=')
return nullptr;
6158 return flag_end + 1;
6176 if (value_str ==
nullptr)
return false;
6179 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
6192 if (value_str ==
nullptr)
return false;
6203 template <
typename String>
6209 if (value_str ==
nullptr)
return false;
6241 GTestColor color = GTestColor::kDefault;
6248 const char*
p = strchr(str,
'@');
6256 const char ch =
p[1];
6260 }
else if (
ch ==
'D') {
6261 color = GTestColor::kDefault;
6262 }
else if (
ch ==
'R') {
6263 color = GTestColor::kRed;
6264 }
else if (
ch ==
'G') {
6265 color = GTestColor::kGreen;
6266 }
else if (
ch ==
'Y') {
6267 color = GTestColor::kYellow;
6275 "This program contains tests written using " GTEST_NAME_ 6276 ". You can use the\n" 6277 "following command line flags to control its behavior:\n" 6282 " List the names of all tests instead of running them. The name of\n" 6283 " TEST(Foo, Bar) is \"Foo.Bar\".\n" 6285 "filter=@YPOSTIVE_PATTERNS" 6286 "[@G-@YNEGATIVE_PATTERNS]@D\n" 6287 " Run only the tests whose name matches one of the positive patterns " 6289 " none of the negative patterns. '?' matches any single character; " 6291 " matches any substring; ':' separates two patterns.\n" 6293 "also_run_disabled_tests@D\n" 6294 " Run all disabled tests too.\n" 6298 "repeat=@Y[COUNT]@D\n" 6299 " Run the tests repeatedly; use a negative count to repeat forever.\n" 6302 " Randomize tests' orders on every iteration.\n" 6304 "random_seed=@Y[NUMBER]@D\n" 6305 " Random number seed to use for shuffling test orders (between 1 and\n" 6306 " 99999, or 0 to use a seed based on the current time).\n" 6310 "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n" 6311 " Enable/disable colored output. The default is @Gauto@D.\n" 6314 " Only print test failures.\n" 6317 " Don't print the elapsed time of each test.\n" 6320 "@Y|@G:@YFILE_PATH]@D\n" 6321 " Generate a JSON or XML report in the given directory or with the " 6323 " file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n" 6324 # if GTEST_CAN_STREAM_RESULTS_ 6326 "stream_result_to=@YHOST@G:@YPORT@D\n" 6327 " Stream test results to the given server.\n" 6328 # endif // GTEST_CAN_STREAM_RESULTS_ 6330 "Assertion Behavior:\n" 6331 # if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 6333 "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" 6334 " Set the default death test style.\n" 6335 # endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 6337 "break_on_failure@D\n" 6338 " Turn assertion failures into debugger break-points.\n" 6340 "throw_on_failure@D\n" 6341 " Turn assertion failures into C++ exceptions for use by an external\n" 6342 " test framework.\n" 6344 "catch_exceptions=0@D\n" 6345 " Do not report exceptions as test failures. Instead, allow them\n" 6346 " to crash the program or throw a pop-up (on Windows).\n" 6349 "list_tests@D, you can alternatively set " 6350 "the corresponding\n" 6351 "environment variable of a flag (all letters in upper-case). For example, " 6353 "disable colored text output, you can either specify " 6355 "color=no@D or set\n" 6357 "COLOR@D environment variable to @Gno@D.\n" 6359 "For more information, please read the " GTEST_NAME_ 6360 " documentation at\n" 6363 "(not one in your own code or tests), please report it to\n" 6397 #if GTEST_USE_OWN_FLAGFILE_FLAG_ 6398 static void LoadFlagsFromFile(
const std::string& path) {
6406 std::vector<std::string> lines;
6408 for (
size_t i = 0;
i < lines.size(); ++
i) {
6409 if (lines[
i].empty())
6415 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ 6420 template <
typename CharType>
6422 for (
int i = 1;
i < *argc;
i++) {
6424 const char*
const arg = arg_string.c_str();
6430 bool remove_flag =
false;
6433 #if GTEST_USE_OWN_FLAGFILE_FLAG_ 6437 #endif // GTEST_USE_OWN_FLAGFILE_FLAG_ 6438 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
6439 arg_string ==
"-?" || arg_string ==
"/?" ||
6451 for (
int j =
i; j != *argc; j++) {
6452 argv[j] = argv[j + 1];
6481 #ifndef GTEST_OS_IOS 6482 if (*_NSGetArgv() == argv) {
6483 *_NSGetArgc() = *argc;
6496 template <
typename CharType>
6501 if (*argc <= 0)
return;
6504 for (
int i = 0;
i != *argc;
i++) {
6509 absl::InitializeSymbolizer(
g_argvs[0].c_str());
6510 #endif // GTEST_HAS_ABSL 6513 GetUnitTestImpl()->PostFlagParsingInit();
6528 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6529 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6530 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6532 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6538 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6539 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv);
6540 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6542 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6550 const auto arg0 =
"dummy";
6551 char* argv0 =
const_cast<char*
>(arg0);
6552 char** argv = &argv0;
6554 #if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6555 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(&argc, argv);
6556 #else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6558 #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) 6562 #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) 6563 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
6566 #if GTEST_OS_WINDOWS_MOBILE 6568 #elif GTEST_OS_WINDOWS 6570 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0')
6572 else if (temp_dir[strlen(temp_dir) - 1] ==
'\\')
6575 return std::string(temp_dir) +
"\\";
6576 #elif GTEST_OS_LINUX_ANDROID 6578 if (temp_dir ==
nullptr || temp_dir[0] ==
'\0')
6579 return "/data/local/tmp/";
6584 #endif // GTEST_OS_WINDOWS_MOBILE 6591 void ScopedTrace::PushTrace(
const char* file,
int line, std::string message) {
6592 internal::TraceInfo trace;
6595 trace.message.swap(message);
6597 UnitTest::GetInstance()->PushGTestTrace(trace);
6601 ScopedTrace::~ScopedTrace()
6603 UnitTest::GetInstance()->PopGTestTrace();
void OnTestEnd(const TestInfo &test_info) override
int reportable_disabled_test_count() const
void SetDefaultResultPrinter(TestEventListener *listener)
const char * value() const
static void PrintJsonUnitTest(::std::ostream *stream, const UnitTest &unit_test)
~ScopedPrematureExitFile()
GTEST_API_ bool IsTrue(bool condition)
void RecordProperty(const std::string &xml_element, const TestProperty &test_property)
const TestResult & ad_hoc_test_result() const
static std::string FormatTestSuiteCount(int test_suite_count)
GTEST_API_ int32_t Int32FromGTestEnv(const char *flag, int32_t default_val)
#define GTEST_REPEATER_METHOD_(Name, Type)
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
ScopedPrematureExitFile(const char *premature_exit_filepath)
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
static bool HasFatalFailure()
TimeInMillis start_timestamp() const
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
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)
SACADO_INLINE_FUNCTION bool operator!(const Expr< ExprT > &expr)
static void PrintXmlUnitTest(::std::ostream *stream, const UnitTest &unit_test)
static bool ParseBoolFlag(const char *str, const char *flag, bool *value)
static bool HasGoogleTestFlagPrefix(const char *str)
void OnEnvironmentsSetUpStart(const UnitTest &) override
void RegisterInstantiation(const char *test_suite_name)
const TestResult * result() const
void OnEnvironmentsSetUpEnd(const UnitTest &) override
void(*)() SetUpTestSuiteFunc
const TestSuite * GetTestSuite(int i) const
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
static const char kDisableTestFilter[]
static AssertionResult HasOneFailure(const char *, const char *, const char *, const TestPartResultArray &results, TestPartResult::Type type, const std::string &substr)
constexpr uint32_t kMaxCodePoint4
virtual void OnTestCaseStart(const TestCase &)
AssertionResult AssertionFailure()
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
void PrintTo(const T &value, ::std::ostream *os)
static const char * TestPartResultTypeToString(TestPartResult::Type type)
static std::string EscapeXmlAttribute(const std::string &str)
static std::string EscapeXml(const std::string &str, bool is_attribute)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
MarkAsIgnored(const char *test_suite)
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
AssertionResult CmpHelperEQ(const char *lhs_expression, const char *rhs_expression, const T1 &lhs, const T2 &rhs)
std::vector< TestInfo * > test_info_list_
int successful_test_count() const
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
internal::TestEventRepeater * repeater_
static void PrintXmlTestsList(std::ostream *stream, const std::vector< TestSuite *> &test_suites)
::std::string PrintToString(const T &value)
static bool IsNormalizableWhitespace(char c)
const char * value_param() const
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
static std::string Indent(size_t width)
void SplitString(const ::std::string &str, char delimiter, ::std::vector< ::std::string > *dest)
static void ClearTestResult(TestInfo *test_info)
GTEST_API_ AssertionResult CmpHelperSTREQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
virtual Test * CreateTest()=0
#define GTEST_FLAG_PREFIX_DASH_
const char * StringFromGTestEnv(const char *flag, const char *default_val)
internal::Mutex test_properites_mutex_
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
TestSuite * GetMutableTestSuite(int i)
#define GTEST_LOG_(severity)
static bool TestSuitePassed(const TestSuite *test_suite)
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
int skipped_test_count() const
bool ShouldUseColor(bool stdout_is_tty)
int test_suite_to_run_count() const
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
static bool ParseGoogleTestFlag(const char *const arg)
GTEST_DISALLOW_COPY_AND_ASSIGN_(JsonUnitTestResultPrinter)
TestEventListener * Release(TestEventListener *listener)
void OnTestPartResult(const TestPartResult &result) override
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
BriefUnitTestResultPrinter()
static const char * GetDefaultFilter()
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
static bool TestPartNonfatallyFailed(const TestPartResult &result)
TestEventListener * repeater()
bool forwarding_enabled() const
TimeInMillis start_timestamp() const
JsonUnitTestResultPrinter(const char *output_file)
void OnTestEnd(const TestInfo &test_info) override
std::list< std::pair< char, const char * > > hunk_adds_
TestPartResult::Type const type
static void PrintXmlTestSuite(::std::ostream *stream, const TestSuite &test_suite)
void SuppressEventForwarding()
void OnTestProgramEnd(const UnitTest &unit_test) override
uint32_t Generate(uint32_t range)
PrettyUnitTestResultPrinter()
const TestResult & ad_hoc_test_result() const
const TestPartResult & GetTestPartResult(int i) const
void RecordProperty(const std::string &key, const std::string &value)
void ColoredPrintf(GTestColor color, const char *fmt,...)
void RegisterTypeParameterizedTestSuiteInstantiation(const char *case_name)
static bool TestPassed(const TestInfo *test_info)
Result HandleSehExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
static const char *const kReservedTestSuiteAttributes[]
void OnTestIterationStart(const UnitTest &, int) override
#define GTEST_PROJECT_URL_
const std::string output_file_
static const char kDeathTestSuiteFilter[]
void OnTestSuiteEnd(const TestSuite ¶meter) override
void set_elapsed_time(TimeInMillis elapsed)
int disabled_test_count() const
TimeInMillis start_timestamp() const
int total_part_count() const
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater)
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
Message & operator<<(const T &val)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
virtual void OnTestStart(const TestInfo &test_info)=0
int test_property_count() const
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
void OnEnvironmentsTearDownEnd(const UnitTest &) override
static bool ValidateTestProperty(const std::string &xml_element, const TestProperty &test_property)
const char kDeathTestUseFork[]
const char * GetEnv(const char *name)
friend class internal::UnitTestImpl
static void PrintSkippedTests(const UnitTest &unit_test)
bool IsUtf16SurrogatePair(wchar_t first, wchar_t second)
void ListTestsMatchingFilter(const std::vector< TestSuite *> &test_suites)
void Append(TestEventListener *listener)
static void SetUpEnvironment(Environment *env)
int test_to_run_count() const
int total_test_case_count() const
static const char kTestTotalShards[]
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
const char kInternalRunDeathTestFlag[]
TestResult ad_hoc_test_result_
static std::string FormatByte(unsigned char value)
#define GTEST_LOCK_EXCLUDED_(locks)
void OnTestProgramEnd(const UnitTest &) override
void OnTestCaseStart(const TestSuite ¶meter) override
void OnTestStart(const TestInfo &) override
const TestProperty & GetTestProperty(int i) const
const char * name() const
static std::vector< std::string > GetReservedAttributesForElement(const std::string &xml_element)
#define GTEST_DISABLE_MSC_DEPRECATED_POP_()
AssertHelperData *const data_
void PushGTestTrace(const internal::TraceInfo &trace) GTEST_LOCK_EXCLUDED_(mutex_)
GTEST_API_ std::vector< std::string > GetArgvs()
static std::string FormatHexInt(int value)
int skipped_test_count() const
GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter)
std::string StreamableToString(const T &streamable)
std::list< std::pair< char, const char * > > hunk_
static const char kTestShardStatusFile[]
static const char * GetAnsiColorCode(GTestColor color)
GTEST_API_ std::string ReadEntireFile(FILE *file)
std::string CodePointToUtf8(uint32_t code_point)
void RunTearDownTestSuite()
internal::TimeInMillis TimeInMillis
GTEST_API_ bool ParseInt32(const Message &src_text, const char *str, int32_t *value)
internal::TestFactoryBase *const factory_
const char * name() const
GTEST_API_ void ReportInvalidTestSuiteType(const char *test_suite_name, CodeLocation code_location)
const char * test_suite_name() const
TestSuite(const char *name, const char *a_type_param, internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc)
int total_test_count() const
const internal::TypeId fixture_class_id_
static void PrintJsonTestList(::std::ostream *stream, const std::vector< TestSuite *> &test_suites)
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.")
friend class internal::UnitTestImpl
static std::string FormatTimeInMillisAsDuration(TimeInMillis ms)
static std::string TestPropertiesAsJson(const TestResult &result, const std::string &indent)
static void OutputJsonTestInfo(::std::ostream *stream, const char *test_suite_name, const TestInfo &test_info)
bool EventForwardingEnabled() const
const std::string error_message_
GTEST_API_ TypeId GetTestTypeId()
static std::string TestPropertiesAsXmlAttributes(const TestResult &result)
static std::string FormatCountableNoun(int count, const char *singular_form, const char *plural_form)
std::list< std::pair< char, const char * > > hunk_removes_
CacheTaylor< T > diff(const CacheTaylor< T > &x, int n=1)
Compute Taylor series of n-th derivative of x.
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
#define GTEST_FLAG_PREFIX_UPPER_
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
GTEST_DEFINE_string_(death_test_style, internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle), "Indicates how to run a death test in a forked child process: " "\hreadsafe\(child process re-executes the test binary " "from the beginning, running only the specific death test) or " "\ast\(child process runs the death test immediately " "after forking).")
void OnTestStart(const TestInfo &test_info) override
std::vector< TestEventListener * > listeners_
void OnTestStart(const TestInfo &test_info) override
TestInfo * GetMutableTestInfo(int i)
AssertionResult AssertionSuccess()
int total_test_suite_count() const
void OnTestPartResult(const TestPartResult &result) override
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
const char kDeathTestStyleFlag[]
void set_forwarding_enabled(bool enable)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
int reportable_test_count() const
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)
#define GTEST_CHECK_(condition)
std::string const message
static std::string FormatHexUInt32(uint32_t value)
TestEventListeners & listeners()
void(*)() TearDownTestSuiteFunc
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
void SetDefaultXmlGenerator(TestEventListener *listener)
int failed_test_count() const
std::vector< TestPartResult > test_part_results_
static bool IsValidXmlCharacter(char c)
std::vector< TestProperty > test_properties_
const char * original_working_dir() const
static const char kValueParamLabel[]
AssertionResult AssertionFailure(const Message &message)
static bool CStringEquals(const char *lhs, const char *rhs)
static const char *const kReservedTestSuitesAttributes[]
AssertHelper(TestPartResult::Type type, const char *file, int line, const char *message)
void OnTestCaseEnd(const TestCase &test_case) override
void ParseGoogleTestFlagsOnly(int *argc, wchar_t **argv)
void OnTestProgramStart(const UnitTest &) override
static bool WideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
const TypeId kTestTypeIdInGoogleTest
static std::string FormatEpochTimeInMillisAsRFC3339(TimeInMillis ms)
internal::UnitTestImpl * impl_
static bool GTestIsInitialized()
std::vector< int > test_indices_
static void OutputXmlTestProperties(std::ostream *stream, const TestResult &result)
GTEST_API_ bool AlwaysTrue()
int failed_test_count() const
static bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
static void PrintColorEncoded(const char *str)
AssertionResult FloatingPointLE(const char *expr1, const char *expr2, RawType val1, RawType val2)
void AddTestPartResult(const TestPartResult &test_part_result)
void ShuffleTests(internal::Random *random)
const char * type_param() const
virtual void OnTestSuiteEnd(const TestSuite &)
void OnEnvironmentsTearDownEnd(const UnitTest &) override
bool is_in_another_shard() const
std::map< std::string, TypeParameterizedTestSuiteInfo > suites_
int StrCaseCmp(const char *s1, const char *s2)
TestInfo * RegisterTest(const char *test_suite_name, const char *test_name, const char *type_param, const char *value_param, const char *file, int line, Factory factory)
constexpr uint32_t kMaxCodePoint1
static const uint32_t kMaxRange
TimeInMillis start_timestamp_
static void OutputXmlAttribute(std::ostream *stream, const std::string &element_name, const std::string &name, const std::string &value)
TimeInMillis elapsed_time() const
static bool TestPartSkipped(const TestPartResult &result)
static const char * ParseFlagValue(const char *str, const char *flag, bool def_optional)
const TestCase * GetTestCase(int i) const
virtual void OnTestSuiteStart(const TestSuite &)
static int SumOverTestSuiteList(const std::vector< TestSuite *> &case_list, int(TestSuite::*method)() const)
void OnTestProgramEnd(const UnitTest &) override
const char * type_param() const
GTEST_IMPL_CMP_HELPER_(NE, !=)
bool operator()(const TestSuite *test_suite) const
const std::string output_file_
static const char kUniversalFilter[]
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static bool ShouldRunTest(const TestInfo *test_info)
FilePath GetCurrentExecutableName()
TimeInMillis GetTimeInMillis()
void OnTestSuiteStart(const TestSuite ¶meter) override
int32_t Int32FromEnvOrDie(const char *var, int32_t default_val)
static void PrintOnOneLine(const char *str, int max_length)
static std::string FormatTestCount(int test_count)
static void PrintTestName(const char *test_suite, const char *test)
static std::string RemoveInvalidXmlCharacters(const std::string &str)
TestSuiteNameIs(const std::string &name)
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
static bool TestPartFatallyFailed(const TestPartResult &result)
void OnTestPartResult(const TestPartResult &result) override
static ::std::vector< std::string > g_argvs
void set_start_timestamp(TimeInMillis start)
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static const char *const kReservedTestCaseAttributes[]
static std::string EscapeXmlText(const char *str)
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
static void PrintTestName(const char *test_suite, const char *test)
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
GTEST_API_ const char kStackTraceMarker[]
static void PrintTestPartResult(const TestPartResult &test_part_result)
TimeInMillis elapsed_time() const
#define GTEST_INIT_GOOGLE_TEST_NAME_
constexpr uint32_t kMaxCodePoint3
bool BoolFromGTestEnv(const char *flag, bool default_val)
FILE * FOpen(const char *path, const char *mode)
void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
static const char kDefaultOutputFile[]
GTEST_API_ void InsertSyntheticTestCase(const std::string &name, CodeLocation location, bool has_test_p)
Environment * AddEnvironment(Environment *env)
static bool ValidateTestPropertyName(const std::string &property_name, const std::vector< std::string > &reserved_names)
static bool TestDisabled(const TestInfo *test_info)
static FILE * OpenFileForWriting(const std::string &output_file)
static const char *const kReservedOutputTestCaseAttributes[]
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_)
internal::UnitTestImpl * impl()
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
void OnTestProgramStart(const UnitTest &) override
std::string GetString() const
void InitGoogleTestImpl(int *argc, CharType **argv)
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.")
int reportable_disabled_test_count() const
TimeInMillis elapsed_time_
int Run() GTEST_MUST_USE_RESULT_
static std::vector< std::string > GetReservedOutputAttributesForElement(const std::string &xml_element)
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
XmlUnitTestResultPrinter(const char *output_file)
void OnTestCaseEnd(const TestCase &) override
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)
void OnTestCaseEnd(const TestCase ¶meter) override
int reportable_test_count() const
TimeInMillis elapsed_time() const
TestEventListener * Release(TestEventListener *listener)
uint32_t ChopLowBits(uint32_t *bits, int n)
static const char kDefaultOutputFormat[]
static void PrintFullTestCommentIfPresent(const TestInfo &test_info)
static std::string FormatWordList(const std::vector< std::string > &words)
TestEventListener * default_xml_generator_
static bool GetDefaultFailFast()
void RegisterTestSuite(const char *test_suite_name, CodeLocation code_location)
int successful_test_case_count() const
static bool HasSameFixtureClass()
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
bool is_reportable() const
void CheckForInstantiations()
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
static const char kTestShardIndex[]
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile)
#define GTEST_HAS_GETTIMEOFDAY_
static bool TestSkipped(const TestInfo *test_info)
TimeInMillis elapsed_time_
TestEventListener * default_result_printer_
void RegisterTypeParameterizedTestSuite(const char *test_suite_name, CodeLocation code_location)
int test_to_run_count() const
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
uint32_t CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
static const char kColorEncodedHelpMessage[]
std::vector< TestInfo * > & test_info_list()
static void PrintJsonTestSuite(::std::ostream *stream, const TestSuite &test_suite)
static void OutputXmlTestInfo(::std::ostream *stream, const char *test_suite_name, const TestInfo &test_info)
static void TearDownEnvironment(Environment *env)
virtual void OnTestCaseEnd(const TestCase &)
virtual void OnTestEnd(const TestInfo &test_info)=0
static bool TestFailed(const TestInfo *test_info)
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
constexpr uint32_t kMaxCodePoint2
void set_should_run(bool should)
void OnEnvironmentsSetUpEnd(const UnitTest &) override
static bool ParseStringFlag(const char *str, const char *flag, String *value)
void OnEnvironmentsSetUpStart(const UnitTest &unit_test) override
int test_case_to_run_count() const
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static UnitTest * GetInstance()
void OnTestIterationEnd(const UnitTest &unit_test, int iteration) override
static bool PortableLocaltime(time_t seconds, struct tm *out)
void ClearTestPartResults()
const char * file() const
void OnEnvironmentsTearDownStart(const UnitTest &unit_test) override
void OnTestCaseStart(const TestCase &) override
static bool TestSuiteFailed(const TestSuite *test_suite)
const TestSuite * current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_)
static void PrintFailedTestSuites(const UnitTest &unit_test)
const TestInfo * GetTestInfo(int i) const
static void RecordProperty(const std::string &key, const std::string &value)
int failed_test_suite_count() const
void OnEnvironmentsTearDownEnd(const UnitTest &unit_test) override
bool HasFatalFailure() const
void OnTestProgramStart(const UnitTest &unit_test) override
void OnTestIterationStart(const UnitTest &unit_test, int iteration) override
#define GTEST_FLAG_SAVER_
int failed_test_case_count() const
const std::string premature_exit_filepath_
static std::string FormatIntWidth2(int value)
void WriteToShardStatusFileIfNeeded()
static bool TestReportable(const TestInfo *test_info)
static bool TestReportableDisabled(const TestInfo *test_info)
bool HasNonfatalFailure() const
int successful_test_suite_count() const
static std::string ShowWideCString(const wchar_t *wide_c_str)
static void PrintFailedTests(const UnitTest &unit_test)
std::string OutputFlagAlsoCheckEnvVar()
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
int successful_test_count() const
bool is_in_another_shard_
std::set< std::string > * GetIgnoredParameterizedTestSuites()
~TestEventRepeater() override
int disabled_test_count() const
const std::unique_ptr< ::std::stringstream > ss_
#define GTEST_FLAG_PREFIX_
void OnEnvironmentsSetUpEnd(const UnitTest &unit_test) override
internal::ParameterizedTestSuiteRegistry & parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_)
void Append(TestEventListener *listener)
void OnEnvironmentsTearDownStart(const UnitTest &) override
static std::string PrintTestPartResultToString(const TestPartResult &test_part_result)
void OnTestCaseStart(const TestCase &test_case) override
static bool ShouldRunTestSuite(const TestSuite *test_suite)
int total_test_count() const
void OnTestEnd(const TestInfo &test_info) override
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
static std::string EscapeJson(const std::string &str)
static void OutputXmlCDataSection(::std::ostream *stream, const char *data)
void operator=(const Message &message) const
GTEST_API_ std::string TempDir()
void AddTestInfo(TestInfo *test_info)
static const char kTypeParamLabel[]
static ExpectedAnswer expected[4]