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.
5 #ifndef BASE_TEST_TEST_SUITE_H_
6 #define BASE_TEST_TEST_SUITE_H_
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.
14 #include "base/at_exit.h"
15 #include "base/memory/scoped_ptr.h"
23 // Instantiates TestSuite, runs it and returns exit code.
24 int RunUnitTestsUsingBaseTestSuite(int argc
, char **argv
);
28 // Match function used by the GetTestCount method.
29 typedef bool (*TestMatch
)(const testing::TestInfo
&);
31 TestSuite(int argc
, char** argv
);
33 TestSuite(int argc
, wchar_t** argv
);
34 #endif // defined(OS_WIN)
37 // Returns true if the test is marked as "MAYBE_".
38 // When using different prefixes depending on platform, we use MAYBE_ and
39 // preprocessor directives to replace MAYBE_ with the target prefix.
40 static bool IsMarkedMaybe(const testing::TestInfo
& test
);
42 void CatchMaybeTests();
44 void ResetCommandLine();
46 void AddTestLauncherResultPrinter();
51 // This constructor is only accessible to specialized test suite
52 // implementations which need to control the creation of an AtExitManager
53 // instance for the duration of the test.
54 TestSuite(int argc
, char** argv
, bool create_at_exit_manager
);
56 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs
57 // which gum up buildbots. Use a minimalistic assert handler which just
58 // terminates the process.
59 static void UnitTestAssertHandler(const std::string
& str
);
61 // Disable crash dialogs so that it doesn't gum up the buildbot
62 virtual void SuppressErrorDialogs();
64 // Override these for custom initialization and shutdown handling. Use these
65 // instead of putting complex code in your constructor/destructor.
67 virtual void Initialize();
68 virtual void Shutdown();
70 // Make sure that we setup an AtExitManager so Singleton objects will be
72 scoped_ptr
<base::AtExitManager
> at_exit_manager_
;
75 void InitializeFromCommandLine(int argc
, char** argv
);
77 void InitializeFromCommandLine(int argc
, wchar_t** argv
);
78 #endif // defined(OS_WIN)
80 // Basic initialization for the test suite happens here.
81 void PreInitialize(bool create_at_exit_manager
);
83 bool initialized_command_line_
;
85 DISALLOW_COPY_AND_ASSIGN(TestSuite
);
90 // TODO(brettw) remove this. This is a temporary hack to allow WebKit to compile
91 // until we can update it to use "base::" (preventing a two-sided patch).
92 using base::TestSuite
;
94 #endif // BASE_TEST_TEST_SUITE_H_