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