60# define GTEST_HAS_GETTIMEOFDAY_ 1
73# define GTEST_HAS_GETTIMEOFDAY_ 1
77# define GTEST_HAS_GETTIMEOFDAY_ 1
83#elif GTEST_OS_WINDOWS_MOBILE
91# include <sys/timeb.h>
92# include <sys/types.h>
95# if GTEST_OS_WINDOWS_MINGW
102# define GTEST_HAS_GETTIMEOFDAY_ 1
103# include <sys/time.h>
116# define GTEST_HAS_GETTIMEOFDAY_ 1
120# include <sys/time.h>
125#if GTEST_HAS_EXCEPTIONS
129#if GTEST_CAN_STREAM_RESULTS_
130# include <arpa/inet.h>
132# include <sys/socket.h>
133# include <sys/types.h>
139# define vsnprintf _vsnprintf
153static const char kDisableTestFilter[] =
"DISABLED_*:*/DISABLED_*";
158static const char kDeathTestCaseFilter[] =
"*DeathTest:*DeathTest/*";
161static const char kUniversalFilter[] =
"*";
164static const char kDefaultOutputFormat[] =
"xml";
166static const char kDefaultOutputFile[] =
"test_detail";
169static const char kTestShardIndex[] =
"GTEST_SHARD_INDEX";
171static const char kTestTotalShards[] =
"GTEST_TOTAL_SHARDS";
173static const char kTestShardStatusFile[] =
"GTEST_SHARD_STATUS_FILE";
189static const char* GetDefaultFilter() {
190 const char*
const testbridge_test_only =
192 if (testbridge_test_only != NULL) {
193 return testbridge_test_only;
195 return kUniversalFilter;
199 also_run_disabled_tests,
201 "Run disabled tests too, in addition to the tests normally being run.");
206 "True iff a failed assertion should be a debugger break-point.");
212 " should catch exceptions and treat them as test failures.");
217 "Whether to use colors in the output. Valid values: yes, no, "
218 "and auto. 'auto' means to use colors if the output is "
219 "being sent to a terminal and the TERM environment variable "
220 "is set to a terminal type that supports colors.");
225 "A colon-separated list of glob (not regex) patterns "
226 "for filtering the tests to run, optionally followed by a "
227 "'-' and a : separated list of negative patterns (tests to "
228 "exclude). A test is run if it matches one of the positive "
229 "patterns and does not match any of the negative patterns.");
232 "List all tests without running them.");
243 "A format (defaults to \"xml\" but can be specified to be \"json\"), "
244 "optionally followed by a colon and an output file name or directory. "
245 "A directory is indicated by a trailing pathname separator. "
246 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
247 "If a directory is specified, output files will be created "
248 "within that directory, with file-names based on the test "
249 "executable's name and, if necessary, made unique by adding "
256 " should display elapsed time in text output.");
262 " prints UTF8 characters as text.");
267 "Random number seed to use when shuffling test orders. Must be in range "
268 "[1, 99999], or 0 to use a seed based on the current time.");
273 "How many times to repeat each test. Specify a negative number "
274 "for repeating forever. Useful for shaking out flaky tests.");
277 show_internal_stack_frames,
false,
278 "True iff " GTEST_NAME_ " should include internal stack frames when "
279 "printing test failure stack traces.");
285 " should randomize tests' order on every run.");
290 "The maximum number of stack frames to print when an "
291 "assertion fails. The valid range is 0 through 100, inclusive.");
296 "This flag specifies the host name and the port number on which to stream "
297 "test results. Example: \"localhost:555\". The flag is effective only on "
303 "When this flag is specified, a failed assertion will throw an exception "
304 "if exceptions are enabled or exit the program with a non-zero code "
305 "otherwise. For use with an external test framework.");
307#if GTEST_USE_OWN_FLAGFILE_FLAG_
311 "This flag specifies the flagfile to read command-line flags from.");
322 state_ =
static_cast<UInt32>(1103515245ULL*state_ + 12345U) %
kMaxRange;
325 <<
"Cannot generate a number in the range [0, 0).";
327 <<
"Generation of a number in [0, " << range <<
") was requested, "
328 <<
"but this can only generate numbers in [0, " <<
kMaxRange <<
").";
333 return state_ % range;
339static bool GTestIsInitialized() {
return GetArgvs().size() > 0; }
344static int SumOverTestCaseList(
const std::vector<TestCase*>& case_list,
347 for (
size_t i = 0; i < case_list.size(); i++) {
348 sum += (case_list[i]->*method)();
354static bool TestCasePassed(
const TestCase* test_case) {
355 return test_case->should_run() && test_case->Passed();
359static bool TestCaseFailed(
const TestCase* test_case) {
360 return test_case->should_run() && test_case->Failed();
365static bool ShouldRunTestCase(
const TestCase* test_case) {
366 return test_case->should_run();
374 : data_(new AssertHelperData(type, file, line, message)) {
384 AddTestPartResult(data_->type, data_->file, data_->line,
385 AppendUserMessage(data_->message, message),
399#if defined(GTEST_CUSTOM_GET_ARGVS_)
402 const auto& custom = GTEST_CUSTOM_GET_ARGVS_();
403 return ::std::vector<std::string>(custom.begin(), custom.end());
420 return result.RemoveDirectoryName();
427 const char*
const gtest_output_flag =
GTEST_FLAG(output).c_str();
428 if (gtest_output_flag == NULL)
return std::string(
"");
430 const char*
const colon = strchr(gtest_output_flag,
':');
431 return (colon == NULL) ?
432 std::string(gtest_output_flag) :
433 std::string(gtest_output_flag, colon - gtest_output_flag);
439 const char*
const gtest_output_flag =
GTEST_FLAG(output).c_str();
440 if (gtest_output_flag == NULL)
445 format = std::string(kDefaultOutputFormat);
447 const char*
const colon = strchr(gtest_output_flag,
':');
456 if (!output_name.IsAbsolutePath())
465 if (!output_name.IsDirectory())
466 return output_name.string();
471 return result.string();
491 return *pattern == *str &&
497 const std::string&
name,
const char* filter) {
498 const char *cur_pattern = filter;
505 cur_pattern = strchr(cur_pattern,
':');
508 if (cur_pattern == NULL) {
520 const std::string &test_name) {
521 const std::string& full_name = test_case_name +
"." + test_name.c_str();
526 const char*
const dash = strchr(
p,
'-');
527 std::string positive;
528 std::string negative;
533 positive = std::string(
p, dash);
534 negative = std::string(dash + 1);
535 if (positive.empty()) {
537 positive = kUniversalFilter;
551int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
560 const DWORD kCxxExceptionCode = 0xe06d7363;
562 bool should_handle =
true;
565 should_handle =
false;
566 else if (exception_code == EXCEPTION_BREAKPOINT)
567 should_handle =
false;
568 else if (exception_code == kCxxExceptionCode)
569 should_handle =
false;
571 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
582 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
592 : intercept_mode_(intercept_mode),
597void ScopedFakeTestPartResultReporter::Init() {
653 const std::string& substr) {
656 "1 non-fatal failure");
659 msg <<
"Expected: " << expected <<
"\n"
660 <<
" Actual: " <<
results.size() <<
" failures";
661 for (
int i = 0; i <
results.size(); i++) {
662 msg <<
"\n" <<
results.GetTestPartResult(i);
667 const TestPartResult&
r =
results.GetTestPartResult(0);
668 if (
r.type() != type) {
674 if (strstr(
r.message(), substr.c_str()) == NULL) {
689 const std::string& substr)
690 : results_(
results), type_(type), substr_(substr) {}
721 return global_test_part_result_repoter_;
728 global_test_part_result_repoter_ = reporter;
734 return per_thread_test_part_result_reporter_.get();
740 per_thread_test_part_result_reporter_.set(reporter);
745 return CountIf(test_cases_, TestCasePassed);
750 return CountIf(test_cases_, TestCaseFailed);
755 return static_cast<int>(test_cases_.size());
761 return CountIf(test_cases_, ShouldRunTestCase);
776 return SumOverTestCaseList(test_cases_,
812 static_cast<int>(
GTEST_FLAG(stack_trace_depth)),
821#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
826 const DWORD kTenthMicrosInMilliSecond = 10000;
828 SYSTEMTIME now_systime;
829 FILETIME now_filetime;
830 ULARGE_INTEGER now_int64;
833 GetSystemTime(&now_systime);
834 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
835 now_int64.LowPart = now_filetime.dwLowDateTime;
836 now_int64.HighPart = now_filetime.dwHighDateTime;
837 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
838 kJavaEpochToWinFileTimeDelta;
839 return now_int64.QuadPart;
842#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
853 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
854#elif GTEST_HAS_GETTIMEOFDAY_
856 gettimeofday(&now, NULL);
857 return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
859# error "Don't know how to get the current time on your system."
867#if GTEST_OS_WINDOWS_MOBILE
872LPCWSTR String::AnsiToUtf16(
const char* ansi) {
873 if (!ansi)
return NULL;
874 const int length = strlen(ansi);
875 const int unicode_length =
876 MultiByteToWideChar(CP_ACP, 0, ansi, length,
878 WCHAR* unicode =
new WCHAR[unicode_length + 1];
879 MultiByteToWideChar(CP_ACP, 0, ansi, length,
880 unicode, unicode_length);
881 unicode[unicode_length] = 0;
889const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
890 if (!utf16_str)
return NULL;
891 const int ansi_length =
892 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
893 NULL, 0, NULL, NULL);
894 char* ansi =
new char[ansi_length + 1];
895 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
896 ansi, ansi_length, NULL, NULL);
897 ansi[ansi_length] = 0;
909 if ( lhs == NULL )
return rhs == NULL;
911 if ( rhs == NULL )
return false;
913 return strcmp(lhs, rhs) == 0;
916#if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
920static void StreamWideCharsToMessage(
const wchar_t* wstr,
size_t length,
922 for (
size_t i = 0; i != length; ) {
923 if (wstr[i] != L
'\0') {
924 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
925 while (i != length && wstr[i] != L
'\0')
937 ::std::vector< ::std::string>* dest) {
938 ::std::vector< ::std::string> parsed;
939 ::std::string::size_type pos = 0;
941 const ::std::string::size_type colon = str.find(delimiter, pos);
942 if (colon == ::std::string::npos) {
943 parsed.push_back(str.substr(pos));
946 parsed.push_back(str.substr(pos, colon - pos));
963 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
975#if GTEST_HAS_STD_WSTRING
979 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
984#if GTEST_HAS_GLOBAL_WSTRING
988 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(),
this);
1002 : success_(other.success_),
1003 message_(other.message_.get() != NULL ?
1004 new ::
std::string(*other.message_) :
1005 static_cast< ::
std::string*>(NULL)) {
1011 swap(success_, other.success_);
1012 swap(message_, other.message_);
1018 if (message_.
get() != NULL)
1019 negation << *message_;
1041namespace edit_distance {
1043 const std::vector<size_t>& right) {
1044 std::vector<std::vector<double> > costs(
1045 left.size() + 1, std::vector<double>(right.size() + 1));
1046 std::vector<std::vector<EditType> > best_move(
1047 left.size() + 1, std::vector<EditType>(right.size() + 1));
1050 for (
size_t l_i = 0; l_i < costs.size(); ++l_i) {
1051 costs[l_i][0] =
static_cast<double>(l_i);
1055 for (
size_t r_i = 1; r_i < costs[0].size(); ++r_i) {
1056 costs[0][r_i] =
static_cast<double>(r_i);
1057 best_move[0][r_i] =
kAdd;
1060 for (
size_t l_i = 0; l_i < left.size(); ++l_i) {
1061 for (
size_t r_i = 0; r_i < right.size(); ++r_i) {
1062 if (left[l_i] == right[r_i]) {
1064 costs[l_i + 1][r_i + 1] = costs[l_i][r_i];
1065 best_move[l_i + 1][r_i + 1] =
kMatch;
1069 const double add = costs[l_i + 1][r_i];
1070 const double remove = costs[l_i][r_i + 1];
1071 const double replace = costs[l_i][r_i];
1072 if (
add < remove &&
add < replace) {
1073 costs[l_i + 1][r_i + 1] =
add + 1;
1074 best_move[l_i + 1][r_i + 1] =
kAdd;
1075 }
else if (remove <
add && remove < replace) {
1076 costs[l_i + 1][r_i + 1] = remove + 1;
1077 best_move[l_i + 1][r_i + 1] =
kRemove;
1081 costs[l_i + 1][r_i + 1] = replace + 1.00001;
1082 best_move[l_i + 1][r_i + 1] =
kReplace;
1088 std::vector<EditType> best_path;
1089 for (
size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) {
1090 EditType move = best_move[l_i][r_i];
1091 best_path.push_back(move);
1092 l_i -= move !=
kAdd;
1095 std::reverse(best_path.begin(), best_path.end());
1102class InternalStrings {
1104 size_t GetId(
const std::string& str) {
1105 IdMap::iterator it = ids_.find(str);
1106 if (it != ids_.end())
return it->second;
1107 size_t id = ids_.size();
1108 return ids_[str] =
id;
1112 typedef std::map<std::string, size_t> IdMap;
1119 const std::vector<std::string>& left,
1120 const std::vector<std::string>& right) {
1121 std::vector<size_t> left_ids, right_ids;
1123 InternalStrings intern_table;
1124 for (
size_t i = 0; i < left.size(); ++i) {
1125 left_ids.push_back(intern_table.GetId(left[i]));
1127 for (
size_t i = 0; i < right.size(); ++i) {
1128 right_ids.push_back(intern_table.GetId(right[i]));
1142 Hunk(
size_t left_start,
size_t right_start)
1143 : left_start_(left_start),
1144 right_start_(right_start),
1149 void PushLine(
char edit,
const char* line) {
1154 hunk_.push_back(std::make_pair(
' ', line));
1158 hunk_removes_.push_back(std::make_pair(
'-', line));
1162 hunk_adds_.push_back(std::make_pair(
'+', line));
1170 for (std::list<std::pair<char, const char*> >::const_iterator it =
1172 it != hunk_.end(); ++it) {
1173 *
os << it->first << it->second <<
"\n";
1177 bool has_edits()
const {
return adds_ || removes_; }
1181 hunk_.splice(hunk_.end(), hunk_removes_);
1182 hunk_.splice(hunk_.end(), hunk_adds_);
1189 void PrintHeader(std::ostream* ss)
const {
1192 *
ss <<
"-" << left_start_ <<
"," << (removes_ + common_);
1194 if (removes_ && adds_) {
1198 *
ss <<
"+" << right_start_ <<
"," << (adds_ + common_);
1203 size_t left_start_, right_start_;
1204 size_t adds_, removes_, common_;
1205 std::list<std::pair<char, const char*> > hunk_, hunk_adds_, hunk_removes_;
1218 const std::vector<std::string>& right,
1222 size_t l_i = 0, r_i = 0, edit_i = 0;
1223 std::stringstream ss;
1224 while (edit_i < edits.size()) {
1226 while (edit_i < edits.size() && edits[edit_i] ==
kMatch) {
1233 const size_t prefix_context = std::min(l_i,
context);
1234 Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1);
1235 for (
size_t i = prefix_context; i > 0; --i) {
1236 hunk.PushLine(
' ', left[l_i - i].c_str());
1241 size_t n_suffix = 0;
1242 for (; edit_i < edits.size(); ++edit_i) {
1245 std::vector<EditType>::const_iterator it = edits.begin() + edit_i;
1246 while (it != edits.end() && *it ==
kMatch) ++it;
1247 if (it == edits.end() || (it - edits.begin()) - edit_i >=
context) {
1255 n_suffix = edit ==
kMatch ? n_suffix + 1 : 0;
1258 hunk.PushLine(edit ==
kMatch ?
' ' :
'-', left[l_i].c_str());
1261 hunk.PushLine(
'+', right[r_i].c_str());
1265 l_i += edit !=
kAdd;
1269 if (!hunk.has_edits()) {
1286std::vector<std::string> SplitEscapedString(
const std::string& str) {
1287 std::vector<std::string>
lines;
1288 size_t start = 0, end = str.size();
1289 if (end > 2 && str[0] ==
'"' && str[end - 1] ==
'"') {
1293 bool escaped =
false;
1294 for (
size_t i = start; i + 1 < end; ++i) {
1297 if (str[i] ==
'n') {
1298 lines.push_back(str.substr(start, i - start - 1));
1302 escaped =
str[i] ==
'\\';
1305 lines.push_back(
str.substr(start, end - start));
1327 const char* rhs_expression,
1328 const std::string& lhs_value,
1329 const std::string& rhs_value,
1330 bool ignoring_case) {
1332 msg <<
"Expected equality of these values:";
1333 msg <<
"\n " << lhs_expression;
1334 if (lhs_value != lhs_expression) {
1335 msg <<
"\n Which is: " << lhs_value;
1337 msg <<
"\n " << rhs_expression;
1338 if (rhs_value != rhs_expression) {
1339 msg <<
"\n Which is: " << rhs_value;
1342 if (ignoring_case) {
1343 msg <<
"\nIgnoring case";
1346 if (!lhs_value.empty() && !rhs_value.empty()) {
1347 const std::vector<std::string> lhs_lines =
1348 SplitEscapedString(lhs_value);
1349 const std::vector<std::string> rhs_lines =
1350 SplitEscapedString(rhs_value);
1351 if (lhs_lines.size() > 1 || rhs_lines.size() > 1) {
1352 msg <<
"\nWith diff:\n"
1363 const char* expression_text,
1364 const char* actual_predicate_value,
1365 const char* expected_predicate_value) {
1366 const char* actual_message = assertion_result.
message();
1368 msg <<
"Value of: " << expression_text
1369 <<
"\n Actual: " << actual_predicate_value;
1370 if (actual_message[0] !=
'\0')
1371 msg <<
" (" << actual_message <<
")";
1372 msg <<
"\nExpected: " << expected_predicate_value;
1379 const char* abs_error_expr,
1383 const double diff =
fabs(val1 - val2);
1389 <<
"The difference between " << expr1 <<
" and " << expr2
1390 <<
" is " <<
diff <<
", which exceeds " << abs_error_expr <<
", where\n"
1391 << expr1 <<
" evaluates to " << val1 <<
",\n"
1392 << expr2 <<
" evaluates to " << val2 <<
", and\n"
1393 << abs_error_expr <<
" evaluates to " << abs_error <<
".";
1398template <
typename RawType>
1410 if (lhs.AlmostEquals(rhs)) {
1418 ::std::stringstream val1_ss;
1419 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1422 ::std::stringstream val2_ss;
1423 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1427 <<
"Expected: (" << expr1 <<
") <= (" << expr2 <<
")\n"
1437 float val1,
float val2) {
1444 double val1,
double val2) {
1453 const char* rhs_expression,
1470#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1471AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1472 BiggestInt val1, BiggestInt val2) {\
1473 if (val1 op val2) {\
1474 return AssertionSuccess();\
1476 return AssertionFailure() \
1477 << "Expected: (" << expr1 << ") " #op " (" << expr2\
1478 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1479 << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1499#undef GTEST_IMPL_CMP_HELPER_
1503 const char* rhs_expression,
1519 const char* rhs_expression,
1535 const char* s2_expression,
1542 << s2_expression <<
"), actual: \""
1543 << s1 <<
"\" vs \"" << s2 <<
"\"";
1549 const char* s2_expression,
1556 <<
"Expected: (" << s1_expression <<
") != ("
1557 << s2_expression <<
") (ignoring case), actual: \""
1558 << s1 <<
"\" vs \"" << s2 <<
"\"";
1572bool IsSubstringPred(
const char* needle,
const char* haystack) {
1573 if (needle == NULL || haystack == NULL)
1574 return needle == haystack;
1576 return strstr(haystack, needle) != NULL;
1579bool IsSubstringPred(
const wchar_t* needle,
const wchar_t* haystack) {
1580 if (needle == NULL || haystack == NULL)
1581 return needle == haystack;
1583 return wcsstr(haystack, needle) != NULL;
1587template <
typename StringType>
1588bool IsSubstringPred(
const StringType& needle,
1589 const StringType& haystack) {
1590 return haystack.find(needle) != StringType::npos;
1597template <
typename StringType>
1598AssertionResult IsSubstringImpl(
1599 bool expected_to_be_substring,
1600 const char* needle_expr,
const char* haystack_expr,
1601 const StringType& needle,
const StringType& haystack) {
1602 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1605 const bool is_wide_string =
sizeof(needle[0]) > 1;
1606 const char*
const begin_string_quote = is_wide_string ?
"L\"" :
"\"";
1608 <<
"Value of: " << needle_expr <<
"\n"
1609 <<
" Actual: " << begin_string_quote << needle <<
"\"\n"
1610 <<
"Expected: " << (expected_to_be_substring ?
"" :
"not ")
1611 <<
"a substring of " << haystack_expr <<
"\n"
1612 <<
"Which is: " << begin_string_quote << haystack <<
"\"";
1622 const char* needle_expr,
const char* haystack_expr,
1623 const char* needle,
const char* haystack) {
1624 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1628 const char* needle_expr,
const char* haystack_expr,
1629 const wchar_t* needle,
const wchar_t* haystack) {
1630 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1634 const char* needle_expr,
const char* haystack_expr,
1635 const char* needle,
const char* haystack) {
1636 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1640 const char* needle_expr,
const char* haystack_expr,
1641 const wchar_t* needle,
const wchar_t* haystack) {
1642 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1646 const char* needle_expr,
const char* haystack_expr,
1647 const ::std::string& needle, const ::std::string& haystack) {
1648 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1652 const char* needle_expr,
const char* haystack_expr,
1653 const ::std::string& needle, const ::std::string& haystack) {
1654 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1657#if GTEST_HAS_STD_WSTRING
1659 const char* needle_expr,
const char* haystack_expr,
1660 const ::std::wstring& needle, const ::std::wstring& haystack) {
1661 return IsSubstringImpl(
true, needle_expr, haystack_expr, needle, haystack);
1665 const char* needle_expr,
const char* haystack_expr,
1666 const ::std::wstring& needle, const ::std::wstring& haystack) {
1667 return IsSubstringImpl(
false, needle_expr, haystack_expr, needle, haystack);
1678AssertionResult HRESULTFailureHelper(
const char* expr,
1679 const char* expected,
1681# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE
1684 const char error_text[] =
"";
1691 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1692 FORMAT_MESSAGE_IGNORE_INSERTS;
1693 const DWORD kBufSize = 4096;
1695 char error_text[kBufSize] = {
'\0' };
1696 DWORD message_length = ::FormatMessageA(kFlags,
1704 for (; message_length &&
IsSpace(error_text[message_length - 1]);
1706 error_text[message_length - 1] =
'\0';
1712 return ::testing::AssertionFailure()
1713 <<
"Expected: " << expr <<
" " << expected <<
".\n"
1714 <<
" Actual: " << error_hex <<
" " << error_text <<
"\n";
1719AssertionResult IsHRESULTSuccess(
const char* expr,
long hr) {
1720 if (SUCCEEDED(hr)) {
1723 return HRESULTFailureHelper(expr,
"succeeds", hr);
1726AssertionResult IsHRESULTFailure(
const char* expr,
long hr) {
1730 return HRESULTFailureHelper(expr,
"fails", hr);
1763 const UInt32 low_bits = *bits & ((
static_cast<UInt32>(1) << n) - 1);
1782 str[0] =
static_cast<char>(code_point);
1785 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1786 str[0] =
static_cast<char>(0xC0 | code_point);
1789 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1790 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1791 str[0] =
static_cast<char>(0xE0 | code_point);
1794 str[3] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1795 str[2] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1796 str[1] =
static_cast<char>(0x80 |
ChopLowBits(&code_point, 6));
1797 str[0] =
static_cast<char>(0xF0 | code_point);
1810 return sizeof(wchar_t) == 2 &&
1811 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1817 const UInt32 mask = (1 << 10) - 1;
1818 return (
sizeof(
wchar_t) == 2) ?
1819 (((first & mask) << 10) | (second & mask)) + 0x10000 :
1822 static_cast<UInt32>(first);
1839 if (num_chars == -1)
1840 num_chars =
static_cast<int>(wcslen(str));
1842 ::std::stringstream stream;
1843 for (
int i = 0; i < num_chars; ++i) {
1844 UInt32 unicode_code_point;
1846 if (str[i] == L
'\0') {
1853 unicode_code_point =
static_cast<UInt32>(str[i]);
1864 if (wide_c_str == NULL)
return "(null)";
1876 if (lhs == NULL)
return rhs == NULL;
1878 if (rhs == NULL)
return false;
1880 return wcscmp(lhs, rhs) == 0;
1885 const char* rhs_expression,
1887 const wchar_t* rhs) {
1901 const char* s2_expression,
1903 const wchar_t* s2) {
1909 << s2_expression <<
"), actual: "
1941 const wchar_t* rhs) {
1942 if (lhs == NULL)
return rhs == NULL;
1944 if (rhs == NULL)
return false;
1947 return _wcsicmp(lhs, rhs) == 0;
1948#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
1949 return wcscasecmp(lhs, rhs) == 0;
1955 left = towlower(*lhs++);
1956 right = towlower(*rhs++);
1957 }
while (left && left == right);
1958 return left == right;
1965 const std::string& str,
const std::string& suffix) {
1966 const size_t str_len = str.length();
1967 const size_t suffix_len = suffix.length();
1968 return (str_len >= suffix_len) &&
1975 std::stringstream ss;
1976 ss << std::setfill(
'0') << std::setw(2) <<
value;
1982 std::stringstream ss;
1983 ss << std::hex << std::uppercase <<
value;
1989 std::stringstream ss;
1990 ss << std::setfill(
'0') << std::setw(2) << std::hex << std::uppercase
1991 <<
static_cast<unsigned int>(
value);
1998 const ::std::string& str = ss->str();
1999 const char*
const start = str.c_str();
2000 const char*
const end = start + str.length();
2003 result.reserve(2 * (end - start));
2004 for (
const char* ch = start; ch != end; ++ch) {
2019 const std::string user_msg_string = user_msg.
GetString();
2020 if (user_msg_string.empty()) {
2024 return gtest_msg +
"\n" + user_msg_string;
2033 : death_test_count_(0),
2047 return test_part_results_.at(i);
2056 return test_properties_.at(i);
2060void TestResult::ClearTestPartResults() {
2061 test_part_results_.clear();
2065void TestResult::AddTestPartResult(
const TestPartResult& test_part_result) {
2066 test_part_results_.push_back(test_part_result);
2072void TestResult::RecordProperty(
const std::string& xml_element,
2073 const TestProperty& test_property) {
2074 if (!ValidateTestProperty(xml_element, test_property)) {
2078 const std::vector<TestProperty>::iterator property_with_matching_key =
2079 std::find_if(test_properties_.begin(), test_properties_.end(),
2080 internal::TestPropertyKeyIs(test_property.key()));
2081 if (property_with_matching_key == test_properties_.end()) {
2082 test_properties_.push_back(test_property);
2085 property_with_matching_key->SetValue(test_property.value());
2090static const char*
const kReservedTestSuitesAttributes[] = {
2103static const char*
const kReservedTestSuiteAttributes[] = {
2113static const char*
const kReservedTestCaseAttributes[] = {
2124 return std::vector<std::string>(array, array + kSize);
2127static std::vector<std::string> GetReservedAttributesForElement(
2128 const std::string& xml_element) {
2129 if (xml_element ==
"testsuites") {
2131 }
else if (xml_element ==
"testsuite") {
2133 }
else if (xml_element ==
"testcase") {
2136 GTEST_CHECK_(
false) <<
"Unrecognized xml_element provided: " << xml_element;
2139 return std::vector<std::string>();
2142static std::string FormatWordList(
const std::vector<std::string>& words) {
2144 for (
size_t i = 0; i < words.size(); ++i) {
2145 if (i > 0 && words.size() > 2) {
2148 if (i == words.size() - 1) {
2149 word_list <<
"and ";
2151 word_list <<
"'" << words[i] <<
"'";
2153 return word_list.GetString();
2156static bool ValidateTestPropertyName(
2157 const std::string& property_name,
2158 const std::vector<std::string>& reserved_names) {
2159 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
2160 reserved_names.end()) {
2161 ADD_FAILURE() <<
"Reserved key used in RecordProperty(): " << property_name
2162 <<
" (" << FormatWordList(reserved_names)
2171bool TestResult::ValidateTestProperty(
const std::string& xml_element,
2172 const TestProperty& test_property) {
2173 return ValidateTestPropertyName(test_property.key(),
2174 GetReservedAttributesForElement(xml_element));
2178void TestResult::Clear() {
2179 test_part_results_.clear();
2180 test_properties_.clear();
2181 death_test_count_ = 0;
2196 return result.fatally_failed();
2201 return CountIf(test_part_results_, TestPartFatallyFailed) > 0;
2205static bool TestPartNonfatallyFailed(
const TestPartResult& result) {
2206 return result.nonfatally_failed();
2211 return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;
2217 return static_cast<int>(test_part_results_.size());
2222 return static_cast<int>(test_properties_.size());
2260 value_message <<
value;
2267 const std::string& message) {
2285bool Test::HasSameFixtureClass() {
2287 const TestCase*
const test_case = impl->current_test_case();
2290 const TestInfo*
const first_test_info = test_case->test_info_list()[0];
2291 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
2292 const char*
const first_test_name = first_test_info->name();
2295 const TestInfo*
const this_test_info = impl->current_test_info();
2296 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
2297 const char*
const this_test_name = this_test_info->name();
2299 if (this_fixture_id != first_fixture_id) {
2305 if (first_is_TEST || this_is_TEST) {
2312 const char*
const TEST_name =
2313 first_is_TEST ? first_test_name : this_test_name;
2314 const char*
const TEST_F_name =
2315 first_is_TEST ? this_test_name : first_test_name;
2318 <<
"All tests in the same test case must use the same test fixture\n"
2319 <<
"class, so mixing TEST_F and TEST in the same test case is\n"
2320 <<
"illegal. In test case " << this_test_info->test_case_name()
2322 <<
"test " << TEST_F_name <<
" is defined using TEST_F but\n"
2323 <<
"test " << TEST_name <<
" is defined using TEST. You probably\n"
2324 <<
"want to change the TEST to TEST_F or move it to another test\n"
2330 <<
"All tests in the same test case must use the same test fixture\n"
2331 <<
"class. However, in test case "
2332 << this_test_info->test_case_name() <<
",\n"
2333 <<
"you defined test " << first_test_name
2334 <<
" and test " << this_test_name <<
"\n"
2335 <<
"using two different test fixture classes. This can happen if\n"
2336 <<
"the two classes are from different namespaces or translation\n"
2337 <<
"units and have the same name. You should probably rename one\n"
2338 <<
"of the classes to put the tests into different test cases.";
2352static std::string* FormatSehExceptionMessage(DWORD exception_code,
2353 const char* location) {
2355 message <<
"SEH exception with code 0x" << std::setbase(16) <<
2356 exception_code << std::setbase(10) <<
" thrown in " << location <<
".";
2358 return new std::string(message.GetString());
2365#if GTEST_HAS_EXCEPTIONS
2368static std::string FormatCxxExceptionMessage(
const char* description,
2369 const char* location) {
2371 if (description != NULL) {
2372 message <<
"C++ exception with description \"" << description <<
"\"";
2374 message <<
"Unknown C++ exception";
2376 message <<
" thrown in " << location <<
".";
2378 return message.GetString();
2381static std::string PrintTestPartResultToString(
2382 const TestPartResult& test_part_result);
2384GoogleTestFailureException::GoogleTestFailureException(
2385 const TestPartResult& failure)
2386 : ::
std::runtime_error(PrintTestPartResultToString(
failure).c_str()) {}
2398template <
class T,
typename Result>
2400 T*
object, Result (
T::*method)(),
const char* location) {
2403 return (
object->*method)();
2404 } __except (internal::UnitTestOptions::GTestShouldProcessSEH(
2405 GetExceptionCode())) {
2409 std::string* exception_message = FormatSehExceptionMessage(
2410 GetExceptionCode(), location);
2412 *exception_message);
2413 delete exception_message;
2414 return static_cast<Result
>(0);
2418 return (
object->*method)();
2425template <
class T,
typename Result>
2427 T*
object, Result (
T::*method)(),
const char* location) {
2452#if GTEST_HAS_EXCEPTIONS
2455 }
catch (
const AssertionException&) {
2457 }
catch (
const internal::GoogleTestFailureException&) {
2462 }
catch (
const std::exception& e) {
2465 FormatCxxExceptionMessage(e.what(), location));
2469 FormatCxxExceptionMessage(NULL, location));
2471 return static_cast<Result
>(0);
2476 return (
object->*method)();
2484 if (!HasSameFixtureClass())
return;
2486 internal::UnitTestImpl*
const impl = internal::GetUnitTestImpl();
2487 impl->os_stack_trace_getter()->UponLeavingGTest();
2488 internal::HandleExceptionsInMethodIfSupported(
this, &Test::SetUp,
"SetUp()");
2490 if (!HasFatalFailure()) {
2491 impl->os_stack_trace_getter()->UponLeavingGTest();
2492 internal::HandleExceptionsInMethodIfSupported(
2493 this, &Test::TestBody,
"the test body");
2499 impl->os_stack_trace_getter()->UponLeavingGTest();
2500 internal::HandleExceptionsInMethodIfSupported(
2501 this, &Test::TearDown,
"TearDown()");
2505bool Test::HasFatalFailure() {
2506 return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
2510bool Test::HasNonfatalFailure() {
2511 return internal::GetUnitTestImpl()->current_test_result()->
2512 HasNonfatalFailure();
2519TestInfo::TestInfo(
const std::string& a_test_case_name,
2520 const std::string& a_name,
2521 const char* a_type_param,
2522 const char* a_value_param,
2526 : test_case_name_(a_test_case_name),
2528 type_param_(a_type_param ? new
std::string(a_type_param) : NULL),
2529 value_param_(a_value_param ? new
std::string(a_value_param) : NULL),
2530 location_(a_code_location),
2531 fixture_class_id_(fixture_class_id),
2533 is_disabled_(false),
2534 matches_filter_(false),
2562 const char* test_case_name,
2564 const char* type_param,
2565 const char* value_param,
2572 new TestInfo(test_case_name,
name, type_param, value_param,
2573 code_location, fixture_class_id, factory);
2582 <<
"Attempted redefinition of test case " << test_case_name <<
".\n"
2583 <<
"All tests in the same test case must use the same test fixture\n"
2584 <<
"class. However, in test case " << test_case_name <<
", you tried\n"
2585 <<
"to define a test using a fixture class different from the one\n"
2586 <<
"used earlier. This can happen if the two fixture classes are\n"
2587 <<
"from different namespaces and have the same name. You should\n"
2588 <<
"probably rename one of the classes to put the tests into different\n"
2612 explicit TestNameIs(
const char*
name)
2616 bool operator()(
const TestInfo * test_info)
const {
2617 return test_info && test_info->name() == name_;
2632 if (!parameterized_tests_registered_) {
2634 parameterized_tests_registered_ =
true;
2642void TestInfo::Run() {
2643 if (!should_run_)
return;
2661 "the test fixture's constructor");
2674 test, &Test::DeleteSelf_,
"the test fixture's destructor");
2690 return CountIf(test_info_list_, TestPassed);
2695 return CountIf(test_info_list_, TestFailed);
2700 return CountIf(test_info_list_, TestReportableDisabled);
2705 return CountIf(test_info_list_, TestDisabled);
2710 return CountIf(test_info_list_, TestReportable);
2715 return CountIf(test_info_list_, ShouldRunTest);
2720 return static_cast<int>(test_info_list_.size());
2736 type_param_(a_type_param ? new
std::string(a_type_param) : NULL),
2737 set_up_tc_(set_up_tc),
2738 tear_down_tc_(tear_down_tc),
2746 ForEach(test_info_list_, internal::Delete<TestInfo>);
2752 const int index = GetElementOr(test_indices_, i, -1);
2753 return index < 0 ? NULL : test_info_list_[index];
2758TestInfo* TestCase::GetMutableTestInfo(
int i) {
2759 const int index = GetElementOr(test_indices_, i, -1);
2760 return index < 0 ? NULL : test_info_list_[index];
2765void TestCase::AddTestInfo(TestInfo * test_info) {
2766 test_info_list_.push_back(test_info);
2767 test_indices_.push_back(
static_cast<int>(test_indices_.size()));
2771void TestCase::Run() {
2772 if (!should_run_)
return;
2775 impl->set_current_test_case(
this);
2780 impl->os_stack_trace_getter()->UponLeavingGTest();
2782 this, &TestCase::RunSetUpTestCase,
"SetUpTestCase()");
2786 GetMutableTestInfo(i)->Run();
2790 impl->os_stack_trace_getter()->UponLeavingGTest();
2792 this, &TestCase::RunTearDownTestCase,
"TearDownTestCase()");
2794 repeater->OnTestCaseEnd(*
this);
2795 impl->set_current_test_case(NULL);
2799void TestCase::ClearResult() {
2800 ad_hoc_test_result_.Clear();
2801 ForEach(test_info_list_, TestInfo::ClearTestResult);
2805void TestCase::ShuffleTests(internal::Random*
random) {
2806 Shuffle(
random, &test_indices_);
2810void TestCase::UnshuffleTests() {
2811 for (
size_t i = 0; i < test_indices_.size(); i++) {
2812 test_indices_[i] =
static_cast<int>(i);
2821static std::string FormatCountableNoun(
int count,
2822 const char * singular_form,
2823 const char * plural_form) {
2825 (
count == 1 ? singular_form : plural_form);
2829static std::string FormatTestCount(
int test_count) {
2830 return FormatCountableNoun(test_count,
"test",
"tests");
2834static std::string FormatTestCaseCount(
int test_case_count) {
2835 return FormatCountableNoun(test_case_count,
"test case",
"test cases");
2855 return "Unknown result type";
2862static std::string PrintTestPartResultToString(
2863 const TestPartResult& test_part_result) {
2866 test_part_result.line_number())
2867 <<
" " << TestPartResultTypeToString(test_part_result.type())
2868 << test_part_result.message()).GetString();
2872static void PrintTestPartResult(
const TestPartResult& test_part_result) {
2873 const std::string& result =
2874 PrintTestPartResultToString(test_part_result);
2875 printf(
"%s\n", result.c_str());
2881#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2885 ::OutputDebugStringA(result.c_str());
2886 ::OutputDebugStringA(
"\n");
2899#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
2900 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
2903static WORD GetColorAttribute(
GTestColor color) {
2907 case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
2912static int GetBitOffset(WORD color_mask) {
2913 if (color_mask == 0)
return 0;
2916 while ((color_mask & 1) == 0) {
2923static WORD GetNewColor(
GTestColor color, WORD old_color_attrs) {
2925 static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN |
2926 BACKGROUND_RED | BACKGROUND_INTENSITY;
2927 static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN |
2928 FOREGROUND_RED | FOREGROUND_INTENSITY;
2929 const WORD existing_bg = old_color_attrs & background_mask;
2932 GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY;
2933 static const int bg_bitOffset = GetBitOffset(background_mask);
2934 static const int fg_bitOffset = GetBitOffset(foreground_mask);
2936 if (((new_color & background_mask) >> bg_bitOffset) ==
2937 ((new_color & foreground_mask) >> fg_bitOffset)) {
2938 new_color ^= FOREGROUND_INTENSITY;
2947static const char* GetAnsiColorCode(
GTestColor color) {
2952 default:
return NULL;
2960 const char*
const gtest_color =
GTEST_FLAG(color).c_str();
2963#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
2966 return stdout_is_tty;
2970 const bool term_supports_color =
2982 return stdout_is_tty && term_supports_color;
2999static void ColoredPrintf(
GTestColor color,
const char* fmt, ...) {
3001 va_start(args, fmt);
3003#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || \
3004 GTEST_OS_IOS || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
3007 static const bool in_color_mode =
3009 const bool use_color = in_color_mode && (color !=
COLOR_DEFAULT);
3019#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
3020 !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW
3021 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
3024 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
3025 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
3026 const WORD old_color_attrs = buffer_info.wAttributes;
3027 const WORD new_color = GetNewColor(color, old_color_attrs);
3033 SetConsoleTextAttribute(stdout_handle, new_color);
3039 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
3041 printf(
"\033[0;3%sm", GetAnsiColorCode(color));
3050static const char kTypeParamLabel[] =
"TypeParam";
3051static const char kValueParamLabel[] =
"GetParam()";
3053static void PrintFullTestCommentIfPresent(
const TestInfo& test_info) {
3054 const char*
const type_param = test_info.type_param();
3055 const char*
const value_param = test_info.value_param();
3057 if (type_param != NULL || value_param != NULL) {
3059 if (type_param != NULL) {
3060 printf(
"%s = %s", kTypeParamLabel, type_param);
3061 if (value_param != NULL)
3064 if (value_param != NULL) {
3065 printf(
"%s = %s", kValueParamLabel, value_param);
3077 printf(
"%s.%s", test_case, test);
3096 static void PrintFailedTests(
const UnitTest& unit_test);
3101 const UnitTest& unit_test,
int iteration) {
3103 printf(
"\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
3105 const char*
const filter =
GTEST_FLAG(filter).c_str();
3117 "Note: This is test shard %d of %s.\n",
3118 static_cast<int>(shard_index) + 1,
3124 "Note: Randomizing tests' orders with a seed of %d .\n",
3128 printf(
"Running %s from %s.\n",
3137 printf(
"Global test environment set-up.\n");
3142 const std::string counts =
3145 printf(
"%s from %s", counts.c_str(), test_case.
name());
3149 printf(
", where %s = %s\n", kTypeParamLabel, test_case.
type_param());
3169 PrintTestPartResult(result);
3177 ColoredPrintf(
COLOR_RED,
"[ FAILED ] ");
3181 PrintFullTestCommentIfPresent(test_info);
3195 const std::string counts =
3198 printf(
"%s from %s (%s ms total)\n\n",
3199 counts.c_str(), test_case.
name(),
3207 printf(
"Global test environment tear-down\n");
3212void PrettyUnitTestResultPrinter::PrintFailedTests(
const UnitTest& unit_test) {
3214 if (failed_test_count == 0) {
3225 if (!test_info.should_run() || test_info.result()->Passed()) {
3228 ColoredPrintf(
COLOR_RED,
"[ FAILED ] ");
3229 printf(
"%s.%s", test_case.
name(), test_info.name());
3230 PrintFullTestCommentIfPresent(test_info);
3239 printf(
"%s from %s ran.",
3243 printf(
" (%s ms total)",
3251 if (!unit_test.
Passed()) {
3253 ColoredPrintf(
COLOR_RED,
"[ FAILED ] ");
3254 printf(
"%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
3255 PrintFailedTests(unit_test);
3261 if (num_disabled && !
GTEST_FLAG(also_run_disabled_tests)) {
3266 " YOU HAVE %d DISABLED %s\n\n",
3268 num_disabled == 1 ?
"TEST" :
"TESTS");
3308 bool forwarding_enabled_;
3310 std::vector<TestEventListener*> listeners_;
3316 ForEach(listeners_, Delete<TestEventListener>);
3320 listeners_.push_back(listener);
3325 for (
size_t i = 0; i < listeners_.size(); ++i) {
3326 if (listeners_[i] == listener) {
3327 listeners_.erase(listeners_.begin() + i);
3337#define GTEST_REPEATER_METHOD_(Name, Type) \
3338void TestEventRepeater::Name(const Type& parameter) { \
3339 if (forwarding_enabled_) { \
3340 for (size_t i = 0; i < listeners_.size(); i++) { \
3341 listeners_[i]->Name(parameter); \
3347#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
3348void TestEventRepeater::Name(const Type& parameter) { \
3349 if (forwarding_enabled_) { \
3350 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
3351 listeners_[i]->Name(parameter); \
3368#undef GTEST_REPEATER_METHOD_
3369#undef GTEST_REVERSE_REPEATER_METHOD_
3373 if (forwarding_enabled_) {
3374 for (
size_t i = 0; i < listeners_.size(); i++) {
3375 listeners_[i]->OnTestIterationStart(unit_test, iteration);
3382 if (forwarding_enabled_) {
3383 for (
int i =
static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
3384 listeners_[i]->OnTestIterationEnd(unit_test, iteration);
3401 static bool IsNormalizableWhitespace(
char c) {
3402 return c == 0x9 || c == 0xA || c == 0xD;
3406 static bool IsValidXmlCharacter(
char c) {
3407 return IsNormalizableWhitespace(c) || c >= 0x20;
3414 static std::string EscapeXml(
const std::string& str,
bool is_attribute);
3417 static std::string RemoveInvalidXmlCharacters(
const std::string& str);
3420 static std::string EscapeXmlAttribute(
const std::string& str) {
3421 return EscapeXml(str,
true);
3425 static std::string EscapeXmlText(
const char* str) {
3426 return EscapeXml(str,
false);
3431 static void OutputXmlAttribute(std::ostream* stream,
3432 const std::string& element_name,
3433 const std::string&
name,
3434 const std::string&
value);
3437 static void OutputXmlCDataSection(::std::ostream* stream,
const char* data);
3440 static void OutputXmlTestInfo(::std::ostream* stream,
3441 const char* test_case_name,
3445 static void PrintXmlTestCase(::std::ostream* stream,
3449 static void PrintXmlUnitTest(::std::ostream* stream,
3456 static std::string TestPropertiesAsXmlAttributes(
const TestResult& result);
3460 static void OutputXmlTestProperties(std::ostream* stream,
3464 const std::string output_file_;
3471 : output_file_(output_file) {
3472 if (output_file_.c_str() == NULL || output_file_.empty()) {
3473 GTEST_LOG_(FATAL) <<
"XML output file may not be null";
3480 FILE* xmlout = NULL;
3481 FilePath output_file(output_file_);
3487 if (xmlout == NULL) {
3499 GTEST_LOG_(FATAL) <<
"Unable to open file \"" << output_file_ <<
"\"";
3501 std::stringstream stream;
3502 PrintXmlUnitTest(&stream, unit_test);
3519std::string XmlUnitTestResultPrinter::EscapeXml(
3520 const std::string& str,
bool is_attribute) {
3523 for (
size_t i = 0; i < str.size(); ++i) {
3524 const char ch = str[i];
3548 if (IsValidXmlCharacter(ch)) {
3549 if (is_attribute && IsNormalizableWhitespace(ch))
3565std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
3566 const std::string& str) {
3568 output.reserve(
str.size());
3569 for (std::string::const_iterator it =
str.begin(); it !=
str.end(); ++it)
3570 if (IsValidXmlCharacter(*it))
3571 output.push_back(*it);
3594 ::std::stringstream ss;
3595 ss << (static_cast<double>(ms) * 1e-3);
3599static bool PortableLocaltime(time_t seconds,
struct tm* out) {
3600#if defined(_MSC_VER)
3601 return localtime_s(out, &seconds) == 0;
3602#elif defined(__MINGW32__) || defined(__MINGW64__)
3605 struct tm* tm_ptr = localtime(&seconds);
3611 return localtime_r(&seconds, out) != NULL;
3618 struct tm time_struct;
3619 if (!PortableLocaltime(
static_cast<time_t
>(ms / 1000), &time_struct))
3631void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
3633 const char* segment = data;
3634 *stream <<
"<![CDATA[";
3636 const char*
const next_segment = strstr(segment,
"]]>");
3637 if (next_segment != NULL) {
3639 segment,
static_cast<std::streamsize
>(next_segment - segment));
3640 *stream <<
"]]>]]><![CDATA[";
3641 segment = next_segment + strlen(
"]]>");
3650void XmlUnitTestResultPrinter::OutputXmlAttribute(
3651 std::ostream* stream,
3652 const std::string& element_name,
3653 const std::string&
name,
3654 const std::string&
value) {
3655 const std::vector<std::string>& allowed_names =
3656 GetReservedAttributesForElement(element_name);
3658 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
3659 allowed_names.end())
3660 <<
"Attribute " <<
name <<
" is not allowed for element <" << element_name
3663 *stream <<
" " <<
name <<
"=\"" << EscapeXmlAttribute(
value) <<
"\"";
3668void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
3669 const char* test_case_name,
3670 const TestInfo& test_info) {
3671 const TestResult& result = *test_info.result();
3672 const std::string kTestcase =
"testcase";
3674 if (test_info.is_in_another_shard()) {
3678 *stream <<
" <testcase";
3679 OutputXmlAttribute(stream, kTestcase,
"name", test_info.name());
3681 if (test_info.value_param() != NULL) {
3682 OutputXmlAttribute(stream, kTestcase,
"value_param",
3683 test_info.value_param());
3685 if (test_info.type_param() != NULL) {
3686 OutputXmlAttribute(stream, kTestcase,
"type_param", test_info.type_param());
3689 OutputXmlAttribute(stream, kTestcase,
"status",
3690 test_info.should_run() ?
"run" :
"notrun");
3691 OutputXmlAttribute(stream, kTestcase,
"time",
3693 OutputXmlAttribute(stream, kTestcase,
"classname", test_case_name);
3696 for (
int i = 0; i < result.total_part_count(); ++i) {
3697 const TestPartResult& part = result.GetTestPartResult(i);
3698 if (part.failed()) {
3699 if (++failures == 1) {
3702 const std::string location =
3704 part.line_number());
3705 const std::string summary = location +
"\n" + part.summary();
3706 *stream <<
" <failure message=\""
3707 << EscapeXmlAttribute(summary.c_str())
3709 const std::string
detail = location +
"\n" + part.message();
3710 OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(
detail).c_str());
3711 *stream <<
"</failure>\n";
3715 if (failures == 0 && result.test_property_count() == 0) {
3718 if (failures == 0) {
3721 OutputXmlTestProperties(stream, result);
3722 *stream <<
" </testcase>\n";
3727void XmlUnitTestResultPrinter::PrintXmlTestCase(std::ostream* stream,
3728 const TestCase& test_case) {
3729 const std::string kTestsuite =
"testsuite";
3730 *stream <<
" <" << kTestsuite;
3731 OutputXmlAttribute(stream, kTestsuite,
"name", test_case.name());
3732 OutputXmlAttribute(stream, kTestsuite,
"tests",
3734 OutputXmlAttribute(stream, kTestsuite,
"failures",
3737 stream, kTestsuite,
"disabled",
3739 OutputXmlAttribute(stream, kTestsuite,
"errors",
"0");
3740 OutputXmlAttribute(stream, kTestsuite,
"time",
3742 *stream << TestPropertiesAsXmlAttributes(test_case.ad_hoc_test_result())
3745 for (
int i = 0; i < test_case.total_test_count(); ++i) {
3746 if (test_case.GetTestInfo(i)->is_reportable())
3747 OutputXmlTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i));
3749 *stream <<
" </" << kTestsuite <<
">\n";
3753void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
3754 const UnitTest& unit_test) {
3755 const std::string kTestsuites =
"testsuites";
3757 *stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3758 *stream <<
"<" << kTestsuites;
3760 OutputXmlAttribute(stream, kTestsuites,
"tests",
3762 OutputXmlAttribute(stream, kTestsuites,
"failures",
3765 stream, kTestsuites,
"disabled",
3767 OutputXmlAttribute(stream, kTestsuites,
"errors",
"0");
3769 stream, kTestsuites,
"timestamp",
3771 OutputXmlAttribute(stream, kTestsuites,
"time",
3775 OutputXmlAttribute(stream, kTestsuites,
"random_seed",
3778 *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result());
3780 OutputXmlAttribute(stream, kTestsuites,
"name",
"AllTests");
3783 for (
int i = 0; i < unit_test.total_test_case_count(); ++i) {
3784 if (unit_test.GetTestCase(i)->reportable_test_count() > 0)
3785 PrintXmlTestCase(stream, *unit_test.GetTestCase(i));
3787 *stream <<
"</" << kTestsuites <<
">\n";
3792std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
3793 const TestResult& result) {
3795 for (
int i = 0; i < result.test_property_count(); ++i) {
3796 const TestProperty&
property = result.GetTestProperty(i);
3797 attributes <<
" " <<
property.key() <<
"="
3798 <<
"\"" << EscapeXmlAttribute(property.value()) <<
"\"";
3800 return attributes.GetString();
3803void XmlUnitTestResultPrinter::OutputXmlTestProperties(
3804 std::ostream* stream,
const TestResult& result) {
3805 const std::string kProperties =
"properties";
3806 const std::string kProperty =
"property";
3808 if (result.test_property_count() <= 0) {
3812 *stream <<
"<" << kProperties <<
">\n";
3813 for (
int i = 0; i < result.test_property_count(); ++i) {
3814 const TestProperty&
property = result.GetTestProperty(i);
3815 *stream <<
"<" << kProperty;
3816 *stream <<
" name=\"" << EscapeXmlAttribute(property.key()) <<
"\"";
3817 *stream <<
" value=\"" << EscapeXmlAttribute(property.value()) <<
"\"";
3820 *stream <<
"</" << kProperties <<
">\n";
3835 static std::string EscapeJson(
const std::string& str);
3839 static void OutputJsonKey(std::ostream* stream,
3840 const std::string& element_name,
3841 const std::string&
name,
3842 const std::string&
value,
3843 const std::string& indent,
3845 static void OutputJsonKey(std::ostream* stream,
3846 const std::string& element_name,
3847 const std::string&
name,
3849 const std::string& indent,
3853 static void OutputJsonTestInfo(::std::ostream* stream,
3854 const char* test_case_name,
3858 static void PrintJsonTestCase(::std::ostream* stream,
3862 static void PrintJsonUnitTest(::std::ostream* stream,
3867 static std::string TestPropertiesAsJson(
const TestResult& result,
3868 const std::string& indent);
3871 const std::string output_file_;
3878 : output_file_(output_file) {
3879 if (output_file_.empty()) {
3880 GTEST_LOG_(FATAL) <<
"JSON output file may not be null";
3886 FILE* jsonout = NULL;
3887 FilePath output_file(output_file_);
3893 if (jsonout == NULL) {
3904 GTEST_LOG_(FATAL) <<
"Unable to open file \""
3905 << output_file_ <<
"\"";
3907 std::stringstream stream;
3908 PrintJsonUnitTest(&stream, unit_test);
3914std::string JsonUnitTestResultPrinter::EscapeJson(
const std::string& str) {
3917 for (
size_t i = 0; i < str.size(); ++i) {
3918 const char ch = str[i];
3957static std::string FormatTimeInMillisAsDuration(
TimeInMillis ms) {
3958 ::std::stringstream
ss;
3959 ss << (static_cast<double>(ms) * 1e-3) <<
"s";
3965static std::string FormatEpochTimeInMillisAsRFC3339(
TimeInMillis ms) {
3966 struct tm time_struct;
3967 if (!PortableLocaltime(
static_cast<time_t
>(ms / 1000), &time_struct))
3978static inline std::string Indent(
int width) {
3979 return std::string(
width,
' ');
3982void JsonUnitTestResultPrinter::OutputJsonKey(
3983 std::ostream* stream,
3984 const std::string& element_name,
3985 const std::string&
name,
3986 const std::string&
value,
3987 const std::string& indent,
3989 const std::vector<std::string>& allowed_names =
3990 GetReservedAttributesForElement(element_name);
3992 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
3993 allowed_names.end())
3994 <<
"Key \"" <<
name <<
"\" is not allowed for value \"" << element_name
3997 *stream << indent <<
"\"" <<
name <<
"\": \"" << EscapeJson(
value) <<
"\"";
4002void JsonUnitTestResultPrinter::OutputJsonKey(
4003 std::ostream* stream,
4004 const std::string& element_name,
4005 const std::string&
name,
4007 const std::string& indent,
4009 const std::vector<std::string>& allowed_names =
4010 GetReservedAttributesForElement(element_name);
4012 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(),
name) !=
4013 allowed_names.end())
4014 <<
"Key \"" <<
name <<
"\" is not allowed for value \"" << element_name
4023void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
4024 const char* test_case_name,
4025 const TestInfo& test_info) {
4026 const TestResult& result = *test_info.result();
4027 const std::string kTestcase =
"testcase";
4028 const std::string kIndent = Indent(10);
4030 *stream << Indent(8) <<
"{\n";
4031 OutputJsonKey(stream, kTestcase,
"name", test_info.name(), kIndent);
4033 if (test_info.value_param() != NULL) {
4034 OutputJsonKey(stream, kTestcase,
"value_param",
4035 test_info.value_param(), kIndent);
4037 if (test_info.type_param() != NULL) {
4038 OutputJsonKey(stream, kTestcase,
"type_param", test_info.type_param(),
4042 OutputJsonKey(stream, kTestcase,
"status",
4043 test_info.should_run() ?
"RUN" :
"NOTRUN", kIndent);
4044 OutputJsonKey(stream, kTestcase,
"time",
4045 FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
4046 OutputJsonKey(stream, kTestcase,
"classname", test_case_name, kIndent,
false);
4047 *stream << TestPropertiesAsJson(result, kIndent);
4050 for (
int i = 0; i < result.total_part_count(); ++i) {
4051 const TestPartResult& part = result.GetTestPartResult(i);
4052 if (part.failed()) {
4054 if (++failures == 1) {
4055 *stream << kIndent <<
"\"" <<
"failures" <<
"\": [\n";
4057 const std::string location =
4059 part.line_number());
4060 const std::string message = EscapeJson(location +
"\n" + part.message());
4061 *stream << kIndent <<
" {\n"
4062 << kIndent <<
" \"failure\": \"" << message <<
"\",\n"
4063 << kIndent <<
" \"type\": \"\"\n"
4069 *stream <<
"\n" << kIndent <<
"]";
4070 *stream <<
"\n" << Indent(8) <<
"}";
4074void JsonUnitTestResultPrinter::PrintJsonTestCase(std::ostream* stream,
4075 const TestCase& test_case) {
4076 const std::string kTestsuite =
"testsuite";
4077 const std::string kIndent = Indent(6);
4079 *stream << Indent(4) <<
"{\n";
4080 OutputJsonKey(stream, kTestsuite,
"name", test_case.name(), kIndent);
4081 OutputJsonKey(stream, kTestsuite,
"tests", test_case.reportable_test_count(),
4083 OutputJsonKey(stream, kTestsuite,
"failures", test_case.failed_test_count(),
4085 OutputJsonKey(stream, kTestsuite,
"disabled",
4086 test_case.reportable_disabled_test_count(), kIndent);
4087 OutputJsonKey(stream, kTestsuite,
"errors", 0, kIndent);
4088 OutputJsonKey(stream, kTestsuite,
"time",
4089 FormatTimeInMillisAsDuration(test_case.elapsed_time()), kIndent,
4091 *stream << TestPropertiesAsJson(test_case.ad_hoc_test_result(), kIndent)
4094 *stream << kIndent <<
"\"" << kTestsuite <<
"\": [\n";
4097 for (
int i = 0; i < test_case.total_test_count(); ++i) {
4098 if (test_case.GetTestInfo(i)->is_reportable()) {
4104 OutputJsonTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i));
4107 *stream <<
"\n" << kIndent <<
"]\n" << Indent(4) <<
"}";
4111void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
4112 const UnitTest& unit_test) {
4113 const std::string kTestsuites =
"testsuites";
4114 const std::string kIndent = Indent(2);
4117 OutputJsonKey(stream, kTestsuites,
"tests", unit_test.reportable_test_count(),
4119 OutputJsonKey(stream, kTestsuites,
"failures", unit_test.failed_test_count(),
4121 OutputJsonKey(stream, kTestsuites,
"disabled",
4122 unit_test.reportable_disabled_test_count(), kIndent);
4123 OutputJsonKey(stream, kTestsuites,
"errors", 0, kIndent);
4125 OutputJsonKey(stream, kTestsuites,
"random_seed", unit_test.random_seed(),
4128 OutputJsonKey(stream, kTestsuites,
"timestamp",
4129 FormatEpochTimeInMillisAsRFC3339(unit_test.start_timestamp()),
4131 OutputJsonKey(stream, kTestsuites,
"time",
4132 FormatTimeInMillisAsDuration(unit_test.elapsed_time()), kIndent,
4135 *stream << TestPropertiesAsJson(unit_test.ad_hoc_test_result(), kIndent)
4138 OutputJsonKey(stream, kTestsuites,
"name",
"AllTests", kIndent);
4139 *stream << kIndent <<
"\"" << kTestsuites <<
"\": [\n";
4142 for (
int i = 0; i < unit_test.total_test_case_count(); ++i) {
4143 if (unit_test.GetTestCase(i)->reportable_test_count() > 0) {
4149 PrintJsonTestCase(stream, *unit_test.GetTestCase(i));
4153 *stream <<
"\n" << kIndent <<
"]\n" <<
"}\n";
4158std::string JsonUnitTestResultPrinter::TestPropertiesAsJson(
4159 const TestResult& result,
const std::string& indent) {
4161 for (
int i = 0; i < result.test_property_count(); ++i) {
4162 const TestProperty&
property = result.GetTestProperty(i);
4163 attributes <<
",\n" << indent <<
"\"" <<
property.key() <<
"\": "
4164 <<
"\"" << EscapeJson(property.value()) <<
"\"";
4166 return attributes.GetString();
4171#if GTEST_CAN_STREAM_RESULTS_
4178std::string StreamingListener::UrlEncode(
const char* str) {
4180 result.reserve(strlen(str) + 1);
4181 for (
char ch = *str;
ch !=
'\0';
ch = *++
str) {
4190 result.push_back(ch);
4197void StreamingListener::SocketWriter::MakeConnection() {
4199 <<
"MakeConnection() can't be called when there is already a connection.";
4202 memset(&hints, 0,
sizeof(hints));
4203 hints.ai_family = AF_UNSPEC;
4204 hints.ai_socktype = SOCK_STREAM;
4205 addrinfo* servinfo = NULL;
4209 const int error_num = getaddrinfo(
4210 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
4211 if (error_num != 0) {
4212 GTEST_LOG_(WARNING) <<
"stream_result_to: getaddrinfo() failed: "
4213 << gai_strerror(error_num);
4217 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;
4218 cur_addr = cur_addr->ai_next) {
4220 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
4221 if (sockfd_ != -1) {
4223 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
4230 freeaddrinfo(servinfo);
4232 if (sockfd_ == -1) {
4233 GTEST_LOG_(WARNING) <<
"stream_result_to: failed to connect to "
4234 << host_name_ <<
":" << port_num_;
4258 : premature_exit_filepath_(premature_exit_filepath ?
4259 premature_exit_filepath :
"") {
4261 if (!premature_exit_filepath_.empty()) {
4265 FILE* pfile = posix::FOpen(premature_exit_filepath,
"w");
4266 fwrite(
"0", 1, 1, pfile);
4272 if (!premature_exit_filepath_.empty()) {
4273 int retval = remove(premature_exit_filepath_.c_str());
4275 GTEST_LOG_(ERROR) <<
"Failed to remove premature exit filepath \""
4276 << premature_exit_filepath_ <<
"\" with error "
4283 const std::string premature_exit_filepath_;
4293 : repeater_(new
internal::TestEventRepeater()),
4294 default_result_printer_(NULL),
4295 default_xml_generator_(NULL) {
4305 repeater_->
Append(listener);
4312 if (listener == default_result_printer_)
4313 default_result_printer_ = NULL;
4314 else if (listener == default_xml_generator_)
4315 default_xml_generator_ = NULL;
4316 return repeater_->
Release(listener);
4328void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {
4329 if (default_result_printer_ != listener) {
4332 delete Release(default_result_printer_);
4333 default_result_printer_ = listener;
4334 if (listener != NULL)
4344void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {
4345 if (default_xml_generator_ != listener) {
4348 delete Release(default_xml_generator_);
4349 default_xml_generator_ = listener;
4350 if (listener != NULL)
4357bool TestEventListeners::EventForwardingEnabled()
const {
4361void TestEventListeners::SuppressEventForwarding() {
4386#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
4402 return impl()->failed_test_case_count();
4407 return impl()->total_test_case_count();
4413 return impl()->test_case_to_run_count();
4418 return impl()->successful_test_count();
4426 return impl()->reportable_disabled_test_count();
4431 return impl()->disabled_test_count();
4436 return impl()->reportable_test_count();
4448 return impl()->start_timestamp();
4453 return impl()->elapsed_time();
4466 return impl()->GetTestCase(i);
4472 return *impl()->ad_hoc_test_result();
4477TestCase* UnitTest::GetMutableTestCase(
int i) {
4478 return impl()->GetMutableTestCase(i);
4484 return *impl()->listeners();
4510void UnitTest::AddTestPartResult(
4512 const char* file_name,
4514 const std::string& message,
4520 if (impl_->gtest_trace_stack().size() > 0) {
4523 for (
int i =
static_cast<int>(impl_->gtest_trace_stack().size());
4525 const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1];
4527 <<
" " << trace.message;
4531 if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {
4535 const TestPartResult result =
4536 TestPartResult(result_type, file_name, line_number,
4537 msg.GetString().c_str());
4538 impl_->GetTestPartResultReporterForCurrentThread()->
4539 ReportTestPartResult(result);
4548#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4553#elif (!defined(__native_client__)) && \
4554 ((defined(__clang__) || defined(__GNUC__)) && \
4555 (defined(__x86_64__) || defined(__i386__)))
4563 *
static_cast<volatile int*
>(NULL) = 1;
4566#if GTEST_HAS_EXCEPTIONS
4567 throw internal::GoogleTestFailureException(result);
4582void UnitTest::RecordProperty(
const std::string& key,
4583 const std::string&
value) {
4593 const bool in_death_test_child_process =
4594 internal::GTEST_FLAG(internal_run_death_test).length() > 0;
4618 in_death_test_child_process ?
4623 impl()->set_catch_exceptions(
GTEST_FLAG(catch_exceptions));
4630 if (impl()->catch_exceptions() || in_death_test_child_process) {
4631# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4633 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
4634 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
4637# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
4641 _set_error_mode(_OUT_TO_STDERR);
4644# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
4657 _set_abort_behavior(
4659 _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
4667 "auxiliary test code (environments or event listeners)") ? 0 : 1;
4673 return impl_->original_working_dir_.
c_str();
4704UnitTest::UnitTest() {
4709UnitTest::~UnitTest() {
4715void UnitTest::PushGTestTrace(
const internal::TraceInfo& trace)
4718 impl_->gtest_trace_stack().push_back(trace);
4722void UnitTest::PopGTestTrace()
4733 default_global_test_part_result_reporter_(this),
4734 default_per_thread_test_part_result_reporter_(this),
4736 global_test_part_result_repoter_(
4737 &default_global_test_part_result_reporter_),
4738 per_thread_test_part_result_reporter_(
4739 &default_per_thread_test_part_result_reporter_),
4740 parameterized_test_registry_(),
4741 parameterized_tests_registered_(false),
4742 last_death_test_case_(-1),
4743 current_test_case_(NULL),
4744 current_test_info_(NULL),
4745 ad_hoc_test_result_(),
4746 os_stack_trace_getter_(NULL),
4747 post_flag_parse_init_performed_(false),
4750 start_timestamp_(0),
4752#
if GTEST_HAS_DEATH_TEST
4753 death_test_factory_(new DefaultDeathTestFactory),
4756 catch_exceptions_(false) {
4762 ForEach(test_cases_, internal::Delete<TestCase>);
4765 ForEach(environments_, internal::Delete<Environment>);
4767 delete os_stack_trace_getter_;
4776 std::string xml_element;
4779 if (current_test_info_ != NULL) {
4780 xml_element =
"testcase";
4781 test_result = &(current_test_info_->result_);
4782 }
else if (current_test_case_ != NULL) {
4783 xml_element =
"testsuite";
4784 test_result = &(current_test_case_->ad_hoc_test_result_);
4786 xml_element =
"testsuites";
4787 test_result = &ad_hoc_test_result_;
4789 test_result->RecordProperty(xml_element, test_property);
4792#if GTEST_HAS_DEATH_TEST
4795void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
4796 if (internal_run_death_test_flag_.get() != NULL)
4805 if (output_format ==
"xml") {
4808 }
else if (output_format ==
"json") {
4811 }
else if (output_format !=
"") {
4812 GTEST_LOG_(WARNING) <<
"WARNING: unrecognized output format \""
4813 << output_format <<
"\" ignored.";
4817#if GTEST_CAN_STREAM_RESULTS_
4820void UnitTestImpl::ConfigureStreamingOutput() {
4821 const std::string& target =
GTEST_FLAG(stream_result_to);
4822 if (!target.empty()) {
4823 const size_t pos = target.find(
':');
4824 if (pos != std::string::npos) {
4826 target.substr(pos+1)));
4828 GTEST_LOG_(WARNING) <<
"unrecognized streaming target \"" << target
4842 if (!post_flag_parse_init_performed_) {
4843 post_flag_parse_init_performed_ =
true;
4845#if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
4850#if GTEST_HAS_DEATH_TEST
4851 InitDeathTestSubprocessControlInfo();
4852 SuppressTestEventsIfInSubprocess();
4864#if GTEST_CAN_STREAM_RESULTS_
4866 ConfigureStreamingOutput();
4887 return test_case != NULL && strcmp(test_case->
name(), name_.c_str()) == 0;
4907 const char* type_param,
4911 const std::vector<TestCase*>::const_reverse_iterator test_case =
4912 std::find_if(test_cases_.rbegin(), test_cases_.rend(),
4915 if (test_case != test_cases_.rend())
4920 new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
4924 kDeathTestCaseFilter)) {
4929 ++last_death_test_case_;
4930 test_cases_.insert(test_cases_.begin() + last_death_test_case_,
4934 test_cases_.push_back(new_test_case);
4937 test_case_indices_.push_back(
static_cast<int>(test_case_indices_.size()));
4938 return new_test_case;
4957 const bool gtest_is_initialized_before_run_all_tests = GTestIsInitialized();
4974 bool in_subprocess_for_death_test =
false;
4976#if GTEST_HAS_DEATH_TEST
4977 in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);
4978# if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
4979 if (in_subprocess_for_death_test) {
4980 GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();
4985 const bool should_shard =
ShouldShard(kTestTotalShards, kTestShardIndex,
4986 in_subprocess_for_death_test);
4990 const bool has_tests_to_run =
FilterTests(should_shard
5005 bool failed =
false;
5014 const int repeat = in_subprocess_for_death_test ? 1 :
GTEST_FLAG(repeat);
5016 const bool forever = repeat < 0;
5017 for (
int i = 0; forever || i != repeat; i++) {
5025 if (has_tests_to_run &&
GTEST_FLAG(shuffle)) {
5037 if (has_tests_to_run) {
5040 ForEach(environments_, SetUpEnvironment);
5054 std::for_each(environments_.rbegin(), environments_.rend(),
5055 TearDownEnvironment);
5085 if (!gtest_is_initialized_before_run_all_tests) {
5088 "\nIMPORTANT NOTICE - DO NOT IGNORE:\n"
5090 "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_
5091 " will start to enforce the valid usage. "
5092 "Please fix it ASAP, or IT WILL START TO FAIL.\n");
5093#if GTEST_FOR_GOOGLE_
5095 "For more details, see http://wiki/Main/ValidGUnitMain.\n");
5107 const char*
const test_shard_file =
posix::GetEnv(kTestShardStatusFile);
5108 if (test_shard_file != NULL) {
5112 "Could not write to the test shard status file \"%s\" "
5113 "specified by the %s environment variable.\n",
5114 test_shard_file, kTestShardStatusFile);
5129 const char* shard_index_env,
5130 bool in_subprocess_for_death_test) {
5131 if (in_subprocess_for_death_test) {
5138 if (total_shards == -1 && shard_index == -1) {
5140 }
else if (total_shards == -1 && shard_index != -1) {
5142 <<
"Invalid environment variables: you have "
5143 << kTestShardIndex <<
" = " << shard_index
5144 <<
", but have left " << kTestTotalShards <<
" unset.\n";
5148 }
else if (total_shards != -1 && shard_index == -1) {
5150 <<
"Invalid environment variables: you have "
5151 << kTestTotalShards <<
" = " << total_shards
5152 <<
", but have left " << kTestShardIndex <<
" unset.\n";
5156 }
else if (shard_index < 0 || shard_index >= total_shards) {
5158 <<
"Invalid environment variables: we require 0 <= "
5159 << kTestShardIndex <<
" < " << kTestTotalShards
5160 <<
", but you have " << kTestShardIndex <<
"=" << shard_index
5161 <<
", " << kTestTotalShards <<
"=" << total_shards <<
".\n";
5167 return total_shards > 1;
5175 if (str_val == NULL) {
5181 str_val, &result)) {
5192 return (test_id % total_shards) == shard_index;
5212 int num_runnable_tests = 0;
5213 int num_selected_tests = 0;
5214 for (
size_t i = 0; i < test_cases_.size(); i++) {
5215 TestCase*
const test_case = test_cases_[i];
5216 const std::string &test_case_name = test_case->
name();
5217 test_case->set_should_run(
false);
5219 for (
size_t j = 0;
j < test_case->test_info_list().size();
j++) {
5220 TestInfo*
const test_info = test_case->test_info_list()[
j];
5221 const std::string test_name(test_info->
name());
5224 const bool is_disabled =
5226 kDisableTestFilter) ||
5228 kDisableTestFilter);
5229 test_info->is_disabled_ = is_disabled;
5231 const bool matches_filter =
5234 test_info->matches_filter_ = matches_filter;
5236 const bool is_runnable =
5237 (
GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
5240 const bool is_in_another_shard =
5243 test_info->is_in_another_shard_ = is_in_another_shard;
5244 const bool is_selected = is_runnable && !is_in_another_shard;
5246 num_runnable_tests += is_runnable;
5247 num_selected_tests += is_selected;
5249 test_info->should_run_ = is_selected;
5250 test_case->set_should_run(test_case->
should_run() || is_selected);
5253 return num_selected_tests;
5260static void PrintOnOneLine(
const char* str,
int max_length) {
5262 for (
int i = 0; *str !=
'\0'; ++str) {
5263 if (i >= max_length) {
5281 const int kMaxParamLength = 250;
5283 for (
size_t i = 0; i < test_cases_.size(); i++) {
5284 const TestCase*
const test_case = test_cases_[i];
5285 bool printed_test_case_name =
false;
5287 for (
size_t j = 0;
j < test_case->test_info_list().size();
j++) {
5289 test_case->test_info_list()[
j];
5290 if (test_info->matches_filter_) {
5291 if (!printed_test_case_name) {
5292 printed_test_case_name =
true;
5293 printf(
"%s.", test_case->
name());
5295 printf(
" # %s = ", kTypeParamLabel);
5298 PrintOnOneLine(test_case->
type_param(), kMaxParamLength);
5302 printf(
" %s", test_info->
name());
5304 printf(
" # %s = ", kValueParamLabel);
5307 PrintOnOneLine(test_info->
value_param(), kMaxParamLength);
5323 if (os_stack_trace_getter_ != getter) {
5324 delete os_stack_trace_getter_;
5325 os_stack_trace_getter_ = getter;
5333 if (os_stack_trace_getter_ == NULL) {
5334#ifdef GTEST_OS_STACK_TRACE_GETTER_
5335 os_stack_trace_getter_ =
new GTEST_OS_STACK_TRACE_GETTER_;
5341 return os_stack_trace_getter_;
5346 if (current_test_info_ != NULL) {
5347 return ¤t_test_info_->result_;
5349 if (current_test_case_ != NULL) {
5350 return ¤t_test_case_->ad_hoc_test_result_;
5352 return &ad_hoc_test_result_;
5363 static_cast<int>(test_cases_.size()), &test_case_indices_);
5366 for (
size_t i = 0; i < test_cases_.size(); i++) {
5367 test_cases_[i]->ShuffleTests(
random());
5373 for (
size_t i = 0; i < test_cases_.size(); i++) {
5375 test_cases_[i]->UnshuffleTests();
5377 test_case_indices_[i] =
static_cast<int>(i);
5401class ClassUniqueToAlwaysTrue {};
5404bool IsTrue(
bool condition) {
return condition; }
5407#if GTEST_HAS_EXCEPTIONS
5411 throw ClassUniqueToAlwaysTrue();
5420 const size_t prefix_len = strlen(prefix);
5421 if (strncmp(*pstr, prefix, prefix_len) == 0) {
5422 *pstr += prefix_len;
5433static const char* ParseFlagValue(
const char* str,
const char* flag,
5434 bool def_optional) {
5436 if (str == NULL || flag == NULL)
return NULL;
5440 const size_t flag_len = flag_str.length();
5441 if (strncmp(str, flag_str.c_str(), flag_len) != 0)
return NULL;
5444 const char* flag_end = str + flag_len;
5447 if (def_optional && (flag_end[0] ==
'\0')) {
5454 if (flag_end[0] !=
'=')
return NULL;
5457 return flag_end + 1;
5470static bool ParseBoolFlag(
const char* str,
const char* flag,
bool*
value) {
5472 const char*
const value_str = ParseFlagValue(str, flag,
true);
5475 if (value_str == NULL)
return false;
5478 *
value = !(*value_str ==
'0' || *value_str ==
'f' || *value_str ==
'F');
5489 const char*
const value_str = ParseFlagValue(str, flag,
false);
5492 if (value_str == NULL)
return false;
5504template <
typename String>
5505static bool ParseStringFlag(
const char* str,
const char* flag, String*
value) {
5507 const char*
const value_str = ParseFlagValue(str, flag,
false);
5510 if (value_str == NULL)
return false;
5523static bool HasGoogleTestFlagPrefix(
const char* str) {
5543static void PrintColorEncoded(
const char* str) {
5551 const char*
p = strchr(str,
'@');
5553 ColoredPrintf(color,
"%s", str);
5557 ColoredPrintf(color,
"%s", std::string(str,
p).c_str());
5559 const char ch =
p[1];
5562 ColoredPrintf(color,
"@");
5563 }
else if (ch ==
'D') {
5565 }
else if (ch ==
'R') {
5567 }
else if (ch ==
'G') {
5569 }
else if (ch ==
'Y') {
5577static const char kColorEncodedHelpMessage[] =
5578"This program contains tests written using " GTEST_NAME_ ". You can use the\n"
5579"following command line flags to control its behavior:\n"
5583" List the names of all tests instead of running them. The name of\n"
5584" TEST(Foo, Bar) is \"Foo.Bar\".\n"
5586 "[@G-@YNEGATIVE_PATTERNS]@D\n"
5587" Run only the tests whose name matches one of the positive patterns but\n"
5588" none of the negative patterns. '?' matches any single character; '*'\n"
5589" matches any substring; ':' separates two patterns.\n"
5591" Run all disabled tests too.\n"
5595" Run the tests repeatedly; use a negative count to repeat forever.\n"
5597" Randomize tests' orders on every iteration.\n"
5599" Random number seed to use for shuffling test orders (between 1 and\n"
5600" 99999, or 0 to use a seed based on the current time).\n"
5604" Enable/disable colored output. The default is @Gauto@D.\n"
5606" Don't print the elapsed time of each test.\n"
5609" Generate a JSON or XML report in the given directory or with the given\n"
5610" file name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n"
5611# if GTEST_CAN_STREAM_RESULTS_
5613" Stream test results to the given server.\n"
5616"Assertion Behavior:\n"
5617# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
5619" Set the default death test style.\n"
5622" Turn assertion failures into debugger break-points.\n"
5624" Turn assertion failures into C++ exceptions for use by an external\n"
5627" Do not report exceptions as test failures. Instead, allow them\n"
5628" to crash the program or throw a pop-up (on Windows).\n"
5631 "the corresponding\n"
5632"environment variable of a flag (all letters in upper-case). For example, to\n"
5634 "color=no@D or set\n"
5637"For more information, please read the " GTEST_NAME_ " documentation at\n"
5639"(not one in your own code or tests), please report it to\n"
5642static bool ParseGoogleTestFlag(
const char*
const arg) {
5672#if GTEST_USE_OWN_FLAGFILE_FLAG_
5673static void LoadFlagsFromFile(
const std::string& path) {
5681 std::vector<std::string>
lines;
5683 for (
size_t i = 0; i <
lines.size(); ++i) {
5684 if (
lines[i].empty())
5686 if (!ParseGoogleTestFlag(
lines[i].c_str()))
5695template <
typename CharType>
5697 for (
int i = 1; i < *argc; i++) {
5699 const char*
const arg = arg_string.c_str();
5701 using internal::ParseBoolFlag;
5703 using internal::ParseStringFlag;
5705 bool remove_flag =
false;
5706 if (ParseGoogleTestFlag(arg)) {
5708#if GTEST_USE_OWN_FLAGFILE_FLAG_
5713 }
else if (arg_string ==
"--help" || arg_string ==
"-h" ||
5714 arg_string ==
"-?" || arg_string ==
"/?" ||
5715 HasGoogleTestFlagPrefix(arg)) {
5726 for (
int j = i;
j != *argc;
j++) {
5743 PrintColorEncoded(kColorEncodedHelpMessage);
5760template <
typename CharType>
5763 if (GTestIsInitialized())
return;
5765 if (*argc <= 0)
return;
5768 for (
int i = 0; i != *argc; i++) {
5788#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
5789 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc,
argv);
5798#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
5799 GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc,
argv);
5806#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
5807 return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
5810#if GTEST_OS_WINDOWS_MOBILE
5812#elif GTEST_OS_WINDOWS
5814 if (temp_dir == NULL || temp_dir[0] ==
'\0')
5816 else if (temp_dir[strlen(temp_dir) - 1] ==
'\\')
5819 return std::string(temp_dir) +
"\\";
5820#elif GTEST_OS_LINUX_ANDROID
5831void ScopedTrace::PushTrace(
const char* file,
int line, std::string message) {
5832 internal::TraceInfo trace;
5835 trace.message.swap(message);
Catch::Generators::GeneratorWrapper< std::string > lines(std::string)
AssertionResult(const AssertionResult &other)
AssertionResult operator!() const
const char * message() const
std::string GetString() const
Message & operator<<(const T &val)
virtual ~ScopedFakeTestPartResultReporter()
virtual void ReportTestPartResult(const TestPartResult &result)
ScopedFakeTestPartResultReporter(TestPartResultArray *result)
const char * type_param() const
const TestInfo * GetTestInfo(int i) const
int test_to_run_count() const
int failed_test_count() const
const char * name() const
TestCase(const char *name, const char *a_type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc)
int disabled_test_count() const
int successful_test_count() const
int total_test_count() const
friend class internal::UnitTestImpl
TimeInMillis elapsed_time() const
int reportable_disabled_test_count() const
int reportable_test_count() const
virtual void OnTestPartResult(const TestPartResult &test_part_result)=0
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)=0
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)=0
virtual void OnTestProgramStart(const UnitTest &unit_test)=0
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)=0
virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test)=0
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)=0
virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test)=0
virtual void OnTestCaseStart(const TestCase &test_case)=0
virtual void OnTestStart(const TestInfo &test_info)=0
virtual void OnTestEnd(const TestInfo &test_info)=0
virtual void OnTestProgramEnd(const UnitTest &unit_test)=0
TestEventListener * Release(TestEventListener *listener)
void Append(TestEventListener *listener)
static void RecordProperty(const std::string &key, const std::string &value)
internal::SetUpTestCaseFunc SetUpTestCaseFunc
static bool HasFatalFailure()
internal::TearDownTestCaseFunc TearDownTestCaseFunc
const char * value_param() const
const char * name() const
const TestResult * result() const
const char * test_case_name() const
void Append(const TestPartResult &result)
virtual void ReportTestPartResult(const TestPartResult &result)=0
bool HasFatalFailure() const
bool HasNonfatalFailure() const
int total_part_count() const
const TestProperty & GetTestProperty(int i) const
TimeInMillis elapsed_time() const
const TestPartResult & GetTestPartResult(int i) const
int test_property_count() const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static UnitTest * GetInstance()
int reportable_disabled_test_count() const
const TestCase * current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_)
int Run() GTEST_MUST_USE_RESULT_
TimeInMillis start_timestamp() const
int reportable_test_count() const
int test_to_run_count() const
int successful_test_count() const
const TestCase * GetTestCase(int i) const
internal::ParameterizedTestCaseRegistry & parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_)
int total_test_case_count() const
int test_case_to_run_count() const
const TestResult & ad_hoc_test_result() const
TestEventListeners & listeners()
int failed_test_case_count() const
int successful_test_case_count() const
int failed_test_count() const
TimeInMillis elapsed_time() const
int disabled_test_count() const
const char * original_working_dir() const
int total_test_count() const
void operator=(const Message &message) const
AssertHelper(TestPartResult::Type type, const char *file, int line, const char *message)
DefaultGlobalTestPartResultReporter(UnitTestImpl *unit_test)
virtual void ReportTestPartResult(const TestPartResult &result)
DefaultPerThreadTestPartResultReporter(UnitTestImpl *unit_test)
virtual void ReportTestPartResult(const TestPartResult &result)
static FilePath GenerateUniqueFileName(const FilePath &directory, const FilePath &base_name, const char *extension)
bool CreateDirectoriesRecursively() const
const std::string & string() const
FilePath RemoveFileName() const
const char * c_str() const
static FilePath MakeFileName(const FilePath &directory, const FilePath &base_name, int number, const char *extension)
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
JsonUnitTestResultPrinter(const char *output_file)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
virtual std::string CurrentStackTrace(int max_depth, int skip_count)
virtual void UponLeavingGTest()
virtual std::string CurrentStackTrace(int max_depth, int skip_count)=0
static const char *const kElidedFramesMarker
virtual void UponLeavingGTest()=0
virtual void OnTestEnd(const TestInfo &test_info)
virtual void OnTestStart(const TestInfo &test_info)
static void PrintTestName(const char *test_case, const char *test)
virtual void OnTestPartResult(const TestPartResult &result)
virtual void OnTestCaseEnd(const TestCase &test_case)
virtual void OnTestProgramStart(const UnitTest &)
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)
virtual void OnTestProgramEnd(const UnitTest &)
PrettyUnitTestResultPrinter()
virtual void OnEnvironmentsSetUpEnd(const UnitTest &)
virtual void OnEnvironmentsTearDownEnd(const UnitTest &)
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
virtual void OnTestCaseStart(const TestCase &test_case)
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)
UInt32 Generate(UInt32 range)
static const UInt32 kMaxRange
ScopedPrematureExitFile(const char *premature_exit_filepath)
~ScopedPrematureExitFile()
SingleFailureChecker(const TestPartResultArray *results, TestPartResult::Type type, const std::string &substr)
static bool CaseInsensitiveCStringEquals(const char *lhs, const char *rhs)
static bool CaseInsensitiveWideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
static bool CStringEquals(const char *lhs, const char *rhs)
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
static std::string ShowWideCString(const wchar_t *wide_c_str)
static bool WideCStringEquals(const wchar_t *lhs, const wchar_t *rhs)
static std::string FormatIntWidth2(int value)
static std::string FormatByte(unsigned char value)
static std::string FormatHexInt(int value)
TestCaseNameIs(const std::string &name)
bool operator()(const TestCase *test_case) const
virtual void OnTestCaseEnd(const TestCase &test_case)
virtual ~TestEventRepeater()
virtual void OnTestProgramStart(const UnitTest &unit_test)
virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test)
virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test)
virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration)
virtual void OnTestProgramEnd(const UnitTest &unit_test)
virtual void OnTestCaseStart(const TestCase &test_case)
virtual void OnTestStart(const TestInfo &test_info)
virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test)
void set_forwarding_enabled(bool enable)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
virtual void OnTestEnd(const TestInfo &test_info)
bool forwarding_enabled() const
TestEventListener * Release(TestEventListener *listener)
virtual void OnTestPartResult(const TestPartResult &result)
void Append(TestEventListener *listener)
virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test)
virtual Test * CreateTest()=0
int reportable_disabled_test_count() const
TestCase * GetMutableTestCase(int i)
int disabled_test_count() const
internal::Random * random()
int test_to_run_count() const
void SetTestPartResultReporterForCurrentThread(TestPartResultReporterInterface *reporter)
void RecordProperty(const TestProperty &test_property)
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
TestPartResultReporterInterface * GetGlobalTestPartResultReporter()
void ConfigureXmlOutput()
TestEventListeners * listeners()
int successful_test_case_count() const
void set_os_stack_trace_getter(OsStackTraceGetterInterface *getter)
TestPartResultReporterInterface * GetTestPartResultReporterForCurrentThread()
UnitTestImpl(UnitTest *parent)
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_
OsStackTraceGetterInterface * os_stack_trace_getter()
void PostFlagParsingInit()
void SetGlobalTestPartResultReporter(TestPartResultReporterInterface *reporter)
int total_test_count() const
void ClearNonAdHocTestResult()
TestInfo * current_test_info()
void set_current_test_info(TestInfo *a_current_test_info)
TestResult * current_test_result()
int FilterTests(ReactionToSharding shard_tests)
const TestCase * GetTestCase(int i) const
std::vector< Environment * > & environments()
int total_test_case_count() const
int successful_test_count() const
std::vector< TraceInfo > & gtest_trace_stack()
@ IGNORE_SHARDING_PROTOCOL
@ HONOR_SHARDING_PROTOCOL
int failed_test_count() const
void ListTestsMatchingFilter()
internal::ParameterizedTestCaseRegistry & parameterized_test_registry()
int reportable_test_count() const
const TestCase * current_test_case() const
void RegisterParameterizedTests()
int failed_test_case_count() const
int test_case_to_run_count() const
static bool MatchesFilter(const std::string &name, const char *filter)
static std::string GetAbsolutePathToOutputFile()
static bool FilterMatchesTest(const std::string &test_case_name, const std::string &test_name)
static std::string GetOutputFormat()
static bool PatternMatchesString(const char *pattern, const char *str)
virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration)
XmlUnitTestResultPrinter(const char *output_file)
#define GTEST_FLAG_PREFIX_
#define GTEST_FLAG_SAVER_
#define GTEST_FLAG_PREFIX_UPPER_
#define GTEST_FLAG_PREFIX_DASH_
#define GTEST_DEFINE_bool_(name, default_val, doc)
#define GTEST_PROJECT_URL_
#define GTEST_LOCK_EXCLUDED_(locks)
#define GTEST_DEFINE_STATIC_MUTEX_(mutex)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_DEFINE_string_(name, default_val, doc)
#define GTEST_DEFINE_int32_(name, default_val, doc)
#define GTEST_LOG_(severity)
#define GTEST_INIT_GOOGLE_TEST_NAME_
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define GTEST_REPEATER_METHOD_(Name, Type)
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type)
#define GTEST_IMPL_CMP_HELPER_(op_name, op)
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3)
void close(T *e, websocketpp::connection_hdl hdl)
void diff(const std::string &a, const std::string &b)
LOGGING_API void printf(Category category, const char *format,...)
static const Reg8 ch(Operand::CH)
static const Segment ss(Segment::ss)
void swap(picojson::value &x, picojson::value &y)
GTEST_API_ std::vector< EditType > CalculateOptimalEdits(const std::vector< size_t > &left, const std::vector< size_t > &right)
GTEST_API_ std::string CreateUnifiedDiff(const std::vector< std::string > &left, const std::vector< std::string > &right, size_t context=2)
int StrCaseCmp(const char *s1, const char *s2)
const char * GetEnv(const char *name)
FILE * FOpen(const char *path, const char *mode)
const char kDeathTestStyleFlag[]
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
void(* TearDownTestCaseFunc)()
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)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
std::string OutputFlagAlsoCheckEnvVar()
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
GTEST_API_ Int32 Int32FromGTestEnv(const char *flag, Int32 default_val)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
const UInt32 kMaxCodePoint1
AssertionResult FloatingPointLE(const char *expr1, const char *expr2, RawType val1, RawType val2)
void WriteToShardStatusFileIfNeeded()
const char kListTestsFlag[]
::std::vector< std::string > g_argvs
int CountIf(const Container &c, Predicate predicate)
GTEST_API_::std::string FormatCompilerIndependentFileLocation(const char *file, int line)
GTEST_API_ bool SkipPrefix(const char *prefix, const char **pstr)
UInt32 ChopLowBits(UInt32 *bits, int n)
GTEST_API_ std::string ReadEntireFile(FILE *file)
void(* SetUpTestCaseFunc)()
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
const char kDeathTestUseFork[]
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
AssertionResult CmpHelperEQ(const char *lhs_expression, const char *rhs_expression, const T1 &lhs, const T2 &rhs)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, double val1, double val2, double abs_error)
GTEST_API_ bool IsTrue(bool condition)
void ForEach(const Container &c, Functor functor)
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
GTEST_API_ std::string GetBoolAssertionFailureMessage(const AssertionResult &assertion_result, const char *expression_text, const char *actual_predicate_value, const char *expected_predicate_value)
TypeWithSize< 8 >::Int TimeInMillis
bool BoolFromGTestEnv(const char *flag, bool default_val)
bool IsUtf16SurrogatePair(wchar_t first, wchar_t second)
int GetNextRandomSeed(int seed)
GTEST_API_ AssertionResult CmpHelperSTREQ(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
GTEST_API_ FilePath GetCurrentExecutableName()
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const char * StringFromGTestEnv(const char *flag, const char *default_val)
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
const char kBreakOnFailureFlag[]
const char kStreamResultToFlag[]
const char kInternalRunDeathTestFlag[]
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string &message)
void SplitString(const ::std::string &str, char delimiter, ::std::vector< ::std::string > *dest)
TypeWithSize< 4 >::Int Int32
void PrintTo(const ReferenceWrapper< T > &ref, ::std::ostream *os)
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
void Shuffle(internal::Random *random, std::vector< E > *v)
std::string FormatForComparisonFailureMessage(const T1 &value, const T2 &)
GTEST_API_ bool AlwaysTrue()
GTEST_API_ bool g_help_flag
GTEST_API_ std::vector< std::string > GetArgvs()
const char kRandomSeedFlag[]
class UnitTestImpl * GetUnitTestImpl()
const char kFlagfileFlag[]
const UInt32 kMaxCodePoint3
const char kPrintTimeFlag[]
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
std::string StreamableToString(const T &streamable)
const char kPrintUTF8Flag[]
GTEST_API_ void ReportInvalidTestCaseType(const char *test_case_name, CodeLocation code_location)
const UInt32 kMaxCodePoint2
GTEST_API_ const char kStackTraceMarker[]
bool ParseInt32(const Message &src_text, const char *str, Int32 *value)
GTEST_API_ std::string StringStreamToString(::std::stringstream *stream)
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
void InitGoogleTestImpl(int *argc, CharType **argv)
Result HandleSehExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, wchar_t second)
const UInt32 kMaxCodePoint4
GTEST_API_ TypeId GetTestTypeId()
const char kAlsoRunDisabledTestsFlag[]
const char kStackTraceDepthFlag[]
const char kThrowOnFailureFlag[]
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
GTEST_API_ std::string AppendUserMessage(const std::string >est_msg, const Message &user_msg)
void ParseGoogleTestFlagsOnlyImpl(int *argc, CharType **argv)
GTEST_API_ TimeInMillis GetTimeInMillis()
int GetRandomSeedFromFlag(Int32 random_seed_flag)
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest *unit_test, int skip_count)
GTEST_API_ AssertionResult CmpHelperSTRNE(const char *s1_expression, const char *s2_expression, const char *s1, const char *s2)
const char kCatchExceptionsFlag[]
const char kShuffleFlag[]
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
GTEST_API_ AssertionResult AssertionFailure()
internal::TimeInMillis TimeInMillis
::std::string PrintToString(const T &value)
GTEST_API_ std::string TempDir()
std::vector< std::string > ArrayAsVector(const char *const (&array)[kSize])
GTEST_API_ AssertionResult AssertionSuccess()
GTEST_API_ AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
#define T(meth, val, expected)
account_query_db::get_accounts_by_authorizers_result results
yh_object_descriptor object
memset(pInfo->slotDescription, ' ', 64)