summaryrefslogtreecommitdiff
path: root/base/test/test_suite.h
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 01:26:09 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-07-15 01:26:09 +0000
commit536b96d958dab9d943af978463fe82fa084d0042 (patch)
tree0f4d08540c8e5fa16bcd0c99cd413fe815560e4b /base/test/test_suite.h
parentb4233fd961752b80d42ae68e8b42acfb3e99be57 (diff)
parent0d51dc717edd4d97116b47bc156e83b8fa193d3d (diff)
downloadlibchrome-536b96d958dab9d943af978463fe82fa084d0042.tar.gz
Snap for 7550844 from 0d51dc717edd4d97116b47bc156e83b8fa193d3d to mainline-conscrypt-releaseandroid-mainline-12.0.0_r8android-mainline-12.0.0_r25android12-mainline-conscrypt-release
Change-Id: I4679185e58ca2896cc6470a6441557faff4b018e
Diffstat (limited to 'base/test/test_suite.h')
-rw-r--r--base/test/test_suite.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/base/test/test_suite.h b/base/test/test_suite.h
new file mode 100644
index 0000000000..6d852bafb9
--- /dev/null
+++ b/base/test/test_suite.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TEST_TEST_SUITE_H_
+#define BASE_TEST_TEST_SUITE_H_
+
+// Defines a basic test suite framework for running gtest based tests. You can
+// instantiate this class in your main function and call its Run method to run
+// any gtest based tests that are linked into your executable.
+
+#include <memory>
+#include <string>
+
+#include "base/at_exit.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/test/scoped_feature_list.h"
+#include "base/test/trace_to_file.h"
+#include "build/build_config.h"
+
+namespace testing {
+class TestInfo;
+}
+
+namespace base {
+
+class XmlUnitTestResultPrinter;
+
+// Instantiates TestSuite, runs it and returns exit code.
+int RunUnitTestsUsingBaseTestSuite(int argc, char **argv);
+
+class TestSuite {
+ public:
+ // Match function used by the GetTestCount method.
+ typedef bool (*TestMatch)(const testing::TestInfo&);
+
+ TestSuite(int argc, char** argv);
+#if defined(OS_WIN)
+ TestSuite(int argc, wchar_t** argv);
+#endif // defined(OS_WIN)
+ virtual ~TestSuite();
+
+ // Returns true if the test is marked as "MAYBE_".
+ // When using different prefixes depending on platform, we use MAYBE_ and
+ // preprocessor directives to replace MAYBE_ with the target prefix.
+ static bool IsMarkedMaybe(const testing::TestInfo& test);
+
+ void CatchMaybeTests();
+
+ void ResetCommandLine();
+
+ void AddTestLauncherResultPrinter();
+
+ int Run();
+
+ protected:
+ // By default fatal log messages (e.g. from DCHECKs) result in error dialogs
+ // which gum up buildbots. Use a minimalistic assert handler which just
+ // terminates the process.
+ void UnitTestAssertHandler(const char* file,
+ int line,
+ const base::StringPiece summary,
+ const base::StringPiece stack_trace);
+
+ // Disable crash dialogs so that it doesn't gum up the buildbot
+ virtual void SuppressErrorDialogs();
+
+ // Override these for custom initialization and shutdown handling. Use these
+ // instead of putting complex code in your constructor/destructor.
+
+ virtual void Initialize();
+ virtual void Shutdown();
+
+ // Make sure that we setup an AtExitManager so Singleton objects will be
+ // destroyed.
+ std::unique_ptr<base::AtExitManager> at_exit_manager_;
+
+ private:
+ void InitializeFromCommandLine(int argc, char** argv);
+#if defined(OS_WIN)
+ void InitializeFromCommandLine(int argc, wchar_t** argv);
+#endif // defined(OS_WIN)
+
+ // Basic initialization for the test suite happens here.
+ void PreInitialize();
+
+ test::TraceToFile trace_to_file_;
+
+ bool initialized_command_line_;
+
+ test::ScopedFeatureList scoped_feature_list_;
+
+ XmlUnitTestResultPrinter* printer_ = nullptr;
+
+ std::unique_ptr<logging::ScopedLogAssertHandler> assert_handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestSuite);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_TEST_SUITE_H_