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_ 63 #endif // GTEST_OS_WINDOWS 120 const char* str,
const char* flag,
Int32* value);
125 const unsigned int raw_seed = (random_seed_flag == 0) ?
127 static_cast<unsigned int>(random_seed_flag);
131 const int normalized_seed =
132 static_cast<int>((raw_seed - 1
U) %
133 static_cast<unsigned int>(kMaxRandomSeed)) + 1;
134 return normalized_seed;
142 <<
"Invalid random seed " << seed <<
" - must be in [1, " 143 << kMaxRandomSeed <<
"].";
144 const int next_seed = seed + 1;
145 return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
253 const char* shard_index_str,
254 bool in_subprocess_for_death_test);
266 int total_shards,
int shard_index,
int test_id);
272 template <
class Container,
typename Predicate>
273 inline int CountIf(
const Container& c, Predicate predicate) {
277 for (
typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
285 template <
class Container,
typename Functor>
286 void ForEach(
const Container& c, Functor functor) {
287 std::for_each(c.begin(), c.end(), functor);
292 template <
typename E>
294 return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
301 template <
typename E>
304 const int size =
static_cast<int>(v->size());
306 <<
"Invalid shuffle range start " << begin <<
": must be in range [0, " 309 <<
"Invalid shuffle range finish " << end <<
": must be in range [" 310 << begin <<
", " << size <<
"].";
314 for (
int range_width = end - begin; range_width >= 2; range_width--) {
315 const int last_in_range = begin + range_width - 1;
316 const int selected = begin + random->
Generate(range_width);
317 std::swap((*v)[selected], (*v)[last_in_range]);
322 template <
typename E>
324 ShuffleRange(random, 0, static_cast<int>(v->size()), v);
329 template <
typename T>
347 return String(test_property.
key()).Compare(key_) == 0;
369 static String GetOutputFormat();
374 static String GetAbsolutePathToOutputFile();
383 static bool PatternMatchesString(
const char *pattern,
const char *str);
387 static bool FilterMatchesTest(
const String &test_case_name,
396 static int GTestShouldProcessSEH(DWORD exception_code);
397 #endif // GTEST_OS_WINDOWS 401 static bool MatchesFilter(
const String& name,
const char* filter);
420 virtual String CurrentStackTrace(
int max_depth,
int skip_count) = 0;
425 virtual void UponLeavingGTest() = 0;
435 virtual String CurrentStackTrace(
int max_depth,
int skip_count);
436 virtual void UponLeavingGTest();
513 void SetGlobalTestPartResultReporter(
520 void SetTestPartResultReporterForCurrentThread(
524 int successful_test_case_count()
const;
527 int failed_test_case_count()
const;
530 int total_test_case_count()
const;
534 int test_case_to_run_count()
const;
537 int successful_test_count()
const;
540 int failed_test_count()
const;
543 int disabled_test_count()
const;
546 int total_test_count()
const;
549 int test_to_run_count()
const;
555 bool Passed()
const {
return !Failed(); }
560 return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
566 const int index =
GetElementOr(test_case_indices_, i, -1);
567 return index < 0 ? NULL : test_cases_[i];
573 const int index =
GetElementOr(test_case_indices_, i, -1);
574 return index < 0 ? NULL : test_cases_[index];
609 String CurrentOsStackTraceExceptTop(
int skip_count);
621 TestCase* GetTestCase(
const char* test_case_name,
622 const char* type_param,
643 if (original_working_dir_.IsEmpty()) {
646 <<
"Failed to get the current working directory.";
652 tear_down_tc)->AddTestInfo(test_info);
655 #if GTEST_HAS_PARAM_TEST 658 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
659 return parameterized_test_registry_;
661 #endif // GTEST_HAS_PARAM_TEST 665 current_test_case_ = a_current_test_case;
672 current_test_info_ = a_current_test_info;
681 void RegisterParameterizedTests();
696 ad_hoc_test_result_.Clear();
701 IGNORE_SHARDING_PROTOCOL
713 void ListTestsMatchingFilter();
725 return *(gtest_trace_stack_.pointer());
728 return gtest_trace_stack_.get();
731 #if GTEST_HAS_DEATH_TEST 732 void InitDeathTestSubprocessControlInfo() {
733 internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
739 const InternalRunDeathTestFlag* internal_run_death_test_flag()
const {
740 return internal_run_death_test_flag_.get();
744 internal::DeathTestFactory* death_test_factory() {
745 return death_test_factory_.get();
748 void SuppressTestEventsIfInSubprocess();
750 friend class ReplaceDeathTestFactory;
751 #endif // GTEST_HAS_DEATH_TEST 755 void ConfigureXmlOutput();
757 #if GTEST_CAN_STREAM_RESULTS_ 760 void ConfigureStreamingOutput();
768 void PostFlagParsingInit();
781 void UnshuffleTests();
788 friend class ::testing::UnitTest;
830 #if GTEST_HAS_PARAM_TEST 833 internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
836 bool parameterized_tests_registered_;
837 #endif // GTEST_HAS_PARAM_TEST 886 #if GTEST_HAS_DEATH_TEST 891 #endif // GTEST_HAS_DEATH_TEST 909 #if GTEST_USES_SIMPLE_RE 913 GTEST_API_ bool IsInSet(
char ch,
const char* str);
920 GTEST_API_ bool AtomMatchesChar(
bool escaped,
char pattern,
char ch);
921 GTEST_API_ bool ValidateRegex(
const char* regex);
922 GTEST_API_ bool MatchRegexAtHead(
const char* regex,
const char* str);
923 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
924 bool escaped,
char ch,
char repeat,
const char* regex,
const char* str);
925 GTEST_API_ bool MatchRegexAnywhere(
const char* regex,
const char* str);
927 #endif // GTEST_USES_SIMPLE_RE 934 #if GTEST_HAS_DEATH_TEST 940 # if GTEST_OS_WINDOWS 944 AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
945 explicit AutoHandle(HANDLE handle) : handle_(handle) {}
947 ~AutoHandle() { Reset(); }
949 HANDLE Get()
const {
return handle_; }
950 void Reset() { Reset(INVALID_HANDLE_VALUE); }
951 void Reset(HANDLE handle) {
952 if (handle != handle_) {
953 if (handle_ != INVALID_HANDLE_VALUE)
954 ::CloseHandle(handle_);
964 # endif // GTEST_OS_WINDOWS 970 template <
typename Integer>
975 if (str.empty() || !
IsDigit(str[0])) {
984 # if GTEST_OS_WINDOWS && !defined(__GNUC__) 987 typedef unsigned __int64 BiggestConvertible;
988 const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
992 typedef unsigned long long BiggestConvertible;
993 const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
995 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__) 997 const bool parse_success = *end ==
'\0' && errno == 0;
1003 const Integer result =
static_cast<Integer
>(parsed);
1004 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1010 #endif // GTEST_HAS_DEATH_TEST 1038 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_ void set_current_test_info(TestInfo *a_current_test_info)
Definition: gtest-internal-inl.h:671
Definition: InputPrereqs.h:76
GTEST_API_ bool g_help_flag
Definition: gtest.cc:178
bool also_run_disabled_tests_
Definition: gtest-internal-inl.h:195
class UnitTestImpl * GetUnitTestImpl()
Definition: gtest-internal-inl.h:905
std::vector< TraceInfo > & gtest_trace_stack()
Definition: gtest-internal-inl.h:724
Definition: gtest-internal-inl.h:497
const char kColorFlag[]
Definition: gtest-internal-inl.h:87
internal::ThreadLocal< std::vector< TraceInfo > > gtest_trace_stack_
Definition: gtest-internal-inl.h:894
const char kAlsoRunDisabledTestsFlag[]
Definition: gtest-internal-inl.h:84
Definition: gtest-test-part.h:143
static void ClearTestPartResults(TestResult *test_result)
Definition: gtest-internal-inl.h:1025
int GetRandomSeedFromFlag(Int32 random_seed_flag)
Definition: gtest-internal-inl.h:124
static UnitTest * GetInstance()
Definition: gtest.cc:3633
internal::SetUpTestCaseFunc SetUpTestCaseFunc
Definition: gtest.h:362
Definition: gmock-actions.h:49
int last_death_test_case_
Definition: gtest-internal-inl.h:840
E GetElementOr(const std::vector< E > &v, int i, E default_value)
Definition: gtest-internal-inl.h:293
bool break_on_failure_
Definition: gtest-internal-inl.h:196
UnitTest *const parent_
Definition: gtest-internal-inl.h:795
Definition: gtest-filepath.h:59
void set_catch_exceptions(bool value)
Definition: gtest-internal-inl.h:792
const char kStreamResultToFlag[]
Definition: gtest-internal-inl.h:96
TestInfo * current_test_info()
Definition: gtest-internal-inl.h:716
internal::ThreadLocal< TestPartResultReporterInterface * > per_thread_test_part_result_reporter_
Definition: gtest-internal-inl.h:814
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
int GetNextRandomSeed(int seed)
Definition: gtest-internal-inl.h:140
OsStackTraceGetterInterface()
Definition: gtest-internal-inl.h:411
bool Passed() const
Definition: gtest-internal-inl.h:555
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
Definition: gtest.cc:2585
Definition: gtest-internal-inl.h:479
std::vector< Environment * > & environments()
Definition: gtest-internal-inl.h:721
std::vector< TestCase * > test_cases_
Definition: gtest-internal-inl.h:822
void ClearNonAdHocTestResult()
Definition: gtest-internal-inl.h:690
::std::string string
Definition: gtest-port.h:756
OsStackTraceGetterInterface * os_stack_trace_getter_
Definition: gtest-internal-inl.h:872
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
Definition: gtest.cc:4366
String internal_run_death_test_
Definition: gtest-internal-inl.h:202
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
Definition: gtest-internal-inl.h:633
TestResult ad_hoc_test_result_
Definition: gtest-internal-inl.h:862
Definition: gtest-internal-inl.h:1018
TestEventListeners listeners_
Definition: gtest-internal-inl.h:866
const char kListTestsFlag[]
Definition: gtest-internal-inl.h:89
bool IsDigit(char ch)
Definition: gtest-port.h:1517
GTEST_DECLARE_bool_(also_run_disabled_tests)
GTEST_API_ char * CodePointToUtf8(UInt32 code_point, char *str)
Definition: gtest.cc:1435
internal::Int32 repeat_
Definition: gtest-internal-inl.h:208
internal::Mutex global_test_part_result_reporter_mutex_
Definition: gtest-internal-inl.h:810
internal::UnitTestImpl * impl()
Definition: gtest.h:1204
bool Failed() const
Definition: gtest-internal-inl.h:559
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
Definition: gtest.cc:3196
Definition: gtest-internal-inl.h:700
Definition: gtest-internal-inl.h:463
#define GTEST_API_
Definition: gtest-port.h:662
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
Definition: gtest.cc:4303
static void ClearTestCaseResult(TestCase *test_case)
Definition: gtest.h:830
virtual ~OsStackTraceGetterInterface()
Definition: gtest-internal-inl.h:412
Definition: gtest-test-part.h:47
TestPartResultReporterInterface * global_test_part_result_repoter_
Definition: gtest-internal-inl.h:807
String death_test_style_
Definition: gtest-internal-inl.h:199
const std::vector< TraceInfo > & gtest_trace_stack() const
Definition: gtest-internal-inl.h:727
DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_
Definition: gtest-internal-inl.h:802
TypeWithSize< 8 >::Int TimeInMillis
Definition: gtest-port.h:1736
Definition: gtest-internal-inl.h:150
bool catch_exceptions_
Definition: gtest-internal-inl.h:898
static const std::vector< testing::TestPartResult > & test_part_results(const TestResult &test_result)
Definition: gtest-internal-inl.h:1029
#define GTEST_FLAG(name)
Definition: gtest-port.h:1741
int line
Definition: gtest-internal-inl.h:457
const TestResult * ad_hoc_test_result() const
Definition: gtest-internal-inl.h:585
internal::FilePath original_working_dir_
Definition: gtest-internal-inl.h:799
TypeWithSize< 4 >::UInt UInt32
Definition: gtest-port.h:1733
const char kRandomSeedFlag[]
Definition: gtest-internal-inl.h:92
const void * TypeId
Definition: gtest-internal.h:474
internal::Int32 stack_trace_depth_
Definition: gtest-internal-inl.h:210
bool catch_exceptions_
Definition: gtest-internal-inl.h:197
TypeWithSize< 4 >::Int Int32
Definition: gtest-port.h:1732
const TestCase * current_test_case() const
Definition: gtest-internal-inl.h:715
bool operator()(const TestProperty &test_property) const
Definition: gtest-internal-inl.h:346
void ClearAdHocTestResult()
Definition: gtest-internal-inl.h:695
std::vector< int > test_case_indices_
Definition: gtest-internal-inl.h:828
const TestInfo * current_test_info() const
Definition: gtest-internal-inl.h:717
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:944
void * caller_frame_
Definition: gtest-internal-inl.h:449
String stream_result_to_
Definition: gtest-internal-inl.h:211
~GTestFlagSaver()
Definition: gtest-internal-inl.h:174
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
Definition: gtest.cc:600
const char * type_param() const
Definition: gtest.h:639
const char * file
Definition: gtest-internal-inl.h:456
TestInfo * current_test_info_
Definition: gtest-internal-inl.h:852
Definition: gtest-string.h:81
TestCase * current_test_case_
Definition: gtest-internal-inl.h:846
const int kMaxRandomSeed
Definition: gtest-internal-inl.h:100
const char * key() const
Definition: gtest.h:481
bool print_time_
Definition: gtest-internal-inl.h:205
ReactionToSharding
Definition: gtest-internal-inl.h:699
int random_seed_
Definition: gtest-internal-inl.h:878
String message
Definition: gtest-internal-inl.h:458
GTEST_API_ FilePath GetCurrentExecutableName()
Definition: gtest.cc:370
static const char *const kElidedFramesMarker
Definition: gtest-internal-inl.h:440
GTEST_API_ TimeInMillis GetTimeInMillis()
Definition: gtest.cc:765
internal::Random * random()
Definition: gtest-internal-inl.h:774
Definition: InputPrereqs.h:78
bool catch_exceptions() const
Definition: gtest-internal-inl.h:785
const char kBreakOnFailureFlag[]
Definition: gtest-internal-inl.h:85
const char kRepeatFlag[]
Definition: gtest-internal-inl.h:93
void ClearTestPartResults()
Definition: gtest.cc:1802
GTEST_API_ String WideStringToUtf8(const wchar_t *str, int num_chars)
Definition: gtest.cc:1504
const char kCatchExceptionsFlag[]
Definition: gtest-internal-inl.h:86
bool post_flag_parse_init_performed_
Definition: gtest-internal-inl.h:875
TimeInMillis elapsed_time_
Definition: gtest-internal-inl.h:884
void swap(StrongPtr< T > &a, StrongPtr< T > &b)
Swaps the contents of two strong pointers.
Definition: StrongPtr.h:284
void set_current_test_case(TestCase *a_current_test_case)
Definition: gtest-internal-inl.h:664
bool shuffle_
Definition: gtest-internal-inl.h:209
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
Definition: gtest-internal-inl.h:302
OsStackTraceGetter()
Definition: gtest-internal-inl.h:434
TestEventListeners * listeners()
Definition: gtest-internal-inl.h:578
internal::TearDownTestCaseFunc TearDownTestCaseFunc
Definition: gtest.h:363
String color_
Definition: gtest-internal-inl.h:198
int CountIf(const Container &c, Predicate predicate)
Definition: gtest-internal-inl.h:273
UnitTestImpl *const unit_test_
Definition: gtest-internal-inl.h:488
void RecordProperty(const TestProperty &test_property)
Definition: gtest.cc:1814
Definition: gtest-internal-inl.h:337
const char kFilterFlag[]
Definition: gtest-internal-inl.h:88
Mutex mutex_
Definition: gtest-internal-inl.h:443
bool pretty_
Definition: gtest-internal-inl.h:206
TestPropertyKeyIs(const char *key)
Definition: gtest-internal-inl.h:342
Definition: gtest-internal-inl.h:364
UInt32 Generate(UInt32 range)
Definition: gtest.cc:284
const TestCase * GetTestCase(int i) const
Definition: gtest-internal-inl.h:565
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
Definition: gtest.cc:4842
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition: gtest-internal-inl.h:323
const char kStackTraceDepthFlag[]
Definition: gtest-internal-inl.h:95
const char kPrintTimeFlag[]
Definition: gtest-internal-inl.h:91
Definition: gtest-port.h:1418
Definition: gtest-internal-inl.h:432
int random_seed() const
Definition: gtest-internal-inl.h:771
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:620
TimeInMillis elapsed_time() const
Definition: gtest-internal-inl.h:552
static FilePath GetCurrentDir()
Definition: gtest-filepath.cc:100
internal::Random random_
Definition: gtest-internal-inl.h:881
Definition: gtest-internal-inl.h:409
Definition: gtest-port.h:1399
const char kThrowOnFailureFlag[]
Definition: gtest-internal-inl.h:97
void ForEach(const Container &c, Functor functor)
Definition: gtest-internal-inl.h:286
std::vector< Environment * > environments_
Definition: gtest-internal-inl.h:818
Definition: gtest-port.h:774
bool death_test_use_fork_
Definition: gtest-internal-inl.h:200
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
Definition: gtest.cc:4348
bool throw_on_failure_
Definition: gtest-internal-inl.h:212
Definition: InputPrereqs.h:80
void WriteToShardStatusFileIfNeeded()
Definition: gtest.cc:4281
DefaultPerThreadTestPartResultReporter default_per_thread_test_part_result_reporter_
Definition: gtest-internal-inl.h:804
const char kShuffleFlag[]
Definition: gtest-internal-inl.h:94
TestCase * GetMutableTestCase(int i)
Definition: gtest-internal-inl.h:572
const char kOutputFlag[]
Definition: gtest-internal-inl.h:90
const std::vector< TestPartResult > & test_part_results() const
Definition: gtest.h:558
String key_
Definition: gtest-internal-inl.h:351
String output_
Definition: gtest-internal-inl.h:204
bool list_tests_
Definition: gtest-internal-inl.h:203
Definition: gtest-internal.h:750
const char * test_case_name() const
Definition: gtest.h:632
internal::Int32 random_seed_
Definition: gtest-internal-inl.h:207
String filter_
Definition: gtest-internal-inl.h:201
static void Delete(T *x)
Definition: gtest-internal-inl.h:330
UnitTestImpl *const unit_test_
Definition: gtest-internal-inl.h:472
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
Definition: gtest.cc:4615
static void RecordProperty(TestResult *test_result, const TestProperty &property)
Definition: gtest-internal-inl.h:1020
Definition: gtest-internal-inl.h:455
GTestFlagSaver()
Definition: gtest-internal-inl.h:153