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"
16 #include "base/test/trace_to_file.h"
24 // Instantiates TestSuite, runs it and returns exit code.
25 int RunUnitTestsUsingBaseTestSuite(int argc
, char **argv
);
29 // Match function used by the GetTestCount method.
30 typedef bool (*TestMatch
)(const testing::TestInfo
&);
32 TestSuite(int argc
, char** argv
);
34 TestSuite(int argc
, wchar_t** argv
);
35 #endif // defined(OS_WIN)
38 // Returns true if the test is marked as "MAYBE_".
39 // When using different prefixes depending on platform, we use MAYBE_ and
40 // preprocessor directives to replace MAYBE_ with the target prefix.
41 static bool IsMarkedMaybe(const testing::TestInfo
& test
);
43 void CatchMaybeTests();
45 void ResetCommandLine();
47 void CreateAtExitManager();
49 void AddTestLauncherResultPrinter();
54 // This constructor is only accessible to specialized test suite
55 // implementations which need to control the creation of an AtExitManager
56 // instance for the duration of the test.
57 TestSuite(int argc
, char** argv
, bool create_at_exit_manager
);
59 // By default fatal log messages (e.g. from DCHECKs) result in error dialogs
60 // which gum up buildbots. Use a minimalistic assert handler which just
61 // terminates the process.
62 static void UnitTestAssertHandler(const std::string
& str
);
64 // Disable crash dialogs so that it doesn't gum up the buildbot
65 virtual void SuppressErrorDialogs();
67 // Override these for custom initialization and shutdown handling. Use these
68 // instead of putting complex code in your constructor/destructor.
70 virtual void Initialize();
71 virtual void Shutdown();
73 // Make sure that we setup an AtExitManager so Singleton objects will be
75 scoped_ptr
<base::AtExitManager
> at_exit_manager_
;
78 void InitializeFromCommandLine(int argc
, char** argv
);
80 void InitializeFromCommandLine(int argc
, wchar_t** argv
);
81 #endif // defined(OS_WIN)
83 // Basic initialization for the test suite happens here.
84 void PreInitialize(bool create_at_exit_manager
);
86 test::TraceToFile trace_to_file_
;
88 bool initialized_command_line_
;
90 DISALLOW_COPY_AND_ASSIGN(TestSuite
);
95 #endif // BASE_TEST_TEST_SUITE_H_