Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2010 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 #pragma once
      8 
      9 // Defines a basic test suite framework for running gtest based tests.  You can
     10 // instantiate this class in your main function and call its Run method to run
     11 // any gtest based tests that are linked into your executable.
     12 
     13 #include <string>
     14 
     15 #include "base/at_exit.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 flaky.
     32   static bool IsMarkedFlaky(const testing::TestInfo& test);
     33 
     34   // Returns true if the test is marked as failing.
     35   static bool IsMarkedFailing(const testing::TestInfo& test);
     36 
     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);
     41 
     42   // Returns true if the test failure should be ignored.
     43   static bool ShouldIgnoreFailure(const testing::TestInfo& test);
     44 
     45   // Returns true if the test failed and the failure shouldn't be ignored.
     46   static bool NonIgnoredFailures(const testing::TestInfo& test);
     47 
     48   // Returns the number of tests where the match function returns true.
     49   int GetTestCount(TestMatch test_match);
     50 
     51   void CatchMaybeTests();
     52 
     53   int Run();
     54 
     55   // A command-line flag that makes a test failure always result in a non-zero
     56   // process exit code.
     57   static const char kStrictFailureHandling[];
     58 
     59  protected:
     60   // By default fatal log messages (e.g. from DCHECKs) result in error dialogs
     61   // which gum up buildbots. Use a minimalistic assert handler which just
     62   // terminates the process.
     63   static void UnitTestAssertHandler(const std::string& str);
     64 
     65   // Disable crash dialogs so that it doesn't gum up the buildbot
     66   virtual void SuppressErrorDialogs();
     67 
     68   // Override these for custom initialization and shutdown handling.  Use these
     69   // instead of putting complex code in your constructor/destructor.
     70 
     71   virtual void Initialize();
     72   virtual void Shutdown();
     73 
     74   // Make sure that we setup an AtExitManager so Singleton objects will be
     75   // destroyed.
     76   base::AtExitManager at_exit_manager_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(TestSuite);
     79 };
     80 
     81 }  // namespace base
     82 
     83 // TODO(brettw) remove this. This is a temporary hack to allow WebKit to compile
     84 // until we can update it to use "base::" (preventing a two-sided patch).
     85 using base::TestSuite;
     86 
     87 #endif  // BASE_TEST_TEST_SUITE_H_
     88