59 # define GTEST_HAS_GETTIMEOFDAY_ 1 66 # include <sys/mman.h> 67 # include <sys/time.h> 71 #elif GTEST_OS_SYMBIAN 72 # define GTEST_HAS_GETTIMEOFDAY_ 1 73 # include <sys/time.h> 76 # define GTEST_HAS_GETTIMEOFDAY_ 1 77 # include <sys/time.h> 82 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. 87 #elif GTEST_OS_WINDOWS // We are on Windows proper. 90 # include <sys/timeb.h> 91 # include <sys/types.h> 92 # include <sys/stat.h> 94 # if GTEST_OS_WINDOWS_MINGW 101 # define GTEST_HAS_GETTIMEOFDAY_ 1 102 # include <sys/time.h> 103 # endif // GTEST_OS_WINDOWS_MINGW 107 # include <windows.h> 115 # define GTEST_HAS_GETTIMEOFDAY_ 1 119 # include <sys/time.h> 122 #endif // GTEST_OS_LINUX 124 #if GTEST_HAS_EXCEPTIONS 125 # include <stdexcept> 128 #if GTEST_CAN_STREAM_RESULTS_ 129 # include <arpa/inet.h> 131 # include <sys/socket.h> 132 # include <sys/types.h> 140 #define GTEST_IMPLEMENTATION_ 1 142 #undef GTEST_IMPLEMENTATION_ 145 # define vsnprintf _vsnprintf 146 #endif // GTEST_OS_WINDOWS 196 also_run_disabled_tests,
198 "Run disabled tests too, in addition to the tests normally being run.");
203 "True iff a failed assertion should be a debugger break-point.");
209 " should catch exceptions and treat them as test failures.");
214 "Whether to use colors in the output. Valid values: yes, no, " 215 "and auto. 'auto' means to use colors if the output is " 216 "being sent to a terminal and the TERM environment variable " 217 "is set to a terminal type that supports colors.");
222 "A colon-separated list of glob (not regex) patterns " 223 "for filtering the tests to run, optionally followed by a " 224 "'-' and a : separated list of negative patterns (tests to " 225 "exclude). A test is run if it matches one of the positive " 226 "patterns and does not match any of the negative patterns.");
229 "List all tests without running them.");
234 "A format (currently must be \"xml\"), optionally followed " 235 "by a colon and an output file name or directory. A directory " 236 "is indicated by a trailing pathname separator. " 237 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". " 238 "If a directory is specified, output files will be created " 239 "within that directory, with file-names based on the test " 240 "executable's name and, if necessary, made unique by adding " 247 " should display elapsed time in text output.");
252 "Random number seed to use when shuffling test orders. Must be in range " 253 "[1, 99999], or 0 to use a seed based on the current time.");
258 "How many times to repeat each test. Specify a negative number " 259 "for repeating forever. Useful for shaking out flaky tests.");
262 show_internal_stack_frames,
false,
263 "True iff " GTEST_NAME_ " should include internal stack frames when " 264 "printing test failure stack traces.");
270 " should randomize tests' order on every run.");
275 "The maximum number of stack frames to print when an " 276 "assertion fails. The valid range is 0 through 100, inclusive.");
281 "This flag specifies the host name and the port number on which to stream " 282 "test results. Example: \"localhost:555\". The flag is effective only on " 288 "When this flag is specified, a failed assertion will throw an exception " 289 "if exceptions are enabled or exit the program with a non-zero code " 299 state_ = (1103515245U*state_ + 12345U) % kMaxRange;
302 <<
"Cannot generate a number in the range [0, 0).";
304 <<
"Generation of a number in [0, " << range <<
") was requested, " 305 <<
"but this can only generate numbers in [0, " << kMaxRange <<
").";
310 return state_ % range;
330 for (
size_t i = 0;
i < case_list.size();
i++) {
331 sum += (case_list[
i]->*method)();
387 result.
Set(
FilePath(g_executable_path).RemoveExtension(
"exe"));
390 #endif // GTEST_OS_WINDOWS 400 if (gtest_output_flag == NULL)
return std::string(
"");
402 const char*
const colon = strchr(gtest_output_flag,
':');
403 return (colon == NULL) ?
405 std::string(gtest_output_flag, colon - gtest_output_flag);
412 if (gtest_output_flag == NULL)
415 const char*
const colon = strchr(gtest_output_flag,
':');
433 return output_name.
string();
437 GetOutputFormat().c_str()));
453 return *str !=
'\0' && PatternMatchesString(pattern + 1, str + 1);
455 return (*str !=
'\0' && PatternMatchesString(pattern, str + 1)) ||
456 PatternMatchesString(pattern + 1, str);
458 return *pattern == *str &&
459 PatternMatchesString(pattern + 1, str + 1);
465 const char *cur_pattern = filter;
467 if (PatternMatchesString(cur_pattern, name.c_str())) {
472 cur_pattern = strchr(cur_pattern,
':');
475 if (cur_pattern == NULL) {
488 const std::string& full_name = test_case_name +
"." + test_name.c_str();
493 const char*
const dash = strchr(p,
'-');
502 if (positive.empty()) {
510 return (MatchesFilter(full_name, positive.c_str()) &&
511 !MatchesFilter(full_name, negative.c_str()));
518 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
527 const DWORD kCxxExceptionCode = 0xe06d7363;
529 bool should_handle =
true;
532 should_handle =
false;
533 else if (exception_code == EXCEPTION_BREAKPOINT)
534 should_handle =
false;
535 else if (exception_code == kCxxExceptionCode)
536 should_handle =
false;
538 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
540 #endif // GTEST_HAS_SEH 549 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
605 return GetTypeId<Test>();
620 const string& substr) {
623 "1 non-fatal failure");
625 if (results.
size() != 1) {
626 msg <<
"Expected: " << expected <<
"\n" 627 <<
" Actual: " << results.
size() <<
" failures";
628 for (
int i = 0;
i < results.
size();
i++) {
635 if (r.
type() != type) {
641 if (strstr(r.
message(), substr.c_str()) == NULL) {
654 SingleFailureChecker:: SingleFailureChecker(
657 const string& substr)
691 return global_test_part_result_repoter_;
698 global_test_part_result_repoter_ = reporter;
704 return per_thread_test_part_result_reporter_.get();
710 per_thread_test_part_result_reporter_.set(reporter);
725 return static_cast<int>(test_cases_.size());
787 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) 792 const DWORD kTenthMicrosInMilliSecond = 10000;
794 SYSTEMTIME now_systime;
795 FILETIME now_filetime;
796 ULARGE_INTEGER now_int64;
799 GetSystemTime(&now_systime);
800 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
801 now_int64.LowPart = now_filetime.dwLowDateTime;
802 now_int64.HighPart = now_filetime.dwHighDateTime;
803 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
804 kJavaEpochToWinFileTimeDelta;
805 return now_int64.QuadPart;
808 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ 819 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
822 gettimeofday(&now, NULL);
825 # error
"Don't know how to get the current time on your system." 833 #if GTEST_OS_WINDOWS_MOBILE 838 LPCWSTR String::AnsiToUtf16(
const char* ansi) {
839 if (!ansi)
return NULL;
840 const int length = strlen(ansi);
841 const int unicode_length =
842 MultiByteToWideChar(CP_ACP, 0, ansi, length,
844 WCHAR* unicode =
new WCHAR[unicode_length + 1];
845 MultiByteToWideChar(CP_ACP, 0, ansi, length,
846 unicode, unicode_length);
847 unicode[unicode_length] = 0;
855 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
856 if (!utf16_str)
return NULL;
857 const int ansi_length =
858 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
859 NULL, 0, NULL, NULL);
860 char* ansi =
new char[ansi_length + 1];
861 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
862 ansi, ansi_length, NULL, NULL);
863 ansi[ansi_length] = 0;
867 #endif // GTEST_OS_WINDOWS_MOBILE 875 if ( lhs == NULL )
return rhs == NULL;
877 if ( rhs == NULL )
return false;
879 return strcmp(lhs, rhs) == 0;
882 #if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING 886 static void StreamWideCharsToMessage(
const wchar_t* wstr,
size_t length,
888 for (
size_t i = 0;
i != length; ) {
889 if (wstr[
i] != L
'\0') {
890 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length -
i));
891 while (
i != length && wstr[
i] != L
'\0')
900 #endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING 912 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
924 #if GTEST_HAS_STD_WSTRING 928 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
931 #endif // GTEST_HAS_STD_WSTRING 933 #if GTEST_HAS_GLOBAL_WSTRING 937 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
940 #endif // GTEST_HAS_GLOBAL_WSTRING 951 : success_(other.success_),
952 message_(other.message_.
get() != NULL ?
990 namespace edit_distance {
992 const std::vector<size_t>& right) {
993 std::vector<std::vector<double> > costs(
994 left.size() + 1, std::vector<double>(right.size() + 1));
995 std::vector<std::vector<EditType> > best_move(
996 left.size() + 1, std::vector<EditType>(right.size() + 1));
999 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1000 costs[l_i][0] =
static_cast<double>(l_i);
1004 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1005 costs[0][r_i] =
static_cast<double>(r_i);
1006 best_move[0][r_i] =
kAdd;
1009 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1010 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1011 if (left[l_i] == right[r_i]) {
1013 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1014 best_move[l_i + 1][r_i + 1] =
kMatch;
1018 const double add = costs[l_i + 1][r_i];
1019 const double remove = costs[l_i][r_i + 1];
1020 const double replace = costs[l_i][r_i];
1021 if (add <
remove && add < replace) {
1022 costs[l_i + 1][r_i + 1] = add + 1;
1023 best_move[l_i + 1][r_i + 1] =
kAdd;
1024 }
else if (
remove < add &&
remove < replace) {
1025 costs[l_i + 1][r_i + 1] =
remove + 1;
1026 best_move[l_i + 1][r_i + 1] =
kRemove;
1030 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1031 best_move[l_i + 1][r_i + 1] =
kReplace;
1037 std::vector<EditType> best_path;
1038 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1040 best_path.push_back(move);
1041 l_i -= move !=
kAdd;
1044 std::reverse(best_path.begin(), best_path.end());
1051 class InternalStrings {
1054 IdMap::iterator it =
ids_.find(str);
1055 if (it !=
ids_.end())
return it->second;
1056 size_t id =
ids_.size();
1061 typedef std::map<std::string, size_t> IdMap;
1068 const std::vector<std::string>& left,
1069 const std::vector<std::string>& right) {
1070 std::vector<size_t> left_ids, right_ids;
1072 InternalStrings intern_table;
1073 for (
size_t i = 0;
i < left.size(); ++
i) {
1074 left_ids.push_back(intern_table.GetId(left[
i]));
1076 for (
size_t i = 0;
i < right.size(); ++
i) {
1077 right_ids.push_back(intern_table.GetId(right[
i]));
1091 Hunk(
size_t left_start,
size_t right_start)
1098 void PushLine(
char edit,
const char* line) {
1103 hunk_.push_back(std::make_pair(
' ', line));
1111 hunk_adds_.push_back(std::make_pair(
'+', line));
1116 void PrintTo(std::ostream* os) {
1119 for (std::list<std::pair<char, const char*> >::const_iterator it =
1121 it !=
hunk_.end(); ++it) {
1122 *os << it->first << it->second <<
"\n";
1138 void PrintHeader(std::ostream* ss)
const {
1167 const std::vector<std::string>& right,
1171 size_t l_i = 0, r_i = 0, edit_i = 0;
1172 std::stringstream ss;
1173 while (edit_i < edits.size()) {
1175 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1182 const size_t prefix_context = std::min(l_i, context);
1183 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1184 for (
size_t i = prefix_context;
i > 0; --
i) {
1185 hunk.PushLine(
' ', left[l_i -
i].c_str());
1190 size_t n_suffix = 0;
1191 for (; edit_i < edits.size(); ++edit_i) {
1192 if (n_suffix >= context) {
1194 std::vector<EditType>::const_iterator it = edits.begin() + edit_i;
1195 while (it != edits.end() && *it ==
kMatch) ++it;
1196 if (it == edits.end() || (it - edits.begin()) - edit_i >= context) {
1204 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1207 hunk.PushLine(edit ==
kMatch ?
' ' :
'-', left[l_i].c_str());
1210 hunk.PushLine(
'+', right[r_i].c_str());
1214 l_i += edit !=
kAdd;
1218 if (!hunk.has_edits()) {
1235 std::vector<std::string> SplitEscapedString(
const std::string&
str) {
1236 std::vector<std::string> lines;
1237 size_t start = 0, end = str.size();
1238 if (end > 2 && str[0] ==
'"' && str[end - 1] ==
'"') {
1242 bool escaped =
false;
1243 for (
size_t i = start;
i + 1 < end; ++
i) {
1246 if (str[
i] ==
'n') {
1247 lines.push_back(str.substr(start,
i - start - 1));
1251 escaped = str[
i] ==
'\\';
1254 lines.push_back(str.substr(start, end - start));
1276 const char* actual_expression,
1279 bool ignoring_case) {
1281 msg <<
"Value of: " << actual_expression;
1282 if (actual_value != actual_expression) {
1283 msg <<
"\n Actual: " << actual_value;
1286 msg <<
"\nExpected: " << expected_expression;
1287 if (ignoring_case) {
1288 msg <<
" (ignoring case)";
1290 if (expected_value != expected_expression) {
1291 msg <<
"\nWhich is: " << expected_value;
1294 if (!expected_value.empty() && !actual_value.empty()) {
1295 const std::vector<std::string> expected_lines =
1296 SplitEscapedString(expected_value);
1297 const std::vector<std::string> actual_lines =
1298 SplitEscapedString(actual_value);
1299 if (expected_lines.size() > 1 || actual_lines.size() > 1) {
1300 msg <<
"\nWith diff:\n" 1311 const char* expression_text,
1312 const char* actual_predicate_value,
1313 const char* expected_predicate_value) {
1314 const char* actual_message = assertion_result.
message();
1316 msg <<
"Value of: " << expression_text
1317 <<
"\n Actual: " << actual_predicate_value;
1318 if (actual_message[0] !=
'\0')
1319 msg <<
" (" << actual_message <<
")";
1320 msg <<
"\nExpected: " << expected_predicate_value;
1327 const char* abs_error_expr,
1331 const double diff = fabs(val1 - val2);
1337 <<
"The difference between " << expr1 <<
" and " << expr2
1338 <<
" is " << diff <<
", which exceeds " << abs_error_expr <<
", where\n" 1339 << expr1 <<
" evaluates to " << val1 <<
",\n" 1340 << expr2 <<
" evaluates to " << val2 <<
", and\n" 1341 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1346 template <
typename RawType>
1358 if (lhs.AlmostEquals(rhs)) {
1366 ::std::stringstream val1_ss;
1367 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1370 ::std::stringstream val2_ss;
1371 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1375 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n" 1385 float val1,
float val2) {
1386 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1392 double val1,
double val2) {
1393 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1396 namespace internal {
1401 const char* actual_expression,
1404 if (expected == actual) {
1418 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\ 1419 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ 1420 BiggestInt val1, BiggestInt val2) {\ 1421 if (val1 op val2) {\ 1422 return AssertionSuccess();\ 1424 return AssertionFailure() \ 1425 << "Expected: (" << expr1 << ") " #op " (" << expr2\ 1426 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ 1427 << " vs " << FormatForComparisonFailureMessage(val2, val1);\ 1447 #undef GTEST_IMPL_CMP_HELPER_ 1451 const char* actual_expression,
1452 const char* expected,
1453 const char* actual) {
1454 if (String::CStringEquals(expected, actual)) {
1467 const char* actual_expression,
1468 const char* expected,
1469 const char* actual) {
1470 if (String::CaseInsensitiveCStringEquals(expected, actual)) {
1483 const char* s2_expression,
1486 if (!String::CStringEquals(s1, s2)) {
1490 << s2_expression <<
"), actual: \"" 1491 << s1 <<
"\" vs \"" << s2 <<
"\"";
1497 const char* s2_expression,
1500 if (!String::CaseInsensitiveCStringEquals(s1, s2)) {
1504 <<
"Expected: (" << s1_expression <<
") != (" 1505 << s2_expression <<
") (ignoring case), actual: \"" 1506 << s1 <<
"\" vs \"" << s2 <<
"\"";
1520 bool IsSubstringPred(
const char* needle,
const char* haystack) {
1521 if (needle == NULL || haystack == NULL)
1522 return needle == haystack;
1524 return strstr(haystack, needle) != NULL;
1527 bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1528 if (needle == NULL || haystack == NULL)
1529 return needle == haystack;
1531 return wcsstr(haystack, needle) != NULL;
1535 template <
typename StringType>
1536 bool IsSubstringPred(
const StringType& needle,
1537 const StringType& haystack) {
1538 return haystack.find(needle) != StringType::npos;
1545 template <
typename StringType>
1547 bool expected_to_be_substring,
1548 const char* needle_expr,
const char* haystack_expr,
1549 const StringType& needle,
const StringType& haystack) {
1550 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1553 const bool is_wide_string =
sizeof(needle[0]) > 1;
1554 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1556 <<
"Value of: " << needle_expr <<
"\n" 1557 <<
" Actual: " << begin_string_quote << needle <<
"\"\n" 1558 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1559 <<
"a substring of " << haystack_expr <<
"\n" 1560 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1570 const char* needle_expr,
const char* haystack_expr,
1571 const char* needle,
const char* haystack) {
1572 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1576 const char* needle_expr,
const char* haystack_expr,
1577 const wchar_t* needle,
const wchar_t* haystack) {
1578 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1582 const char* needle_expr,
const char* haystack_expr,
1583 const char* needle,
const char* haystack) {
1584 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1588 const char* needle_expr,
const char* haystack_expr,
1589 const wchar_t* needle,
const wchar_t* haystack) {
1590 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1594 const char* needle_expr,
const char* haystack_expr,
1596 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1600 const char* needle_expr,
const char* haystack_expr,
1602 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1605 #if GTEST_HAS_STD_WSTRING 1607 const char* needle_expr,
const char* haystack_expr,
1609 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1613 const char* needle_expr,
const char* haystack_expr,
1615 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1617 #endif // GTEST_HAS_STD_WSTRING 1619 namespace internal {
1621 #if GTEST_OS_WINDOWS 1627 const char* expected,
1629 # if GTEST_OS_WINDOWS_MOBILE 1632 const char error_text[] =
"";
1639 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1640 FORMAT_MESSAGE_IGNORE_INSERTS;
1641 const DWORD kBufSize = 4096;
1643 char error_text[kBufSize] = {
'\0' };
1644 DWORD message_length = ::FormatMessageA(kFlags,
1652 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1654 error_text[message_length - 1] =
'\0';
1657 # endif // GTEST_OS_WINDOWS_MOBILE 1659 const std::string error_hex(
"0x" + String::FormatHexInt(hr));
1661 <<
"Expected: " << expr <<
" " << expected <<
".\n" 1662 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1668 if (SUCCEEDED(hr)) {
1671 return HRESULTFailureHelper(expr,
"succeeds", hr);
1678 return HRESULTFailureHelper(expr,
"fails", hr);
1681 #endif // GTEST_OS_WINDOWS 1711 const UInt32 low_bits = *bits & ((
static_cast<UInt32>(1) << n) - 1);
1723 if (code_point > kMaxCodePoint4) {
1724 return "(Invalid Unicode 0x" + String::FormatHexInt(code_point) +
")";
1728 if (code_point <= kMaxCodePoint1) {
1730 str[0] =
static_cast<char>(code_point);
1731 }
else if (code_point <= kMaxCodePoint2) {
1733 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1734 str[0] =
static_cast<char>(0xC0 | code_point);
1735 }
else if (code_point <= kMaxCodePoint3) {
1737 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1738 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1739 str[0] =
static_cast<char>(0xE0 | code_point);
1742 str[3] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1743 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1744 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1745 str[0] =
static_cast<char>(0xF0 | code_point);
1758 return sizeof(wchar_t) == 2 &&
1759 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1765 const UInt32 mask = (1 << 10) - 1;
1766 return (
sizeof(
wchar_t) == 2) ?
1767 (((first & mask) << 10) | (second & mask)) + 0x10000 :
1770 static_cast<UInt32>(first);
1787 if (num_chars == -1)
1788 num_chars =
static_cast<int>(wcslen(str));
1790 ::std::stringstream stream;
1791 for (
int i = 0;
i < num_chars; ++
i) {
1792 UInt32 unicode_code_point;
1794 if (str[
i] == L
'\0') {
1801 unicode_code_point =
static_cast<UInt32>(str[
i]);
1812 if (wide_c_str == NULL)
return "(null)";
1823 bool String::WideCStringEquals(
const wchar_t * lhs,
const wchar_t * rhs) {
1824 if (lhs == NULL)
return rhs == NULL;
1826 if (rhs == NULL)
return false;
1828 return wcscmp(lhs, rhs) == 0;
1833 const char* actual_expression,
1834 const wchar_t* expected,
1835 const wchar_t* actual) {
1836 if (String::WideCStringEquals(expected, actual)) {
1849 const char* s2_expression,
1851 const wchar_t* s2) {
1852 if (!String::WideCStringEquals(s1, s2)) {
1857 << s2_expression <<
"), actual: " 1868 bool String::CaseInsensitiveCStringEquals(
const char * lhs,
const char * rhs) {
1888 bool String::CaseInsensitiveWideCStringEquals(
const wchar_t* lhs,
1889 const wchar_t* rhs) {
1890 if (lhs == NULL)
return rhs == NULL;
1892 if (rhs == NULL)
return false;
1894 #if GTEST_OS_WINDOWS 1895 return _wcsicmp(lhs, rhs) == 0;
1896 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID 1897 return wcscasecmp(lhs, rhs) == 0;
1903 left = towlower(*lhs++);
1904 right = towlower(*rhs++);
1905 }
while (left && left == right);
1906 return left == right;
1907 #endif // OS selector 1912 bool String::EndsWithCaseInsensitive(
1914 const size_t str_len = str.length();
1915 const size_t suffix_len = suffix.length();
1916 return (str_len >= suffix_len) &&
1917 CaseInsensitiveCStringEquals(str.c_str() + str_len - suffix_len,
1923 std::stringstream ss;
1924 ss << std::setfill(
'0') << std::setw(2) <<
value;
1930 std::stringstream ss;
1931 ss << std::hex << std::uppercase <<
value;
1937 std::stringstream ss;
1938 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
1939 <<
static_cast<unsigned int>(
value);
1947 const char*
const start = str.c_str();
1948 const char*
const end = start + str.length();
1951 result.reserve(2 * (end - start));
1952 for (
const char* ch = start; ch != end; ++ch) {
1968 if (user_msg_string.empty()) {
1972 return gtest_msg +
"\n" + user_msg_string;
1981 : death_test_count_(0),
2026 const std::vector<TestProperty>::iterator property_with_matching_key =
2033 property_with_matching_key->SetValue(test_property.
value());
2070 template <
int kSize>
2072 return std::vector<std::string>(array, array + kSize);
2077 if (xml_element ==
"testsuites") {
2079 }
else if (xml_element ==
"testsuite") {
2081 }
else if (xml_element ==
"testcase") {
2084 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2087 return std::vector<std::string>();
2092 for (
size_t i = 0;
i < words.size(); ++
i) {
2093 if (
i > 0 && words.size() > 2) {
2096 if (
i == words.size() - 1) {
2097 word_list <<
"and ";
2099 word_list <<
"'" << words[
i] <<
"'";
2105 const std::vector<std::string>& reserved_names) {
2106 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
2107 reserved_names.end()) {
2108 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2178 : gtest_flag_saver_(new internal::GTestFlagSaver) {
2206 value_message <<
value;
2210 namespace internal {
2238 const char*
const first_test_name = first_test_info->
name();
2243 const char*
const this_test_name = this_test_info->
name();
2245 if (this_fixture_id != first_fixture_id) {
2251 if (first_is_TEST || this_is_TEST) {
2258 const char*
const TEST_name =
2259 first_is_TEST ? first_test_name : this_test_name;
2260 const char*
const TEST_F_name =
2261 first_is_TEST ? this_test_name : first_test_name;
2264 <<
"All tests in the same test case must use the same test fixture\n" 2265 <<
"class, so mixing TEST_F and TEST in the same test case is\n" 2268 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n" 2269 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n" 2270 <<
"want to change the TEST to TEST_F or move it to another test\n" 2276 <<
"All tests in the same test case must use the same test fixture\n" 2277 <<
"class. However, in test case " 2279 <<
"you defined test " << first_test_name
2280 <<
" and test " << this_test_name <<
"\n" 2281 <<
"using two different test fixture classes. This can happen if\n" 2282 <<
"the two classes are from different namespaces or translation\n" 2283 <<
"units and have the same name. You should probably rename one\n" 2284 <<
"of the classes to put the tests into different test cases.";
2298 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2299 const char* location) {
2301 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2302 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2307 #endif // GTEST_HAS_SEH 2309 namespace internal {
2311 #if GTEST_HAS_EXCEPTIONS 2314 static std::string FormatCxxExceptionMessage(
const char* description,
2315 const char* location) {
2317 if (description != NULL) {
2318 message <<
"C++ exception with description \"" << description <<
"\"";
2320 message <<
"Unknown C++ exception";
2322 message <<
" thrown in " << location <<
".";
2330 GoogleTestFailureException::GoogleTestFailureException(
2334 #endif // GTEST_HAS_EXCEPTIONS 2344 template <
class T,
typename Result>
2346 T*
object, Result (T::*method)(),
const char* location) {
2349 return (object->*method)();
2350 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2351 GetExceptionCode())) {
2355 std::string* exception_message = FormatSehExceptionMessage(
2356 GetExceptionCode(), location);
2358 *exception_message);
2359 delete exception_message;
2360 return static_cast<Result
>(0);
2364 return (object->*method)();
2365 #endif // GTEST_HAS_SEH 2371 template <
class T,
typename Result>
2373 T*
object, Result (T::*method)(),
const char* location) {
2398 #if GTEST_HAS_EXCEPTIONS 2401 }
catch (
const internal::GoogleTestFailureException&) {
2406 }
catch (
const std::exception& e) {
2409 FormatCxxExceptionMessage(e.what(), location));
2413 FormatCxxExceptionMessage(NULL, location));
2415 return static_cast<Result
>(0);
2418 #endif // GTEST_HAS_EXCEPTIONS 2420 return (object->*method)();
2465 const char* a_type_param,
2466 const char* a_value_param,
2469 : test_case_name_(a_test_case_name),
2471 type_param_(a_type_param ? new
std::
string(a_type_param) : NULL),
2472 value_param_(a_value_param ? new
std::
string(a_value_param) : NULL),
2473 fixture_class_id_(fixture_class_id),
2475 is_disabled_(
false),
2476 matches_filter_(
false),
2483 namespace internal {
2512 new TestInfo(test_case_name, name, type_param, value_param,
2513 fixture_class_id, factory);
2518 #if GTEST_HAS_PARAM_TEST 2520 const char* file,
int line) {
2523 <<
"Attempted redefinition of test case " << test_case_name <<
".\n" 2524 <<
"All tests in the same test case must use the same test fixture\n" 2525 <<
"class. However, in test case " << test_case_name <<
", you tried\n" 2526 <<
"to define a test using a fixture class different from the one\n" 2527 <<
"used earlier. This can happen if the two fixture classes are\n" 2528 <<
"from different namespaces and have the same name. You should\n" 2529 <<
"probably rename one of the classes to put the tests into different\n" 2535 #endif // GTEST_HAS_PARAM_TEST 2554 explicit TestNameIs(
const char*
name)
2558 bool operator()(
const TestInfo * test_info)
const {
2559 return test_info && test_info->
name() ==
name_;
2568 namespace internal {
2573 void UnitTestImpl::RegisterParameterizedTests() {
2574 #if GTEST_HAS_PARAM_TEST 2575 if (!parameterized_tests_registered_) {
2576 parameterized_test_registry_.RegisterTests();
2577 parameterized_tests_registered_ =
true;
2605 "the test fixture's constructor");
2634 return CountIf(test_info_list_, TestPassed);
2639 return CountIf(test_info_list_, TestFailed);
2644 return CountIf(test_info_list_, TestReportableDisabled);
2649 return CountIf(test_info_list_, TestDisabled);
2654 return CountIf(test_info_list_, TestReportable);
2659 return CountIf(test_info_list_, ShouldRunTest);
2664 return static_cast<int>(test_info_list_.size());
2681 set_up_tc_(set_up_tc),
2682 tear_down_tc_(tear_down_tc),
2766 const char * singular_form,
2767 const char * plural_form) {
2769 (count == 1 ? singular_form : plural_form);
2799 return "Unknown result type";
2803 namespace internal {
2812 << test_part_result.
message()).GetString();
2819 printf(
"%s\n", result.c_str());
2825 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2829 ::OutputDebugStringA(result.c_str());
2830 ::OutputDebugStringA(
"\n");
2843 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ 2844 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 2851 case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
2865 default:
return NULL;
2869 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2873 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
2875 if (String::CaseInsensitiveCStringEquals(gtest_color,
"auto")) {
2876 #if GTEST_OS_WINDOWS 2879 return stdout_is_tty;
2883 const bool term_supports_color =
2884 String::CStringEquals(term,
"xterm") ||
2885 String::CStringEquals(term,
"xterm-color") ||
2886 String::CStringEquals(term,
"xterm-256color") ||
2887 String::CStringEquals(term,
"screen") ||
2888 String::CStringEquals(term,
"screen-256color") ||
2889 String::CStringEquals(term,
"linux") ||
2890 String::CStringEquals(term,
"cygwin");
2891 return stdout_is_tty && term_supports_color;
2892 #endif // GTEST_OS_WINDOWS 2895 return String::CaseInsensitiveCStringEquals(gtest_color,
"yes") ||
2896 String::CaseInsensitiveCStringEquals(gtest_color,
"true") ||
2897 String::CaseInsensitiveCStringEquals(gtest_color,
"t") ||
2898 String::CStringEquals(gtest_color,
"1");
2910 va_start(args, fmt);
2912 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || \ 2913 GTEST_OS_IOS || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT 2916 static const bool in_color_mode =
2918 const bool use_color = in_color_mode && (color !=
COLOR_DEFAULT);
2919 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS 2928 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ 2929 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 2930 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
2933 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
2934 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
2935 const WORD old_color_attrs = buffer_info.wAttributes;
2941 SetConsoleTextAttribute(stdout_handle,
2942 GetColorAttribute(color) | FOREGROUND_INTENSITY);
2947 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
2952 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE 2963 const char*
const value_param = test_info.
value_param();
2965 if (type_param != NULL || value_param != NULL) {
2967 if (type_param != NULL) {
2968 printf(
"%s = %s", kTypeParamLabel, type_param);
2969 if (value_param != NULL)
2972 if (value_param != NULL) {
2973 printf(
"%s = %s", kValueParamLabel, value_param);
2985 printf(
"%s.%s", test_case, test);
2990 virtual void OnTestIterationStart(
const UnitTest& unit_test,
int iteration);
2991 virtual void OnEnvironmentsSetUpStart(
const UnitTest& unit_test);
2993 virtual void OnTestCaseStart(
const TestCase& test_case);
2994 virtual void OnTestStart(
const TestInfo& test_info);
2996 virtual void OnTestEnd(
const TestInfo& test_info);
2997 virtual void OnTestCaseEnd(
const TestCase& test_case);
2998 virtual void OnEnvironmentsTearDownStart(
const UnitTest& unit_test);
3000 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
3004 static void PrintFailedTests(
const UnitTest& unit_test);
3008 void PrettyUnitTestResultPrinter::OnTestIterationStart(
3009 const UnitTest& unit_test,
int iteration) {
3011 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3013 const char*
const filter =
GTEST_FLAG(filter).c_str();
3017 if (!String::CStringEquals(filter, kUniversalFilter)) {
3025 "Note: This is test shard %d of %s.\n",
3026 static_cast<int>(shard_index) + 1,
3032 "Note: Randomizing tests' orders with a seed of %d .\n",
3037 printf(
"Running %s from %s.\n",
3043 void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
3046 printf(
"Global test environment set-up.\n");
3050 void PrettyUnitTestResultPrinter::OnTestCaseStart(
const TestCase& test_case) {
3054 printf(
"%s from %s", counts.c_str(), test_case.
name());
3063 void PrettyUnitTestResultPrinter::OnTestStart(
const TestInfo& test_info) {
3071 void PrettyUnitTestResultPrinter::OnTestPartResult(
3082 void PrettyUnitTestResultPrinter::OnTestEnd(
const TestInfo& test_info) {
3101 void PrettyUnitTestResultPrinter::OnTestCaseEnd(
const TestCase& test_case) {
3107 printf(
"%s from %s (%s ms total)\n\n",
3108 counts.c_str(), test_case.
name(),
3113 void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
3116 printf(
"Global test environment tear-down\n");
3121 void PrettyUnitTestResultPrinter::PrintFailedTests(
const UnitTest& unit_test) {
3123 if (failed_test_count == 0) {
3145 void PrettyUnitTestResultPrinter::OnTestIterationEnd(
const UnitTest& unit_test,
3148 printf(
"%s from %s ran.",
3160 if (!unit_test.
Passed()) {
3164 PrintFailedTests(unit_test);
3165 printf(
"\n%2d FAILED %s\n", num_failures,
3166 num_failures == 1 ?
"TEST" :
"TESTS");
3170 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3171 if (!num_failures) {
3175 " YOU HAVE %d DISABLED %s\n\n",
3177 num_disabled == 1 ?
"TEST" :
"TESTS");
3200 virtual void OnTestProgramStart(
const UnitTest& unit_test);
3201 virtual void OnTestIterationStart(
const UnitTest& unit_test,
int iteration);
3202 virtual void OnEnvironmentsSetUpStart(
const UnitTest& unit_test);
3203 virtual void OnEnvironmentsSetUpEnd(
const UnitTest& unit_test);
3204 virtual void OnTestCaseStart(
const TestCase& test_case);
3205 virtual void OnTestStart(
const TestInfo& test_info);
3207 virtual void OnTestEnd(
const TestInfo& test_info);
3208 virtual void OnTestCaseEnd(
const TestCase& test_case);
3209 virtual void OnEnvironmentsTearDownStart(
const UnitTest& unit_test);
3210 virtual void OnEnvironmentsTearDownEnd(
const UnitTest& unit_test);
3211 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
3212 virtual void OnTestProgramEnd(
const UnitTest& unit_test);
3224 TestEventRepeater::~TestEventRepeater() {
3225 ForEach(listeners_, Delete<TestEventListener>);
3229 listeners_.push_back(listener);
3234 for (
size_t i = 0;
i < listeners_.size(); ++
i) {
3235 if (listeners_[
i] == listener) {
3236 listeners_.erase(listeners_.begin() +
i);
3246 #define GTEST_REPEATER_METHOD_(Name, Type) \ 3247 void TestEventRepeater::Name(const Type& parameter) { \ 3248 if (forwarding_enabled_) { \ 3249 for (size_t i = 0; i < listeners_.size(); i++) { \ 3250 listeners_[i]->Name(parameter); \ 3256 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \ 3257 void TestEventRepeater::Name(const Type& parameter) { \ 3258 if (forwarding_enabled_) { \ 3259 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \ 3260 listeners_[i]->Name(parameter); \ 3277 #undef GTEST_REPEATER_METHOD_ 3278 #undef GTEST_REVERSE_REPEATER_METHOD_ 3280 void TestEventRepeater::OnTestIterationStart(
const UnitTest& unit_test,
3282 if (forwarding_enabled_) {
3283 for (
size_t i = 0;
i < listeners_.size();
i++) {
3284 listeners_[
i]->OnTestIterationStart(unit_test, iteration);
3289 void TestEventRepeater::OnTestIterationEnd(
const UnitTest& unit_test,
3291 if (forwarding_enabled_) {
3292 for (
int i = static_cast<int>(listeners_.size()) - 1;
i >= 0;
i--) {
3293 listeners_[
i]->OnTestIterationEnd(unit_test, iteration);
3305 virtual void OnTestIterationEnd(
const UnitTest& unit_test,
int iteration);
3311 return c == 0x9 || c == 0xA || c == 0xD;
3316 return IsNormalizableWhitespace(c) || c >= 0x20;
3330 return EscapeXml(str,
true);
3335 return EscapeXml(str,
false);
3340 static void OutputXmlAttribute(std::ostream* stream,
3346 static void OutputXmlCDataSection(::std::ostream* stream,
const char*
data);
3349 static void OutputXmlTestInfo(::std::ostream* stream,
3350 const char* test_case_name,
3354 static void PrintXmlTestCase(::std::ostream* stream,
3358 static void PrintXmlUnitTest(::std::ostream* stream,
3374 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(
const char* output_file)
3375 : output_file_(output_file) {
3377 fprintf(stderr,
"XML output file may not be null\n");
3386 FILE* xmlout = NULL;
3390 if (output_dir.CreateDirectoriesRecursively()) {
3393 if (xmlout == NULL) {
3405 "Unable to open file \"%s\"\n",
3410 std::stringstream stream;
3432 for (
size_t i = 0;
i < str.size(); ++
i) {
3433 const char ch = str[
i];
3477 output.reserve(str.size());
3478 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
3480 output.push_back(*it);
3503 ::std::stringstream ss;
3509 #if defined(_MSC_VER) 3510 return localtime_s(out, &seconds) == 0;
3511 #elif defined(__MINGW32__) || defined(__MINGW64__) 3514 struct tm* tm_ptr = localtime(&seconds);
3520 return localtime_r(&seconds, out) != NULL;
3527 struct tm time_struct;
3542 const char* segment =
data;
3543 *stream <<
"<![CDATA[";
3545 const char*
const next_segment = strstr(segment,
"]]>");
3546 if (next_segment != NULL) {
3548 segment, static_cast<std::streamsize>(next_segment - segment));
3549 *stream <<
"]]>]]><![CDATA[";
3550 segment = next_segment + strlen(
"]]>");
3560 std::ostream* stream,
3564 const std::vector<std::string>& allowed_names =
3567 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
3568 allowed_names.end())
3569 <<
"Attribute " << name <<
" is not allowed for element <" << element_name
3578 const char* test_case_name,
3583 *stream <<
" <testcase";
3605 if (++failures == 1) {
3610 const string summary = location +
"\n" + part.
summary();
3611 *stream <<
" <failure message=\"" 3614 const string detail = location +
"\n" + part.
message();
3616 *stream <<
"</failure>\n";
3623 *stream <<
" </testcase>\n";
3630 *stream <<
" <" << kTestsuite;
3637 stream, kTestsuite,
"disabled",
3649 *stream <<
" </" << kTestsuite <<
">\n";
3657 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3658 *stream <<
"<" << kTestsuites;
3665 stream, kTestsuites,
"disabled",
3669 stream, kTestsuites,
"timestamp",
3688 *stream <<
"</" << kTestsuites <<
">\n";
3698 attributes <<
" " <<
property.key() <<
"=" 3706 #if GTEST_CAN_STREAM_RESULTS_ 3713 string StreamingListener::UrlEncode(
const char*
str) {
3715 result.reserve(strlen(str) + 1);
3716 for (
char ch = *str; ch !=
'\0'; ch = *++
str) {
3725 result.push_back(ch);
3732 void StreamingListener::SocketWriter::MakeConnection() {
3734 <<
"MakeConnection() can't be called when there is already a connection.";
3737 memset(&hints, 0,
sizeof(hints));
3738 hints.ai_family = AF_UNSPEC;
3739 hints.ai_socktype = SOCK_STREAM;
3740 addrinfo* servinfo = NULL;
3745 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
3746 if (error_num != 0) {
3747 GTEST_LOG_(WARNING) <<
"stream_result_to: getaddrinfo() failed: " 3748 << gai_strerror(error_num);
3752 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;
3753 cur_addr = cur_addr->ai_next) {
3755 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
3756 if (sockfd_ != -1) {
3758 if (
connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
3765 freeaddrinfo(servinfo);
3767 if (sockfd_ == -1) {
3768 GTEST_LOG_(WARNING) <<
"stream_result_to: failed to connect to " 3769 << host_name_ <<
":" << port_num_;
3774 #endif // GTEST_CAN_STREAM_RESULTS__ 3785 trace.
message = message.GetString();
3825 : premature_exit_filepath_(premature_exit_filepath) {
3827 if (premature_exit_filepath != NULL && *premature_exit_filepath !=
'\0') {
3831 FILE* pfile =
posix::FOpen(premature_exit_filepath,
"w");
3832 fwrite(
"0", 1, 1, pfile);
3838 if (premature_exit_filepath_ != NULL && *premature_exit_filepath_ !=
'\0') {
3839 remove(premature_exit_filepath_);
3854 : repeater_(new internal::TestEventRepeater()),
3855 default_result_printer_(NULL),
3856 default_xml_generator_(NULL) {
3895 if (listener != NULL)
3911 if (listener != NULL)
3947 #if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) 3953 #endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) 3958 return impl()->successful_test_case_count();
3963 return impl()->failed_test_case_count();
3968 return impl()->total_test_case_count();
3974 return impl()->test_case_to_run_count();
3979 return impl()->successful_test_count();
3987 return impl()->reportable_disabled_test_count();
3992 return impl()->disabled_test_count();
3997 return impl()->reportable_test_count();
4009 return impl()->start_timestamp();
4014 return impl()->elapsed_time();
4027 return impl()->GetTestCase(i);
4033 return *impl()->ad_hoc_test_result();
4039 return impl()->GetMutableTestCase(i);
4045 return *impl()->listeners();
4063 impl_->environments().push_back(env);
4073 const char* file_name,
4081 if (impl_->gtest_trace_stack().size() > 0) {
4084 for (
int i = static_cast<int>(impl_->gtest_trace_stack().size());
4092 if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {
4099 impl_->GetTestPartResultReporterForCurrentThread()->
4100 ReportTestPartResult(result);
4109 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 4119 *
static_cast<volatile int*
>(NULL) = 1;
4120 #endif // GTEST_OS_WINDOWS 4122 #if GTEST_HAS_EXCEPTIONS 4123 throw internal::GoogleTestFailureException(result);
4149 const bool in_death_test_child_process =
4174 in_death_test_child_process ?
4179 impl()->set_catch_exceptions(
GTEST_FLAG(catch_exceptions));
4186 if (impl()->catch_exceptions() || in_death_test_child_process) {
4187 # if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT 4189 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
4190 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
4191 # endif // !GTEST_OS_WINDOWS_MOBILE 4193 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE 4197 _set_error_mode(_OUT_TO_STDERR);
4200 # if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE 4213 _set_abort_behavior(
4215 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
4218 #endif // GTEST_HAS_SEH 4223 "auxiliary test code (environments or event listeners)") ? 0 : 1;
4229 return impl_->original_working_dir_.c_str();
4237 return impl_->current_test_case();
4245 return impl_->current_test_info();
4251 #if GTEST_HAS_PARAM_TEST 4254 internal::ParameterizedTestCaseRegistry&
4255 UnitTest::parameterized_test_registry()
4257 return impl_->parameterized_test_registry();
4259 #endif // GTEST_HAS_PARAM_TEST 4276 impl_->gtest_trace_stack().push_back(
trace);
4283 impl_->gtest_trace_stack().pop_back();
4286 namespace internal {
4291 default_global_test_part_result_reporter_(this),
4292 default_per_thread_test_part_result_reporter_(this),
4294 global_test_part_result_repoter_(
4295 &default_global_test_part_result_reporter_),
4296 per_thread_test_part_result_reporter_(
4297 &default_per_thread_test_part_result_reporter_),
4299 parameterized_test_registry_(),
4300 parameterized_tests_registered_(
false),
4302 last_death_test_case_(-1),
4303 current_test_case_(NULL),
4304 current_test_info_(NULL),
4305 ad_hoc_test_result_(),
4306 os_stack_trace_getter_(NULL),
4307 post_flag_parse_init_performed_(
false),
4310 start_timestamp_(0),
4312 #
if GTEST_HAS_DEATH_TEST
4313 death_test_factory_(new DefaultDeathTestFactory),
4316 catch_exceptions_(
false) {
4340 xml_element =
"testcase";
4343 xml_element =
"testsuite";
4346 xml_element =
"testsuites";
4352 #if GTEST_HAS_DEATH_TEST 4355 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
4356 if (internal_run_death_test_flag_.get() != NULL)
4359 #endif // GTEST_HAS_DEATH_TEST 4365 if (output_format ==
"xml") {
4368 }
else if (output_format !=
"") {
4369 printf(
"WARNING: unrecognized output format \"%s\" ignored.\n",
4370 output_format.c_str());
4375 #if GTEST_CAN_STREAM_RESULTS_ 4378 void UnitTestImpl::ConfigureStreamingOutput() {
4380 if (!target.empty()) {
4381 const size_t pos = target.find(
':');
4382 if (pos != std::string::npos) {
4384 target.substr(pos+1)));
4386 printf(
"WARNING: unrecognized streaming target \"%s\" ignored.\n",
4392 #endif // GTEST_CAN_STREAM_RESULTS_ 4404 #if GTEST_HAS_DEATH_TEST 4405 InitDeathTestSubprocessControlInfo();
4406 SuppressTestEventsIfInSubprocess();
4407 #endif // GTEST_HAS_DEATH_TEST 4418 #if GTEST_CAN_STREAM_RESULTS_ 4420 ConfigureStreamingOutput();
4421 #endif // GTEST_CAN_STREAM_RESULTS_ 4441 return test_case != NULL && strcmp(test_case->
name(),
name_.c_str()) == 0;
4461 const char* type_param,
4465 const std::vector<TestCase*>::const_iterator test_case =
4474 new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
4478 kDeathTestCaseFilter)) {
4492 return new_test_case;
4513 "\nThis test program did NOT call ::testing::InitGoogleTest " 4514 "before calling RUN_ALL_TESTS(). Please fix it.\n");
4533 bool in_subprocess_for_death_test =
false;
4535 #if GTEST_HAS_DEATH_TEST 4536 in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);
4537 #endif // GTEST_HAS_DEATH_TEST 4539 const bool should_shard =
ShouldShard(kTestTotalShards, kTestShardIndex,
4540 in_subprocess_for_death_test);
4544 const bool has_tests_to_run =
FilterTests(should_shard
4559 bool failed =
false;
4568 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
4570 const bool forever = repeat < 0;
4571 for (
int i = 0; forever ||
i != repeat;
i++) {
4579 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
4591 if (has_tests_to_run) {
4647 const char*
const test_shard_file =
posix::GetEnv(kTestShardStatusFile);
4648 if (test_shard_file != NULL) {
4652 "Could not write to the test shard status file \"%s\" " 4653 "specified by the %s environment variable.\n",
4654 test_shard_file, kTestShardStatusFile);
4669 const char* shard_index_env,
4670 bool in_subprocess_for_death_test) {
4671 if (in_subprocess_for_death_test) {
4678 if (total_shards == -1 && shard_index == -1) {
4680 }
else if (total_shards == -1 && shard_index != -1) {
4682 <<
"Invalid environment variables: you have " 4683 << kTestShardIndex <<
" = " << shard_index
4684 <<
", but have left " << kTestTotalShards <<
" unset.\n";
4688 }
else if (total_shards != -1 && shard_index == -1) {
4690 <<
"Invalid environment variables: you have " 4691 << kTestTotalShards <<
" = " << total_shards
4692 <<
", but have left " << kTestShardIndex <<
" unset.\n";
4696 }
else if (shard_index < 0 || shard_index >= total_shards) {
4698 <<
"Invalid environment variables: we require 0 <= " 4699 << kTestShardIndex <<
" < " << kTestTotalShards
4700 <<
", but you have " << kTestShardIndex <<
"=" << shard_index
4701 <<
", " << kTestTotalShards <<
"=" << total_shards <<
".\n";
4707 return total_shards > 1;
4715 if (str_val == NULL) {
4721 str_val, &result)) {
4732 return (test_id % total_shards) == shard_index;
4752 int num_runnable_tests = 0;
4753 int num_selected_tests = 0;
4764 const bool is_disabled =
4766 kDisableTestFilter) ||
4768 kDisableTestFilter);
4771 const bool matches_filter =
4776 const bool is_runnable =
4777 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
4780 const bool is_selected = is_runnable &&
4783 num_runnable_tests));
4785 num_runnable_tests += is_runnable;
4786 num_selected_tests += is_selected;
4792 return num_selected_tests;
4801 for (
int i = 0; *str !=
'\0'; ++
str) {
4802 if (
i >= max_length) {
4820 const int kMaxParamLength = 250;
4824 bool printed_test_case_name =
false;
4830 if (!printed_test_case_name) {
4831 printed_test_case_name =
true;
4834 printf(
" # %s = ", kTypeParamLabel);
4843 printf(
" # %s = ", kValueParamLabel);
4932 class ClassUniqueToAlwaysTrue {};
4935 bool IsTrue(
bool condition) {
return condition; }
4938 #if GTEST_HAS_EXCEPTIONS 4942 throw ClassUniqueToAlwaysTrue();
4943 #endif // GTEST_HAS_EXCEPTIONS 4951 const size_t prefix_len = strlen(prefix);
4952 if (strncmp(*pstr, prefix, prefix_len) == 0) {
4953 *pstr += prefix_len;
4966 bool def_optional) {
4968 if (str == NULL || flag == NULL)
return NULL;
4972 const size_t flag_len = flag_str.length();
4973 if (strncmp(str, flag_str.c_str(), flag_len) != 0)
return NULL;
4976 const char* flag_end = str + flag_len;
4979 if (def_optional && (flag_end[0] ==
'\0')) {
4986 if (flag_end[0] !=
'=')
return NULL;
4989 return flag_end + 1;
5007 if (value_str == NULL)
return false;
5010 *value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
5024 if (value_str == NULL)
return false;
5041 if (value_str == NULL)
return false;
5082 const char*
p = strchr(str,
'@');
5090 const char ch = p[1];
5094 }
else if (ch ==
'D') {
5096 }
else if (ch ==
'R') {
5098 }
else if (ch ==
'G') {
5100 }
else if (ch ==
'Y') {
5109 "This program contains tests written using " GTEST_NAME_ ". You can use the\n" 5110 "following command line flags to control its behavior:\n" 5114 " List the names of all tests instead of running them. The name of\n" 5115 " TEST(Foo, Bar) is \"Foo.Bar\".\n" 5117 "[@G-@YNEGATIVE_PATTERNS]@D\n" 5118 " Run only the tests whose name matches one of the positive patterns but\n" 5119 " none of the negative patterns. '?' matches any single character; '*'\n" 5120 " matches any substring; ':' separates two patterns.\n" 5122 " Run all disabled tests too.\n" 5126 " Run the tests repeatedly; use a negative count to repeat forever.\n" 5128 " Randomize tests' orders on every iteration.\n" 5130 " Random number seed to use for shuffling test orders (between 1 and\n" 5131 " 99999, or 0 to use a seed based on the current time).\n" 5135 " Enable/disable colored output. The default is @Gauto@D.\n" 5137 " Don't print the elapsed time of each test.\n" 5140 " Generate an XML report in the given directory or with the given file\n" 5141 " name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n" 5142 #if GTEST_CAN_STREAM_RESULTS_ 5144 " Stream test results to the given server.\n" 5145 #endif // GTEST_CAN_STREAM_RESULTS_ 5147 "Assertion Behavior:\n" 5148 #if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 5150 " Set the default death test style.\n" 5151 #endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS 5153 " Turn assertion failures into debugger break-points.\n" 5155 " Turn assertion failures into C++ exceptions.\n" 5157 " Do not report exceptions as test failures. Instead, allow them\n" 5158 " to crash the program or throw a pop-up (on Windows).\n" 5161 "the corresponding\n" 5162 "environment variable of a flag (all letters in upper-case). For example, to\n" 5164 "color=no@D or set\n" 5167 "For more information, please read the " GTEST_NAME_ " documentation at\n" 5169 "(not one in your own code or tests), please report it to\n" 5175 template <
typename CharType>
5177 for (
int i = 1;
i < *argc;
i++) {
5179 const char*
const arg = arg_string.c_str();
5217 for (
int j = i;
j != *argc;
j++) {
5218 argv[
j] = argv[
j + 1];
5227 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
5228 arg_string ==
"-?" || arg_string ==
"/?" ||
5257 template <
typename CharType>
5259 g_init_gtest_count++;
5262 if (g_init_gtest_count != 1)
return;
5264 if (*argc <= 0)
return;
5268 #if GTEST_HAS_DEATH_TEST 5271 for (
int i = 0;
i != *argc;
i++) {
5275 #endif // GTEST_HAS_DEATH_TEST GTEST_API_ bool g_help_flag
#define GTEST_IMPL_CMP_HELPER_(op_name, op)
int failed_test_count() const
void SetDefaultResultPrinter(TestEventListener *listener)
TestPartResultReporterInterface * GetTestPartResultReporterForCurrentThread()
const TestPartResultArray *const results_
const internal::GTestFlagSaver *const gtest_flag_saver_
class UnitTestImpl * GetUnitTestImpl()
internal::SetUpTestCaseFunc SetUpTestCaseFunc
const char * type_param() const
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
~ScopedPrematureExitFile()
GTEST_API_ bool IsTrue(bool condition)
void RecordProperty(const std::string &xml_element, const TestProperty &test_property)
#define GTEST_REPEATER_METHOD_(Name, Type)
const char kAlsoRunDisabledTestsFlag[]
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()
TestPartResultArray *const result_
int successful_test_count() const
static void PrintXmlUnitTest(::std::ostream *stream, const UnitTest &unit_test)
int reportable_disabled_test_count() const
TimeInMillis elapsed_time() const
static bool HasGoogleTestFlagPrefix(const char *str)
static int SumOverTestCaseList(const std::vector< TestCase * > &case_list, int(TestCase::*method)() const)
std::vector< TestInfo * > test_info_list_
const char * summary() const
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
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
GTEST_API_ AssertionResult AssertionFailure()
UInt32 ChopLowBits(UInt32 *bits, int n)
const char kStreamResultToFlag[]
TimeInMillis elapsed_time_
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)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
void PrintFullTestCommentIfPresent(const TestInfo &test_info)
std::vector< Environment * > environments_
void set_current_test_info(TestInfo *a_current_test_info)
TestPartResultReporterInterface * GetGlobalTestPartResultReporter()
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
internal::TestEventRepeater * repeater_
void RegisterParameterizedTests()
::std::string PrintToString(const T &value)
static bool IsNormalizableWhitespace(char c)
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
#define GTEST_FLAG_PREFIX_DASH_
const char * StringFromGTestEnv(const char *flag, const char *default_val)
internal::Mutex test_properites_mutex_
#define GTEST_LOG_(severity)
GTEST_API_ int g_init_gtest_count
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
virtual void ReportTestPartResult(const TestPartResult &result)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
ScopedFakeTestPartResultReporter(TestPartResultArray *result)
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
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()
TimeInMillis elapsed_time_
std::list< std::pair< char, const char * > > hunk_adds_
TestPartResult::Type const type
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
void SuppressEventForwarding()
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
PrettyUnitTestResultPrinter()
void SetGlobalTestPartResultReporter(TestPartResultReporterInterface *reporter)
void RecordProperty(const std::string &key, const std::string &value)
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
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[]
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)=0
const char kListTestsFlag[]
virtual void OnTestCaseEnd(const TestCase &test_case)=0
#define GTEST_PROJECT_URL_
const std::string output_file_
void set_elapsed_time(TimeInMillis elapsed)
virtual void OnEnvironmentsSetUpEnd(const UnitTest &)
GTEST_API_ 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)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
virtual void OnTestStart(const TestInfo &test_info)=0
void set_current_test_case(TestCase *a_current_test_case)
static bool ValidateTestProperty(const std::string &xml_element, const TestProperty &test_property)
void operator=(const Message &message) const
int reportable_disabled_test_count() const
const TestPartResult & GetTestPartResult(int i) const
const char kDeathTestUseFork[]
std::vector< TestInfo * > & test_info_list()
const TestProperty & GetTestProperty(int i) const
const char * GetEnv(const char *name)
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)
if(strcmp(arg,"1305")!=0)
int test_case_to_run_count() const
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
bool catch_exceptions() const
UnitTestImpl *const unit_test_
static const char kTestTotalShards[]
GTEST_API_ 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 add(const actionlib::TwoIntsGoal &req, actionlib::TwoIntsResult &res)
bool ParseBoolFlag(const char *str, const char *flag, bool *value)
const char kInternalRunDeathTestFlag[]
TypeWithSize< 8 >::Int TimeInMillis
static std::string FormatByte(unsigned char value)
int reportable_test_count() const
#define GTEST_LOCK_EXCLUDED_(locks)
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
UNITTEST_START int result
static std::vector< std::string > GetReservedAttributesForElement(const std::string &xml_element)
TestCase * current_test_case_
AssertHelperData *const data_
virtual void OnTestProgramStart(const UnitTest &)
void PushGTestTrace(const internal::TraceInfo &trace) GTEST_LOCK_EXCLUDED_(mutex_)
OsStackTraceGetterInterface * os_stack_trace_getter_
GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter)
TimeInMillis start_timestamp() const
int total_test_count() const
std::string StreamableToString(const T &streamable)
std::list< std::pair< char, const char * > > hunk_
AssertionResult(const AssertionResult &other)
static const char kTestShardStatusFile[]
bool HasNonfatalFailure() const
internal::TimeInMillis TimeInMillis
internal::scoped_ptr< ::std::string > message_
int reportable_test_count() const
TypeWithSize< 4 >::UInt UInt32
internal::TestFactoryBase *const factory_
const char kRandomSeedFlag[]
std::vector< int > test_case_indices_
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_)
TypeWithSize< 4 >::Int Int32
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
DefaultGlobalTestPartResultReporter(UnitTestImpl *unit_test)
void Set(const FilePath &rhs)
TestResult ad_hoc_test_result_
static char * GetEnv(const char *variable)
GTEST_API_ TypeId GetTestTypeId()
static std::string TestPropertiesAsXmlAttributes(const TestResult &result)
TimeInMillis start_timestamp_
static std::string FormatCountableNoun(int count, const char *singular_form, const char *plural_form)
std::list< std::pair< char, const char * > > hunk_removes_
GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex)
bool is_reportable() const
UNITTEST_START char * output
const char * name() const
int test_case_to_run_count() const
#define GTEST_FLAG_PREFIX_UPPER_
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
std::vector< TestEventListener * > listeners_
int test_to_run_count() const
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase)
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
TestCase * GetMutableTestCase(int i)
OsStackTraceGetterInterface * os_stack_trace_getter()
bool GTEST_FLAG(internal_skip_environment_and_ad_hoc_tests)
const char * message() const
GTEST_API_ AssertionResult AssertionSuccess()
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
const char * ParseFlagValue(const char *str, const char *flag, bool def_optional)
const char kDeathTestStyleFlag[]
void set_forwarding_enabled(bool enable)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
TestResult ad_hoc_test_result_
const UInt32 kMaxCodePoint1
#define GTEST_CHECK_(condition)
std::string const message
static std::string GetOutputFormat()
TestEventListeners & listeners()
const internal::scoped_ptr< const ::std::string > type_param_
void SetDefaultXmlGenerator(TestEventListener *listener)
bool forwarding_enabled() const
const int kMaxStackTraceDepth
std::vector< TestPartResult > test_part_results_
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)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
std::vector< TestProperty > test_properties_
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
int successful_test_case_count() const
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
static bool GTestIsInitialized()
const std::string & string() const
UNITTEST_START struct Curl_easy data
const TestCase * GetTestCase(int i) const
TestInfo * GetMutableTestInfo(int i)
GTEST_API_ bool AlwaysTrue()
const char * file_name() const
static void PrintColorEncoded(const char *str)
void(* SetUpTestCaseFunc)()
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
static std::string FormatTestCaseCount(int test_case_count)
void(* TearDownTestCaseFunc)()
void swap(AssertionResult &other)
int StrCaseCmp(const char *s1, const char *s2)
TestResult * current_test_result()
const InterceptMode intercept_mode_
bool HasFatalFailure() const
UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
void ClearNonAdHocTestResult()
static void OutputXmlAttribute(std::ostream *stream, const std::string &element_name, const std::string &name, const std::string &value)
UnitTestImpl *const unit_test_
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[]
GTEST_API_ 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()
GTEST_API_ 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
const char kBreakOnFailureFlag[]
static bool TestPartFatallyFailed(const TestPartResult &result)
const TestCase * GetTestCase(int i) const
static void PrintXmlTestCase(::std::ostream *stream, const TestCase &test_case)
const TestPartResult & GetTestPartResult(int index) const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
const TestPartResult::Type type_
static const char *const kReservedTestCaseAttributes[]
const char kCatchExceptionsFlag[]
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
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
const char * GetAnsiColorCode(GTestColor color)
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const TestResult & ad_hoc_test_result() const
GTEST_API_ const char kStackTraceMarker[]
void PrintTo(const T &value,::std::ostream *os)
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 BoolFromGTestEnv(const char *flag, bool default_val)
FILE * FOpen(const char *path, const char *mode)
bool IsAbsolutePath() const
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_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.")
Environment * AddEnvironment(Environment *env)
TestCaseNameIs(const std::string &name)
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
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 InitGoogleTestImpl(int *argc, CharType **argv)
int Run() GTEST_MUST_USE_RESULT_
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
int FilterTests(ReactionToSharding shard_tests)
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)
TestEventListeners * listeners()
std::vector< TestCase * > test_cases_
TestEventListener * Release(TestEventListener *listener)
AssertionResult CmpHelperEQ(const char *expected_expression, const char *actual_expression, const T1 &expected, const T2 &actual)
#define GTEST_HAS_PARAM_TEST
static std::string FormatWordList(const std::vector< std::string > &words)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
TestEventListener * default_xml_generator_
void ConfigureXmlOutput()
virtual void ReportTestPartResult(const TestPartResult &result)=0
bool post_flag_parse_init_performed_
static bool HasSameFixtureClass()
void Shuffle(internal::Random *random, std::vector< E > *v)
virtual void OnTestCaseStart(const TestCase &test_case)=0
GTEST_API_ 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
const char kStackTraceDepthFlag[]
int total_test_count() const
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
const char kPrintTimeFlag[]
internal::Random * random()
static const char kTestShardIndex[]
void RunTearDownTestCase()
virtual void OnEnvironmentsTearDownEnd(const UnitTest &)
virtual void OnTestPartResult(const TestPartResult &test_part_result)=0
static bool TestCasePassed(const TestCase *test_case)
#define GTEST_HAS_GETTIMEOFDAY_
TimeInMillis elapsed_time_
TestEventListener * default_result_printer_
virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test)=0
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
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 OnTestEnd(const TestInfo &test_info)=0
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
TestInfo * current_test_info_
void set_should_run(bool should)
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
const UInt32 kMaxCodePoint4
UNITTEST_START int * value
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
int failed_test_case_count() const
const char * name() const
int successful_test_case_count() const
TimeInMillis elapsed_time() const
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
std::string g_executable_path
const TestResult * result() const
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static UnitTest * GetInstance()
void Append(const TestPartResult &result)
static bool PortableLocaltime(time_t seconds, struct tm *out)
void ClearTestPartResults()
GTEST_API_ 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
const char kThrowOnFailureFlag[]
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
const char *const premature_exit_filepath_
static void RecordProperty(const std::string &key, const std::string &value)
const TestResult & ad_hoc_test_result() const
const char * value() const
static bool FilterMatchesTest(const std::string &test_case_name, const std::string &test_name)
int last_death_test_case_
TestPartResultReporterInterface * old_reporter_
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
virtual void TestBody()=0
static std::string FormatIntWidth2(int value)
void WriteToShardStatusFileIfNeeded()
const char kShuffleFlag[]
static std::string ShowWideCString(const wchar_t *wide_c_str)
const T & move(const T &t)
static bool MatchesFilter(const std::string &name, const char *filter)
DefaultPerThreadTestPartResultReporter(UnitTestImpl *unit_test)
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
static bool HasNonfatalFailure()
std::vector< int > test_indices_
TestInfo * current_test_info()
bool ValidateTestPropertyName(const std::string &property_name, const std::vector< std::string > &reserved_names)
#define GTEST_FLAG_PREFIX_
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 ~ScopedFakeTestPartResultReporter()
virtual void OnTestProgramEnd(const UnitTest &)
TestCase * GetMutableTestCase(int i)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_
const internal::scoped_ptr< ::std::stringstream > ss_
static void OutputXmlCDataSection(::std::ostream *stream, const char *data)
TimeInMillis elapsed_time() const
static const char kTypeParamLabel[]