From 4d9bdfafcd1393385860bc9fe947e0c07719c0f4 Mon Sep 17 00:00:00 2001 From: "darin@google.com" Date: Tue, 26 Aug 2008 05:53:57 +0000 Subject: Allow consumers of MessageLoop to specify the type of MessageLoop they want. This CL introduces a Type enum to MessageLoop, and I also created subclasses of MessageLoop corresponding to the non-default types: MessageLoopForIO and MessageLoopForUI. I moved all of the platform-specific MessageLoop APIs onto either MessageLoopForIO or MessageLoopForUI. MessageLoopForIO gets the Watcher API, and MessageLoopForUI gets the Observer and Dispatcher APIs. Under the hood, both are implemented in terms of MessagePumpWin, but that will change in a future CL. The Thread class is changed to allow the consumer to specify the Type of MessageLoop they want to have setup on the created thread. I re-organized message_loop_unittest.cc and timer_unittest.cc so that I could exercise all (or most) of the tests against each type of MessageLoop. Note: I know that "explicit MessageLoop(Type type = TYPE_DEFAULT);" is in violation to the style-guide's restriction against default arguments. I'm working on finding a decent solution to that problem. Please ignore this issue for now. The corresponding chrome/ changes are coming in a separate CL due to Reitveld data size limitations. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1362 0039d316-1c4b-4281-b951-d872f2087c98 --- base/test_suite.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'base/test_suite.h') diff --git a/base/test_suite.h b/base/test_suite.h index 8a163ec..ae5faf1 100644 --- a/base/test_suite.h +++ b/base/test_suite.h @@ -9,13 +9,11 @@ // instantiate this class in your main function and call its Run method to run // any gtest based tests that are linked into your executable. -#include "build/build_config.h" - +#include "base/at_exit.h" #include "base/command_line.h" #include "base/debug_on_start.h" #include "base/icu_util.h" #include "base/logging.h" -#include "base/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_WIN) @@ -26,23 +24,18 @@ class TestSuite { public: TestSuite(int argc, char** argv) { + CommandLine::SetArgcArgv(argc, argv); testing::InitGoogleTest(&argc, argv); } - virtual ~TestSuite() { - // Flush any remaining messages. This ensures that any accumulated Task - // objects get destroyed before we exit, which avoids noise in purify - // leak-test results. - message_loop_.RunAllPending(); - } + virtual ~TestSuite() {} int Run() { Initialize(); #if defined(OS_WIN) // Check to see if we are being run as a client process. - std::wstring client_func = - parsed_command_line_.GetSwitchValue(kRunClientProcess); + std::wstring client_func = CommandLine().GetSwitchValue(kRunClientProcess); if (!client_func.empty()) { // Convert our function name to a usable string for GetProcAddress. std::string func_name(client_func.begin(), client_func.end()); @@ -57,7 +50,11 @@ class TestSuite { return -1; } #endif - return RUN_ALL_TESTS(); + + int result = RUN_ALL_TESTS(); + + Shutdown(); + return result; } protected: @@ -80,11 +77,14 @@ class TestSuite { } #endif + // Override these for custom initialization and shutdown handling. Use these + // instead of putting complex code in your constructor/destructor. + virtual void Initialize() { #if defined(OS_WIN) // In some cases, we do not want to see standard error dialogs. if (!IsDebuggerPresent() && - !parsed_command_line_.HasSwitch(L"show-error-dialogs")) { + !CommandLine().HasSwitch(L"show-error-dialogs")) { SuppressErrorDialogs(); logging::SetLogAssertHandler(UnitTestAssertHandler); } @@ -93,8 +93,12 @@ class TestSuite { icu_util::Initialize(); } - CommandLine parsed_command_line_; - MessageLoop message_loop_; + virtual void Shutdown() { + } + + // Make sure that we setup an AtExitManager so Singleton objects will be + // destroyed. + base::AtExitManager at_exit_manager_; }; #endif // BASE_TEST_SUITE_H_ -- cgit v1.1