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
131 const char* str,
const char* flag,
Int32* value);
136 const unsigned int raw_seed = (random_seed_flag == 0) ?
138 static_cast<unsigned int>(random_seed_flag);
142 const int normalized_seed =
143 static_cast<int>((raw_seed - 1U) %
144 static_cast<unsigned int>(kMaxRandomSeed)) + 1;
145 return normalized_seed;
153 <<
"Invalid random seed " << seed <<
" - must be in [1, "
154 << kMaxRandomSeed <<
"].";
155 const int next_seed = seed + 1;
156 return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
165 also_run_disabled_tests_ =
GTEST_FLAG(also_run_disabled_tests);
166 break_on_failure_ =
GTEST_FLAG(break_on_failure);
167 catch_exceptions_ =
GTEST_FLAG(catch_exceptions);
169 death_test_style_ =
GTEST_FLAG(death_test_style);
170 death_test_use_fork_ =
GTEST_FLAG(death_test_use_fork);
172 internal_run_death_test_ =
GTEST_FLAG(internal_run_death_test);
179 stack_trace_depth_ =
GTEST_FLAG(stack_trace_depth);
180 stream_result_to_ =
GTEST_FLAG(stream_result_to);
181 throw_on_failure_ =
GTEST_FLAG(throw_on_failure);
186 GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
187 GTEST_FLAG(break_on_failure) = break_on_failure_;
188 GTEST_FLAG(catch_exceptions) = catch_exceptions_;
190 GTEST_FLAG(death_test_style) = death_test_style_;
191 GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
193 GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
200 GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
201 GTEST_FLAG(stream_result_to) = stream_result_to_;
202 GTEST_FLAG(throw_on_failure) = throw_on_failure_;
207 bool also_run_disabled_tests_;
208 bool break_on_failure_;
209 bool catch_exceptions_;
212 bool death_test_use_fork_;
223 bool throw_on_failure_;
262 const char* shard_index_str,
263 bool in_subprocess_for_death_test);
275 int total_shards,
int shard_index,
int test_id);
281 template <
class Container,
typename Predicate>
282 inline int CountIf(
const Container&
c, Predicate predicate) {
286 for (
typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
294 template <
class Container,
typename Functor>
295 void ForEach(
const Container&
c, Functor functor) {
296 std::for_each(c.begin(), c.end(), functor);
301 template <
typename E>
302 inline E
GetElementOr(
const std::vector<E>& v,
int i, E default_value) {
303 return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
310 template <
typename E>
313 const int size =
static_cast<int>(v->size());
315 <<
"Invalid shuffle range start " << begin <<
": must be in range [0, "
318 <<
"Invalid shuffle range finish " << end <<
": must be in range ["
319 << begin <<
", " << size <<
"].";
323 for (
int range_width = end - begin; range_width >= 2; range_width--) {
324 const int last_in_range = begin + range_width - 1;
325 const int selected = begin + random->
Generate(range_width);
326 std::swap((*v)[selected], (*v)[last_in_range]);
331 template <
typename E>
333 ShuffleRange(random, 0, static_cast<int>(v->size()), v);
338 template <
typename T>
339 static void Delete(
T* x) {
355 return test_property.
key() == key_;
391 static bool PatternMatchesString(
const char *pattern,
const char *str);
395 static bool FilterMatchesTest(
const std::string &test_case_name,
404 static int GTestShouldProcessSEH(DWORD exception_code);
405 #endif // GTEST_OS_WINDOWS
409 static bool MatchesFilter(
const std::string& name,
const char* filter);
524 void SetGlobalTestPartResultReporter(
531 void SetTestPartResultReporterForCurrentThread(
535 int successful_test_case_count()
const;
538 int failed_test_case_count()
const;
541 int total_test_case_count()
const;
545 int test_case_to_run_count()
const;
548 int successful_test_count()
const;
551 int failed_test_count()
const;
554 int reportable_disabled_test_count()
const;
557 int disabled_test_count()
const;
560 int reportable_test_count()
const;
563 int total_test_count()
const;
566 int test_to_run_count()
const;
576 bool Passed()
const {
return !Failed(); }
581 return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
587 const int index =
GetElementOr(test_case_indices_, i, -1);
588 return index < 0 ? NULL : test_cases_[i];
594 const int index =
GetElementOr(test_case_indices_, i, -1);
595 return index < 0 ? NULL : test_cases_[index];
642 TestCase* GetTestCase(
const char* test_case_name,
643 const char* type_param,
664 if (original_working_dir_.IsEmpty()) {
667 <<
"Failed to get the current working directory.";
673 tear_down_tc)->AddTestInfo(test_info);
676 #if GTEST_HAS_PARAM_TEST
679 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
680 return parameterized_test_registry_;
682 #endif // GTEST_HAS_PARAM_TEST
686 current_test_case_ = a_current_test_case;
693 current_test_info_ = a_current_test_info;
702 void RegisterParameterizedTests();
712 ForEach(test_cases_, TestCase::ClearTestCaseResult);
717 ad_hoc_test_result_.Clear();
728 IGNORE_SHARDING_PROTOCOL
737 int FilterTests(ReactionToSharding shard_tests);
740 void ListTestsMatchingFilter();
752 return *(gtest_trace_stack_.pointer());
755 return gtest_trace_stack_.get();
758 #if GTEST_HAS_DEATH_TEST
759 void InitDeathTestSubprocessControlInfo() {
760 internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
766 const InternalRunDeathTestFlag* internal_run_death_test_flag()
const {
767 return internal_run_death_test_flag_.get();
771 internal::DeathTestFactory* death_test_factory() {
772 return death_test_factory_.get();
775 void SuppressTestEventsIfInSubprocess();
777 friend class ReplaceDeathTestFactory;
778 #endif // GTEST_HAS_DEATH_TEST
782 void ConfigureXmlOutput();
784 #if GTEST_CAN_STREAM_RESULTS_
787 void ConfigureStreamingOutput();
795 void PostFlagParsingInit();
808 void UnshuffleTests();
815 friend class ::testing::UnitTest;
819 void set_catch_exceptions(
bool value) { catch_exceptions_ = value; }
831 default_per_thread_test_part_result_reporter_;
841 per_thread_test_part_result_reporter_;
845 std::vector<Environment*> environments_;
849 std::vector<TestCase*> test_cases_;
855 std::vector<int> test_case_indices_;
857 #if GTEST_HAS_PARAM_TEST
860 internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
863 bool parameterized_tests_registered_;
864 #endif // GTEST_HAS_PARAM_TEST
867 int last_death_test_case_;
902 bool post_flag_parse_init_performed_;
917 #if GTEST_HAS_DEATH_TEST
922 #endif // GTEST_HAS_DEATH_TEST
929 bool catch_exceptions_;
940 #if GTEST_USES_SIMPLE_RE
944 GTEST_API_ bool IsInSet(
char ch,
const char* str);
951 GTEST_API_ bool AtomMatchesChar(
bool escaped,
char pattern,
char ch);
952 GTEST_API_ bool ValidateRegex(
const char* regex);
953 GTEST_API_ bool MatchRegexAtHead(
const char* regex,
const char* str);
954 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
955 bool escaped,
char ch,
char repeat,
const char* regex,
const char* str);
956 GTEST_API_ bool MatchRegexAnywhere(
const char* regex,
const char* str);
958 #endif // GTEST_USES_SIMPLE_RE
965 #if GTEST_HAS_DEATH_TEST
971 # if GTEST_OS_WINDOWS
975 AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
976 explicit AutoHandle(HANDLE handle) : handle_(handle) {}
978 ~AutoHandle() { Reset(); }
980 HANDLE Get()
const {
return handle_; }
981 void Reset() { Reset(INVALID_HANDLE_VALUE); }
982 void Reset(HANDLE handle) {
983 if (handle != handle_) {
984 if (handle_ != INVALID_HANDLE_VALUE)
985 ::CloseHandle(handle_);
995 # endif // GTEST_OS_WINDOWS
1001 template <
typename Integer>
1006 if (str.empty() || !
IsDigit(str[0])) {
1015 # if GTEST_OS_WINDOWS && !defined(__GNUC__)
1018 typedef unsigned __int64 BiggestConvertible;
1019 const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
1023 typedef unsigned long long BiggestConvertible;
1024 const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
1026 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
1028 const bool parse_success = *end ==
'\0' && errno == 0;
1034 const Integer result =
static_cast<Integer
>(parsed);
1035 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1041 #endif // GTEST_HAS_DEATH_TEST
1054 test_result->RecordProperty(xml_element, property);
1058 test_result->ClearTestPartResults();
1063 return test_result.test_part_results();
1067 #if GTEST_CAN_STREAM_RESULTS_
1073 class AbstractSocketWriter {
1075 virtual ~AbstractSocketWriter() {}
1078 virtual void Send(
const string& message) = 0;
1081 virtual void CloseConnection() {}
1084 void SendLn(
const string& message) {
1085 Send(message +
"\n");
1090 class SocketWriter :
public AbstractSocketWriter {
1092 SocketWriter(
const string& host,
const string& port)
1093 : sockfd_(-1), host_name_(host), port_num_(port) {
1097 virtual ~SocketWriter() {
1103 virtual void Send(
const string& message) {
1105 <<
"Send() can be called only when there is a connection.";
1107 const int len =
static_cast<int>(message.length());
1108 if (write(sockfd_, message.c_str(), len) != len) {
1110 <<
"stream_result_to: failed to stream to "
1111 << host_name_ <<
":" << port_num_;
1117 void MakeConnection();
1120 void CloseConnection() {
1122 <<
"CloseConnection() can be called only when there is a connection.";
1129 const string host_name_;
1130 const string port_num_;
1136 static string UrlEncode(
const char* str);
1138 StreamingListener(
const string& host,
const string& port)
1139 : socket_writer_(new SocketWriter(host, port)) { Start(); }
1141 explicit StreamingListener(AbstractSocketWriter* socket_writer)
1142 : socket_writer_(socket_writer) { Start(); }
1144 void OnTestProgramStart(
const UnitTest& ) {
1145 SendLn(
"event=TestProgramStart");
1148 void OnTestProgramEnd(
const UnitTest& unit_test) {
1151 SendLn(
"event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
1154 socket_writer_->CloseConnection();
1157 void OnTestIterationStart(
const UnitTest& ,
int iteration) {
1158 SendLn(
"event=TestIterationStart&iteration=" +
1162 void OnTestIterationEnd(
const UnitTest& unit_test,
int ) {
1163 SendLn(
"event=TestIterationEnd&passed=" +
1164 FormatBool(unit_test.Passed()) +
"&elapsed_time=" +
1168 void OnTestCaseStart(
const TestCase& test_case) {
1169 SendLn(
std::string(
"event=TestCaseStart&name=") + test_case.name());
1172 void OnTestCaseEnd(
const TestCase& test_case) {
1173 SendLn(
"event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
1178 void OnTestStart(
const TestInfo& test_info) {
1179 SendLn(
std::string(
"event=TestStart&name=") + test_info.name());
1182 void OnTestEnd(
const TestInfo& test_info) {
1183 SendLn(
"event=TestEnd&passed=" +
1184 FormatBool((test_info.result())->Passed()) +
1189 void OnTestPartResult(
const TestPartResult& test_part_result) {
1190 const char* file_name = test_part_result.file_name();
1191 if (file_name == NULL)
1193 SendLn(
"event=TestPartResult&file=" + UrlEncode(file_name) +
1195 "&message=" + UrlEncode(test_part_result.message()));
1200 void SendLn(
const string& message) { socket_writer_->SendLn(message); }
1204 void Start() { SendLn(
"gtest_streaming_protocol_version=1.0"); }
1206 string FormatBool(
bool value) {
return value ?
"1" :
"0"; }
1208 const scoped_ptr<AbstractSocketWriter> socket_writer_;
1213 #endif // GTEST_CAN_STREAM_RESULTS_
1218 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
GTEST_API_ bool g_help_flag
Definition: gtest.cc:181
class UnitTestImpl * GetUnitTestImpl()
Definition: gtest-internal-inl.h:936
internal::SetUpTestCaseFunc SetUpTestCaseFunc
Definition: gtest.h:353
std::vector< Environment * > & environments()
Definition: gtest-internal-inl.h:748
const char kColorFlag[]
Definition: gtest-internal-inl.h:92
const char kAlsoRunDisabledTestsFlag[]
Definition: gtest-internal-inl.h:89
static const std::vector< testing::TestPartResult > & test_part_results(const TestResult &test_result)
Definition: gtest-internal-inl.h:1061
int GetRandomSeedFromFlag(Int32 random_seed_flag)
Definition: gtest-internal-inl.h:135
Definition: gtest-death-test.h:43
const TestResult * ad_hoc_test_result() const
Definition: gtest-internal-inl.h:606
TestPropertyKeyIs(const std::string &key)
Definition: gtest-internal-inl.h:351
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
Definition: gtest.cc:3221
E GetElementOr(const std::vector< E > &v, int i, E default_value)
Definition: gtest-internal-inl.h:302
const char kStreamResultToFlag[]
Definition: gtest-internal-inl.h:101
void set_current_test_info(TestInfo *a_current_test_info)
Definition: gtest-internal-inl.h:692
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
Definition: gtest-port.h:1566
int GetNextRandomSeed(int seed)
Definition: gtest-internal-inl.h:151
#define GTEST_LOG_(severity)
Definition: gtest-port.h:1039
Definition: gtest-internal-inl.h:474
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
Definition: gtest.cc:2585
::std::string string
Definition: gtest-port.h:872
const char * file
Definition: gtest-internal-inl.h:467
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
Definition: gtest.cc:4444
const char * key() const
Definition: gtest.h:473
Definition: gtest-internal-inl.h:490
TimeInMillis start_timestamp() const
Definition: gtest-internal-inl.h:570
void ClearAdHocTestResult()
Definition: gtest-internal-inl.h:716
bool Passed() const
Definition: gtest-internal-inl.h:576
const char kListTestsFlag[]
Definition: gtest-internal-inl.h:94
bool IsDigit(char ch)
Definition: gtest-port.h:1665
GTEST_DECLARE_bool_(also_run_disabled_tests)
Definition: gtest-internal.h:676
virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_)
Definition: gtest.cc:3518
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
Definition: gtest.cc:3213
GTestFlagSaver()
Definition: gtest-internal-inl.h:164
void set_current_test_case(TestCase *a_current_test_case)
Definition: gtest-internal-inl.h:685
internal::TearDownTestCaseFunc TearDownTestCaseFunc
Definition: gtest.h:354
#define GTEST_API_
Definition: gtest-port.h:768
static void ClearTestPartResults(TestResult *test_result)
Definition: gtest-internal-inl.h:1057
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
Definition: gtest.cc:4381
std::string message
Definition: gtest-internal-inl.h:469
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
Definition: gtest.cc:1436
bool catch_exceptions() const
Definition: gtest-internal-inl.h:812
Definition: gtest-internal-inl.h:727
TypeWithSize< 8 >::Int TimeInMillis
Definition: gtest-port.h:1904
#define GTEST_LOCK_EXCLUDED_(locks)
Definition: gtest-port.h:1928
#define GTEST_FLAG(name)
Definition: gtest-port.h:1909
ReactionToSharding
Definition: gtest-internal-inl.h:726
~GTestFlagSaver()
Definition: gtest-internal-inl.h:185
std::string StreamableToString(const T &streamable)
Definition: gtest-message.h:243
Definition: gtest-internal-inl.h:372
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:1901
const char kRandomSeedFlag[]
Definition: gtest-internal-inl.h:97
const void * TypeId
Definition: gtest-internal.h:399
virtual string CurrentStackTrace(int max_depth, int skip_count) GTEST_LOCK_EXCLUDED_(mutex_)
Definition: gtest.cc:3512
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:1900
const std::vector< TraceInfo > & gtest_trace_stack() const
Definition: gtest-internal-inl.h:754
Definition: gtest-internal-inl.h:440
Definition: gtest-internal-inl.h:161
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1060
#define GTEST_NO_INLINE_
Definition: gtest-port.h:775
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
Definition: gtest-internal-inl.h:654
UInt32 Generate(UInt32 range)
Definition: gtest.cc:291
Definition: gtest-port.h:1545
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
Definition: gtest.cc:604
Definition: gtest-test-part.h:47
static void RecordProperty(TestResult *test_result, const std::string &xml_element, const TestProperty &property)
Definition: gtest-internal-inl.h:1051
const TestCase * GetTestCase(int i) const
Definition: gtest-internal-inl.h:586
int line
Definition: gtest-internal-inl.h:468
const TestCase * current_test_case() const
Definition: gtest-internal-inl.h:742
virtual string CurrentStackTrace(int max_depth, int skip_count)=0
const int kMaxRandomSeed
Definition: gtest-internal-inl.h:105
void ClearNonAdHocTestResult()
Definition: gtest-internal-inl.h:711
virtual ~OsStackTraceGetterInterface()
Definition: gtest-internal-inl.h:420
Definition: gtest-internal-inl.h:417
GTEST_API_ FilePath GetCurrentExecutableName()
Definition: gtest.cc:377
GTEST_API_ TimeInMillis GetTimeInMillis()
Definition: gtest.cc:780
Definition: gtest-internal-inl.h:346
const TestInfo * current_test_info() const
Definition: gtest-internal-inl.h:744
const char * test_case_name() const
Definition: gtest.h:628
const char kBreakOnFailureFlag[]
Definition: gtest-internal-inl.h:90
const char kRepeatFlag[]
Definition: gtest-internal-inl.h:98
int random_seed() const
Definition: gtest-internal-inl.h:798
const char kCatchExceptionsFlag[]
Definition: gtest-internal-inl.h:91
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
Definition: gtest.cc:1500
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
Definition: gtest-internal-inl.h:311
Definition: gtest-internal-inl.h:466
static FilePath GetCurrentDir()
Definition: gtest-filepath.cc:101
int CountIf(const Container &c, Predicate predicate)
Definition: gtest-internal-inl.h:282
bool operator()(const TestProperty &test_property) const
Definition: gtest-internal-inl.h:354
const char kFilterFlag[]
Definition: gtest-internal-inl.h:93
Definition: gtest-internal-inl.h:508
TestEventListeners * listeners()
Definition: gtest-internal-inl.h:599
Definition: gtest-internal-inl.h:1049
OsStackTraceGetter()
Definition: gtest-internal-inl.h:442
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
Definition: gtest.cc:4959
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition: gtest-internal-inl.h:332
Definition: gtest-filepath.h:59
const char kStackTraceDepthFlag[]
Definition: gtest-internal-inl.h:100
const char kPrintTimeFlag[]
Definition: gtest-internal-inl.h:96
internal::Random * random()
Definition: gtest-internal-inl.h:801
bool Failed() const
Definition: gtest-internal-inl.h:580
std::vector< TraceInfo > & gtest_trace_stack()
Definition: gtest-internal-inl.h:751
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:726
virtual void UponLeavingGTest()=0
static const char *const kElidedFramesMarker
Definition: gtest-internal-inl.h:451
static UnitTest * GetInstance()
Definition: gtest.cc:3641
Definition: gtest-test-part.h:146
OsStackTraceGetterInterface()
Definition: gtest-internal-inl.h:419
const char * type_param() const
Definition: gtest.h:635
const char kThrowOnFailureFlag[]
Definition: gtest-internal-inl.h:102
void ForEach(const Container &c, Functor functor)
Definition: gtest-internal-inl.h:295
Definition: gtest-port.h:890
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
Definition: gtest.cc:4426
TimeInMillis elapsed_time() const
Definition: gtest-internal-inl.h:573
void WriteToShardStatusFileIfNeeded()
Definition: gtest.cc:4359
const char kShuffleFlag[]
Definition: gtest-internal-inl.h:99
const double c
Definition: gfit.cc:200
const char kOutputFlag[]
Definition: gtest-internal-inl.h:95
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition: mpreal.h:3069
TestInfo * current_test_info()
Definition: gtest-internal-inl.h:743
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
Definition: gtest.cc:4732
TestCase * GetMutableTestCase(int i)
Definition: gtest-internal-inl.h:593