| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 981d57e commit 301541c
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1262,6 +1262,20 @@ class GTEST_API_ UnitTest { | |||
| 1262 | 1262 | // total_test_suite_count() - 1. If i is not in that range, returns NULL. | |
| 1263 | 1263 | TestSuite* GetMutableTestSuite(int i); | |
| 1264 | 1264 | ||
| 1265 | + // Invokes OsStackTrackGetterInterface::UponLeavingGTest. UponLeavingGTest() | ||
| 1266 | + // should be called immediately before Google Test calls user code. It saves | ||
| 1267 | + // some information about the current stack that CurrentStackTrace() will use | ||
| 1268 | + // to find and hide Google Test stack frames. | ||
| 1269 | + void UponLeavingGTest(); | ||
| 1270 | + | ||
| 1271 | + // Sets the TestSuite object for the test that's currently running. | ||
| 1272 | + void set_current_test_suite(TestSuite* a_current_test_suite) | ||
| 1273 | + GTEST_LOCK_EXCLUDED_(mutex_); | ||
| 1274 | + | ||
| 1275 | + // Sets the TestInfo object for the test that's currently running. | ||
| 1276 | + void set_current_test_info(TestInfo* a_current_test_info) | ||
| 1277 | + GTEST_LOCK_EXCLUDED_(mutex_); | ||
| 1278 | + | ||
| 1265 | 1279 | // Accessors for the implementation object. | |
| 1266 | 1280 | internal::UnitTestImpl* impl() { return impl_; } | |
| 1267 | 1281 | const internal::UnitTestImpl* impl() const { return impl_; } | |
@@ -1270,6 +1284,8 @@ class GTEST_API_ UnitTest { | |||
| 1270 | 1284 | // members of UnitTest. | |
| 1271 | 1285 | friend class ScopedTrace; | |
| 1272 | 1286 | friend class Test; | |
| 1287 | + friend class TestInfo; | ||
| 1288 | + friend class TestSuite; | ||
| 1273 | 1289 | friend class internal::AssertHelper; | |
| 1274 | 1290 | friend class internal::StreamingListenerTest; | |
| 1275 | 1291 | friend class internal::UnitTestRecordPropertyTestHelper; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -630,13 +630,13 @@ bool DeathTestImpl::Passed(bool status_ok) { | |||
| 630 | 630 | #ifndef GTEST_OS_WINDOWS | |
| 631 | 631 | // Note: The return value points into args, so the return value's lifetime is | |
| 632 | 632 | // bound to that of args. | |
| 633 | - static std::unique_ptr<char*[]> CreateArgvFromArgs( | ||
| 634 | - std::vector<std::string>& args) { | ||
| 635 | - auto result = std::make_unique<char*[]>(args.size() + 1); | ||
| 636 | - for (size_t i = 0; i < args.size(); ++i) { | ||
| 637 | - result[i] = &args[i][0]; | ||
| 633 | + static std::vector<char*> CreateArgvFromArgs(std::vector<std::string>& args) { | ||
| 634 | + std::vector<char*> result; | ||
| 635 | + result.reserve(args.size() + 1); | ||
| 636 | + for (auto& arg : args) { | ||
| 637 | + result.push_back(&arg[0]); | ||
| 638 | 638 | } | |
| 639 | - result[args.size()] = nullptr; // extra null terminator | ||
| 639 | + result.push_back(nullptr); // Extra null terminator. | ||
| 640 | 640 | return result; | |
| 641 | 641 | } | |
| 642 | 642 | #endif | |
@@ -1036,8 +1036,8 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { | |||
| 1036 | 1036 | // "Fuchsia Test Component" which contains a "Fuchsia Component Manifest") | |
| 1037 | 1037 | // Launching processes is a privileged operation in Fuchsia, and the | |
| 1038 | 1038 | // declaration indicates that the ability is required for the component. | |
| 1039 | - std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args); | ||
| 1040 | - status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(), | ||
| 1039 | + std::vector<char*> argv = CreateArgvFromArgs(args); | ||
| 1040 | + status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.data(), | ||
| 1041 | 1041 | nullptr, 2, spawn_actions, | |
| 1042 | 1042 | child_process_.reset_and_get_address(), nullptr); | |
| 1043 | 1043 | GTEST_DEATH_TEST_CHECK_(status == ZX_OK); | |
@@ -1388,8 +1388,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { | |||
| 1388 | 1388 | // is necessary. | |
| 1389 | 1389 | FlushInfoLog(); | |
| 1390 | 1390 | ||
| 1391 | - std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args); | ||
| 1392 | - const pid_t child_pid = ExecDeathTestSpawnChild(argv.get(), pipe_fd[0]); | ||
| 1391 | + std::vector<char*> argv = CreateArgvFromArgs(args); | ||
| 1392 | + const pid_t child_pid = ExecDeathTestSpawnChild(argv.data(), pipe_fd[0]); | ||
| 1393 | 1393 | GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); | |
| 1394 | 1394 | set_child_pid(child_pid); | |
| 1395 | 1395 | set_read_fd(pipe_fd[0]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -709,18 +709,6 @@ class GTEST_API_ UnitTestImpl { | |||
| 709 | 709 | return type_parameterized_test_registry_; | |
| 710 | 710 | } | |
| 711 | 711 | ||
| 712 | - // Sets the TestSuite object for the test that's currently running. | ||
| 713 | - void set_current_test_suite(TestSuite* a_current_test_suite) { | ||
| 714 | - current_test_suite_ = a_current_test_suite; | ||
| 715 | - } | ||
| 716 | - | ||
| 717 | - // Sets the TestInfo object for the test that's currently running. If | ||
| 718 | - // current_test_info is NULL, the assertion results will be stored in | ||
| 719 | - // ad_hoc_test_result_. | ||
| 720 | - void set_current_test_info(TestInfo* a_current_test_info) { | ||
| 721 | - current_test_info_ = a_current_test_info; | ||
| 722 | - } | ||
| 723 | - | ||
| 724 | 712 | // Registers all parameterized tests defined using TEST_P and | |
| 725 | 713 | // INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter | |
| 726 | 714 | // combination. This method can be called more then once; it has guards | |
@@ -841,6 +829,18 @@ class GTEST_API_ UnitTestImpl { | |||
| 841 | 829 | // GTEST_FLAG(catch_exceptions) at the moment it starts. | |
| 842 | 830 | void set_catch_exceptions(bool value) { catch_exceptions_ = value; } | |
| 843 | 831 | ||
| 832 | + // Sets the TestSuite object for the test that's currently running. | ||
| 833 | + void set_current_test_suite(TestSuite* a_current_test_suite) { | ||
| 834 | + current_test_suite_ = a_current_test_suite; | ||
| 835 | + } | ||
| 836 | + | ||
| 837 | + // Sets the TestInfo object for the test that's currently running. If | ||
| 838 | + // current_test_info is NULL, the assertion results will be stored in | ||
| 839 | + // ad_hoc_test_result_. | ||
| 840 | + void set_current_test_info(TestInfo* a_current_test_info) { | ||
| 841 | + current_test_info_ = a_current_test_info; | ||
| 842 | + } | ||
| 843 | + | ||
| 844 | 844 | // The UnitTest object that owns this implementation object. | |
| 845 | 845 | UnitTest* const parent_; | |
| 846 | 846 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2836,14 +2836,13 @@ void TestInfo::Run() { | |||
| 2836 | 2836 | } | |
| 2837 | 2837 | ||
| 2838 | 2838 | // Tells UnitTest where to store test result. | |
| 2839 | - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); | ||
| 2840 | - impl->set_current_test_info(this); | ||
| 2839 | + UnitTest::GetInstance()->set_current_test_info(this); | ||
| 2841 | 2840 | ||
| 2842 | 2841 | // Notifies the unit test event listeners that a test is about to start. | |
| 2843 | 2842 | repeater->OnTestStart(*this); | |
| 2844 | 2843 | result_.set_start_timestamp(internal::GetTimeInMillis()); | |
| 2845 | 2844 | internal::Timer timer; | |
| 2846 | - impl->os_stack_trace_getter()->UponLeavingGTest(); | ||
| 2845 | + UnitTest::GetInstance()->UponLeavingGTest(); | ||
| 2847 | 2846 | ||
| 2848 | 2847 | // Creates the test object. | |
| 2849 | 2848 | Test* const test = internal::HandleExceptionsInMethodIfSupported( | |
@@ -2861,7 +2860,7 @@ void TestInfo::Run() { | |||
| 2861 | 2860 | ||
| 2862 | 2861 | if (test != nullptr) { | |
| 2863 | 2862 | // Deletes the test object. | |
| 2864 | - impl->os_stack_trace_getter()->UponLeavingGTest(); | ||
| 2863 | + UnitTest::GetInstance()->UponLeavingGTest(); | ||
| 2865 | 2864 | internal::HandleExceptionsInMethodIfSupported( | |
| 2866 | 2865 | test, &Test::DeleteSelf_, "the test fixture's destructor"); | |
| 2867 | 2866 | } | |
@@ -2873,15 +2872,14 @@ void TestInfo::Run() { | |||
| 2873 | 2872 | ||
| 2874 | 2873 | // Tells UnitTest to stop associating assertion results to this | |
| 2875 | 2874 | // test. | |
| 2876 | - impl->set_current_test_info(nullptr); | ||
| 2875 | + UnitTest::GetInstance()->set_current_test_info(nullptr); | ||
| 2877 | 2876 | } | |
| 2878 | 2877 | ||
| 2879 | 2878 | // Skip and records a skipped test result for this object. | |
| 2880 | 2879 | void TestInfo::Skip() { | |
| 2881 | 2880 | if (!should_run_) return; | |
| 2882 | 2881 | ||
| 2883 | - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); | ||
| 2884 | - impl->set_current_test_info(this); | ||
| 2882 | + UnitTest::GetInstance()->set_current_test_info(this); | ||
| 2885 | 2883 | ||
| 2886 | 2884 | TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); | |
| 2887 | 2885 | ||
@@ -2890,12 +2888,13 @@ void TestInfo::Skip() { | |||
| 2890 | 2888 | ||
| 2891 | 2889 | const TestPartResult test_part_result = | |
| 2892 | 2890 | TestPartResult(TestPartResult::kSkip, this->file(), this->line(), ""); | |
| 2893 | - impl->GetTestPartResultReporterForCurrentThread()->ReportTestPartResult( | ||
| 2894 | - test_part_result); | ||
| 2891 | + internal::GetUnitTestImpl() | ||
| 2892 | + ->GetTestPartResultReporterForCurrentThread() | ||
| 2893 | + ->ReportTestPartResult(test_part_result); | ||
| 2895 | 2894 | ||
| 2896 | 2895 | // Notifies the unit test event listener that a test has just finished. | |
| 2897 | 2896 | repeater->OnTestEnd(*this); | |
| 2898 | - impl->set_current_test_info(nullptr); | ||
| 2897 | + UnitTest::GetInstance()->set_current_test_info(nullptr); | ||
| 2899 | 2898 | } | |
| 2900 | 2899 | ||
| 2901 | 2900 | // class TestSuite | |
@@ -2991,8 +2990,7 @@ void TestSuite::AddTestInfo(TestInfo* test_info) { | |||
| 2991 | 2990 | void TestSuite::Run() { | |
| 2992 | 2991 | if (!should_run_) return; | |
| 2993 | 2992 | ||
| 2994 | - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); | ||
| 2995 | - impl->set_current_test_suite(this); | ||
| 2993 | + UnitTest::GetInstance()->set_current_test_suite(this); | ||
| 2996 | 2994 | ||
| 2997 | 2995 | TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); | |
| 2998 | 2996 | ||
@@ -3022,7 +3020,7 @@ void TestSuite::Run() { | |||
| 3022 | 3020 | repeater->OnTestCaseStart(*this); | |
| 3023 | 3021 | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| 3024 | 3022 | ||
| 3025 | - impl->os_stack_trace_getter()->UponLeavingGTest(); | ||
| 3023 | + UnitTest::GetInstance()->UponLeavingGTest(); | ||
| 3026 | 3024 | internal::HandleExceptionsInMethodIfSupported( | |
| 3027 | 3025 | this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()"); | |
| 3028 | 3026 | ||
@@ -3047,7 +3045,7 @@ void TestSuite::Run() { | |||
| 3047 | 3045 | } | |
| 3048 | 3046 | elapsed_time_ = timer.Elapsed(); | |
| 3049 | 3047 | ||
| 3050 | - impl->os_stack_trace_getter()->UponLeavingGTest(); | ||
| 3048 | + UnitTest::GetInstance()->UponLeavingGTest(); | ||
| 3051 | 3049 | internal::HandleExceptionsInMethodIfSupported( | |
| 3052 | 3050 | this, &TestSuite::RunTearDownTestSuite, "TearDownTestSuite()"); | |
| 3053 | 3051 | ||
@@ -3058,15 +3056,14 @@ void TestSuite::Run() { | |||
| 3058 | 3056 | repeater->OnTestCaseEnd(*this); | |
| 3059 | 3057 | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| 3060 | 3058 | ||
| 3061 | - impl->set_current_test_suite(nullptr); | ||
| 3059 | + UnitTest::GetInstance()->set_current_test_suite(nullptr); | ||
| 3062 | 3060 | } | |
| 3063 | 3061 | ||
| 3064 | 3062 | // Skips all tests under this TestSuite. | |
| 3065 | 3063 | void TestSuite::Skip() { | |
| 3066 | 3064 | if (!should_run_) return; | |
| 3067 | 3065 | ||
| 3068 | - internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); | ||
| 3069 | - impl->set_current_test_suite(this); | ||
| 3066 | + UnitTest::GetInstance()->set_current_test_suite(this); | ||
| 3070 | 3067 | ||
| 3071 | 3068 | TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); | |
| 3072 | 3069 | ||
@@ -3088,7 +3085,7 @@ void TestSuite::Skip() { | |||
| 3088 | 3085 | repeater->OnTestCaseEnd(*this); | |
| 3089 | 3086 | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |
| 3090 | 3087 | ||
| 3091 | - impl->set_current_test_suite(nullptr); | ||
| 3088 | + UnitTest::GetInstance()->set_current_test_suite(nullptr); | ||
| 3092 | 3089 | } | |
| 3093 | 3090 | ||
| 3094 | 3091 | // Clears the results of all tests in this test suite. | |
@@ -5304,6 +5301,22 @@ TestSuite* UnitTest::GetMutableTestSuite(int i) { | |||
| 5304 | 5301 | return impl()->GetMutableSuiteCase(i); | |
| 5305 | 5302 | } | |
| 5306 | 5303 | ||
| 5304 | + void UnitTest::UponLeavingGTest() { | ||
| 5305 | + impl()->os_stack_trace_getter()->UponLeavingGTest(); | ||
| 5306 | + } | ||
| 5307 | + | ||
| 5308 | + // Sets the TestSuite object for the test that's currently running. | ||
| 5309 | + void UnitTest::set_current_test_suite(TestSuite* a_current_test_suite) { | ||
| 5310 | + internal::MutexLock lock(&mutex_); | ||
| 5311 | + impl_->set_current_test_suite(a_current_test_suite); | ||
| 5312 | + } | ||
| 5313 | + | ||
| 5314 | + // Sets the TestInfo object for the test that's currently running. | ||
| 5315 | + void UnitTest::set_current_test_info(TestInfo* a_current_test_info) { | ||
| 5316 | + internal::MutexLock lock(&mutex_); | ||
| 5317 | + impl_->set_current_test_info(a_current_test_info); | ||
| 5318 | + } | ||
| 5319 | + | ||
| 5307 | 5320 | // Returns the list of event listeners that can be used to track events | |
| 5308 | 5321 | // inside Google Test. | |
| 5309 | 5322 | TestEventListeners& UnitTest::listeners() { return *impl()->listeners(); } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments