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