37 #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
38 #define GTEST_SRC_GTEST_INTERNAL_INL_H_
42 #if !GTEST_IMPLEMENTATION_
44 # error "gtest-internal-inl.h is part of Google Test's internal implementation."
45 # error "It must not be included except by Google Test itself."
46 #endif // GTEST_IMPLEMENTATION_
61 #if GTEST_CAN_STREAM_RESULTS_
62 # include <arpa/inet.h>
68 #endif // GTEST_OS_WINDOWS
137 const unsigned int raw_seed = (random_seed_flag == 0) ?
139 static_cast<unsigned int>(random_seed_flag);
143 const int normalized_seed =
144 static_cast<int>((raw_seed - 1U) %
146 return normalized_seed;
154 <<
"Invalid random seed " << seed <<
" - must be in [1, "
156 const int next_seed = seed + 1;
157 return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
263 const char* shard_index_str,
264 bool in_subprocess_for_death_test);
276 int total_shards,
int shard_index,
int test_id);
282 template <
class Container,
typename Predicate>
283 inline int CountIf(
const Container&
c, Predicate predicate) {
287 for (
typename Container::const_iterator
it = c.begin();
it != c.end(); ++
it) {
295 template <
class Container,
typename Functor>
296 void ForEach(
const Container&
c, Functor functor) {
297 std::for_each(c.begin(), c.end(), functor);
302 template <
typename E>
304 return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[
i];
311 template <
typename E>
314 const int size =
static_cast<int>(v->size());
316 <<
"Invalid shuffle range start " << begin <<
": must be in range [0, "
319 <<
"Invalid shuffle range finish " << end <<
": must be in range ["
320 << begin <<
", " << size <<
"].";
324 for (
int range_width = end - begin; range_width >= 2; range_width--) {
325 const int last_in_range = begin + range_width - 1;
326 const int selected = begin + random->
Generate(range_width);
327 std::swap((*v)[selected], (*v)[last_in_range]);
332 template <
typename E>
334 ShuffleRange(random, 0, static_cast<int>(v->size()), v);
339 template <
typename T>
356 return test_property.
key() ==
key_;
392 static bool PatternMatchesString(
const char *pattern,
const char *
str);
396 static bool FilterMatchesTest(
const std::string &test_case_name,
405 static int GTestShouldProcessSEH(DWORD exception_code);
406 #endif // GTEST_OS_WINDOWS
515 void SetGlobalTestPartResultReporter(
522 void SetTestPartResultReporterForCurrentThread(
526 int successful_test_case_count()
const;
529 int failed_test_case_count()
const;
532 int total_test_case_count()
const;
536 int test_case_to_run_count()
const;
539 int successful_test_count()
const;
542 int failed_test_count()
const;
545 int reportable_disabled_test_count()
const;
548 int disabled_test_count()
const;
551 int reportable_test_count()
const;
554 int total_test_count()
const;
557 int test_to_run_count()
const;
567 bool Passed()
const {
return !Failed(); }
572 return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
579 return index < 0 ? NULL : test_cases_[
i];
586 return index < 0 ? NULL : test_cases_[
index];
633 TestCase* GetTestCase(
const char* test_case_name,
634 const char* type_param,
658 <<
"Failed to get the current working directory.";
664 tear_down_tc)->AddTestInfo(test_info);
667 #if GTEST_HAS_PARAM_TEST
670 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
671 return parameterized_test_registry_;
673 #endif // GTEST_HAS_PARAM_TEST
677 current_test_case_ = a_current_test_case;
684 current_test_info_ = a_current_test_info;
693 void RegisterParameterizedTests();
708 ad_hoc_test_result_.Clear();
719 IGNORE_SHARDING_PROTOCOL
728 int FilterTests(ReactionToSharding shard_tests);
731 void ListTestsMatchingFilter();
743 return *(gtest_trace_stack_.pointer());
746 return gtest_trace_stack_.get();
749 #if GTEST_HAS_DEATH_TEST
750 void InitDeathTestSubprocessControlInfo() {
751 internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
757 const InternalRunDeathTestFlag* internal_run_death_test_flag()
const {
758 return internal_run_death_test_flag_.get();
762 internal::DeathTestFactory* death_test_factory() {
763 return death_test_factory_.get();
766 void SuppressTestEventsIfInSubprocess();
768 friend class ReplaceDeathTestFactory;
769 #endif // GTEST_HAS_DEATH_TEST
773 void ConfigureXmlOutput();
775 #if GTEST_CAN_STREAM_RESULTS_
778 void ConfigureStreamingOutput();
786 void PostFlagParsingInit();
799 void UnshuffleTests();
806 friend class ::testing::UnitTest;
848 #if GTEST_HAS_PARAM_TEST
851 internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
854 bool parameterized_tests_registered_;
855 #endif // GTEST_HAS_PARAM_TEST
908 #if GTEST_HAS_DEATH_TEST
913 #endif // GTEST_HAS_DEATH_TEST
931 #if GTEST_USES_SIMPLE_RE
942 GTEST_API_ bool AtomMatchesChar(
bool escaped,
char pattern,
char ch);
943 GTEST_API_ bool ValidateRegex(
const char* regex);
944 GTEST_API_ bool MatchRegexAtHead(
const char* regex,
const char*
str);
945 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
946 bool escaped,
char ch,
char repeat,
const char* regex,
const char*
str);
947 GTEST_API_ bool MatchRegexAnywhere(
const char* regex,
const char*
str);
949 #endif // GTEST_USES_SIMPLE_RE
956 #if GTEST_HAS_DEATH_TEST
966 template <
typename Integer>
971 if (str.empty() || !
IsDigit(str[0])) {
980 # if GTEST_OS_WINDOWS && !defined(__GNUC__)
983 typedef unsigned __int64 BiggestConvertible;
984 const BiggestConvertible parsed = _strtoui64(str.c_str(), &
end, 10);
988 typedef unsigned long long BiggestConvertible;
989 const BiggestConvertible parsed = strtoull(str.c_str(), &
end, 10);
991 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
993 const bool parse_success = *end ==
'\0' && errno == 0;
999 const Integer result =
static_cast<Integer
>(parsed);
1000 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1006 #endif // GTEST_HAS_DEATH_TEST
1032 #if GTEST_CAN_STREAM_RESULTS_
1038 class AbstractSocketWriter {
1040 virtual ~AbstractSocketWriter() {}
1043 virtual void Send(
const string&
message) = 0;
1046 virtual void CloseConnection() {}
1049 void SendLn(
const string&
message) {
1050 Send(message +
"\n");
1055 class SocketWriter :
public AbstractSocketWriter {
1057 SocketWriter(
const string& host,
const string& port)
1058 : sockfd_(-1), host_name_(host), port_num_(port) {
1062 virtual ~SocketWriter() {
1068 virtual void Send(
const string&
message) {
1070 <<
"Send() can be called only when there is a connection.";
1072 const int len =
static_cast<int>(message.length());
1073 if (
write(sockfd_, message.c_str(), len) != len) {
1075 <<
"stream_result_to: failed to stream to "
1076 << host_name_ <<
":" << port_num_;
1082 void MakeConnection();
1085 void CloseConnection() {
1087 <<
"CloseConnection() can be called only when there is a connection.";
1094 const string host_name_;
1095 const string port_num_;
1101 static string UrlEncode(
const char* str);
1103 StreamingListener(
const string& host,
const string& port)
1104 : socket_writer_(new SocketWriter(host, port)) { Start(); }
1106 explicit StreamingListener(AbstractSocketWriter* socket_writer)
1107 : socket_writer_(socket_writer) { Start(); }
1109 void OnTestProgramStart(
const UnitTest& ) {
1110 SendLn(
"event=TestProgramStart");
1113 void OnTestProgramEnd(
const UnitTest& unit_test) {
1116 SendLn(
"event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
1119 socket_writer_->CloseConnection();
1122 void OnTestIterationStart(
const UnitTest& ,
int iteration) {
1123 SendLn(
"event=TestIterationStart&iteration=" +
1127 void OnTestIterationEnd(
const UnitTest& unit_test,
int ) {
1128 SendLn(
"event=TestIterationEnd&passed=" +
1129 FormatBool(unit_test.Passed()) +
"&elapsed_time=" +
1133 void OnTestCaseStart(
const TestCase& test_case) {
1134 SendLn(
std::string(
"event=TestCaseStart&name=") + test_case.name());
1137 void OnTestCaseEnd(
const TestCase& test_case) {
1138 SendLn(
"event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
1143 void OnTestStart(
const TestInfo& test_info) {
1144 SendLn(
std::string(
"event=TestStart&name=") + test_info.name());
1147 void OnTestEnd(
const TestInfo& test_info) {
1148 SendLn(
"event=TestEnd&passed=" +
1149 FormatBool((test_info.result())->Passed()) +
1154 void OnTestPartResult(
const TestPartResult& test_part_result) {
1155 const char* file_name = test_part_result.file_name();
1156 if (file_name == NULL)
1158 SendLn(
"event=TestPartResult&file=" + UrlEncode(file_name) +
1160 "&message=" + UrlEncode(test_part_result.message()));
1165 void SendLn(
const string& message) { socket_writer_->SendLn(message); }
1169 void Start() { SendLn(
"gtest_streaming_protocol_version=1.0"); }
1171 string FormatBool(
bool value) {
return value ?
"1" :
"0"; }
1173 const scoped_ptr<AbstractSocketWriter> socket_writer_;
1178 #endif // GTEST_CAN_STREAM_RESULTS_
1183 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_