diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 05:53:57 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 05:53:57 +0000 |
commit | 4d9bdfafcd1393385860bc9fe947e0c07719c0f4 (patch) | |
tree | 67c91c3fa4c658352995e22b894535e60b04f282 /base/test_suite.h | |
parent | 3c17b9c00d5fc28f5523ab60b0df502dd7c2a596 (diff) | |
download | chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.zip chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.tar.gz chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.tar.bz2 |
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
Diffstat (limited to 'base/test_suite.h')
-rw-r--r-- | base/test_suite.h | 34 |
1 files changed, 19 insertions, 15 deletions
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_ |