OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 // Defines a basic test suite framework for running gtest based tests. You can | 9 // Defines a basic test suite framework for running gtest based tests. You can |
10 // instantiate this class in your main function and call its Run method to run | 10 // instantiate this class in your main function and call its Run method to run |
11 // any gtest based tests that are linked into your executable. | 11 // any gtest based tests that are linked into your executable. |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
| 16 #include "base/memory/scoped_ptr.h" |
16 | 17 |
17 namespace testing { | 18 namespace testing { |
18 class TestInfo; | 19 class TestInfo; |
19 } | 20 } |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 | 23 |
23 class TestSuite { | 24 class TestSuite { |
24 public: | 25 public: |
25 // Match function used by the GetTestCount method. | 26 // Match function used by the GetTestCount method. |
(...skipping 26 matching lines...) Expand all Loading... |
52 | 53 |
53 void ResetCommandLine(); | 54 void ResetCommandLine(); |
54 | 55 |
55 int Run(); | 56 int Run(); |
56 | 57 |
57 // A command-line flag that makes a test failure always result in a non-zero | 58 // A command-line flag that makes a test failure always result in a non-zero |
58 // process exit code. | 59 // process exit code. |
59 static const char kStrictFailureHandling[]; | 60 static const char kStrictFailureHandling[]; |
60 | 61 |
61 protected: | 62 protected: |
| 63 // This constructor is only accessible to specialized test suite |
| 64 // implementations which need to control the creation of an AtExitManager |
| 65 // instance for the duration of the test. |
| 66 TestSuite(int argc, char** argv, bool create_at_exit_manager); |
| 67 |
62 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs | 68 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs |
63 // which gum up buildbots. Use a minimalistic assert handler which just | 69 // which gum up buildbots. Use a minimalistic assert handler which just |
64 // terminates the process. | 70 // terminates the process. |
65 static void UnitTestAssertHandler(const std::string& str); | 71 static void UnitTestAssertHandler(const std::string& str); |
66 | 72 |
67 // Disable crash dialogs so that it doesn't gum up the buildbot | 73 // Disable crash dialogs so that it doesn't gum up the buildbot |
68 virtual void SuppressErrorDialogs(); | 74 virtual void SuppressErrorDialogs(); |
69 | 75 |
70 // Override these for custom initialization and shutdown handling. Use these | 76 // Override these for custom initialization and shutdown handling. Use these |
71 // instead of putting complex code in your constructor/destructor. | 77 // instead of putting complex code in your constructor/destructor. |
72 | 78 |
73 virtual void Initialize(); | 79 virtual void Initialize(); |
74 virtual void Shutdown(); | 80 virtual void Shutdown(); |
75 | 81 |
76 // Make sure that we setup an AtExitManager so Singleton objects will be | 82 // Make sure that we setup an AtExitManager so Singleton objects will be |
77 // destroyed. | 83 // destroyed. |
78 base::AtExitManager at_exit_manager_; | 84 scoped_ptr<base::AtExitManager> at_exit_manager_; |
| 85 |
| 86 private: |
| 87 // Basic initialization for the test suite happens here. |
| 88 void PreInitialize(int argc, char** argv, bool create_at_exit_manager); |
79 | 89 |
80 DISALLOW_COPY_AND_ASSIGN(TestSuite); | 90 DISALLOW_COPY_AND_ASSIGN(TestSuite); |
81 }; | 91 }; |
82 | 92 |
83 } // namespace base | 93 } // namespace base |
84 | 94 |
85 // TODO(brettw) remove this. This is a temporary hack to allow WebKit to compile | 95 // TODO(brettw) remove this. This is a temporary hack to allow WebKit to compile |
86 // until we can update it to use "base::" (preventing a two-sided patch). | 96 // until we can update it to use "base::" (preventing a two-sided patch). |
87 using base::TestSuite; | 97 using base::TestSuite; |
88 | 98 |
89 #endif // BASE_TEST_TEST_SUITE_H_ | 99 #endif // BASE_TEST_TEST_SUITE_H_ |
OLD | NEW |