00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
00038 #define GTEST_SRC_GTEST_INTERNAL_INL_H_
00039
00040
00041
00042 #if !GTEST_IMPLEMENTATION_
00043
00044 # error "gtest-internal-inl.h is part of Google Test's internal implementation."
00045 # error "It must not be included except by Google Test itself."
00046 #endif // GTEST_IMPLEMENTATION_
00047
00048 #ifndef _WIN32_WCE
00049 # include <errno.h>
00050 #endif // !_WIN32_WCE
00051 #include <stddef.h>
00052 #include <stdlib.h>
00053 #include <string.h>
00054
00055 #include <algorithm>
00056 #include <string>
00057 #include <vector>
00058
00059 #include "gtest/internal/gtest-port.h"
00060
00061 #if GTEST_OS_WINDOWS
00062 # include <windows.h>
00063 #endif // GTEST_OS_WINDOWS
00064
00065 #include "gtest/gtest.h"
00066 #include "gtest/gtest-spi.h"
00067
00068 namespace testing {
00069
00070
00071
00072
00073
00074
00075 GTEST_DECLARE_bool_(death_test_use_fork);
00076
00077 namespace internal {
00078
00079
00080
00081 GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
00082
00083
00084 const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
00085 const char kBreakOnFailureFlag[] = "break_on_failure";
00086 const char kCatchExceptionsFlag[] = "catch_exceptions";
00087 const char kColorFlag[] = "color";
00088 const char kFilterFlag[] = "filter";
00089 const char kListTestsFlag[] = "list_tests";
00090 const char kOutputFlag[] = "output";
00091 const char kPrintTimeFlag[] = "print_time";
00092 const char kRandomSeedFlag[] = "random_seed";
00093 const char kRepeatFlag[] = "repeat";
00094 const char kShuffleFlag[] = "shuffle";
00095 const char kStackTraceDepthFlag[] = "stack_trace_depth";
00096 const char kStreamResultToFlag[] = "stream_result_to";
00097 const char kThrowOnFailureFlag[] = "throw_on_failure";
00098
00099
00100 const int kMaxRandomSeed = 99999;
00101
00102
00103
00104 GTEST_API_ extern bool g_help_flag;
00105
00106
00107 GTEST_API_ TimeInMillis GetTimeInMillis();
00108
00109
00110 GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
00111
00112
00113 GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
00114
00115
00116
00117
00118
00119 GTEST_API_ bool ParseInt32Flag(
00120 const char* str, const char* flag, Int32* value);
00121
00122
00123
00124 inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
00125 const unsigned int raw_seed = (random_seed_flag == 0) ?
00126 static_cast<unsigned int>(GetTimeInMillis()) :
00127 static_cast<unsigned int>(random_seed_flag);
00128
00129
00130
00131 const int normalized_seed =
00132 static_cast<int>((raw_seed - 1U) %
00133 static_cast<unsigned int>(kMaxRandomSeed)) + 1;
00134 return normalized_seed;
00135 }
00136
00137
00138
00139
00140 inline int GetNextRandomSeed(int seed) {
00141 GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
00142 << "Invalid random seed " << seed << " - must be in [1, "
00143 << kMaxRandomSeed << "].";
00144 const int next_seed = seed + 1;
00145 return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
00146 }
00147
00148
00149
00150 class GTestFlagSaver {
00151 public:
00152
00153 GTestFlagSaver() {
00154 also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
00155 break_on_failure_ = GTEST_FLAG(break_on_failure);
00156 catch_exceptions_ = GTEST_FLAG(catch_exceptions);
00157 color_ = GTEST_FLAG(color);
00158 death_test_style_ = GTEST_FLAG(death_test_style);
00159 death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
00160 filter_ = GTEST_FLAG(filter);
00161 internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
00162 list_tests_ = GTEST_FLAG(list_tests);
00163 output_ = GTEST_FLAG(output);
00164 print_time_ = GTEST_FLAG(print_time);
00165 random_seed_ = GTEST_FLAG(random_seed);
00166 repeat_ = GTEST_FLAG(repeat);
00167 shuffle_ = GTEST_FLAG(shuffle);
00168 stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
00169 stream_result_to_ = GTEST_FLAG(stream_result_to);
00170 throw_on_failure_ = GTEST_FLAG(throw_on_failure);
00171 }
00172
00173
00174 ~GTestFlagSaver() {
00175 GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
00176 GTEST_FLAG(break_on_failure) = break_on_failure_;
00177 GTEST_FLAG(catch_exceptions) = catch_exceptions_;
00178 GTEST_FLAG(color) = color_;
00179 GTEST_FLAG(death_test_style) = death_test_style_;
00180 GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
00181 GTEST_FLAG(filter) = filter_;
00182 GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
00183 GTEST_FLAG(list_tests) = list_tests_;
00184 GTEST_FLAG(output) = output_;
00185 GTEST_FLAG(print_time) = print_time_;
00186 GTEST_FLAG(random_seed) = random_seed_;
00187 GTEST_FLAG(repeat) = repeat_;
00188 GTEST_FLAG(shuffle) = shuffle_;
00189 GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
00190 GTEST_FLAG(stream_result_to) = stream_result_to_;
00191 GTEST_FLAG(throw_on_failure) = throw_on_failure_;
00192 }
00193 private:
00194
00195 bool also_run_disabled_tests_;
00196 bool break_on_failure_;
00197 bool catch_exceptions_;
00198 String color_;
00199 String death_test_style_;
00200 bool death_test_use_fork_;
00201 String filter_;
00202 String internal_run_death_test_;
00203 bool list_tests_;
00204 String output_;
00205 bool print_time_;
00206 bool pretty_;
00207 internal::Int32 random_seed_;
00208 internal::Int32 repeat_;
00209 bool shuffle_;
00210 internal::Int32 stack_trace_depth_;
00211 String stream_result_to_;
00212 bool throw_on_failure_;
00213 } GTEST_ATTRIBUTE_UNUSED_;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);
00239
00240
00241
00242
00243
00244 void WriteToShardStatusFileIfNeeded();
00245
00246
00247
00248
00249
00250
00251
00252 GTEST_API_ bool ShouldShard(const char* total_shards_str,
00253 const char* shard_index_str,
00254 bool in_subprocess_for_death_test);
00255
00256
00257
00258
00259 GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
00260
00261
00262
00263
00264
00265 GTEST_API_ bool ShouldRunTestOnShard(
00266 int total_shards, int shard_index, int test_id);
00267
00268
00269
00270
00271
00272 template <class Container, typename Predicate>
00273 inline int CountIf(const Container& c, Predicate predicate) {
00274
00275
00276 int count = 0;
00277 for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
00278 if (predicate(*it))
00279 ++count;
00280 }
00281 return count;
00282 }
00283
00284
00285 template <class Container, typename Functor>
00286 void ForEach(const Container& c, Functor functor) {
00287 std::for_each(c.begin(), c.end(), functor);
00288 }
00289
00290
00291
00292 template <typename E>
00293 inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
00294 return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
00295 }
00296
00297
00298
00299
00300
00301 template <typename E>
00302 void ShuffleRange(internal::Random* random, int begin, int end,
00303 std::vector<E>* v) {
00304 const int size = static_cast<int>(v->size());
00305 GTEST_CHECK_(0 <= begin && begin <= size)
00306 << "Invalid shuffle range start " << begin << ": must be in range [0, "
00307 << size << "].";
00308 GTEST_CHECK_(begin <= end && end <= size)
00309 << "Invalid shuffle range finish " << end << ": must be in range ["
00310 << begin << ", " << size << "].";
00311
00312
00313
00314 for (int range_width = end - begin; range_width >= 2; range_width--) {
00315 const int last_in_range = begin + range_width - 1;
00316 const int selected = begin + random->Generate(range_width);
00317 std::swap((*v)[selected], (*v)[last_in_range]);
00318 }
00319 }
00320
00321
00322 template <typename E>
00323 inline void Shuffle(internal::Random* random, std::vector<E>* v) {
00324 ShuffleRange(random, 0, static_cast<int>(v->size()), v);
00325 }
00326
00327
00328
00329 template <typename T>
00330 static void Delete(T* x) {
00331 delete x;
00332 }
00333
00334
00335
00336
00337 class TestPropertyKeyIs {
00338 public:
00339
00340
00341
00342 explicit TestPropertyKeyIs(const char* key)
00343 : key_(key) {}
00344
00345
00346 bool operator()(const TestProperty& test_property) const {
00347 return String(test_property.key()).Compare(key_) == 0;
00348 }
00349
00350 private:
00351 String key_;
00352 };
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 class GTEST_API_ UnitTestOptions {
00365 public:
00366
00367
00368
00369 static String GetOutputFormat();
00370
00371
00372
00373
00374 static String GetAbsolutePathToOutputFile();
00375
00376
00377
00378
00379
00380
00381
00382
00383 static bool PatternMatchesString(const char *pattern, const char *str);
00384
00385
00386
00387 static bool FilterMatchesTest(const String &test_case_name,
00388 const String &test_name);
00389
00390 #if GTEST_OS_WINDOWS
00391
00392
00393
00394
00395
00396 static int GTestShouldProcessSEH(DWORD exception_code);
00397 #endif // GTEST_OS_WINDOWS
00398
00399
00400
00401 static bool MatchesFilter(const String& name, const char* filter);
00402 };
00403
00404
00405
00406 GTEST_API_ FilePath GetCurrentExecutableName();
00407
00408
00409 class OsStackTraceGetterInterface {
00410 public:
00411 OsStackTraceGetterInterface() {}
00412 virtual ~OsStackTraceGetterInterface() {}
00413
00414
00415
00416
00417
00418
00419
00420 virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;
00421
00422
00423
00424
00425 virtual void UponLeavingGTest() = 0;
00426
00427 private:
00428 GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
00429 };
00430
00431
00432 class OsStackTraceGetter : public OsStackTraceGetterInterface {
00433 public:
00434 OsStackTraceGetter() : caller_frame_(NULL) {}
00435 virtual String CurrentStackTrace(int max_depth, int skip_count);
00436 virtual void UponLeavingGTest();
00437
00438
00439
00440 static const char* const kElidedFramesMarker;
00441
00442 private:
00443 Mutex mutex_;
00444
00445
00446
00447
00448
00449 void* caller_frame_;
00450
00451 GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
00452 };
00453
00454
00455 struct TraceInfo {
00456 const char* file;
00457 int line;
00458 String message;
00459 };
00460
00461
00462
00463 class DefaultGlobalTestPartResultReporter
00464 : public TestPartResultReporterInterface {
00465 public:
00466 explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
00467
00468
00469 virtual void ReportTestPartResult(const TestPartResult& result);
00470
00471 private:
00472 UnitTestImpl* const unit_test_;
00473
00474 GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
00475 };
00476
00477
00478
00479 class DefaultPerThreadTestPartResultReporter
00480 : public TestPartResultReporterInterface {
00481 public:
00482 explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
00483
00484
00485 virtual void ReportTestPartResult(const TestPartResult& result);
00486
00487 private:
00488 UnitTestImpl* const unit_test_;
00489
00490 GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
00491 };
00492
00493
00494
00495
00496
00497 class GTEST_API_ UnitTestImpl {
00498 public:
00499 explicit UnitTestImpl(UnitTest* parent);
00500 virtual ~UnitTestImpl();
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
00511
00512
00513 void SetGlobalTestPartResultReporter(
00514 TestPartResultReporterInterface* reporter);
00515
00516
00517 TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
00518
00519
00520 void SetTestPartResultReporterForCurrentThread(
00521 TestPartResultReporterInterface* reporter);
00522
00523
00524 int successful_test_case_count() const;
00525
00526
00527 int failed_test_case_count() const;
00528
00529
00530 int total_test_case_count() const;
00531
00532
00533
00534 int test_case_to_run_count() const;
00535
00536
00537 int successful_test_count() const;
00538
00539
00540 int failed_test_count() const;
00541
00542
00543 int disabled_test_count() const;
00544
00545
00546 int total_test_count() const;
00547
00548
00549 int test_to_run_count() const;
00550
00551
00552 TimeInMillis elapsed_time() const { return elapsed_time_; }
00553
00554
00555 bool Passed() const { return !Failed(); }
00556
00557
00558
00559 bool Failed() const {
00560 return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
00561 }
00562
00563
00564
00565 const TestCase* GetTestCase(int i) const {
00566 const int index = GetElementOr(test_case_indices_, i, -1);
00567 return index < 0 ? NULL : test_cases_[i];
00568 }
00569
00570
00571
00572 TestCase* GetMutableTestCase(int i) {
00573 const int index = GetElementOr(test_case_indices_, i, -1);
00574 return index < 0 ? NULL : test_cases_[index];
00575 }
00576
00577
00578 TestEventListeners* listeners() { return &listeners_; }
00579
00580
00581
00582 TestResult* current_test_result();
00583
00584
00585 const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
00586
00587
00588
00589
00590
00591
00592 void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
00593
00594
00595
00596
00597 OsStackTraceGetterInterface* os_stack_trace_getter();
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 String CurrentOsStackTraceExceptTop(int skip_count);
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621 TestCase* GetTestCase(const char* test_case_name,
00622 const char* type_param,
00623 Test::SetUpTestCaseFunc set_up_tc,
00624 Test::TearDownTestCaseFunc tear_down_tc);
00625
00626
00627
00628
00629
00630
00631
00632
00633 void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
00634 Test::TearDownTestCaseFunc tear_down_tc,
00635 TestInfo* test_info) {
00636
00637
00638
00639
00640
00641
00642
00643 if (original_working_dir_.IsEmpty()) {
00644 original_working_dir_.Set(FilePath::GetCurrentDir());
00645 GTEST_CHECK_(!original_working_dir_.IsEmpty())
00646 << "Failed to get the current working directory.";
00647 }
00648
00649 GetTestCase(test_info->test_case_name(),
00650 test_info->type_param(),
00651 set_up_tc,
00652 tear_down_tc)->AddTestInfo(test_info);
00653 }
00654
00655 #if GTEST_HAS_PARAM_TEST
00656
00657
00658 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
00659 return parameterized_test_registry_;
00660 }
00661 #endif // GTEST_HAS_PARAM_TEST
00662
00663
00664 void set_current_test_case(TestCase* a_current_test_case) {
00665 current_test_case_ = a_current_test_case;
00666 }
00667
00668
00669
00670
00671 void set_current_test_info(TestInfo* a_current_test_info) {
00672 current_test_info_ = a_current_test_info;
00673 }
00674
00675
00676
00677
00678
00679
00680
00681 void RegisterParameterizedTests();
00682
00683
00684
00685
00686
00687 bool RunAllTests();
00688
00689
00690 void ClearNonAdHocTestResult() {
00691 ForEach(test_cases_, TestCase::ClearTestCaseResult);
00692 }
00693
00694
00695 void ClearAdHocTestResult() {
00696 ad_hoc_test_result_.Clear();
00697 }
00698
00699 enum ReactionToSharding {
00700 HONOR_SHARDING_PROTOCOL,
00701 IGNORE_SHARDING_PROTOCOL
00702 };
00703
00704
00705
00706
00707
00708
00709
00710 int FilterTests(ReactionToSharding shard_tests);
00711
00712
00713 void ListTestsMatchingFilter();
00714
00715 const TestCase* current_test_case() const { return current_test_case_; }
00716 TestInfo* current_test_info() { return current_test_info_; }
00717 const TestInfo* current_test_info() const { return current_test_info_; }
00718
00719
00720
00721 std::vector<Environment*>& environments() { return environments_; }
00722
00723
00724 std::vector<TraceInfo>& gtest_trace_stack() {
00725 return *(gtest_trace_stack_.pointer());
00726 }
00727 const std::vector<TraceInfo>& gtest_trace_stack() const {
00728 return gtest_trace_stack_.get();
00729 }
00730
00731 #if GTEST_HAS_DEATH_TEST
00732 void InitDeathTestSubprocessControlInfo() {
00733 internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
00734 }
00735
00736
00737
00738
00739 const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
00740 return internal_run_death_test_flag_.get();
00741 }
00742
00743
00744 internal::DeathTestFactory* death_test_factory() {
00745 return death_test_factory_.get();
00746 }
00747
00748 void SuppressTestEventsIfInSubprocess();
00749
00750 friend class ReplaceDeathTestFactory;
00751 #endif // GTEST_HAS_DEATH_TEST
00752
00753
00754
00755 void ConfigureXmlOutput();
00756
00757 #if GTEST_CAN_STREAM_RESULTS_
00758
00759
00760 void ConfigureStreamingOutput();
00761 #endif
00762
00763
00764
00765
00766
00767
00768 void PostFlagParsingInit();
00769
00770
00771 int random_seed() const { return random_seed_; }
00772
00773
00774 internal::Random* random() { return &random_; }
00775
00776
00777
00778 void ShuffleTests();
00779
00780
00781 void UnshuffleTests();
00782
00783
00784
00785 bool catch_exceptions() const { return catch_exceptions_; }
00786
00787 private:
00788 friend class ::testing::UnitTest;
00789
00790
00791
00792 void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
00793
00794
00795 UnitTest* const parent_;
00796
00797
00798
00799 internal::FilePath original_working_dir_;
00800
00801
00802 DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
00803 DefaultPerThreadTestPartResultReporter
00804 default_per_thread_test_part_result_reporter_;
00805
00806
00807 TestPartResultReporterInterface* global_test_part_result_repoter_;
00808
00809
00810 internal::Mutex global_test_part_result_reporter_mutex_;
00811
00812
00813 internal::ThreadLocal<TestPartResultReporterInterface*>
00814 per_thread_test_part_result_reporter_;
00815
00816
00817
00818 std::vector<Environment*> environments_;
00819
00820
00821
00822 std::vector<TestCase*> test_cases_;
00823
00824
00825
00826
00827
00828 std::vector<int> test_case_indices_;
00829
00830 #if GTEST_HAS_PARAM_TEST
00831
00832
00833 internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
00834
00835
00836 bool parameterized_tests_registered_;
00837 #endif // GTEST_HAS_PARAM_TEST
00838
00839
00840 int last_death_test_case_;
00841
00842
00843
00844
00845
00846 TestCase* current_test_case_;
00847
00848
00849
00850
00851
00852 TestInfo* current_test_info_;
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862 TestResult ad_hoc_test_result_;
00863
00864
00865
00866 TestEventListeners listeners_;
00867
00868
00869
00870
00871
00872 OsStackTraceGetterInterface* os_stack_trace_getter_;
00873
00874
00875 bool post_flag_parse_init_performed_;
00876
00877
00878 int random_seed_;
00879
00880
00881 internal::Random random_;
00882
00883
00884 TimeInMillis elapsed_time_;
00885
00886 #if GTEST_HAS_DEATH_TEST
00887
00888
00889 internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
00890 internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
00891 #endif // GTEST_HAS_DEATH_TEST
00892
00893
00894 internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
00895
00896
00897
00898 bool catch_exceptions_;
00899
00900 GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
00901 };
00902
00903
00904
00905 inline UnitTestImpl* GetUnitTestImpl() {
00906 return UnitTest::GetInstance()->impl();
00907 }
00908
00909 #if GTEST_USES_SIMPLE_RE
00910
00911
00912
00913 GTEST_API_ bool IsInSet(char ch, const char* str);
00914 GTEST_API_ bool IsAsciiDigit(char ch);
00915 GTEST_API_ bool IsAsciiPunct(char ch);
00916 GTEST_API_ bool IsRepeat(char ch);
00917 GTEST_API_ bool IsAsciiWhiteSpace(char ch);
00918 GTEST_API_ bool IsAsciiWordChar(char ch);
00919 GTEST_API_ bool IsValidEscape(char ch);
00920 GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
00921 GTEST_API_ bool ValidateRegex(const char* regex);
00922 GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
00923 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
00924 bool escaped, char ch, char repeat, const char* regex, const char* str);
00925 GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
00926
00927 #endif // GTEST_USES_SIMPLE_RE
00928
00929
00930
00931 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
00932 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
00933
00934 #if GTEST_HAS_DEATH_TEST
00935
00936
00937
00938 GTEST_API_ String GetLastErrnoDescription();
00939
00940 # if GTEST_OS_WINDOWS
00941
00942 class AutoHandle {
00943 public:
00944 AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
00945 explicit AutoHandle(HANDLE handle) : handle_(handle) {}
00946
00947 ~AutoHandle() { Reset(); }
00948
00949 HANDLE Get() const { return handle_; }
00950 void Reset() { Reset(INVALID_HANDLE_VALUE); }
00951 void Reset(HANDLE handle) {
00952 if (handle != handle_) {
00953 if (handle_ != INVALID_HANDLE_VALUE)
00954 ::CloseHandle(handle_);
00955 handle_ = handle;
00956 }
00957 }
00958
00959 private:
00960 HANDLE handle_;
00961
00962 GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
00963 };
00964 # endif // GTEST_OS_WINDOWS
00965
00966
00967
00968
00969
00970 template <typename Integer>
00971 bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
00972
00973
00974
00975 if (str.empty() || !IsDigit(str[0])) {
00976 return false;
00977 }
00978 errno = 0;
00979
00980 char* end;
00981
00982
00983
00984 # if GTEST_OS_WINDOWS && !defined(__GNUC__)
00985
00986
00987 typedef unsigned __int64 BiggestConvertible;
00988 const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
00989
00990 # else
00991
00992 typedef unsigned long long BiggestConvertible;
00993 const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
00994
00995 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
00996
00997 const bool parse_success = *end == '\0' && errno == 0;
00998
00999
01000
01001 GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
01002
01003 const Integer result = static_cast<Integer>(parsed);
01004 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
01005 *number = result;
01006 return true;
01007 }
01008 return false;
01009 }
01010 #endif // GTEST_HAS_DEATH_TEST
01011
01012
01013
01014
01015
01016
01017
01018 class TestResultAccessor {
01019 public:
01020 static void RecordProperty(TestResult* test_result,
01021 const TestProperty& property) {
01022 test_result->RecordProperty(property);
01023 }
01024
01025 static void ClearTestPartResults(TestResult* test_result) {
01026 test_result->ClearTestPartResults();
01027 }
01028
01029 static const std::vector<testing::TestPartResult>& test_part_results(
01030 const TestResult& test_result) {
01031 return test_result.test_part_results();
01032 }
01033 };
01034
01035 }
01036 }
01037
01038 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_