OLD | NEW |
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 #ifndef BASE_TEST_TEST_SUITE_H_ | 5 #ifndef BASE_TEST_TEST_SUITE_H_ |
6 #define BASE_TEST_TEST_SUITE_H_ | 6 #define BASE_TEST_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 <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/logging.h" | |
17 #include "base/macros.h" | 16 #include "base/macros.h" |
18 #include "base/test/trace_to_file.h" | 17 #include "base/test/trace_to_file.h" |
19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
20 | 19 |
21 namespace testing { | 20 namespace testing { |
22 class TestInfo; | 21 class TestInfo; |
23 } | 22 } |
24 | 23 |
25 namespace base { | 24 namespace base { |
26 | 25 |
27 class XmlUnitTestResultPrinter; | |
28 | |
29 // Instantiates TestSuite, runs it and returns exit code. | 26 // Instantiates TestSuite, runs it and returns exit code. |
30 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv); | 27 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv); |
31 | 28 |
32 class TestSuite { | 29 class TestSuite { |
33 public: | 30 public: |
34 // Match function used by the GetTestCount method. | 31 // Match function used by the GetTestCount method. |
35 typedef bool (*TestMatch)(const testing::TestInfo&); | 32 typedef bool (*TestMatch)(const testing::TestInfo&); |
36 | 33 |
37 TestSuite(int argc, char** argv); | 34 TestSuite(int argc, char** argv); |
38 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
(...skipping 11 matching lines...) Expand all Loading... |
50 void ResetCommandLine(); | 47 void ResetCommandLine(); |
51 | 48 |
52 void AddTestLauncherResultPrinter(); | 49 void AddTestLauncherResultPrinter(); |
53 | 50 |
54 int Run(); | 51 int Run(); |
55 | 52 |
56 protected: | 53 protected: |
57 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs | 54 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs |
58 // which gum up buildbots. Use a minimalistic assert handler which just | 55 // which gum up buildbots. Use a minimalistic assert handler which just |
59 // terminates the process. | 56 // terminates the process. |
60 void UnitTestAssertHandler(const char* file, | 57 static void UnitTestAssertHandler(const std::string& str); |
61 int line, | |
62 const base::StringPiece summary, | |
63 const base::StringPiece stack_trace); | |
64 | 58 |
65 // Disable crash dialogs so that it doesn't gum up the buildbot | 59 // Disable crash dialogs so that it doesn't gum up the buildbot |
66 virtual void SuppressErrorDialogs(); | 60 virtual void SuppressErrorDialogs(); |
67 | 61 |
68 // Override these for custom initialization and shutdown handling. Use these | 62 // Override these for custom initialization and shutdown handling. Use these |
69 // instead of putting complex code in your constructor/destructor. | 63 // instead of putting complex code in your constructor/destructor. |
70 | 64 |
71 virtual void Initialize(); | 65 virtual void Initialize(); |
72 virtual void Shutdown(); | 66 virtual void Shutdown(); |
73 | 67 |
74 // Make sure that we setup an AtExitManager so Singleton objects will be | 68 // Make sure that we setup an AtExitManager so Singleton objects will be |
75 // destroyed. | 69 // destroyed. |
76 std::unique_ptr<base::AtExitManager> at_exit_manager_; | 70 std::unique_ptr<base::AtExitManager> at_exit_manager_; |
77 | 71 |
78 private: | 72 private: |
79 void InitializeFromCommandLine(int argc, char** argv); | 73 void InitializeFromCommandLine(int argc, char** argv); |
80 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
81 void InitializeFromCommandLine(int argc, wchar_t** argv); | 75 void InitializeFromCommandLine(int argc, wchar_t** argv); |
82 #endif // defined(OS_WIN) | 76 #endif // defined(OS_WIN) |
83 | 77 |
84 // Basic initialization for the test suite happens here. | 78 // Basic initialization for the test suite happens here. |
85 void PreInitialize(); | 79 void PreInitialize(); |
86 | 80 |
87 test::TraceToFile trace_to_file_; | 81 test::TraceToFile trace_to_file_; |
88 | 82 |
89 bool initialized_command_line_; | 83 bool initialized_command_line_; |
90 | 84 |
91 bool created_feature_list_; | 85 bool created_feature_list_; |
92 | 86 |
93 XmlUnitTestResultPrinter* printer_ = nullptr; | |
94 | |
95 std::unique_ptr<logging::ScopedLogAssertHandler> assert_handler_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(TestSuite); | 87 DISALLOW_COPY_AND_ASSIGN(TestSuite); |
98 }; | 88 }; |
99 | 89 |
100 } // namespace base | 90 } // namespace base |
101 | 91 |
102 #endif // BASE_TEST_TEST_SUITE_H_ | 92 #endif // BASE_TEST_TEST_SUITE_H_ |
OLD | NEW |