| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_TEST_SUITE_H_ | 5 #ifndef BASE_TEST_SUITE_H_ |
| 6 #define BASE_TEST_SUITE_H_ | 6 #define BASE_TEST_SUITE_H_ |
| 7 | 7 |
| 8 // Defines a basic test suite framework for running gtest based tests. You can | 8 // Defines a basic test suite framework for running gtest based tests. You can |
| 9 // instantiate this class in your main function and call its Run method to run | 9 // instantiate this class in your main function and call its Run method to run |
| 10 // any gtest based tests that are linked into your executable. | 10 // any gtest based tests that are linked into your executable. |
| 11 | 11 |
| 12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug_on_start.h" | 14 #include "base/debug_on_start.h" |
| 15 #include "base/icu_util.h" | 15 #include "base/icu_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/multiprocess_test.h" | 17 #include "base/multiprocess_test.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "testing/multiprocess_func_list.h" |
| 19 | 20 |
| 20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 21 #include <windows.h> | 22 #include <windows.h> |
| 22 #include "base/multiprocess_test.h" | |
| 23 #elif defined(OS_LINUX) | 23 #elif defined(OS_LINUX) |
| 24 #include <dlfcn.h> | |
| 25 #include <gtk/gtk.h> | 24 #include <gtk/gtk.h> |
| 26 #elif defined(OS_MACOSX) | |
| 27 #include <dlfcn.h> | |
| 28 #endif | 25 #endif |
| 29 | 26 |
| 30 class TestSuite { | 27 class TestSuite { |
| 31 public: | 28 public: |
| 32 TestSuite(int argc, char** argv) { | 29 TestSuite(int argc, char** argv) { |
| 33 CommandLine::SetArgcArgv(argc, argv); | 30 CommandLine::SetArgcArgv(argc, argv); |
| 34 testing::InitGoogleTest(&argc, argv); | 31 testing::InitGoogleTest(&argc, argv); |
| 35 #if defined(OS_LINUX) | 32 #if defined(OS_LINUX) |
| 36 gtk_init_check(&argc, &argv); | 33 gtk_init_check(&argc, &argv); |
| 37 #endif | 34 #endif |
| 38 } | 35 } |
| 39 | 36 |
| 40 virtual ~TestSuite() {} | 37 virtual ~TestSuite() {} |
| 41 | 38 |
| 42 int Run() { | 39 int Run() { |
| 43 Initialize(); | 40 Initialize(); |
| 44 std::wstring client_func = CommandLine().GetSwitchValue(kRunClientProcess); | 41 std::wstring client_func = CommandLine().GetSwitchValue(kRunClientProcess); |
| 45 // Check to see if we are being run as a client process. | 42 // Check to see if we are being run as a client process. |
| 46 if (!client_func.empty()) { | 43 if (!client_func.empty()) { |
| 47 // Convert our function name to a usable string for GetProcAddress. | 44 // Convert our function name to a usable string for GetProcAddress. |
| 48 std::string func_name(client_func.begin(), client_func.end()); | 45 std::string func_name(client_func.begin(), client_func.end()); |
| 49 | 46 |
| 50 #if defined(OS_WIN) | 47 return multi_process_function_list::InvokeChildProcessTest(func_name); |
| 51 // Get our module handle and search for an exported function | |
| 52 // which we can use as our client main. | |
| 53 MultiProcessTest::ChildFunctionPtr func = | |
| 54 reinterpret_cast<MultiProcessTest::ChildFunctionPtr>( | |
| 55 GetProcAddress(GetModuleHandle(NULL), func_name.c_str())); | |
| 56 #elif defined(OS_LINUX) | |
| 57 void* exobj = dlopen(0, RTLD_LAZY); | |
| 58 MultiProcessTest::ChildFunctionPtr func = | |
| 59 reinterpret_cast<MultiProcessTest::ChildFunctionPtr>( | |
| 60 dlsym(exobj, func_name.c_str())); | |
| 61 #elif defined(OS_MACOSX) | |
| 62 MultiProcessTest::ChildFunctionPtr func = | |
| 63 reinterpret_cast<MultiProcessTest::ChildFunctionPtr>( | |
| 64 dlsym(RTLD_SELF, func_name.c_str())); | |
| 65 #endif // defined(OS_MACOSX) | |
| 66 | |
| 67 if (func) | |
| 68 return (*func)(); | |
| 69 return -1; | |
| 70 } | 48 } |
| 71 int result = RUN_ALL_TESTS(); | 49 int result = RUN_ALL_TESTS(); |
| 72 | 50 |
| 73 Shutdown(); | 51 Shutdown(); |
| 74 return result; | 52 return result; |
| 75 } | 53 } |
| 76 | 54 |
| 77 protected: | 55 protected: |
| 78 // All fatal log messages (e.g. DCHECK failures) imply unit test failures | 56 // All fatal log messages (e.g. DCHECK failures) imply unit test failures |
| 79 static void UnitTestAssertHandler(const std::string& str) { | 57 static void UnitTestAssertHandler(const std::string& str) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 virtual void Shutdown() { | 91 virtual void Shutdown() { |
| 114 } | 92 } |
| 115 | 93 |
| 116 // Make sure that we setup an AtExitManager so Singleton objects will be | 94 // Make sure that we setup an AtExitManager so Singleton objects will be |
| 117 // destroyed. | 95 // destroyed. |
| 118 base::AtExitManager at_exit_manager_; | 96 base::AtExitManager at_exit_manager_; |
| 119 }; | 97 }; |
| 120 | 98 |
| 121 #endif // BASE_TEST_SUITE_H_ | 99 #endif // BASE_TEST_SUITE_H_ |
| 122 | 100 |
| OLD | NEW |