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 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_TEST_SUITE_H_ 6 #define BASE_TEST_TEST_SUITE_H_ 7 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 10 // any gtest based tests that are linked into your executable. 11 12 #include <string> 13 14 #include "base/at_exit.h" 15 #include "base/memory/scoped_ptr.h" 16 17 namespace testing { 18 class TestInfo; 19 } 20 21 namespace base { 22 23 class TestSuite { 24 public: 25 // Match function used by the GetTestCount method. 26 typedef bool (*TestMatch)(const testing::TestInfo&); 27 28 TestSuite(int argc, char** argv); 29 virtual ~TestSuite(); 30 31 // Returns true if the test is marked as "MAYBE_". 32 // When using different prefixes depending on platform, we use MAYBE_ and 33 // preprocessor directives to replace MAYBE_ with the target prefix. 34 static bool IsMarkedMaybe(const testing::TestInfo& test); 35 36 void CatchMaybeTests(); 37 38 void ResetCommandLine(); 39 40 int Run(); 41 42 protected: 43 // This constructor is only accessible to specialized test suite 44 // implementations which need to control the creation of an AtExitManager 45 // instance for the duration of the test. 46 TestSuite(int argc, char** argv, bool create_at_exit_manager); 47 48 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs 49 // which gum up buildbots. Use a minimalistic assert handler which just 50 // terminates the process. 51 static void UnitTestAssertHandler(const std::string& str); 52 53 // Disable crash dialogs so that it doesn't gum up the buildbot 54 virtual void SuppressErrorDialogs(); 55 56 // Override these for custom initialization and shutdown handling. Use these 57 // instead of putting complex code in your constructor/destructor. 58 59 virtual void Initialize(); 60 virtual void Shutdown(); 61 62 // Make sure that we setup an AtExitManager so Singleton objects will be 63 // destroyed. 64 scoped_ptr<base::AtExitManager> at_exit_manager_; 65 66 private: 67 // Basic initialization for the test suite happens here. 68 void PreInitialize(int argc, char** argv, bool create_at_exit_manager); 69 70 bool initialized_command_line_; 71 72 DISALLOW_COPY_AND_ASSIGN(TestSuite); 73 }; 74 75 } // namespace base 76 77 // TODO(brettw) remove this. This is a temporary hack to allow WebKit to compile 78 // until we can update it to use "base::" (preventing a two-sided patch). 79 using base::TestSuite; 80 81 #endif // BASE_TEST_TEST_SUITE_H_ 82