Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: base/test/test_suite.cc

Issue 645133002: Prefix CommandLine usege with base namespace (Part 1: base/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated #3 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_util_unittest.cc ('k') | base/test/test_timeouts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/test_suite.h" 5 #include "base/test/test_suite.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) 51 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info))
52 << "Probably the OS #ifdefs don't include all of the necessary " 52 << "Probably the OS #ifdefs don't include all of the necessary "
53 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " 53 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix "
54 "after the code is preprocessed."; 54 "after the code is preprocessed.";
55 } 55 }
56 }; 56 };
57 57
58 class TestClientInitializer : public testing::EmptyTestEventListener { 58 class TestClientInitializer : public testing::EmptyTestEventListener {
59 public: 59 public:
60 TestClientInitializer() 60 TestClientInitializer()
61 : old_command_line_(CommandLine::NO_PROGRAM) { 61 : old_command_line_(base::CommandLine::NO_PROGRAM) {
62 } 62 }
63 63
64 virtual void OnTestStart(const testing::TestInfo& test_info) override { 64 virtual void OnTestStart(const testing::TestInfo& test_info) override {
65 old_command_line_ = *CommandLine::ForCurrentProcess(); 65 old_command_line_ = *base::CommandLine::ForCurrentProcess();
66 } 66 }
67 67
68 virtual void OnTestEnd(const testing::TestInfo& test_info) override { 68 virtual void OnTestEnd(const testing::TestInfo& test_info) override {
69 *CommandLine::ForCurrentProcess() = old_command_line_; 69 *base::CommandLine::ForCurrentProcess() = old_command_line_;
70 } 70 }
71 71
72 private: 72 private:
73 CommandLine old_command_line_; 73 base::CommandLine old_command_line_;
74 74
75 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); 75 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer);
76 }; 76 };
77 77
78 } // namespace 78 } // namespace
79 79
80 namespace base { 80 namespace base {
81 81
82 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { 82 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) {
83 TestSuite test_suite(argc, argv); 83 TestSuite test_suite(argc, argv);
(...skipping 17 matching lines...) Expand all
101 #endif // defined(OS_WIN) 101 #endif // defined(OS_WIN)
102 102
103 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) 103 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager)
104 : initialized_command_line_(false) { 104 : initialized_command_line_(false) {
105 PreInitialize(create_at_exit_manager); 105 PreInitialize(create_at_exit_manager);
106 InitializeFromCommandLine(argc, argv); 106 InitializeFromCommandLine(argc, argv);
107 } 107 }
108 108
109 TestSuite::~TestSuite() { 109 TestSuite::~TestSuite() {
110 if (initialized_command_line_) 110 if (initialized_command_line_)
111 CommandLine::Reset(); 111 base::CommandLine::Reset();
112 } 112 }
113 113
114 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { 114 void TestSuite::InitializeFromCommandLine(int argc, char** argv) {
115 initialized_command_line_ = CommandLine::Init(argc, argv); 115 initialized_command_line_ = base::CommandLine::Init(argc, argv);
116 testing::InitGoogleTest(&argc, argv); 116 testing::InitGoogleTest(&argc, argv);
117 testing::InitGoogleMock(&argc, argv); 117 testing::InitGoogleMock(&argc, argv);
118 118
119 #if defined(OS_IOS) 119 #if defined(OS_IOS)
120 InitIOSRunHook(this, argc, argv); 120 InitIOSRunHook(this, argc, argv);
121 #endif 121 #endif
122 } 122 }
123 123
124 #if defined(OS_WIN) 124 #if defined(OS_WIN)
125 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { 125 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) {
126 // Windows CommandLine::Init ignores argv anyway. 126 // Windows CommandLine::Init ignores argv anyway.
127 initialized_command_line_ = CommandLine::Init(argc, NULL); 127 initialized_command_line_ = base::CommandLine::Init(argc, NULL);
128 testing::InitGoogleTest(&argc, argv); 128 testing::InitGoogleTest(&argc, argv);
129 testing::InitGoogleMock(&argc, argv); 129 testing::InitGoogleMock(&argc, argv);
130 } 130 }
131 #endif // defined(OS_WIN) 131 #endif // defined(OS_WIN)
132 132
133 void TestSuite::PreInitialize(bool create_at_exit_manager) { 133 void TestSuite::PreInitialize(bool create_at_exit_manager) {
134 #if defined(OS_WIN) 134 #if defined(OS_WIN)
135 testing::GTEST_FLAG(catch_exceptions) = false; 135 testing::GTEST_FLAG(catch_exceptions) = false;
136 #endif 136 #endif
137 base::EnableTerminationOnHeapCorruption(); 137 base::EnableTerminationOnHeapCorruption();
(...skipping 29 matching lines...) Expand all
167 167
168 void TestSuite::ResetCommandLine() { 168 void TestSuite::ResetCommandLine() {
169 testing::TestEventListeners& listeners = 169 testing::TestEventListeners& listeners =
170 testing::UnitTest::GetInstance()->listeners(); 170 testing::UnitTest::GetInstance()->listeners();
171 listeners.Append(new TestClientInitializer); 171 listeners.Append(new TestClientInitializer);
172 } 172 }
173 173
174 #if !defined(OS_IOS) 174 #if !defined(OS_IOS)
175 void TestSuite::AddTestLauncherResultPrinter() { 175 void TestSuite::AddTestLauncherResultPrinter() {
176 // Only add the custom printer if requested. 176 // Only add the custom printer if requested.
177 if (!CommandLine::ForCurrentProcess()->HasSwitch( 177 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
178 switches::kTestLauncherOutput)) { 178 switches::kTestLauncherOutput)) {
179 return; 179 return;
180 } 180 }
181 181
182 FilePath output_path(CommandLine::ForCurrentProcess()->GetSwitchValuePath( 182 FilePath output_path(base::CommandLine::ForCurrentProcess()->
183 switches::kTestLauncherOutput)); 183 GetSwitchValuePath(switches::kTestLauncherOutput));
184 184
185 // Do not add the result printer if output path already exists. It's an 185 // Do not add the result printer if output path already exists. It's an
186 // indicator there is a process printing to that file, and we're likely 186 // indicator there is a process printing to that file, and we're likely
187 // its child. Do not clobber the results in that case. 187 // its child. Do not clobber the results in that case.
188 if (PathExists(output_path)) { 188 if (PathExists(output_path)) {
189 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() 189 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe()
190 << " exists. Not adding test launcher result printer."; 190 << " exists. Not adding test launcher result printer.";
191 return; 191 return;
192 } 192 }
193 193
(...skipping 11 matching lines...) Expand all
205 #if defined(OS_IOS) 205 #if defined(OS_IOS)
206 RunTestsFromIOSApp(); 206 RunTestsFromIOSApp();
207 #endif 207 #endif
208 208
209 #if defined(OS_MACOSX) 209 #if defined(OS_MACOSX)
210 base::mac::ScopedNSAutoreleasePool scoped_pool; 210 base::mac::ScopedNSAutoreleasePool scoped_pool;
211 #endif 211 #endif
212 212
213 Initialize(); 213 Initialize();
214 std::string client_func = 214 std::string client_func =
215 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 215 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
216 switches::kTestChildProcess); 216 switches::kTestChildProcess);
217 217
218 // Check to see if we are being run as a client process. 218 // Check to see if we are being run as a client process.
219 if (!client_func.empty()) 219 if (!client_func.empty())
220 return multi_process_function_list::InvokeChildProcessTest(client_func); 220 return multi_process_function_list::InvokeChildProcessTest(client_func);
221 #if defined(OS_IOS) 221 #if defined(OS_IOS)
222 base::test_listener_ios::RegisterTestEndListener(); 222 base::test_listener_ios::RegisterTestEndListener();
223 #endif 223 #endif
224 int result = RUN_ALL_TESTS(); 224 int result = RUN_ALL_TESTS();
225 225
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 CHECK(base::debug::EnableInProcessStackDumping()); 309 CHECK(base::debug::EnableInProcessStackDumping());
310 #if defined(OS_WIN) 310 #if defined(OS_WIN)
311 // Make sure we run with high resolution timer to minimize differences 311 // Make sure we run with high resolution timer to minimize differences
312 // between production code and test code. 312 // between production code and test code.
313 base::Time::EnableHighResolutionTimer(true); 313 base::Time::EnableHighResolutionTimer(true);
314 #endif // defined(OS_WIN) 314 #endif // defined(OS_WIN)
315 315
316 // In some cases, we do not want to see standard error dialogs. 316 // In some cases, we do not want to see standard error dialogs.
317 if (!base::debug::BeingDebugged() && 317 if (!base::debug::BeingDebugged() &&
318 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { 318 !base::CommandLine::ForCurrentProcess()->HasSwitch(
319 "show-error-dialogs")) {
319 SuppressErrorDialogs(); 320 SuppressErrorDialogs();
320 base::debug::SetSuppressDebugUI(true); 321 base::debug::SetSuppressDebugUI(true);
321 logging::SetLogAssertHandler(UnitTestAssertHandler); 322 logging::SetLogAssertHandler(UnitTestAssertHandler);
322 } 323 }
323 324
324 base::i18n::InitializeICU(); 325 base::i18n::InitializeICU();
325 326
326 CatchMaybeTests(); 327 CatchMaybeTests();
327 ResetCommandLine(); 328 ResetCommandLine();
328 #if !defined(OS_IOS) 329 #if !defined(OS_IOS)
329 AddTestLauncherResultPrinter(); 330 AddTestLauncherResultPrinter();
330 #endif // !defined(OS_IOS) 331 #endif // !defined(OS_IOS)
331 332
332 TestTimeouts::Initialize(); 333 TestTimeouts::Initialize();
333 334
334 trace_to_file_.BeginTracingFromCommandLineOptions(); 335 trace_to_file_.BeginTracingFromCommandLineOptions();
335 } 336 }
336 337
337 void TestSuite::Shutdown() { 338 void TestSuite::Shutdown() {
338 } 339 }
OLDNEW
« no previous file with comments | « base/process/process_util_unittest.cc ('k') | base/test/test_timeouts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698