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