34 #include "gtest/gtest.h" 35 #include "gtest/gtest-spi.h" 57 # define GTEST_HAS_GETTIMEOFDAY_ 1 64 # include <sys/mman.h> 65 # include <sys/time.h> 69 #elif GTEST_OS_SYMBIAN 70 # define GTEST_HAS_GETTIMEOFDAY_ 1 71 # include <sys/time.h> 74 # define GTEST_HAS_GETTIMEOFDAY_ 1 75 # include <sys/time.h> 80 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. 84 #elif GTEST_OS_WINDOWS // We are on Windows proper. 87 # include <sys/timeb.h> 88 # include <sys/types.h> 89 # include <sys/stat.h> 91 # if GTEST_OS_WINDOWS_MINGW 98 # define GTEST_HAS_GETTIMEOFDAY_ 1 99 # include <sys/time.h> 100 # endif // GTEST_OS_WINDOWS_MINGW 104 # include <windows.h> 111 # define GTEST_HAS_GETTIMEOFDAY_ 1 115 # include <sys/time.h> 118 #endif // GTEST_OS_LINUX 120 #if GTEST_HAS_EXCEPTIONS 121 # include <stdexcept> 124 #if GTEST_CAN_STREAM_RESULTS_ 125 # include <arpa/inet.h> 134 #define GTEST_IMPLEMENTATION_ 1 135 #include "src/gtest-internal-inl.h" 136 #undef GTEST_IMPLEMENTATION_ 139 # define vsnprintf _vsnprintf 140 #endif // GTEST_OS_WINDOWS 190 also_run_disabled_tests,
192 "Run disabled tests too, in addition to the tests normally being run.");
197 "True iff a failed assertion should be a debugger break-point.");
203 " should catch exceptions and treat them as test failures.");
208 "Whether to use colors in the output. Valid values: yes, no, " 209 "and auto. 'auto' means to use colors if the output is " 210 "being sent to a terminal and the TERM environment variable " 211 "is set to a terminal type that supports colors.");
216 "A colon-separated list of glob (not regex) patterns " 217 "for filtering the tests to run, optionally followed by a " 218 "'-' and a : separated list of negative patterns (tests to " 219 "exclude). A test is run if it matches one of the positive " 220 "patterns and does not match any of the negative patterns.");
223 "List all tests without running them.");
228 "A format (currently must be \"xml\"), optionally followed " 229 "by a colon and an output file name or directory. A directory " 230 "is indicated by a trailing pathname separator. " 231 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". " 232 "If a directory is specified, output files will be created " 233 "within that directory, with file-names based on the test " 234 "executable's name and, if necessary, made unique by adding " 241 " should display elapsed time in text output.");
246 "Random number seed to use when shuffling test orders. Must be in range " 247 "[1, 99999], or 0 to use a seed based on the current time.");
252 "How many times to repeat each test. Specify a negative number " 253 "for repeating forever. Useful for shaking out flaky tests.");
256 show_internal_stack_frames,
false,
257 "True iff " GTEST_NAME_ " should include internal stack frames when " 258 "printing test failure stack traces.");
264 " should randomize tests' order on every run.");
269 "The maximum number of stack frames to print when an " 270 "assertion fails. The valid range is 0 through 100, inclusive.");
275 "This flag specifies the host name and the port number on which to stream " 276 "test results. Example: \"localhost:555\". The flag is effective only on " 282 "When this flag is specified, a failed assertion will throw an exception " 283 "if exceptions are enabled or exit the program with a non-zero code " 293 state_ = (1103515245U*state_ + 12345U) % kMaxRange;
296 <<
"Cannot generate a number in the range [0, 0).";
298 <<
"Generation of a number in [0, " << range <<
") was requested, " 299 <<
"but this can only generate numbers in [0, " << kMaxRange <<
").";
304 return state_ % range;
324 for (
size_t i = 0; i < case_list.size(); i++) {
325 sum += (case_list[i]->*method)();
351 : data_(
new AssertHelperData(type, file, line, message)) {
361 AddTestPartResult(data_->type, data_->file, data_->line,
381 result.
Set(
FilePath(g_executable_path).RemoveExtension(
"exe"));
384 #endif // GTEST_OS_WINDOWS 394 if (gtest_output_flag == NULL)
return std::string(
"");
396 const char*
const colon = strchr(gtest_output_flag,
':');
397 return (colon == NULL) ?
399 std::string(gtest_output_flag, colon - gtest_output_flag);
406 if (gtest_output_flag == NULL)
409 const char*
const colon = strchr(gtest_output_flag,
':');
427 return output_name.
string();
431 GetOutputFormat().c_str()));
447 return *str !=
'\0' && PatternMatchesString(pattern + 1, str + 1);
449 return (*str !=
'\0' && PatternMatchesString(pattern, str + 1)) ||
450 PatternMatchesString(pattern + 1, str);
452 return *pattern == *str &&
453 PatternMatchesString(pattern + 1, str + 1);
459 const char *cur_pattern = filter;
461 if (PatternMatchesString(cur_pattern, name.c_str())) {
466 cur_pattern = strchr(cur_pattern,
':');
469 if (cur_pattern == NULL) {
482 const std::string& full_name = test_case_name +
"." + test_name.c_str();
486 const char*
const p =
GTEST_FLAG(filter).c_str();
487 const char*
const dash = strchr(p,
'-');
496 if (positive.empty()) {
504 return (MatchesFilter(full_name, positive.c_str()) &&
505 !MatchesFilter(full_name, negative.c_str()));
512 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
521 const DWORD kCxxExceptionCode = 0xe06d7363;
523 bool should_handle =
true;
526 should_handle =
false;
527 else if (exception_code == EXCEPTION_BREAKPOINT)
528 should_handle =
false;
529 else if (exception_code == kCxxExceptionCode)
530 should_handle =
false;
532 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
534 #endif // GTEST_HAS_SEH 543 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
553 : intercept_mode_(intercept_mode),
560 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
573 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
584 result_->Append(result);
599 return GetTypeId<Test>();
614 const string& substr) {
617 "1 non-fatal failure");
619 if (results.
size() != 1) {
620 msg <<
"Expected: " << expected <<
"\n" 621 <<
" Actual: " << results.
size() <<
" failures";
622 for (
int i = 0; i < results.
size(); i++) {
629 if (r.
type() != type) {
635 if (strstr(r.
message(), substr.c_str()) == NULL) {
651 const string& substr)
669 unit_test_->current_test_result()->AddTestPartResult(result);
670 unit_test_->listeners()->repeater()->OnTestPartResult(result);
678 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
685 return global_test_part_result_repoter_;
692 global_test_part_result_repoter_ = reporter;
698 return per_thread_test_part_result_reporter_.get();
704 per_thread_test_part_result_reporter_.set(reporter);
719 return static_cast<int>(test_cases_.size());
781 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) 786 const DWORD kTenthMicrosInMilliSecond = 10000;
788 SYSTEMTIME now_systime;
789 FILETIME now_filetime;
790 ULARGE_INTEGER now_int64;
793 GetSystemTime(&now_systime);
794 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
795 now_int64.LowPart = now_filetime.dwLowDateTime;
796 now_int64.HighPart = now_filetime.dwHighDateTime;
797 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
798 kJavaEpochToWinFileTimeDelta;
799 return now_int64.QuadPart;
802 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ 811 # pragma warning(push) // Saves the current warning state. 812 # pragma warning(disable:4996) // Temporarily disables warning 4996. 814 # pragma warning(pop) // Restores the warning state. 821 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
824 gettimeofday(&now, NULL);
825 return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
827 # error
"Don't know how to get the current time on your system." 835 #if GTEST_OS_WINDOWS_MOBILE 840 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
841 if (!ansi)
return NULL;
842 const int length = strlen(ansi);
843 const int unicode_length =
844 MultiByteToWideChar(CP_ACP, 0, ansi, length,
846 WCHAR* unicode =
new WCHAR[unicode_length + 1];
847 MultiByteToWideChar(CP_ACP, 0, ansi, length,
848 unicode, unicode_length);
849 unicode[unicode_length] = 0;
857 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
858 if (!utf16_str)
return NULL;
859 const int ansi_length =
860 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
861 NULL, 0, NULL, NULL);
862 char* ansi =
new char[ansi_length + 1];
863 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
864 ansi, ansi_length, NULL, NULL);
865 ansi[ansi_length] = 0;
869 #endif // GTEST_OS_WINDOWS_MOBILE 877 if ( lhs == NULL )
return rhs == NULL;
879 if ( rhs == NULL )
return false;
881 return strcmp(lhs, rhs) == 0;
884 #if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING 890 for (
size_t i = 0; i != length; ) {
891 if (wstr[i] != L
'\0') {
892 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
893 while (i != length && wstr[i] != L
'\0')
902 #endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING 914 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
926 #if GTEST_HAS_STD_WSTRING 933 #endif // GTEST_HAS_STD_WSTRING 935 #if GTEST_HAS_GLOBAL_WSTRING 942 #endif // GTEST_HAS_GLOBAL_WSTRING 962 if (message_.get() != NULL)
963 negation << *message_;
1001 const char* actual_expression,
1004 bool ignoring_case) {
1006 msg <<
"Value of: " << actual_expression;
1007 if (actual_value != actual_expression) {
1008 msg <<
"\n Actual: " << actual_value;
1011 msg <<
"\nExpected: " << expected_expression;
1012 if (ignoring_case) {
1013 msg <<
" (ignoring case)";
1015 if (expected_value != expected_expression) {
1016 msg <<
"\nWhich is: " << expected_value;
1025 const char* expression_text,
1026 const char* actual_predicate_value,
1027 const char* expected_predicate_value) {
1028 const char* actual_message = assertion_result.
message();
1030 msg <<
"Value of: " << expression_text
1031 <<
"\n Actual: " << actual_predicate_value;
1032 if (actual_message[0] !=
'\0')
1033 msg <<
" (" << actual_message <<
")";
1034 msg <<
"\nExpected: " << expected_predicate_value;
1041 const char* abs_error_expr,
1045 const double diff = fabs(val1 - val2);
1051 <<
"The difference between " << expr1 <<
" and " << expr2
1052 <<
" is " << diff <<
", which exceeds " << abs_error_expr <<
", where\n" 1053 << expr1 <<
" evaluates to " << val1 <<
",\n" 1054 << expr2 <<
" evaluates to " << val2 <<
", and\n" 1055 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1060 template <
typename RawType>
1072 if (lhs.AlmostEquals(rhs)) {
1080 ::std::stringstream val1_ss;
1081 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1084 ::std::stringstream val2_ss;
1085 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1089 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n" 1099 float val1,
float val2) {
1100 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1106 double val1,
double val2) {
1107 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1110 namespace internal {
1115 const char* actual_expression,
1118 if (expected == actual) {
1132 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\ 1133 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ 1134 BiggestInt val1, BiggestInt val2) {\ 1135 if (val1 op val2) {\ 1136 return AssertionSuccess();\ 1138 return AssertionFailure() \ 1139 << "Expected: (" << expr1 << ") " #op " (" << expr2\ 1140 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ 1141 << " vs " << FormatForComparisonFailureMessage(val2, val1);\ 1161 #undef GTEST_IMPL_CMP_HELPER_ 1165 const char* actual_expression,
1166 const char* expected,
1167 const char* actual) {
1181 const char* actual_expression,
1182 const char* expected,
1183 const char* actual) {
1197 const char* s2_expression,
1204 << s2_expression <<
"), actual: \"" 1205 << s1 <<
"\" vs \"" << s2 <<
"\"";
1211 const char* s2_expression,
1218 <<
"Expected: (" << s1_expression <<
") != (" 1219 << s2_expression <<
") (ignoring case), actual: \"" 1220 << s1 <<
"\" vs \"" << s2 <<
"\"";
1234 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1235 if (needle == NULL || haystack == NULL)
1236 return needle == haystack;
1238 return strstr(haystack, needle) != NULL;
1241 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1242 if (needle == NULL || haystack == NULL)
1243 return needle == haystack;
1245 return wcsstr(haystack, needle) != NULL;
1249 template <
typename StringType>
1250 bool IsSubstringPred(
const StringType& needle,
1251 const StringType& haystack) {
1252 return haystack.find(needle) != StringType::npos;
1259 template <
typename StringType>
1260 AssertionResult IsSubstringImpl(
1261 bool expected_to_be_substring,
1262 const char* needle_expr,
const char* haystack_expr,
1263 const StringType& needle,
const StringType& haystack) {
1264 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1267 const bool is_wide_string =
sizeof(needle[0]) > 1;
1268 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1270 <<
"Value of: " << needle_expr <<
"\n" 1271 <<
" Actual: " << begin_string_quote << needle <<
"\"\n" 1272 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1273 <<
"a substring of " << haystack_expr <<
"\n" 1274 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1284 const char* needle_expr,
const char* haystack_expr,
1285 const char* needle,
const char* haystack) {
1286 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1290 const char* needle_expr,
const char* haystack_expr,
1291 const wchar_t* needle,
const wchar_t* haystack) {
1292 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1296 const char* needle_expr,
const char* haystack_expr,
1297 const char* needle,
const char* haystack) {
1298 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1302 const char* needle_expr,
const char* haystack_expr,
1303 const wchar_t* needle,
const wchar_t* haystack) {
1304 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1308 const char* needle_expr,
const char* haystack_expr,
1310 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1314 const char* needle_expr,
const char* haystack_expr,
1316 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1319 #if GTEST_HAS_STD_WSTRING 1321 const char* needle_expr,
const char* haystack_expr,
1323 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1327 const char* needle_expr,
const char* haystack_expr,
1329 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1331 #endif // GTEST_HAS_STD_WSTRING 1333 namespace internal {
1335 #if GTEST_OS_WINDOWS 1340 AssertionResult HRESULTFailureHelper(
const char* expr,
1341 const char* expected,
1343 # if GTEST_OS_WINDOWS_MOBILE 1346 const char error_text[] =
"";
1353 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1354 FORMAT_MESSAGE_IGNORE_INSERTS;
1355 const DWORD kBufSize = 4096;
1357 char error_text[kBufSize] = {
'\0' };
1358 DWORD message_length = ::FormatMessageA(kFlags,
1366 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1368 error_text[message_length - 1] =
'\0';
1371 # endif // GTEST_OS_WINDOWS_MOBILE 1375 <<
"Expected: " << expr <<
" " << expected <<
".\n" 1376 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1381 AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1382 if (SUCCEEDED(hr)) {
1385 return HRESULTFailureHelper(expr,
"succeeds", hr);
1388 AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1392 return HRESULTFailureHelper(expr,
"fails", hr);
1395 #endif // GTEST_OS_WINDOWS 1425 const UInt32 low_bits = *bits & ((
static_cast<UInt32>(1) << n) - 1);
1437 if (code_point > kMaxCodePoint4) {
1442 if (code_point <= kMaxCodePoint1) {
1444 str[0] =
static_cast<char>(code_point);
1445 }
else if (code_point <= kMaxCodePoint2) {
1447 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1448 str[0] =
static_cast<char>(0xC0 | code_point);
1449 }
else if (code_point <= kMaxCodePoint3) {
1451 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1452 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1453 str[0] =
static_cast<char>(0xE0 | code_point);
1456 str[3] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1457 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1458 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1459 str[0] =
static_cast<char>(0xF0 | code_point);
1472 return sizeof(wchar_t) == 2 &&
1473 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1479 const UInt32 mask = (1 << 10) - 1;
1480 return (
sizeof(
wchar_t) == 2) ?
1481 (((first & mask) << 10) | (second & mask)) + 0x10000 :
1484 static_cast<UInt32>(first);
1501 if (num_chars == -1)
1502 num_chars =
static_cast<int>(wcslen(str));
1504 ::std::stringstream stream;
1505 for (
int i = 0; i < num_chars; ++i) {
1506 UInt32 unicode_code_point;
1508 if (str[i] == L
'\0') {
1515 unicode_code_point =
static_cast<UInt32>(str[i]);
1526 if (wide_c_str == NULL)
return "(null)";
1538 if (lhs == NULL)
return rhs == NULL;
1540 if (rhs == NULL)
return false;
1542 return wcscmp(lhs, rhs) == 0;
1547 const char* actual_expression,
1548 const wchar_t* expected,
1549 const wchar_t* actual) {
1563 const char* s2_expression,
1565 const wchar_t* s2) {
1571 << s2_expression <<
"), actual: " 1603 const wchar_t* rhs) {
1604 if (lhs == NULL)
return rhs == NULL;
1606 if (rhs == NULL)
return false;
1608 #if GTEST_OS_WINDOWS 1609 return _wcsicmp(lhs, rhs) == 0;
1610 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID 1611 return wcscasecmp(lhs, rhs) == 0;
1617 left = towlower(*lhs++);
1618 right = towlower(*rhs++);
1619 }
while (left && left == right);
1620 return left == right;
1621 #endif // OS selector 1628 const size_t str_len = str.length();
1629 const size_t suffix_len = suffix.length();
1630 return (str_len >= suffix_len) &&
1637 std::stringstream ss;
1638 ss << std::setfill(
'0') << std::setw(2) << value;
1644 std::stringstream ss;
1645 ss <<
std::hex << std::uppercase << value;
1651 std::stringstream ss;
1652 ss << std::setfill(
'0') << std::setw(2) <<
std::hex << std::uppercase
1653 <<
static_cast<unsigned int>(value);
1661 const char*
const start = str.c_str();
1662 const char*
const end = start + str.length();
1665 result.reserve(2 * (end - start));
1666 for (
const char* ch = start; ch !=
end; ++ch) {
1681 const std::string user_msg_string = user_msg.GetString();
1682 if (user_msg_string.empty()) {
1686 return gtest_msg +
"\n" + user_msg_string;
1695 : death_test_count_(0),
1707 if (i < 0 || i >= total_part_count())
1709 return test_part_results_.at(i);
1716 if (i < 0 || i >= test_property_count())
1718 return test_properties_.at(i);
1723 test_part_results_.clear();
1728 test_part_results_.push_back(test_part_result);
1735 const TestProperty& test_property) {
1736 if (!ValidateTestProperty(xml_element, test_property)) {
1740 const std::vector<TestProperty>::iterator property_with_matching_key =
1741 std::find_if(test_properties_.begin(), test_properties_.end(),
1742 internal::TestPropertyKeyIs(test_property.key()));
1743 if (property_with_matching_key == test_properties_.end()) {
1744 test_properties_.push_back(test_property);
1747 property_with_matching_key->SetValue(test_property.value());
1784 template <
int kSize>
1785 std::vector<std::string>
ArrayAsVector(
const char*
const (&array)[kSize]) {
1786 return std::vector<std::string>(array, array + kSize);
1791 if (xml_element ==
"testsuites") {
1793 }
else if (xml_element ==
"testsuite") {
1795 }
else if (xml_element ==
"testcase") {
1798 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
1801 return std::vector<std::string>();
1806 for (
size_t i = 0; i < words.size(); ++i) {
1807 if (i > 0 && words.size() > 2) {
1810 if (i == words.size() - 1) {
1811 word_list <<
"and ";
1813 word_list <<
"'" << words[i] <<
"'";
1819 const std::vector<std::string>& reserved_names) {
1820 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
1821 reserved_names.end()) {
1822 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
1840 test_part_results_.clear();
1841 test_properties_.clear();
1842 death_test_count_ = 0;
1848 for (
int i = 0; i < total_part_count(); ++i) {
1849 if (GetTestPartResult(i).failed())
1878 return static_cast<int>(test_part_results_.size());
1883 return static_cast<int>(test_properties_.size());
1897 delete gtest_flag_saver_;
1920 value_message << value;
1921 RecordProperty(key, value_message.
GetString().c_str());
1924 namespace internal {
1952 const char*
const first_test_name = first_test_info->
name();
1957 const char*
const this_test_name = this_test_info->
name();
1959 if (this_fixture_id != first_fixture_id) {
1965 if (first_is_TEST || this_is_TEST) {
1972 const char*
const TEST_name =
1973 first_is_TEST ? first_test_name : this_test_name;
1974 const char*
const TEST_F_name =
1975 first_is_TEST ? this_test_name : first_test_name;
1978 <<
"All tests in the same test case must use the same test fixture\n" 1979 <<
"class, so mixing TEST_F and TEST in the same test case is\n" 1982 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n" 1983 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n" 1984 <<
"want to change the TEST to TEST_F or move it to another test\n" 1990 <<
"All tests in the same test case must use the same test fixture\n" 1991 <<
"class. However, in test case " 1993 <<
"you defined test " << first_test_name
1994 <<
" and test " << this_test_name <<
"\n" 1995 <<
"using two different test fixture classes. This can happen if\n" 1996 <<
"the two classes are from different namespaces or translation\n" 1997 <<
"units and have the same name. You should probably rename one\n" 1998 <<
"of the classes to put the tests into different test cases.";
2012 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2013 const char* location) {
2015 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2016 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2021 #endif // GTEST_HAS_SEH 2023 namespace internal {
2025 #if GTEST_HAS_EXCEPTIONS 2029 const char* location) {
2031 if (description != NULL) {
2032 message <<
"C++ exception with description \"" << description <<
"\"";
2034 message <<
"Unknown C++ exception";
2036 message <<
" thrown in " << location <<
".";
2044 GoogleTestFailureException::GoogleTestFailureException(
2048 #endif // GTEST_HAS_EXCEPTIONS 2058 template <
class T,
typename Result>
2060 T*
object, Result (T::*method)(),
const char* location) {
2063 return (object->*method)();
2064 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2065 GetExceptionCode())) {
2069 std::string* exception_message = FormatSehExceptionMessage(
2070 GetExceptionCode(), location);
2072 *exception_message);
2073 delete exception_message;
2074 return static_cast<Result
>(0);
2078 return (object->*method)();
2079 #endif // GTEST_HAS_SEH 2085 template <
class T,
typename Result>
2087 T*
object, Result (T::*method)(),
const char* location) {
2112 #if GTEST_HAS_EXCEPTIONS 2115 }
catch (
const internal::GoogleTestFailureException&) {
2120 }
catch (
const std::exception& e) {
2123 FormatCxxExceptionMessage(e.what(), location));
2127 FormatCxxExceptionMessage(NULL, location));
2129 return static_cast<Result
>(0);
2132 #endif // GTEST_HAS_EXCEPTIONS 2134 return (object->*method)();
2142 if (!HasSameFixtureClass())
return;
2148 if (!HasFatalFailure()) {
2170 HasNonfatalFailure();
2179 const char* a_type_param,
2180 const char* a_value_param,
2183 : test_case_name_(a_test_case_name),
2185 type_param_(a_type_param ?
new std::string(a_type_param) : NULL),
2186 value_param_(a_value_param ?
new std::string(a_value_param) : NULL),
2187 fixture_class_id_(fixture_class_id),
2189 is_disabled_(
false),
2190 matches_filter_(
false),
2197 namespace internal {
2217 const char* test_case_name,
2219 const char* type_param,
2220 const char* value_param,
2224 TestFactoryBase* factory) {
2226 new TestInfo(test_case_name, name, type_param, value_param,
2227 fixture_class_id, factory);
2232 #if GTEST_HAS_PARAM_TEST 2234 const char* file,
int line) {
2237 <<
"Attempted redefinition of test case " << test_case_name <<
".\n" 2238 <<
"All tests in the same test case must use the same test fixture\n" 2239 <<
"class. However, in test case " << test_case_name <<
", you tried\n" 2240 <<
"to define a test using a fixture class different from the one\n" 2241 <<
"used earlier. This can happen if the two fixture classes are\n" 2242 <<
"from different namespaces and have the same name. You should\n" 2243 <<
"probably rename one of the classes to put the tests into different\n" 2249 #endif // GTEST_HAS_PARAM_TEST 2268 explicit TestNameIs(
const char*
name)
2272 bool operator()(
const TestInfo * test_info)
const {
2273 return test_info && test_info->
name() ==
name_;
2282 namespace internal {
2288 #if GTEST_HAS_PARAM_TEST 2289 if (!parameterized_tests_registered_) {
2290 parameterized_test_registry_.RegisterTests();
2291 parameterized_tests_registered_ =
true;
2301 if (!should_run_)
return;
2305 impl->set_current_test_info(
this);
2314 impl->os_stack_trace_getter()->UponLeavingGTest();
2319 "the test fixture's constructor");
2330 impl->os_stack_trace_getter()->UponLeavingGTest();
2337 repeater->OnTestEnd(*
this);
2341 impl->set_current_test_info(NULL);
2348 return CountIf(test_info_list_, TestPassed);
2353 return CountIf(test_info_list_, TestFailed);
2358 return CountIf(test_info_list_, TestReportableDisabled);
2363 return CountIf(test_info_list_, TestDisabled);
2368 return CountIf(test_info_list_, TestReportable);
2373 return CountIf(test_info_list_, ShouldRunTest);
2378 return static_cast<int>(test_info_list_.size());
2394 type_param_(a_type_param ?
new std::string(a_type_param) : NULL),
2395 set_up_tc_(set_up_tc),
2396 tear_down_tc_(tear_down_tc),
2404 ForEach(test_info_list_, internal::Delete<TestInfo>);
2411 return index < 0 ? NULL : test_info_list_[index];
2418 return index < 0 ? NULL : test_info_list_[index];
2424 test_info_list_.push_back(test_info);
2425 test_indices_.push_back(static_cast<int>(test_indices_.size()));
2430 if (!should_run_)
return;
2433 impl->set_current_test_case(
this);
2438 impl->os_stack_trace_getter()->UponLeavingGTest();
2443 for (
int i = 0; i < total_test_count(); i++) {
2444 GetMutableTestInfo(i)->Run();
2448 impl->os_stack_trace_getter()->UponLeavingGTest();
2452 repeater->OnTestCaseEnd(*
this);
2453 impl->set_current_test_case(NULL);
2458 ad_hoc_test_result_.Clear();
2464 Shuffle(random, &test_indices_);
2469 for (
size_t i = 0; i < test_indices_.size(); i++) {
2470 test_indices_[i] =
static_cast<int>(i);
2480 const char * singular_form,
2481 const char * plural_form) {
2483 (count == 1 ? singular_form : plural_form);
2513 return "Unknown result type";
2517 namespace internal {
2526 << test_part_result.
message()).GetString();
2533 printf(
"%s\n", result.c_str());
2539 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2543 ::OutputDebugStringA(result.c_str());
2544 ::OutputDebugStringA(
"\n");
2557 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2564 case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
2577 case COLOR_YELLOW:
return "3";
2578 default:
return NULL;
2582 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2586 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
2589 #if GTEST_OS_WINDOWS 2592 return stdout_is_tty;
2596 const bool term_supports_color =
2604 return stdout_is_tty && term_supports_color;
2605 #endif // GTEST_OS_WINDOWS 2623 va_start(args, fmt);
2625 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || GTEST_OS_IOS 2626 const bool use_color =
false;
2628 static const bool in_color_mode =
2630 const bool use_color = in_color_mode && (color !=
COLOR_DEFAULT);
2631 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS 2640 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2641 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
2644 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
2645 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
2646 const WORD old_color_attrs = buffer_info.wAttributes;
2652 SetConsoleTextAttribute(stdout_handle,
2653 GetColorAttribute(color) | FOREGROUND_INTENSITY);
2658 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
2663 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2673 const char*
const type_param = test_info.
type_param();
2674 const char*
const value_param = test_info.
value_param();
2676 if (type_param != NULL || value_param != NULL) {
2678 if (type_param != NULL) {
2679 printf(
"%s = %s", kTypeParamLabel, type_param);
2680 if (value_param != NULL)
2683 if (value_param != NULL) {
2684 printf(
"%s = %s", kValueParamLabel, value_param);
2696 printf(
"%s.%s", test_case, test);
2701 virtual void OnTestIterationStart(
const UnitTest& unit_test,
int iteration);
2702 virtual void OnEnvironmentsSetUpStart(
const UnitTest& unit_test);
2704 virtual void OnTestCaseStart(
const TestCase& test_case);
2705 virtual void OnTestStart(
const TestInfo& test_info);
2707 virtual void OnTestEnd(
const TestInfo& test_info);
2708 virtual void OnTestCaseEnd(
const TestCase& test_case);
2709 virtual void OnEnvironmentsTearDownStart(
const UnitTest& unit_test);
2711 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
2715 static void PrintFailedTests(
const UnitTest& unit_test);
2720 const UnitTest& unit_test,
int iteration) {
2722 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
2724 const char*
const filter =
GTEST_FLAG(filter).c_str();
2736 "Note: This is test shard %d of %s.\n",
2737 static_cast<int>(shard_index) + 1,
2743 "Note: Randomizing tests' orders with a seed of %d .\n",
2748 printf(
"Running %s from %s.\n",
2757 printf(
"Global test environment set-up.\n");
2765 printf(
"%s from %s", counts.c_str(), test_case.
name());
2818 printf(
"%s from %s (%s ms total)\n\n",
2819 counts.c_str(), test_case.
name(),
2827 printf(
"Global test environment tear-down\n");
2834 if (failed_test_count == 0) {
2859 printf(
"%s from %s ran.",
2871 if (!unit_test.
Passed()) {
2875 PrintFailedTests(unit_test);
2876 printf(
"\n%2d FAILED %s\n", num_failures,
2877 num_failures == 1 ?
"TEST" :
"TESTS");
2881 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
2882 if (!num_failures) {
2886 " YOU HAVE %d DISABLED %s\n\n",
2888 num_disabled == 1 ?
"TEST" :
"TESTS");
2911 virtual void OnTestProgramStart(
const UnitTest& unit_test);
2912 virtual void OnTestIterationStart(
const UnitTest& unit_test,
int iteration);
2913 virtual void OnEnvironmentsSetUpStart(
const UnitTest& unit_test);
2914 virtual void OnEnvironmentsSetUpEnd(
const UnitTest& unit_test);
2915 virtual void OnTestCaseStart(
const TestCase& test_case);
2916 virtual void OnTestStart(
const TestInfo& test_info);
2918 virtual void OnTestEnd(
const TestInfo& test_info);
2919 virtual void OnTestCaseEnd(
const TestCase& test_case);
2920 virtual void OnEnvironmentsTearDownStart(
const UnitTest& unit_test);
2921 virtual void OnEnvironmentsTearDownEnd(
const UnitTest& unit_test);
2922 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
2923 virtual void OnTestProgramEnd(
const UnitTest& unit_test);
2928 bool forwarding_enabled_;
2930 std::vector<TestEventListener*> listeners_;
2936 ForEach(listeners_, Delete<TestEventListener>);
2940 listeners_.push_back(listener);
2945 for (
size_t i = 0; i < listeners_.size(); ++i) {
2946 if (listeners_[i] == listener) {
2947 listeners_.erase(listeners_.begin() + i);
2957 #define GTEST_REPEATER_METHOD_(Name, Type) \ 2958 void TestEventRepeater::Name(const Type& parameter) { \ 2959 if (forwarding_enabled_) { \ 2960 for (size_t i = 0; i < listeners_.size(); i++) { \ 2961 listeners_[i]->Name(parameter); \ 2967 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \ 2968 void TestEventRepeater::Name(const Type& parameter) { \ 2969 if (forwarding_enabled_) { \ 2970 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \ 2971 listeners_[i]->Name(parameter); \ 2988 #undef GTEST_REPEATER_METHOD_ 2989 #undef GTEST_REVERSE_REPEATER_METHOD_ 2993 if (forwarding_enabled_) {
2994 for (
size_t i = 0; i < listeners_.size(); i++) {
2995 listeners_[i]->OnTestIterationStart(unit_test, iteration);
3002 if (forwarding_enabled_) {
3003 for (
int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
3004 listeners_[i]->OnTestIterationEnd(unit_test, iteration);
3012 class XmlUnitTestResultPrinter :
public EmptyTestEventListener {
3014 explicit XmlUnitTestResultPrinter(
const char* output_file);
3016 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
3022 return c == 0x9 || c == 0xA || c == 0xD;
3027 return IsNormalizableWhitespace(c) || c >= 0x20;
3041 return EscapeXml(str,
true);
3046 return EscapeXml(str,
false);
3051 static void OutputXmlAttribute(std::ostream* stream,
3057 static void OutputXmlCDataSection(::std::ostream* stream,
const char* data);
3060 static void OutputXmlTestInfo(::std::ostream* stream,
3061 const char* test_case_name,
3065 static void PrintXmlTestCase(::std::ostream* stream,
3069 static void PrintXmlUnitTest(::std::ostream* stream,
3086 : output_file_(output_file) {
3087 if (output_file_.c_str() == NULL || output_file_.empty()) {
3088 fprintf(stderr,
"XML output file may not be null\n");
3097 FILE* xmlout = NULL;
3098 FilePath output_file(output_file_);
3101 if (
output_dir.CreateDirectoriesRecursively()) {
3104 if (xmlout == NULL) {
3116 "Unable to open file \"%s\"\n",
3117 output_file_.c_str());
3121 std::stringstream stream;
3122 PrintXmlUnitTest(&stream, unit_test);
3143 for (
size_t i = 0; i < str.size(); ++i) {
3144 const char ch = str[i];
3168 if (IsValidXmlCharacter(ch)) {
3169 if (is_attribute && IsNormalizableWhitespace(ch))
3188 output.reserve(str.size());
3189 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
3190 if (IsValidXmlCharacter(*it))
3191 output.push_back(*it);
3214 ::std::stringstream ss;
3223 time_t seconds =
static_cast<time_t
>(ms / 1000);
3225 # pragma warning(push) // Saves the current warning state. 3226 # pragma warning(disable:4996) // Temporarily disables warning 4996 3228 const struct tm*
const time_struct =
localtime(&seconds);
3229 # pragma warning(pop) // Restores the warning state again. 3231 const struct tm*
const time_struct =
localtime(&seconds);
3233 if (time_struct == NULL)
3248 const char* segment = data;
3249 *stream <<
"<![CDATA[";
3251 const char*
const next_segment = strstr(segment,
"]]>");
3252 if (next_segment != NULL) {
3254 segment, static_cast<std::streamsize>(next_segment - segment));
3255 *stream <<
"]]>]]><![CDATA[";
3256 segment = next_segment + strlen(
"]]>");
3266 std::ostream* stream,
3270 const std::vector<std::string>& allowed_names =
3273 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
3274 allowed_names.end())
3275 <<
"Attribute " << name <<
" is not allowed for element <" << element_name
3278 *stream <<
" " << name <<
"=\"" << EscapeXmlAttribute(value) <<
"\"";
3284 const char* test_case_name,
3289 *stream <<
" <testcase";
3290 OutputXmlAttribute(stream, kTestcase,
"name", test_info.
name());
3293 OutputXmlAttribute(stream, kTestcase,
"value_param",
3297 OutputXmlAttribute(stream, kTestcase,
"type_param", test_info.
type_param());
3300 OutputXmlAttribute(stream, kTestcase,
"status",
3302 OutputXmlAttribute(stream, kTestcase,
"time",
3304 OutputXmlAttribute(stream, kTestcase,
"classname", test_case_name);
3305 *stream << TestPropertiesAsXmlAttributes(result);
3311 if (++failures == 1) {
3316 const string summary = location +
"\n" + part.
summary();
3317 *stream <<
" <failure message=\"" 3318 << EscapeXmlAttribute(summary.c_str())
3320 const string detail = location +
"\n" + part.
message();
3321 OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
3322 *stream <<
"</failure>\n";
3329 *stream <<
" </testcase>\n";
3336 *stream <<
" <" << kTestsuite;
3337 OutputXmlAttribute(stream, kTestsuite,
"name", test_case.
name());
3338 OutputXmlAttribute(stream, kTestsuite,
"tests",
3340 OutputXmlAttribute(stream, kTestsuite,
"failures",
3343 stream, kTestsuite,
"disabled",
3345 OutputXmlAttribute(stream, kTestsuite,
"errors",
"0");
3346 OutputXmlAttribute(stream, kTestsuite,
"time",
3353 OutputXmlTestInfo(stream, test_case.
name(), *test_case.
GetTestInfo(i));
3355 *stream <<
" </" << kTestsuite <<
">\n";
3363 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3364 *stream <<
"<" << kTestsuites;
3366 OutputXmlAttribute(stream, kTestsuites,
"tests",
3368 OutputXmlAttribute(stream, kTestsuites,
"failures",
3371 stream, kTestsuites,
"disabled",
3373 OutputXmlAttribute(stream, kTestsuites,
"errors",
"0");
3375 stream, kTestsuites,
"timestamp",
3377 OutputXmlAttribute(stream, kTestsuites,
"time",
3381 OutputXmlAttribute(stream, kTestsuites,
"random_seed",
3387 OutputXmlAttribute(stream, kTestsuites,
"name",
"AllTests");
3392 PrintXmlTestCase(stream, *unit_test.
GetTestCase(i));
3394 *stream <<
"</" << kTestsuites <<
">\n";
3404 attributes <<
" " <<
property.key() <<
"=" 3405 <<
"\"" << EscapeXmlAttribute(property.value()) <<
"\"";
3412 #if GTEST_CAN_STREAM_RESULTS_ 3419 string StreamingListener::UrlEncode(
const char* str) {
3421 result.reserve(strlen(str) + 1);
3422 for (
char ch = *str; ch !=
'\0'; ch = *++str) {
3431 result.push_back(ch);
3438 void StreamingListener::SocketWriter::MakeConnection() {
3440 <<
"MakeConnection() can't be called when there is already a connection.";
3443 memset(&hints, 0,
sizeof(hints));
3444 hints.ai_family = AF_UNSPEC;
3445 hints.ai_socktype = SOCK_STREAM;
3446 addrinfo* servinfo = NULL;
3450 const int error_num = getaddrinfo(
3451 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
3452 if (error_num != 0) {
3453 GTEST_LOG_(WARNING) <<
"stream_result_to: getaddrinfo() failed: " 3454 << gai_strerror(error_num);
3458 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;
3459 cur_addr = cur_addr->ai_next) {
3461 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
3462 if (sockfd_ != -1) {
3464 if (
connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
3471 freeaddrinfo(servinfo);
3473 if (sockfd_ == -1) {
3474 GTEST_LOG_(WARNING) <<
"stream_result_to: failed to connect to " 3475 << host_name_ <<
":" << port_num_;
3480 #endif // GTEST_CAN_STREAM_RESULTS__ 3531 : premature_exit_filepath_(premature_exit_filepath) {
3533 if (premature_exit_filepath != NULL && *premature_exit_filepath !=
'\0') {
3537 FILE* pfile =
posix::FOpen(premature_exit_filepath,
"w");
3538 fwrite(
"0", 1, 1, pfile);
3544 if (premature_exit_filepath_ != NULL && *premature_exit_filepath_ !=
'\0') {
3545 remove(premature_exit_filepath_);
3550 const char*
const premature_exit_filepath_;
3561 default_result_printer_(NULL),
3562 default_xml_generator_(NULL) {
3572 repeater_->Append(listener);
3579 if (listener == default_result_printer_)
3580 default_result_printer_ = NULL;
3581 else if (listener == default_xml_generator_)
3582 default_xml_generator_ = NULL;
3583 return repeater_->Release(listener);
3596 if (default_result_printer_ != listener) {
3599 delete Release(default_result_printer_);
3600 default_result_printer_ = listener;
3601 if (listener != NULL)
3612 if (default_xml_generator_ != listener) {
3615 delete Release(default_xml_generator_);
3616 default_xml_generator_ = listener;
3617 if (listener != NULL)
3625 return repeater_->forwarding_enabled();
3629 repeater_->set_forwarding_enabled(
false);
3653 #if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) 3659 #endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) 3664 return impl()->successful_test_case_count();
3669 return impl()->failed_test_case_count();
3674 return impl()->total_test_case_count();
3680 return impl()->test_case_to_run_count();
3685 return impl()->successful_test_count();
3693 return impl()->reportable_disabled_test_count();
3698 return impl()->disabled_test_count();
3703 return impl()->reportable_test_count();
3715 return impl()->start_timestamp();
3720 return impl()->elapsed_time();
3733 return impl()->GetTestCase(i);
3739 return *impl()->ad_hoc_test_result();
3745 return impl()->GetMutableTestCase(i);
3751 return *impl()->listeners();
3769 impl_->environments().push_back(env);
3779 const char* file_name,
3787 if (impl_->gtest_trace_stack().size() > 0) {
3790 for (
int i = static_cast<int>(impl_->gtest_trace_stack().size());
3798 if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {
3805 impl_->GetTestPartResultReporterForCurrentThread()->
3806 ReportTestPartResult(result);
3815 #if GTEST_OS_WINDOWS 3825 *
static_cast<volatile int*
>(NULL) = 1;
3826 #endif // GTEST_OS_WINDOWS 3828 #if GTEST_HAS_EXCEPTIONS 3829 throw internal::GoogleTestFailureException(result);
3855 const bool in_death_test_child_process =
3880 in_death_test_child_process ?
3885 impl()->set_catch_exceptions(
GTEST_FLAG(catch_exceptions));
3892 if (impl()->catch_exceptions() || in_death_test_child_process) {
3893 # if !GTEST_OS_WINDOWS_MOBILE 3895 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
3896 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
3897 # endif // !GTEST_OS_WINDOWS_MOBILE 3899 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE 3903 _set_error_mode(_OUT_TO_STDERR);
3906 # if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE 3919 _set_abort_behavior(
3921 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
3924 #endif // GTEST_HAS_SEH 3929 "auxiliary test code (environments or event listeners)") ? 0 : 1;
3935 return impl_->original_working_dir_.c_str();
3943 return impl_->current_test_case();
3951 return impl_->current_test_info();
3957 #if GTEST_HAS_PARAM_TEST 3963 return impl_->parameterized_test_registry();
3965 #endif // GTEST_HAS_PARAM_TEST 3982 impl_->gtest_trace_stack().push_back(trace);
3989 impl_->gtest_trace_stack().pop_back();
3992 namespace internal {
3997 # pragma warning(push) // Saves the current warning state. 3998 # pragma warning(disable:4355) // Temporarily disables warning 4355 4000 default_global_test_part_result_reporter_(
this),
4001 default_per_thread_test_part_result_reporter_(
this),
4002 # pragma warning(pop) // Restores the warning state again. 4004 default_global_test_part_result_reporter_(
this),
4005 default_per_thread_test_part_result_reporter_(
this),
4007 global_test_part_result_repoter_(
4008 &default_global_test_part_result_reporter_),
4009 per_thread_test_part_result_reporter_(
4010 &default_per_thread_test_part_result_reporter_),
4011 #if GTEST_HAS_PARAM_TEST 4012 parameterized_test_registry_(),
4013 parameterized_tests_registered_(
false),
4014 #endif // GTEST_HAS_PARAM_TEST 4015 last_death_test_case_(-1),
4016 current_test_case_(NULL),
4017 current_test_info_(NULL),
4018 ad_hoc_test_result_(),
4019 os_stack_trace_getter_(NULL),
4020 post_flag_parse_init_performed_(
false),
4023 start_timestamp_(0),
4025 #if GTEST_HAS_DEATH_TEST 4026 death_test_factory_(
new DefaultDeathTestFactory),
4029 catch_exceptions_(
false) {
4035 ForEach(test_cases_, internal::Delete<TestCase>);
4038 ForEach(environments_, internal::Delete<Environment>);
4040 delete os_stack_trace_getter_;
4052 if (current_test_info_ != NULL) {
4053 xml_element =
"testcase";
4054 test_result = &(current_test_info_->result_);
4055 }
else if (current_test_case_ != NULL) {
4056 xml_element =
"testsuite";
4057 test_result = &(current_test_case_->ad_hoc_test_result_);
4059 xml_element =
"testsuites";
4060 test_result = &ad_hoc_test_result_;
4065 #if GTEST_HAS_DEATH_TEST 4068 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
4069 if (internal_run_death_test_flag_.get() != NULL)
4070 listeners()->SuppressEventForwarding();
4072 #endif // GTEST_HAS_DEATH_TEST 4078 if (output_format ==
"xml") {
4081 }
else if (output_format !=
"") {
4082 printf(
"WARNING: unrecognized output format \"%s\" ignored.\n",
4083 output_format.c_str());
4088 #if GTEST_CAN_STREAM_RESULTS_ 4091 void UnitTestImpl::ConfigureStreamingOutput() {
4093 if (!target.empty()) {
4094 const size_t pos = target.find(
':');
4095 if (pos != std::string::npos) {
4096 listeners()->Append(
new StreamingListener(target.substr(0, pos),
4097 target.substr(pos+1)));
4099 printf(
"WARNING: unrecognized streaming target \"%s\" ignored.\n",
4105 #endif // GTEST_CAN_STREAM_RESULTS_ 4114 if (!post_flag_parse_init_performed_) {
4115 post_flag_parse_init_performed_ =
true;
4117 #if GTEST_HAS_DEATH_TEST 4118 InitDeathTestSubprocessControlInfo();
4119 SuppressTestEventsIfInSubprocess();
4120 #endif // GTEST_HAS_DEATH_TEST 4125 RegisterParameterizedTests();
4129 ConfigureXmlOutput();
4131 #if GTEST_CAN_STREAM_RESULTS_ 4133 ConfigureStreamingOutput();
4134 #endif // GTEST_CAN_STREAM_RESULTS_ 4154 return test_case != NULL && strcmp(test_case->
name(),
name_.c_str()) == 0;
4174 const char* type_param,
4178 const std::vector<TestCase*>::const_iterator test_case =
4179 std::find_if(test_cases_.begin(), test_cases_.end(),
4182 if (test_case != test_cases_.end())
4187 new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
4191 kDeathTestCaseFilter)) {
4196 ++last_death_test_case_;
4197 test_cases_.insert(test_cases_.begin() + last_death_test_case_,
4201 test_cases_.push_back(new_test_case);
4204 test_case_indices_.push_back(static_cast<int>(test_case_indices_.size()));
4205 return new_test_case;
4226 "\nThis test program did NOT call ::testing::InitGoogleTest " 4227 "before calling RUN_ALL_TESTS(). Please fix it.\n");
4237 PostFlagParsingInit();
4246 bool in_subprocess_for_death_test =
false;
4248 #if GTEST_HAS_DEATH_TEST 4249 in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);
4250 #endif // GTEST_HAS_DEATH_TEST 4252 const bool should_shard =
ShouldShard(kTestTotalShards, kTestShardIndex,
4253 in_subprocess_for_death_test);
4257 const bool has_tests_to_run = FilterTests(should_shard
4258 ? HONOR_SHARDING_PROTOCOL
4259 : IGNORE_SHARDING_PROTOCOL) > 0;
4264 ListTestsMatchingFilter();
4272 bool failed =
false;
4281 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
4283 const bool forever = repeat < 0;
4284 for (
int i = 0; forever || i != repeat; i++) {
4287 ClearNonAdHocTestResult();
4292 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
4293 random()->Reseed(random_seed_);
4304 if (has_tests_to_run) {
4313 for (
int test_index = 0; test_index < total_test_case_count();
4315 GetMutableTestCase(test_index)->Run();
4321 std::for_each(environments_.rbegin(), environments_.rend(),
4360 const char*
const test_shard_file =
posix::GetEnv(kTestShardStatusFile);
4361 if (test_shard_file != NULL) {
4365 "Could not write to the test shard status file \"%s\" " 4366 "specified by the %s environment variable.\n",
4367 test_shard_file, kTestShardStatusFile);
4382 const char* shard_index_env,
4383 bool in_subprocess_for_death_test) {
4384 if (in_subprocess_for_death_test) {
4391 if (total_shards == -1 && shard_index == -1) {
4393 }
else if (total_shards == -1 && shard_index != -1) {
4395 <<
"Invalid environment variables: you have " 4396 << kTestShardIndex <<
" = " << shard_index
4397 <<
", but have left " << kTestTotalShards <<
" unset.\n";
4401 }
else if (total_shards != -1 && shard_index == -1) {
4403 <<
"Invalid environment variables: you have " 4404 << kTestTotalShards <<
" = " << total_shards
4405 <<
", but have left " << kTestShardIndex <<
" unset.\n";
4409 }
else if (shard_index < 0 || shard_index >= total_shards) {
4411 <<
"Invalid environment variables: we require 0 <= " 4412 << kTestShardIndex <<
" < " << kTestTotalShards
4413 <<
", but you have " << kTestShardIndex <<
"=" << shard_index
4414 <<
", " << kTestTotalShards <<
"=" << total_shards <<
".\n";
4420 return total_shards > 1;
4428 if (str_val == NULL) {
4434 str_val, &result)) {
4445 return (test_id % total_shards) == shard_index;
4456 const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
4458 const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
4465 int num_runnable_tests = 0;
4466 int num_selected_tests = 0;
4467 for (
size_t i = 0; i < test_cases_.size(); i++) {
4468 TestCase*
const test_case = test_cases_[i];
4472 for (
size_t j = 0; j < test_case->
test_info_list().size(); j++) {
4477 const bool is_disabled =
4479 kDisableTestFilter) ||
4481 kDisableTestFilter);
4484 const bool matches_filter =
4489 const bool is_runnable =
4490 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
4493 const bool is_selected = is_runnable &&
4494 (shard_tests == IGNORE_SHARDING_PROTOCOL ||
4496 num_runnable_tests));
4498 num_runnable_tests += is_runnable;
4499 num_selected_tests += is_selected;
4505 return num_selected_tests;
4514 for (
int i = 0; *str !=
'\0'; ++str) {
4515 if (i >= max_length) {
4533 const int kMaxParamLength = 250;
4535 for (
size_t i = 0; i < test_cases_.size(); i++) {
4536 const TestCase*
const test_case = test_cases_[i];
4537 bool printed_test_case_name =
false;
4539 for (
size_t j = 0; j < test_case->
test_info_list().size(); j++) {
4543 if (!printed_test_case_name) {
4544 printed_test_case_name =
true;
4547 printf(
" # %s = ", kTypeParamLabel);
4556 printf(
" # %s = ", kValueParamLabel);
4575 if (os_stack_trace_getter_ != getter) {
4576 delete os_stack_trace_getter_;
4577 os_stack_trace_getter_ = getter;
4585 if (os_stack_trace_getter_ == NULL) {
4589 return os_stack_trace_getter_;
4595 return current_test_info_ ?
4596 &(current_test_info_->result_) : &ad_hoc_test_result_;
4603 ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_);
4607 static_cast<int>(test_cases_.size()), &test_case_indices_);
4610 for (
size_t i = 0; i < test_cases_.size(); i++) {
4611 test_cases_[i]->ShuffleTests(random());
4617 for (
size_t i = 0; i < test_cases_.size(); i++) {
4619 test_cases_[i]->UnshuffleTests();
4621 test_case_indices_[i] =
static_cast<int>(i);
4645 class ClassUniqueToAlwaysTrue {};
4648 bool IsTrue(
bool condition) {
return condition; }
4651 #if GTEST_HAS_EXCEPTIONS 4655 throw ClassUniqueToAlwaysTrue();
4656 #endif // GTEST_HAS_EXCEPTIONS 4663 bool SkipPrefix(
const char* prefix,
const char** pstr) {
4664 const size_t prefix_len = strlen(prefix);
4665 if (strncmp(*pstr, prefix, prefix_len) == 0) {
4666 *pstr += prefix_len;
4679 bool def_optional) {
4681 if (str == NULL || flag == NULL)
return NULL;
4685 const size_t flag_len = flag_str.length();
4686 if (strncmp(str, flag_str.c_str(), flag_len) != 0)
return NULL;
4689 const char* flag_end = str + flag_len;
4692 if (def_optional && (flag_end[0] ==
'\0')) {
4699 if (flag_end[0] !=
'=')
return NULL;
4702 return flag_end + 1;
4715 bool ParseBoolFlag(
const char* str,
const char* flag,
bool* value) {
4720 if (value_str == NULL)
return false;
4723 *value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
4737 if (value_str == NULL)
return false;
4754 if (value_str == NULL)
return false;
4795 const char* p = strchr(str,
'@');
4803 const char ch = p[1];
4807 }
else if (ch ==
'D') {
4809 }
else if (ch ==
'R') {
4811 }
else if (ch ==
'G') {
4813 }
else if (ch ==
'Y') {
4822 "This program contains tests written using " GTEST_NAME_ ". You can use the\n" 4823 "following command line flags to control its behavior:\n" 4827 " List the names of all tests instead of running them. The name of\n" 4828 " TEST(Foo, Bar) is \"Foo.Bar\".\n" 4830 "[@G-@YNEGATIVE_PATTERNS]@D\n" 4831 " Run only the tests whose name matches one of the positive patterns but\n" 4832 " none of the negative patterns. '?' matches any single character; '*'\n" 4833 " matches any substring; ':' separates two patterns.\n" 4835 " Run all disabled tests too.\n" 4839 " Run the tests repeatedly; use a negative count to repeat forever.\n" 4841 " Randomize tests' orders on every iteration.\n" 4843 " Random number seed to use for shuffling test orders (between 1 and\n" 4844 " 99999, or 0 to use a seed based on the current time).\n" 4848 " Enable/disable colored output. The default is @Gauto@D.\n" 4850 " Don't print the elapsed time of each test.\n" 4853 " Generate an XML report in the given directory or with the given file\n" 4854 " name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n" 4855 #if GTEST_CAN_STREAM_RESULTS_ 4857 " Stream test results to the given server.\n" 4858 #endif // GTEST_CAN_STREAM_RESULTS_ 4860 "Assertion Behavior:\n" 4861 #if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 4863 " Set the default death test style.\n" 4864 #endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 4866 " Turn assertion failures into debugger break-points.\n" 4868 " Turn assertion failures into C++ exceptions.\n" 4870 " Do not report exceptions as test failures. Instead, allow them\n" 4871 " to crash the program or throw a pop-up (on Windows).\n" 4874 "the corresponding\n" 4875 "environment variable of a flag (all letters in upper-case). For example, to\n" 4877 "color=no@D or set\n" 4880 "For more information, please read the " GTEST_NAME_ " documentation at\n" 4882 "(not one in your own code or tests), please report it to\n" 4888 template <
typename CharType>
4890 for (
int i = 1; i < *argc; i++) {
4892 const char*
const arg = arg_string.c_str();
4930 for (
int j = i; j != *argc; j++) {
4931 argv[j] = argv[j + 1];
4940 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
4941 arg_string ==
"-?" || arg_string ==
"/?" ||
4970 template <
typename CharType>
4972 g_init_gtest_count++;
4975 if (g_init_gtest_count != 1)
return;
4977 if (*argc <= 0)
return;
4981 #if GTEST_HAS_DEATH_TEST 4984 for (
int i = 0; i != *argc; i++) {
4988 #endif // GTEST_HAS_DEATH_TEST const char kDeathTestUseFork[]
GTEST_API_ bool g_help_flag
int failed_test_count() const
void SetDefaultResultPrinter(TestEventListener *listener)
TestPartResultReporterInterface * GetTestPartResultReporterForCurrentThread()
UnitTestImpl * GetUnitTestImpl()
internal::SetUpTestCaseFunc SetUpTestCaseFunc
const char * type_param() const
~ScopedPrematureExitFile()
bool IsTrue(bool condition)
void RecordProperty(const std::string &xml_element, const TestProperty &test_property)
const char * original_working_dir() const
bool fatally_failed() const
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
int disabled_test_count() const
int GetRandomSeedFromFlag(Int32 random_seed_flag)
ScopedPrematureExitFile(const char *premature_exit_filepath)
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
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.")
static bool HasFatalFailure()
int successful_test_count() const
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)
int reportable_disabled_test_count() const
TimeInMillis elapsed_time() const
static bool HasGoogleTestFlagPrefix(const char *str)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
static int SumOverTestCaseList(const std::vector< TestCase * > &case_list, int(TestCase::*method)() const)
void(* TearDownTestCaseFunc)()
const char * summary() const
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
static const char kDisableTestFilter[]
E GetElementOr(const std::vector< E > &v, int i, E default_value)
int failed_test_count() const
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)
AssertionResult AssertionFailure()
const char kAlsoRunDisabledTestsFlag[]
UInt32 ChopLowBits(UInt32 *bits, int n)
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)=0
virtual void ReportTestPartResult(const TestPartResult &result)
const TestInfo * GetTestInfo(int i) const
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
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)
const char kListTestsFlag[]
void PrintFullTestCommentIfPresent(const TestInfo &test_info)
TestPartResultReporterInterface * GetGlobalTestPartResultReporter()
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
SingleFailureChecker(const TestPartResultArray *results, TestPartResult::Type type, const string &substr)
void RegisterParameterizedTests()
::std::string PrintToString(const T &value)
const char kStreamResultToFlag[]
TypeWithSize< 4 >::Int Int32
static bool IsNormalizableWhitespace(char c)
FILE * FOpen(const char *path, const char *mode)
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
TestCase(const char *name, const char *a_type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc)
const char * message() const
int GetNextRandomSeed(int seed)
static void ClearTestResult(TestInfo *test_info)
virtual Test * CreateTest()=0
bool BoolFromGTestEnv(const char *flag, bool default_value)
GTEST_API_ int g_init_gtest_count
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
virtual void ReportTestPartResult(const TestPartResult &result)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
static void PrintXmlTestCase(::std::ostream *stream, const TestCase &test_case)
ScopedFakeTestPartResultReporter(TestPartResultArray *result)
AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
TypeWithSize< 4 >::UInt UInt32
TestEventListener * Release(TestEventListener *listener)
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
void ListTestsMatchingFilter()
static const char * GetDefaultFilter()
bool operator()(const TestCase *test_case) const
static bool TestPartNonfatallyFailed(const TestPartResult &result)
TestEventListener * repeater()
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
void(* SetUpTestCaseFunc)()
void SuppressEventForwarding()
std::vector< TestInfo * > & test_info_list()
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
PrettyUnitTestResultPrinter()
void SetGlobalTestPartResultReporter(TestPartResultReporterInterface *reporter)
bool connect(ros_opcua_srvs::Connect::Request &req, ros_opcua_srvs::Connect::Response &res)
void RecordProperty(const std::string &key, const std::string &value)
std::string StringStreamToString(::std::stringstream *ss)
static void PrintXmlUnitTest(::std::ostream *stream, const UnitTest &unit_test)
void ColoredPrintf(GTestColor color, const char *fmt,...)
int test_to_run_count() const
Result HandleSehExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
static const char *const kReservedTestSuiteAttributes[]
GTEST_DEFINE_bool_(also_run_disabled_tests, internal::BoolFromGTestEnv("also_run_disabled_tests", false),"Run disabled tests too, in addition to the tests normally being run.")
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)=0
virtual void OnEnvironmentsSetUpEnd(const UnitTest &)
AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
static std::string GetAbsolutePathToOutputFile()
virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_)
Message & operator<<(const T &val)
bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
virtual void OnTestStart(const TestInfo &test_info)=0
static bool ValidateTestProperty(const std::string &xml_element, const TestProperty &test_property)
void operator=(const Message &message) const
virtual void OnTestCaseEnd(const TestCase &test_case)
int reportable_disabled_test_count() const
const TestPartResult & GetTestPartResult(int i) const
const TestProperty & GetTestProperty(int i) const
internal::TearDownTestCaseFunc TearDownTestCaseFunc
bool IsUtf16SurrogatePair(wchar_t first, wchar_t second)
void Append(TestEventListener *listener)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
static void SetUpEnvironment(Environment *env)
int test_case_to_run_count() const
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
const char kBreakOnFailureFlag[]
static const char kTestTotalShards[]
TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
static bool PatternMatchesString(const char *pattern, const char *str)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
bool ParseBoolFlag(const char *str, const char *flag, bool *value)
static std::string FormatByte(unsigned char value)
int reportable_test_count() const
spdlog::log_clock::time_point now()
int disabled_test_count() const
int total_test_count() const
AssertionResult HasOneFailure(const char *, const char *, const char *, const TestPartResultArray &results, TestPartResult::Type type, const string &substr)
const UInt32 kMaxCodePoint3
static std::vector< std::string > GetReservedAttributesForElement(const std::string &xml_element)
void ReportInvalidTestCaseType(const char *test_case_name, const char *file, int line)
virtual void OnTestProgramStart(const UnitTest &)
void PushGTestTrace(const internal::TraceInfo &trace) GTEST_LOCK_EXCLUDED_(mutex_)
static std::string FormatHexInt(int value)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
const char kRandomSeedFlag[]
TimeInMillis start_timestamp() const
int total_test_count() const
std::string StreamableToString(const T &streamable)
AssertionResult(const AssertionResult &other)
const char kShuffleFlag[]
static const char kTestShardStatusFile[]
bool HasNonfatalFailure() const
int reportable_test_count() const
#define GTEST_FLAG_PREFIX_DASH_
const char * StringFromGTestEnv(const char *flag, const char *default_value)
void PostFlagParsingInit()
const internal::TypeId fixture_class_id_
void AddTestInfo(TestInfo *test_info)
virtual string CurrentStackTrace(int max_depth, int skip_count) GTEST_LOCK_EXCLUDED_(mutex_)
AssertionResult CmpHelperEQ(const char *expected_expression, const char *actual_expression, BiggestInt expected, BiggestInt actual)
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
DefaultGlobalTestPartResultReporter(UnitTestImpl *unit_test)
void Set(const FilePath &rhs)
static std::string TestPropertiesAsXmlAttributes(const TestResult &result)
static std::string FormatCountableNoun(int count, const char *singular_form, const char *plural_form)
GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex)
GTEST_IMPL_CMP_HELPER_(NE,!=)
bool is_reportable() const
const char * name() const
int test_case_to_run_count() const
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
int test_to_run_count() const
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
TestCase * GetMutableTestCase(int i)
OsStackTraceGetterInterface * os_stack_trace_getter()
const char kDeathTestStyleFlag[]
const char * message() const
AssertionResult AssertionSuccess()
void set_forwarding_enabled(bool enable)
std::tm localtime(const std::time_t &time_tt)
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
const UInt32 kMaxCodePoint1
static std::string GetOutputFormat()
TestEventListeners & listeners()
void SetDefaultXmlGenerator(TestEventListener *listener)
bool forwarding_enabled() const
const int kMaxStackTraceDepth
static bool IsValidXmlCharacter(char c)
virtual void ReportTestPartResult(const TestPartResult &result)
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
static const char kValueParamLabel[]
static const char kDeathTestCaseFilter[]
UInt32 Generate(UInt32 range)
static bool CStringEquals(const char *lhs, const char *rhs)
int reportable_test_count() const
void RecordProperty(const TestProperty &test_property)
FilePath RemoveFileName() const
void SetTestPartResultReporterForCurrentThread(TestPartResultReporterInterface *reporter)
TestInfo(const std::string &test_case_name, const std::string &name, const char *a_type_param, const char *a_value_param, internal::TypeId fixture_class_id, internal::TestFactoryBase *factory)
static const char *const kReservedTestSuitesAttributes[]
AssertHelper(TestPartResult::Type type, const char *file, int line, const char *message)
int successful_test_count() const
std::string GetCurrentOsStackTraceExceptTop(UnitTest *, int skip_count)
int successful_test_case_count() const
static bool WideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
static bool GTestIsInitialized()
const std::string & string() const
bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
#define GTEST_PROJECT_URL_
const TestCase * GetTestCase(int i) const
TestInfo * GetMutableTestInfo(int i)
static bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
const char * file_name() const
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)
const TestCase * current_test_case() const
internal::ParameterizedTestCaseRegistry & parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_)
static std::string FormatTestCaseCount(int test_case_count)
int StrCaseCmp(const char *s1, const char *s2)
virtual void OnTestCaseStart(const TestCase &test_case)
TestResult * current_test_result()
bool HasFatalFailure() const
UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
static void OutputXmlAttribute(std::ostream *stream, const std::string &element_name, const std::string &name, const std::string &value)
ScopedTrace(const char *file, int line, const Message &message)
bool ParseStringFlag(const char *str, const char *flag, std::string *value)
const char * value_param() const
std::string GetString() const
int failed_test_count() const
static const char kUniversalFilter[]
AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ FilePath GetCurrentExecutableName()
int test_to_run_count() const
GTEST_API_ TimeInMillis GetTimeInMillis()
AssertionResult CmpHelperSTRCASEEQ(const char *expected_expression, const char *actual_expression, const char *expected, const char *actual)
int total_test_case_count() const
int total_test_case_count() const
static void PrintOnOneLine(const char *str, int max_length)
static std::string FormatTestCount(int test_count)
static std::string RemoveInvalidXmlCharacters(const std::string &str)
void ShuffleTests(internal::Random *random)
const char * test_case_name() const
static bool TestPartFatallyFailed(const TestPartResult &result)
const TestCase * GetTestCase(int i) const
const TestPartResult & GetTestPartResult(int index) const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
#define GTEST_HAS_GETTIMEOFDAY_
static const char *const kReservedTestCaseAttributes[]
static std::string EscapeXmlText(const char *str)
virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test)=0
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
int failed_test_case_count() const
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
bool EventForwardingEnabled() const
const char * ParseFlagValue(const char *str, const char *flag, bool def_optional)
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
virtual ~TestEventRepeater()
internal::scoped_ptr< ::std::string > message_
AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const TestResult & ad_hoc_test_result() const
const char kStackTraceMarker[]
static void PrintTestPartResult(const TestPartResult &test_part_result)
int test_property_count() const
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
bool IsAbsolutePath() const
void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_)
std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
static const char kDefaultOutputFile[]
Environment * AddEnvironment(Environment *env)
TestCaseNameIs(const std::string &name)
static void StreamWideCharsToMessage(const wchar_t *wstr, size_t length, Message *msg)
static bool ShouldRunTestCase(const TestCase *test_case)
int reportable_disabled_test_count() const
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
int CountIf(const Container &c, Predicate predicate)
int disabled_test_count() const
internal::NamedArg< char > arg(StringRef name, const T &arg)
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()
const char kStackTraceDepthFlag[]
const char * GetAnsiColorCode(GTestColor color)
const char kCatchExceptionsFlag[]
const char kInternalRunDeathTestFlag[]
void InitGoogleTestImpl(int *argc, CharType **argv)
int Run() GTEST_MUST_USE_RESULT_
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
XmlUnitTestResultPrinter(const char *output_file)
int FilterTests(ReactionToSharding shard_tests)
AssertionResult EqFailure(const char *expected_expression, const char *actual_expression, const std::string &expected_value, const std::string &actual_value, bool ignoring_case)
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
TestEventListener * Release(TestEventListener *listener)
static std::string FormatWordList(const std::vector< std::string > &words)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
void ConfigureXmlOutput()
static bool HasSameFixtureClass()
void Shuffle(internal::Random *random, std::vector< E > *v)
virtual void OnTestCaseStart(const TestCase &test_case)=0
std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
int successful_test_count() const
int total_test_count() const
static const char kTestShardIndex[]
void RunTearDownTestCase()
virtual void OnEnvironmentsTearDownEnd(const UnitTest &)
static bool TestCasePassed(const TestCase *test_case)
virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test)=0
#define GTEST_FLAG_PREFIX_
static const char kColorEncodedHelpMessage[]
virtual void UponLeavingGTest()=0
int total_part_count() const
AssertionResult operator!() const
static const char *const kElidedFramesMarker
static void TearDownEnvironment(Environment *env)
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
void set_should_run(bool should)
AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
const UInt32 kMaxCodePoint4
void InitGoogleTest(int *argc, char **argv)
int failed_test_case_count() const
const char * name() const
int successful_test_case_count() const
Int32 Int32FromGTestEnv(const char *flag, Int32 default_value)
virtual void OnTestStart(const TestInfo &test_info)
TimeInMillis elapsed_time() const
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
#define GTEST_REPEATER_METHOD_(Name, Type)
std::string g_executable_path
const TestResult * result() const
AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static UnitTest * GetInstance()
void ClearTestPartResults()
AssertionResult CmpHelperSTREQ(const char *expected_expression, const char *actual_expression, const char *expected, const char *actual)
GTEST_DEFINE_string_(internal_run_death_test,"","Indicates the file, line number, temporal index of ""the single death test to run, and a file descriptor to ""which a success code may be sent, all separated by ""the '|' characters. This flag is specified if and only if the current ""process is a sub-process launched for running a thread-safe ""death test. FOR INTERNAL USE ONLY.")
const UInt32 kMaxCodePoint2
static void PrintTestName(const char *test_case, const char *test)
const char * type_param() const
TypeWithSize< 8 >::Int TimeInMillis
static void OutputXmlTestInfo(::std::ostream *stream, const char *test_case_name, const TestInfo &test_info)
static bool TestCaseFailed(const TestCase *test_case)
void ForEach(const Container &c, Functor functor)
FilePath RemoveDirectoryName() const
bool nonfatally_failed() const
static void RecordProperty(const std::string &key, const std::string &value)
const TestResult & ad_hoc_test_result() const
#define GTEST_CHECK_(condition)
static bool FilterMatchesTest(const std::string &test_case_name, const std::string &test_name)
const char * GetEnv(const char *name)
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
virtual void TestBody()=0
static std::string FormatIntWidth2(int value)
void WriteToShardStatusFileIfNeeded()
#define GTEST_FLAG_PREFIX_UPPER_
UnitTestImpl(UnitTest *parent)
static std::string ShowWideCString(const wchar_t *wide_c_str)
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)
static void PrintFailedTests(const UnitTest &unit_test)
#define GTEST_LOG_(severity)
virtual void OnTestPartResult(const TestPartResult &result)
static bool MatchesFilter(const std::string &name, const char *filter)
DefaultPerThreadTestPartResultReporter(UnitTestImpl *unit_test)
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)
static bool HasNonfatalFailure()
const char kPrintTimeFlag[]
TestInfo * current_test_info()
const char kThrowOnFailureFlag[]
bool ValidateTestPropertyName(const std::string &property_name, const std::vector< std::string > &reserved_names)
void Append(TestEventListener *listener)
static std::string PrintTestPartResultToString(const TestPartResult &test_part_result)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
virtual void OnTestEnd(const TestInfo &test_info)
virtual ~ScopedFakeTestPartResultReporter()
virtual void OnTestProgramEnd(const UnitTest &)
#define GTEST_LOCK_EXCLUDED_(locks)
AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
static void OutputXmlCDataSection(::std::ostream *stream, const char *data)
TimeInMillis elapsed_time() const
static const char kTypeParamLabel[]