Blame googletest/include/gtest/gtest.h

Packit bd1cd8
// Copyright 2005, Google Inc.
Packit bd1cd8
// All rights reserved.
Packit bd1cd8
//
Packit bd1cd8
// Redistribution and use in source and binary forms, with or without
Packit bd1cd8
// modification, are permitted provided that the following conditions are
Packit bd1cd8
// met:
Packit bd1cd8
//
Packit bd1cd8
//     * Redistributions of source code must retain the above copyright
Packit bd1cd8
// notice, this list of conditions and the following disclaimer.
Packit bd1cd8
//     * Redistributions in binary form must reproduce the above
Packit bd1cd8
// copyright notice, this list of conditions and the following disclaimer
Packit bd1cd8
// in the documentation and/or other materials provided with the
Packit bd1cd8
// distribution.
Packit bd1cd8
//     * Neither the name of Google Inc. nor the names of its
Packit bd1cd8
// contributors may be used to endorse or promote products derived from
Packit bd1cd8
// this software without specific prior written permission.
Packit bd1cd8
//
Packit bd1cd8
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit bd1cd8
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit bd1cd8
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit bd1cd8
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit bd1cd8
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit bd1cd8
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit bd1cd8
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit bd1cd8
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit bd1cd8
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit bd1cd8
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit bd1cd8
//
Packit bd1cd8
// Author: wan@google.com (Zhanyong Wan)
Packit bd1cd8
//
Packit bd1cd8
// The Google C++ Testing Framework (Google Test)
Packit bd1cd8
//
Packit bd1cd8
// This header file defines the public API for Google Test.  It should be
Packit bd1cd8
// included by any test program that uses Google Test.
Packit bd1cd8
//
Packit bd1cd8
// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
Packit bd1cd8
// leave some internal implementation details in this header file.
Packit bd1cd8
// They are clearly marked by comments like this:
Packit bd1cd8
//
Packit bd1cd8
//   // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
//
Packit bd1cd8
// Such code is NOT meant to be used by a user directly, and is subject
Packit bd1cd8
// to CHANGE WITHOUT NOTICE.  Therefore DO NOT DEPEND ON IT in a user
Packit bd1cd8
// program!
Packit bd1cd8
//
Packit bd1cd8
// Acknowledgment: Google Test borrowed the idea of automatic test
Packit bd1cd8
// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
Packit bd1cd8
// easyUnit framework.
Packit bd1cd8
Packit bd1cd8
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
Packit bd1cd8
#define GTEST_INCLUDE_GTEST_GTEST_H_
Packit bd1cd8
Packit bd1cd8
#include <limits>
Packit bd1cd8
#include <ostream>
Packit bd1cd8
#include <vector>
Packit bd1cd8
Packit bd1cd8
#include "gtest/internal/gtest-internal.h"
Packit bd1cd8
#include "gtest/internal/gtest-string.h"
Packit bd1cd8
#include "gtest/gtest-death-test.h"
Packit bd1cd8
#include "gtest/gtest-message.h"
Packit bd1cd8
#include "gtest/gtest-param-test.h"
Packit bd1cd8
#include "gtest/gtest-printers.h"
Packit bd1cd8
#include "gtest/gtest_prod.h"
Packit bd1cd8
#include "gtest/gtest-test-part.h"
Packit bd1cd8
#include "gtest/gtest-typed-test.h"
Packit bd1cd8
Packit bd1cd8
// Depending on the platform, different string classes are available.
Packit bd1cd8
// On Linux, in addition to ::std::string, Google also makes use of
Packit bd1cd8
// class ::string, which has the same interface as ::std::string, but
Packit bd1cd8
// has a different implementation.
Packit bd1cd8
//
Packit bd1cd8
// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
Packit bd1cd8
// ::string is available AND is a distinct type to ::std::string, or
Packit bd1cd8
// define it to 0 to indicate otherwise.
Packit bd1cd8
//
Packit bd1cd8
// If ::std::string and ::string are the same class on your platform
Packit bd1cd8
// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
Packit bd1cd8
//
Packit bd1cd8
// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
Packit bd1cd8
// heuristically.
Packit bd1cd8
Packit bd1cd8
namespace testing {
Packit bd1cd8
Packit bd1cd8
// Declares the flags.
Packit bd1cd8
Packit bd1cd8
// This flag temporary enables the disabled tests.
Packit bd1cd8
GTEST_DECLARE_bool_(also_run_disabled_tests);
Packit bd1cd8
Packit bd1cd8
// This flag brings the debugger on an assertion failure.
Packit bd1cd8
GTEST_DECLARE_bool_(break_on_failure);
Packit bd1cd8
Packit bd1cd8
// This flag controls whether Google Test catches all test-thrown exceptions
Packit bd1cd8
// and logs them as failures.
Packit bd1cd8
GTEST_DECLARE_bool_(catch_exceptions);
Packit bd1cd8
Packit bd1cd8
// This flag enables using colors in terminal output. Available values are
Packit bd1cd8
// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
Packit bd1cd8
// to let Google Test decide.
Packit bd1cd8
GTEST_DECLARE_string_(color);
Packit bd1cd8
Packit bd1cd8
// This flag sets up the filter to select by name using a glob pattern
Packit bd1cd8
// the tests to run. If the filter is not given all tests are executed.
Packit bd1cd8
GTEST_DECLARE_string_(filter);
Packit bd1cd8
Packit bd1cd8
// This flag causes the Google Test to list tests. None of the tests listed
Packit bd1cd8
// are actually run if the flag is provided.
Packit bd1cd8
GTEST_DECLARE_bool_(list_tests);
Packit bd1cd8
Packit bd1cd8
// This flag controls whether Google Test emits a detailed XML report to a file
Packit bd1cd8
// in addition to its normal textual output.
Packit bd1cd8
GTEST_DECLARE_string_(output);
Packit bd1cd8
Packit bd1cd8
// This flags control whether Google Test prints the elapsed time for each
Packit bd1cd8
// test.
Packit bd1cd8
GTEST_DECLARE_bool_(print_time);
Packit bd1cd8
Packit bd1cd8
// This flag specifies the random number seed.
Packit bd1cd8
GTEST_DECLARE_int32_(random_seed);
Packit bd1cd8
Packit bd1cd8
// This flag sets how many times the tests are repeated. The default value
Packit bd1cd8
// is 1. If the value is -1 the tests are repeating forever.
Packit bd1cd8
GTEST_DECLARE_int32_(repeat);
Packit bd1cd8
Packit bd1cd8
// This flag controls whether Google Test includes Google Test internal
Packit bd1cd8
// stack frames in failure stack traces.
Packit bd1cd8
GTEST_DECLARE_bool_(show_internal_stack_frames);
Packit bd1cd8
Packit bd1cd8
// When this flag is specified, tests' order is randomized on every iteration.
Packit bd1cd8
GTEST_DECLARE_bool_(shuffle);
Packit bd1cd8
Packit bd1cd8
// This flag specifies the maximum number of stack frames to be
Packit bd1cd8
// printed in a failure message.
Packit bd1cd8
GTEST_DECLARE_int32_(stack_trace_depth);
Packit bd1cd8
Packit bd1cd8
// When this flag is specified, a failed assertion will throw an
Packit bd1cd8
// exception if exceptions are enabled, or exit the program with a
Packit bd1cd8
// non-zero code otherwise.
Packit bd1cd8
GTEST_DECLARE_bool_(throw_on_failure);
Packit bd1cd8
Packit bd1cd8
// When this flag is set with a "host:port" string, on supported
Packit bd1cd8
// platforms test results are streamed to the specified port on
Packit bd1cd8
// the specified host machine.
Packit bd1cd8
GTEST_DECLARE_string_(stream_result_to);
Packit bd1cd8
Packit bd1cd8
// The upper limit for valid stack trace depths.
Packit bd1cd8
const int kMaxStackTraceDepth = 100;
Packit bd1cd8
Packit bd1cd8
namespace internal {
Packit bd1cd8
Packit bd1cd8
class AssertHelper;
Packit bd1cd8
class DefaultGlobalTestPartResultReporter;
Packit bd1cd8
class ExecDeathTest;
Packit bd1cd8
class NoExecDeathTest;
Packit bd1cd8
class FinalSuccessChecker;
Packit bd1cd8
class GTestFlagSaver;
Packit bd1cd8
class StreamingListenerTest;
Packit bd1cd8
class TestResultAccessor;
Packit bd1cd8
class TestEventListenersAccessor;
Packit bd1cd8
class TestEventRepeater;
Packit bd1cd8
class UnitTestRecordPropertyTestHelper;
Packit bd1cd8
class WindowsDeathTest;
Packit bd1cd8
class UnitTestImpl* GetUnitTestImpl();
Packit bd1cd8
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
Packit bd1cd8
                                    const std::string& message);
Packit bd1cd8
Packit bd1cd8
}  // namespace internal
Packit bd1cd8
Packit bd1cd8
// The friend relationship of some of these classes is cyclic.
Packit bd1cd8
// If we don't forward declare them the compiler might confuse the classes
Packit bd1cd8
// in friendship clauses with same named classes on the scope.
Packit bd1cd8
class Test;
Packit bd1cd8
class TestCase;
Packit bd1cd8
class TestInfo;
Packit bd1cd8
class UnitTest;
Packit bd1cd8
Packit bd1cd8
// A class for indicating whether an assertion was successful.  When
Packit bd1cd8
// the assertion wasn't successful, the AssertionResult object
Packit bd1cd8
// remembers a non-empty message that describes how it failed.
Packit bd1cd8
//
Packit bd1cd8
// To create an instance of this class, use one of the factory functions
Packit bd1cd8
// (AssertionSuccess() and AssertionFailure()).
Packit bd1cd8
//
Packit bd1cd8
// This class is useful for two purposes:
Packit bd1cd8
//   1. Defining predicate functions to be used with Boolean test assertions
Packit bd1cd8
//      EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
Packit bd1cd8
//   2. Defining predicate-format functions to be
Packit bd1cd8
//      used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
Packit bd1cd8
//
Packit bd1cd8
// For example, if you define IsEven predicate:
Packit bd1cd8
//
Packit bd1cd8
//   testing::AssertionResult IsEven(int n) {
Packit bd1cd8
//     if ((n % 2) == 0)
Packit bd1cd8
//       return testing::AssertionSuccess();
Packit bd1cd8
//     else
Packit bd1cd8
//       return testing::AssertionFailure() << n << " is odd";
Packit bd1cd8
//   }
Packit bd1cd8
//
Packit bd1cd8
// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
Packit bd1cd8
// will print the message
Packit bd1cd8
//
Packit bd1cd8
//   Value of: IsEven(Fib(5))
Packit bd1cd8
//     Actual: false (5 is odd)
Packit bd1cd8
//   Expected: true
Packit bd1cd8
//
Packit bd1cd8
// instead of a more opaque
Packit bd1cd8
//
Packit bd1cd8
//   Value of: IsEven(Fib(5))
Packit bd1cd8
//     Actual: false
Packit bd1cd8
//   Expected: true
Packit bd1cd8
//
Packit bd1cd8
// in case IsEven is a simple Boolean predicate.
Packit bd1cd8
//
Packit bd1cd8
// If you expect your predicate to be reused and want to support informative
Packit bd1cd8
// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
Packit bd1cd8
// about half as often as positive ones in our tests), supply messages for
Packit bd1cd8
// both success and failure cases:
Packit bd1cd8
//
Packit bd1cd8
//   testing::AssertionResult IsEven(int n) {
Packit bd1cd8
//     if ((n % 2) == 0)
Packit bd1cd8
//       return testing::AssertionSuccess() << n << " is even";
Packit bd1cd8
//     else
Packit bd1cd8
//       return testing::AssertionFailure() << n << " is odd";
Packit bd1cd8
//   }
Packit bd1cd8
//
Packit bd1cd8
// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
Packit bd1cd8
//
Packit bd1cd8
//   Value of: IsEven(Fib(6))
Packit bd1cd8
//     Actual: true (8 is even)
Packit bd1cd8
//   Expected: false
Packit bd1cd8
//
Packit bd1cd8
// NB: Predicates that support negative Boolean assertions have reduced
Packit bd1cd8
// performance in positive ones so be careful not to use them in tests
Packit bd1cd8
// that have lots (tens of thousands) of positive Boolean assertions.
Packit bd1cd8
//
Packit bd1cd8
// To use this class with EXPECT_PRED_FORMAT assertions such as:
Packit bd1cd8
//
Packit bd1cd8
//   // Verifies that Foo() returns an even number.
Packit bd1cd8
//   EXPECT_PRED_FORMAT1(IsEven, Foo());
Packit bd1cd8
//
Packit bd1cd8
// you need to define:
Packit bd1cd8
//
Packit bd1cd8
//   testing::AssertionResult IsEven(const char* expr, int n) {
Packit bd1cd8
//     if ((n % 2) == 0)
Packit bd1cd8
//       return testing::AssertionSuccess();
Packit bd1cd8
//     else
Packit bd1cd8
//       return testing::AssertionFailure()
Packit bd1cd8
//         << "Expected: " << expr << " is even\n  Actual: it's " << n;
Packit bd1cd8
//   }
Packit bd1cd8
//
Packit bd1cd8
// If Foo() returns 5, you will see the following message:
Packit bd1cd8
//
Packit bd1cd8
//   Expected: Foo() is even
Packit bd1cd8
//     Actual: it's 5
Packit bd1cd8
//
Packit bd1cd8
class GTEST_API_ AssertionResult {
Packit bd1cd8
 public:
Packit bd1cd8
  // Copy constructor.
Packit bd1cd8
  // Used in EXPECT_TRUE/FALSE(assertion_result).
Packit bd1cd8
  AssertionResult(const AssertionResult& other);
Packit bd1cd8
Packit bd1cd8
  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
Packit bd1cd8
Packit bd1cd8
  // Used in the EXPECT_TRUE/FALSE(bool_expression).
Packit bd1cd8
  //
Packit bd1cd8
  // T must be contextually convertible to bool.
Packit bd1cd8
  //
Packit bd1cd8
  // The second parameter prevents this overload from being considered if
Packit bd1cd8
  // the argument is implicitly convertible to AssertionResult. In that case
Packit bd1cd8
  // we want AssertionResult's copy constructor to be used.
Packit bd1cd8
  template <typename T>
Packit bd1cd8
  explicit AssertionResult(
Packit bd1cd8
      const T& success,
Packit bd1cd8
      typename internal::EnableIf<
Packit bd1cd8
          !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
Packit bd1cd8
          /*enabler*/ = NULL)
Packit bd1cd8
      : success_(success) {}
Packit bd1cd8
Packit bd1cd8
  GTEST_DISABLE_MSC_WARNINGS_POP_()
Packit bd1cd8
Packit bd1cd8
  // Assignment operator.
Packit bd1cd8
  AssertionResult& operator=(AssertionResult other) {
Packit bd1cd8
    swap(other);
Packit bd1cd8
    return *this;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the assertion succeeded.
Packit bd1cd8
  operator bool() const { return success_; }  // NOLINT
Packit bd1cd8
Packit bd1cd8
  // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
Packit bd1cd8
  AssertionResult operator!() const;
Packit bd1cd8
Packit bd1cd8
  // Returns the text streamed into this AssertionResult. Test assertions
Packit bd1cd8
  // use it when they fail (i.e., the predicate's outcome doesn't match the
Packit bd1cd8
  // assertion's expectation). When nothing has been streamed into the
Packit bd1cd8
  // object, returns an empty string.
Packit bd1cd8
  const char* message() const {
Packit bd1cd8
    return message_.get() != NULL ?  message_->c_str() : "";
Packit bd1cd8
  }
Packit bd1cd8
  // TODO(vladl@google.com): Remove this after making sure no clients use it.
Packit bd1cd8
  // Deprecated; please use message() instead.
Packit bd1cd8
  const char* failure_message() const { return message(); }
Packit bd1cd8
Packit bd1cd8
  // Streams a custom failure message into this object.
Packit bd1cd8
  template <typename T> AssertionResult& operator<<(const T& value) {
Packit bd1cd8
    AppendMessage(Message() << value);
Packit bd1cd8
    return *this;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Allows streaming basic output manipulators such as endl or flush into
Packit bd1cd8
  // this object.
Packit bd1cd8
  AssertionResult& operator<<(
Packit bd1cd8
      ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
Packit bd1cd8
    AppendMessage(Message() << basic_manipulator);
Packit bd1cd8
    return *this;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // Appends the contents of message to message_.
Packit bd1cd8
  void AppendMessage(const Message& a_message) {
Packit bd1cd8
    if (message_.get() == NULL)
Packit bd1cd8
      message_.reset(new ::std::string);
Packit bd1cd8
    message_->append(a_message.GetString().c_str());
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Swap the contents of this AssertionResult with other.
Packit bd1cd8
  void swap(AssertionResult& other);
Packit bd1cd8
Packit bd1cd8
  // Stores result of the assertion predicate.
Packit bd1cd8
  bool success_;
Packit bd1cd8
  // Stores the message describing the condition in case the expectation
Packit bd1cd8
  // construct is not satisfied with the predicate's outcome.
Packit bd1cd8
  // Referenced via a pointer to avoid taking too much stack frame space
Packit bd1cd8
  // with test assertions.
Packit bd1cd8
  internal::scoped_ptr< ::std::string> message_;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Makes a successful assertion result.
Packit bd1cd8
GTEST_API_ AssertionResult AssertionSuccess();
Packit bd1cd8
Packit bd1cd8
// Makes a failed assertion result.
Packit bd1cd8
GTEST_API_ AssertionResult AssertionFailure();
Packit bd1cd8
Packit bd1cd8
// Makes a failed assertion result with the given failure message.
Packit bd1cd8
// Deprecated; use AssertionFailure() << msg.
Packit bd1cd8
GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
Packit bd1cd8
Packit bd1cd8
// The abstract class that all tests inherit from.
Packit bd1cd8
//
Packit bd1cd8
// In Google Test, a unit test program contains one or many TestCases, and
Packit bd1cd8
// each TestCase contains one or many Tests.
Packit bd1cd8
//
Packit bd1cd8
// When you define a test using the TEST macro, you don't need to
Packit bd1cd8
// explicitly derive from Test - the TEST macro automatically does
Packit bd1cd8
// this for you.
Packit bd1cd8
//
Packit bd1cd8
// The only time you derive from Test is when defining a test fixture
Packit bd1cd8
// to be used a TEST_F.  For example:
Packit bd1cd8
//
Packit bd1cd8
//   class FooTest : public testing::Test {
Packit bd1cd8
//    protected:
Packit bd1cd8
//     void SetUp() override { ... }
Packit bd1cd8
//     void TearDown() override { ... }
Packit bd1cd8
//     ...
Packit bd1cd8
//   };
Packit bd1cd8
//
Packit bd1cd8
//   TEST_F(FooTest, Bar) { ... }
Packit bd1cd8
//   TEST_F(FooTest, Baz) { ... }
Packit bd1cd8
//
Packit bd1cd8
// Test is not copyable.
Packit bd1cd8
class GTEST_API_ Test {
Packit bd1cd8
 public:
Packit bd1cd8
  friend class TestInfo;
Packit bd1cd8
Packit bd1cd8
  // Defines types for pointers to functions that set up and tear down
Packit bd1cd8
  // a test case.
Packit bd1cd8
  typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
Packit bd1cd8
  typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
Packit bd1cd8
Packit bd1cd8
  // The d'tor is virtual as we intend to inherit from Test.
Packit bd1cd8
  virtual ~Test();
Packit bd1cd8
Packit bd1cd8
  // Sets up the stuff shared by all tests in this test case.
Packit bd1cd8
  //
Packit bd1cd8
  // Google Test will call Foo::SetUpTestCase() before running the first
Packit bd1cd8
  // test in test case Foo.  Hence a sub-class can define its own
Packit bd1cd8
  // SetUpTestCase() method to shadow the one defined in the super
Packit bd1cd8
  // class.
Packit bd1cd8
  static void SetUpTestCase() {}
Packit bd1cd8
Packit bd1cd8
  // Tears down the stuff shared by all tests in this test case.
Packit bd1cd8
  //
Packit bd1cd8
  // Google Test will call Foo::TearDownTestCase() after running the last
Packit bd1cd8
  // test in test case Foo.  Hence a sub-class can define its own
Packit bd1cd8
  // TearDownTestCase() method to shadow the one defined in the super
Packit bd1cd8
  // class.
Packit bd1cd8
  static void TearDownTestCase() {}
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the current test has a fatal failure.
Packit bd1cd8
  static bool HasFatalFailure();
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the current test has a non-fatal failure.
Packit bd1cd8
  static bool HasNonfatalFailure();
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the current test has a (either fatal or
Packit bd1cd8
  // non-fatal) failure.
Packit bd1cd8
  static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
Packit bd1cd8
Packit bd1cd8
  // Logs a property for the current test, test case, or for the entire
Packit bd1cd8
  // invocation of the test program when used outside of the context of a
Packit bd1cd8
  // test case.  Only the last value for a given key is remembered.  These
Packit bd1cd8
  // are public static so they can be called from utility functions that are
Packit bd1cd8
  // not members of the test fixture.  Calls to RecordProperty made during
Packit bd1cd8
  // lifespan of the test (from the moment its constructor starts to the
Packit bd1cd8
  // moment its destructor finishes) will be output in XML as attributes of
Packit bd1cd8
  // the <testcase> element.  Properties recorded from fixture's
Packit bd1cd8
  // SetUpTestCase or TearDownTestCase are logged as attributes of the
Packit bd1cd8
  // corresponding <testsuite> element.  Calls to RecordProperty made in the
Packit bd1cd8
  // global context (before or after invocation of RUN_ALL_TESTS and from
Packit bd1cd8
  // SetUp/TearDown method of Environment objects registered with Google
Packit bd1cd8
  // Test) will be output as attributes of the <testsuites> element.
Packit bd1cd8
  static void RecordProperty(const std::string& key, const std::string& value);
Packit bd1cd8
  static void RecordProperty(const std::string& key, int value);
Packit bd1cd8
Packit bd1cd8
 protected:
Packit bd1cd8
  // Creates a Test object.
Packit bd1cd8
  Test();
Packit bd1cd8
Packit bd1cd8
  // Sets up the test fixture.
Packit bd1cd8
  virtual void SetUp();
Packit bd1cd8
Packit bd1cd8
  // Tears down the test fixture.
Packit bd1cd8
  virtual void TearDown();
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // Returns true iff the current test has the same fixture class as
Packit bd1cd8
  // the first test in the current test case.
Packit bd1cd8
  static bool HasSameFixtureClass();
Packit bd1cd8
Packit bd1cd8
  // Runs the test after the test fixture has been set up.
Packit bd1cd8
  //
Packit bd1cd8
  // A sub-class must implement this to define the test logic.
Packit bd1cd8
  //
Packit bd1cd8
  // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
Packit bd1cd8
  // Instead, use the TEST or TEST_F macro.
Packit bd1cd8
  virtual void TestBody() = 0;
Packit bd1cd8
Packit bd1cd8
  // Sets up, executes, and tears down the test.
Packit bd1cd8
  void Run();
Packit bd1cd8
Packit bd1cd8
  // Deletes self.  We deliberately pick an unusual name for this
Packit bd1cd8
  // internal method to avoid clashing with names used in user TESTs.
Packit bd1cd8
  void DeleteSelf_() { delete this; }
Packit bd1cd8
Packit bd1cd8
  const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
Packit bd1cd8
Packit bd1cd8
  // Often a user misspells SetUp() as Setup() and spends a long time
Packit bd1cd8
  // wondering why it is never called by Google Test.  The declaration of
Packit bd1cd8
  // the following method is solely for catching such an error at
Packit bd1cd8
  // compile time:
Packit bd1cd8
  //
Packit bd1cd8
  //   - The return type is deliberately chosen to be not void, so it
Packit bd1cd8
  //   will be a conflict if void Setup() is declared in the user's
Packit bd1cd8
  //   test fixture.
Packit bd1cd8
  //
Packit bd1cd8
  //   - This method is private, so it will be another compiler error
Packit bd1cd8
  //   if the method is called from the user's test fixture.
Packit bd1cd8
  //
Packit bd1cd8
  // DO NOT OVERRIDE THIS FUNCTION.
Packit bd1cd8
  //
Packit bd1cd8
  // If you see an error about overriding the following function or
Packit bd1cd8
  // about it being private, you have mis-spelled SetUp() as Setup().
Packit bd1cd8
  struct Setup_should_be_spelled_SetUp {};
Packit bd1cd8
  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
Packit bd1cd8
Packit bd1cd8
  // We disallow copying Tests.
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
typedef internal::TimeInMillis TimeInMillis;
Packit bd1cd8
Packit bd1cd8
// A copyable object representing a user specified test property which can be
Packit bd1cd8
// output as a key/value string pair.
Packit bd1cd8
//
Packit bd1cd8
// Don't inherit from TestProperty as its destructor is not virtual.
Packit bd1cd8
class TestProperty {
Packit bd1cd8
 public:
Packit bd1cd8
  // C'tor.  TestProperty does NOT have a default constructor.
Packit bd1cd8
  // Always use this constructor (with parameters) to create a
Packit bd1cd8
  // TestProperty object.
Packit bd1cd8
  TestProperty(const std::string& a_key, const std::string& a_value) :
Packit bd1cd8
    key_(a_key), value_(a_value) {
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Gets the user supplied key.
Packit bd1cd8
  const char* key() const {
Packit bd1cd8
    return key_.c_str();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Gets the user supplied value.
Packit bd1cd8
  const char* value() const {
Packit bd1cd8
    return value_.c_str();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Sets a new value, overriding the one supplied in the constructor.
Packit bd1cd8
  void SetValue(const std::string& new_value) {
Packit bd1cd8
    value_ = new_value;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // The key supplied by the user.
Packit bd1cd8
  std::string key_;
Packit bd1cd8
  // The value supplied by the user.
Packit bd1cd8
  std::string value_;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// The result of a single Test.  This includes a list of
Packit bd1cd8
// TestPartResults, a list of TestProperties, a count of how many
Packit bd1cd8
// death tests there are in the Test, and how much time it took to run
Packit bd1cd8
// the Test.
Packit bd1cd8
//
Packit bd1cd8
// TestResult is not copyable.
Packit bd1cd8
class GTEST_API_ TestResult {
Packit bd1cd8
 public:
Packit bd1cd8
  // Creates an empty TestResult.
Packit bd1cd8
  TestResult();
Packit bd1cd8
Packit bd1cd8
  // D'tor.  Do not inherit from TestResult.
Packit bd1cd8
  ~TestResult();
Packit bd1cd8
Packit bd1cd8
  // Gets the number of all test parts.  This is the sum of the number
Packit bd1cd8
  // of successful test parts and the number of failed test parts.
Packit bd1cd8
  int total_part_count() const;
Packit bd1cd8
Packit bd1cd8
  // Returns the number of the test properties.
Packit bd1cd8
  int test_property_count() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test passed (i.e. no test part failed).
Packit bd1cd8
  bool Passed() const { return !Failed(); }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test failed.
Packit bd1cd8
  bool Failed() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test fatally failed.
Packit bd1cd8
  bool HasFatalFailure() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test has a non-fatal failure.
Packit bd1cd8
  bool HasNonfatalFailure() const;
Packit bd1cd8
Packit bd1cd8
  // Returns the elapsed time, in milliseconds.
Packit bd1cd8
  TimeInMillis elapsed_time() const { return elapsed_time_; }
Packit bd1cd8
Packit bd1cd8
  // Returns the i-th test part result among all the results. i can range
Packit bd1cd8
  // from 0 to test_property_count() - 1. If i is not in that range, aborts
Packit bd1cd8
  // the program.
Packit bd1cd8
  const TestPartResult& GetTestPartResult(int i) const;
Packit bd1cd8
Packit bd1cd8
  // Returns the i-th test property. i can range from 0 to
Packit bd1cd8
  // test_property_count() - 1. If i is not in that range, aborts the
Packit bd1cd8
  // program.
Packit bd1cd8
  const TestProperty& GetTestProperty(int i) const;
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  friend class TestInfo;
Packit bd1cd8
  friend class TestCase;
Packit bd1cd8
  friend class UnitTest;
Packit bd1cd8
  friend class internal::DefaultGlobalTestPartResultReporter;
Packit bd1cd8
  friend class internal::ExecDeathTest;
Packit bd1cd8
  friend class internal::TestResultAccessor;
Packit bd1cd8
  friend class internal::UnitTestImpl;
Packit bd1cd8
  friend class internal::WindowsDeathTest;
Packit bd1cd8
Packit bd1cd8
  // Gets the vector of TestPartResults.
Packit bd1cd8
  const std::vector<TestPartResult>& test_part_results() const {
Packit bd1cd8
    return test_part_results_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Gets the vector of TestProperties.
Packit bd1cd8
  const std::vector<TestProperty>& test_properties() const {
Packit bd1cd8
    return test_properties_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Sets the elapsed time.
Packit bd1cd8
  void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
Packit bd1cd8
Packit bd1cd8
  // Adds a test property to the list. The property is validated and may add
Packit bd1cd8
  // a non-fatal failure if invalid (e.g., if it conflicts with reserved
Packit bd1cd8
  // key names). If a property is already recorded for the same key, the
Packit bd1cd8
  // value will be updated, rather than storing multiple values for the same
Packit bd1cd8
  // key.  xml_element specifies the element for which the property is being
Packit bd1cd8
  // recorded and is used for validation.
Packit bd1cd8
  void RecordProperty(const std::string& xml_element,
Packit bd1cd8
                      const TestProperty& test_property);
Packit bd1cd8
Packit bd1cd8
  // Adds a failure if the key is a reserved attribute of Google Test
Packit bd1cd8
  // testcase tags.  Returns true if the property is valid.
Packit bd1cd8
  // TODO(russr): Validate attribute names are legal and human readable.
Packit bd1cd8
  static bool ValidateTestProperty(const std::string& xml_element,
Packit bd1cd8
                                   const TestProperty& test_property);
Packit bd1cd8
Packit bd1cd8
  // Adds a test part result to the list.
Packit bd1cd8
  void AddTestPartResult(const TestPartResult& test_part_result);
Packit bd1cd8
Packit bd1cd8
  // Returns the death test count.
Packit bd1cd8
  int death_test_count() const { return death_test_count_; }
Packit bd1cd8
Packit bd1cd8
  // Increments the death test count, returning the new count.
Packit bd1cd8
  int increment_death_test_count() { return ++death_test_count_; }
Packit bd1cd8
Packit bd1cd8
  // Clears the test part results.
Packit bd1cd8
  void ClearTestPartResults();
Packit bd1cd8
Packit bd1cd8
  // Clears the object.
Packit bd1cd8
  void Clear();
Packit bd1cd8
Packit bd1cd8
  // Protects mutable state of the property vector and of owned
Packit bd1cd8
  // properties, whose values may be updated.
Packit bd1cd8
  internal::Mutex test_properites_mutex_;
Packit bd1cd8
Packit bd1cd8
  // The vector of TestPartResults
Packit bd1cd8
  std::vector<TestPartResult> test_part_results_;
Packit bd1cd8
  // The vector of TestProperties
Packit bd1cd8
  std::vector<TestProperty> test_properties_;
Packit bd1cd8
  // Running count of death tests.
Packit bd1cd8
  int death_test_count_;
Packit bd1cd8
  // The elapsed time, in milliseconds.
Packit bd1cd8
  TimeInMillis elapsed_time_;
Packit bd1cd8
Packit bd1cd8
  // We disallow copying TestResult.
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
Packit bd1cd8
};  // class TestResult
Packit bd1cd8
Packit bd1cd8
// A TestInfo object stores the following information about a test:
Packit bd1cd8
//
Packit bd1cd8
//   Test case name
Packit bd1cd8
//   Test name
Packit bd1cd8
//   Whether the test should be run
Packit bd1cd8
//   A function pointer that creates the test object when invoked
Packit bd1cd8
//   Test result
Packit bd1cd8
//
Packit bd1cd8
// The constructor of TestInfo registers itself with the UnitTest
Packit bd1cd8
// singleton such that the RUN_ALL_TESTS() macro knows which tests to
Packit bd1cd8
// run.
Packit bd1cd8
class GTEST_API_ TestInfo {
Packit bd1cd8
 public:
Packit bd1cd8
  // Destructs a TestInfo object.  This function is not virtual, so
Packit bd1cd8
  // don't inherit from TestInfo.
Packit bd1cd8
  ~TestInfo();
Packit bd1cd8
Packit bd1cd8
  // Returns the test case name.
Packit bd1cd8
  const char* test_case_name() const { return test_case_name_.c_str(); }
Packit bd1cd8
Packit bd1cd8
  // Returns the test name.
Packit bd1cd8
  const char* name() const { return name_.c_str(); }
Packit bd1cd8
Packit bd1cd8
  // Returns the name of the parameter type, or NULL if this is not a typed
Packit bd1cd8
  // or a type-parameterized test.
Packit bd1cd8
  const char* type_param() const {
Packit bd1cd8
    if (type_param_.get() != NULL)
Packit bd1cd8
      return type_param_->c_str();
Packit bd1cd8
    return NULL;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the text representation of the value parameter, or NULL if this
Packit bd1cd8
  // is not a value-parameterized test.
Packit bd1cd8
  const char* value_param() const {
Packit bd1cd8
    if (value_param_.get() != NULL)
Packit bd1cd8
      return value_param_->c_str();
Packit bd1cd8
    return NULL;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the file name where this test is defined.
Packit bd1cd8
  const char* file() const { return location_.file.c_str(); }
Packit bd1cd8
Packit bd1cd8
  // Returns the line where this test is defined.
Packit bd1cd8
  int line() const { return location_.line; }
Packit bd1cd8
Packit bd1cd8
  // Returns true if this test should run, that is if the test is not
Packit bd1cd8
  // disabled (or it is disabled but the also_run_disabled_tests flag has
Packit bd1cd8
  // been specified) and its full name matches the user-specified filter.
Packit bd1cd8
  //
Packit bd1cd8
  // Google Test allows the user to filter the tests by their full names.
Packit bd1cd8
  // The full name of a test Bar in test case Foo is defined as
Packit bd1cd8
  // "Foo.Bar".  Only the tests that match the filter will run.
Packit bd1cd8
  //
Packit bd1cd8
  // A filter is a colon-separated list of glob (not regex) patterns,
Packit bd1cd8
  // optionally followed by a '-' and a colon-separated list of
Packit bd1cd8
  // negative patterns (tests to exclude).  A test is run if it
Packit bd1cd8
  // matches one of the positive patterns and does not match any of
Packit bd1cd8
  // the negative patterns.
Packit bd1cd8
  //
Packit bd1cd8
  // For example, *A*:Foo.* is a filter that matches any string that
Packit bd1cd8
  // contains the character 'A' or starts with "Foo.".
Packit bd1cd8
  bool should_run() const { return should_run_; }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff this test will appear in the XML report.
Packit bd1cd8
  bool is_reportable() const {
Packit bd1cd8
    // For now, the XML report includes all tests matching the filter.
Packit bd1cd8
    // In the future, we may trim tests that are excluded because of
Packit bd1cd8
    // sharding.
Packit bd1cd8
    return matches_filter_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the result of the test.
Packit bd1cd8
  const TestResult* result() const { return &result_; }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
#if GTEST_HAS_DEATH_TEST
Packit bd1cd8
  friend class internal::DefaultDeathTestFactory;
Packit bd1cd8
#endif  // GTEST_HAS_DEATH_TEST
Packit bd1cd8
  friend class Test;
Packit bd1cd8
  friend class TestCase;
Packit bd1cd8
  friend class internal::UnitTestImpl;
Packit bd1cd8
  friend class internal::StreamingListenerTest;
Packit bd1cd8
  friend TestInfo* internal::MakeAndRegisterTestInfo(
Packit bd1cd8
      const char* test_case_name,
Packit bd1cd8
      const char* name,
Packit bd1cd8
      const char* type_param,
Packit bd1cd8
      const char* value_param,
Packit bd1cd8
      internal::CodeLocation code_location,
Packit bd1cd8
      internal::TypeId fixture_class_id,
Packit bd1cd8
      Test::SetUpTestCaseFunc set_up_tc,
Packit bd1cd8
      Test::TearDownTestCaseFunc tear_down_tc,
Packit bd1cd8
      internal::TestFactoryBase* factory);
Packit bd1cd8
Packit bd1cd8
  // Constructs a TestInfo object. The newly constructed instance assumes
Packit bd1cd8
  // ownership of the factory object.
Packit bd1cd8
  TestInfo(const std::string& test_case_name,
Packit bd1cd8
           const std::string& name,
Packit bd1cd8
           const char* a_type_param,   // NULL if not a type-parameterized test
Packit bd1cd8
           const char* a_value_param,  // NULL if not a value-parameterized test
Packit bd1cd8
           internal::CodeLocation a_code_location,
Packit bd1cd8
           internal::TypeId fixture_class_id,
Packit bd1cd8
           internal::TestFactoryBase* factory);
Packit bd1cd8
Packit bd1cd8
  // Increments the number of death tests encountered in this test so
Packit bd1cd8
  // far.
Packit bd1cd8
  int increment_death_test_count() {
Packit bd1cd8
    return result_.increment_death_test_count();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Creates the test object, runs it, records its result, and then
Packit bd1cd8
  // deletes it.
Packit bd1cd8
  void Run();
Packit bd1cd8
Packit bd1cd8
  static void ClearTestResult(TestInfo* test_info) {
Packit bd1cd8
    test_info->result_.Clear();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // These fields are immutable properties of the test.
Packit bd1cd8
  const std::string test_case_name_;     // Test case name
Packit bd1cd8
  const std::string name_;               // Test name
Packit bd1cd8
  // Name of the parameter type, or NULL if this is not a typed or a
Packit bd1cd8
  // type-parameterized test.
Packit bd1cd8
  const internal::scoped_ptr<const ::std::string> type_param_;
Packit bd1cd8
  // Text representation of the value parameter, or NULL if this is not a
Packit bd1cd8
  // value-parameterized test.
Packit bd1cd8
  const internal::scoped_ptr<const ::std::string> value_param_;
Packit bd1cd8
  internal::CodeLocation location_;
Packit bd1cd8
  const internal::TypeId fixture_class_id_;   // ID of the test fixture class
Packit bd1cd8
  bool should_run_;                 // True iff this test should run
Packit bd1cd8
  bool is_disabled_;                // True iff this test is disabled
Packit bd1cd8
  bool matches_filter_;             // True if this test matches the
Packit bd1cd8
                                    // user-specified filter.
Packit bd1cd8
  internal::TestFactoryBase* const factory_;  // The factory that creates
Packit bd1cd8
                                              // the test object
Packit bd1cd8
Packit bd1cd8
  // This field is mutable and needs to be reset before running the
Packit bd1cd8
  // test for the second time.
Packit bd1cd8
  TestResult result_;
Packit bd1cd8
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// A test case, which consists of a vector of TestInfos.
Packit bd1cd8
//
Packit bd1cd8
// TestCase is not copyable.
Packit bd1cd8
class GTEST_API_ TestCase {
Packit bd1cd8
 public:
Packit bd1cd8
  // Creates a TestCase with the given name.
Packit bd1cd8
  //
Packit bd1cd8
  // TestCase does NOT have a default constructor.  Always use this
Packit bd1cd8
  // constructor to create a TestCase object.
Packit bd1cd8
  //
Packit bd1cd8
  // Arguments:
Packit bd1cd8
  //
Packit bd1cd8
  //   name:         name of the test case
Packit bd1cd8
  //   a_type_param: the name of the test's type parameter, or NULL if
Packit bd1cd8
  //                 this is not a type-parameterized test.
Packit bd1cd8
  //   set_up_tc:    pointer to the function that sets up the test case
Packit bd1cd8
  //   tear_down_tc: pointer to the function that tears down the test case
Packit bd1cd8
  TestCase(const char* name, const char* a_type_param,
Packit bd1cd8
           Test::SetUpTestCaseFunc set_up_tc,
Packit bd1cd8
           Test::TearDownTestCaseFunc tear_down_tc);
Packit bd1cd8
Packit bd1cd8
  // Destructor of TestCase.
Packit bd1cd8
  virtual ~TestCase();
Packit bd1cd8
Packit bd1cd8
  // Gets the name of the TestCase.
Packit bd1cd8
  const char* name() const { return name_.c_str(); }
Packit bd1cd8
Packit bd1cd8
  // Returns the name of the parameter type, or NULL if this is not a
Packit bd1cd8
  // type-parameterized test case.
Packit bd1cd8
  const char* type_param() const {
Packit bd1cd8
    if (type_param_.get() != NULL)
Packit bd1cd8
      return type_param_->c_str();
Packit bd1cd8
    return NULL;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true if any test in this test case should run.
Packit bd1cd8
  bool should_run() const { return should_run_; }
Packit bd1cd8
Packit bd1cd8
  // Gets the number of successful tests in this test case.
Packit bd1cd8
  int successful_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of failed tests in this test case.
Packit bd1cd8
  int failed_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of disabled tests that will be reported in the XML report.
Packit bd1cd8
  int reportable_disabled_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of disabled tests in this test case.
Packit bd1cd8
  int disabled_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of tests to be printed in the XML report.
Packit bd1cd8
  int reportable_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Get the number of tests in this test case that should run.
Packit bd1cd8
  int test_to_run_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of all tests in this test case.
Packit bd1cd8
  int total_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test case passed.
Packit bd1cd8
  bool Passed() const { return !Failed(); }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test case failed.
Packit bd1cd8
  bool Failed() const { return failed_test_count() > 0; }
Packit bd1cd8
Packit bd1cd8
  // Returns the elapsed time, in milliseconds.
Packit bd1cd8
  TimeInMillis elapsed_time() const { return elapsed_time_; }
Packit bd1cd8
Packit bd1cd8
  // Returns the i-th test among all the tests. i can range from 0 to
Packit bd1cd8
  // total_test_count() - 1. If i is not in that range, returns NULL.
Packit bd1cd8
  const TestInfo* GetTestInfo(int i) const;
Packit bd1cd8
Packit bd1cd8
  // Returns the TestResult that holds test properties recorded during
Packit bd1cd8
  // execution of SetUpTestCase and TearDownTestCase.
Packit bd1cd8
  const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  friend class Test;
Packit bd1cd8
  friend class internal::UnitTestImpl;
Packit bd1cd8
Packit bd1cd8
  // Gets the (mutable) vector of TestInfos in this TestCase.
Packit bd1cd8
  std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
Packit bd1cd8
Packit bd1cd8
  // Gets the (immutable) vector of TestInfos in this TestCase.
Packit bd1cd8
  const std::vector<TestInfo*>& test_info_list() const {
Packit bd1cd8
    return test_info_list_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the i-th test among all the tests. i can range from 0 to
Packit bd1cd8
  // total_test_count() - 1. If i is not in that range, returns NULL.
Packit bd1cd8
  TestInfo* GetMutableTestInfo(int i);
Packit bd1cd8
Packit bd1cd8
  // Sets the should_run member.
Packit bd1cd8
  void set_should_run(bool should) { should_run_ = should; }
Packit bd1cd8
Packit bd1cd8
  // Adds a TestInfo to this test case.  Will delete the TestInfo upon
Packit bd1cd8
  // destruction of the TestCase object.
Packit bd1cd8
  void AddTestInfo(TestInfo * test_info);
Packit bd1cd8
Packit bd1cd8
  // Clears the results of all tests in this test case.
Packit bd1cd8
  void ClearResult();
Packit bd1cd8
Packit bd1cd8
  // Clears the results of all tests in the given test case.
Packit bd1cd8
  static void ClearTestCaseResult(TestCase* test_case) {
Packit bd1cd8
    test_case->ClearResult();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Runs every test in this TestCase.
Packit bd1cd8
  void Run();
Packit bd1cd8
Packit bd1cd8
  // Runs SetUpTestCase() for this TestCase.  This wrapper is needed
Packit bd1cd8
  // for catching exceptions thrown from SetUpTestCase().
Packit bd1cd8
  void RunSetUpTestCase() { (*set_up_tc_)(); }
Packit bd1cd8
Packit bd1cd8
  // Runs TearDownTestCase() for this TestCase.  This wrapper is
Packit bd1cd8
  // needed for catching exceptions thrown from TearDownTestCase().
Packit bd1cd8
  void RunTearDownTestCase() { (*tear_down_tc_)(); }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff test passed.
Packit bd1cd8
  static bool TestPassed(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->should_run() && test_info->result()->Passed();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff test failed.
Packit bd1cd8
  static bool TestFailed(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->should_run() && test_info->result()->Failed();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the test is disabled and will be reported in the XML
Packit bd1cd8
  // report.
Packit bd1cd8
  static bool TestReportableDisabled(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->is_reportable() && test_info->is_disabled_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff test is disabled.
Packit bd1cd8
  static bool TestDisabled(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->is_disabled_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff this test will appear in the XML report.
Packit bd1cd8
  static bool TestReportable(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->is_reportable();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true if the given test should run.
Packit bd1cd8
  static bool ShouldRunTest(const TestInfo* test_info) {
Packit bd1cd8
    return test_info->should_run();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Shuffles the tests in this test case.
Packit bd1cd8
  void ShuffleTests(internal::Random* random);
Packit bd1cd8
Packit bd1cd8
  // Restores the test order to before the first shuffle.
Packit bd1cd8
  void UnshuffleTests();
Packit bd1cd8
Packit bd1cd8
  // Name of the test case.
Packit bd1cd8
  std::string name_;
Packit bd1cd8
  // Name of the parameter type, or NULL if this is not a typed or a
Packit bd1cd8
  // type-parameterized test.
Packit bd1cd8
  const internal::scoped_ptr<const ::std::string> type_param_;
Packit bd1cd8
  // The vector of TestInfos in their original order.  It owns the
Packit bd1cd8
  // elements in the vector.
Packit bd1cd8
  std::vector<TestInfo*> test_info_list_;
Packit bd1cd8
  // Provides a level of indirection for the test list to allow easy
Packit bd1cd8
  // shuffling and restoring the test order.  The i-th element in this
Packit bd1cd8
  // vector is the index of the i-th test in the shuffled test list.
Packit bd1cd8
  std::vector<int> test_indices_;
Packit bd1cd8
  // Pointer to the function that sets up the test case.
Packit bd1cd8
  Test::SetUpTestCaseFunc set_up_tc_;
Packit bd1cd8
  // Pointer to the function that tears down the test case.
Packit bd1cd8
  Test::TearDownTestCaseFunc tear_down_tc_;
Packit bd1cd8
  // True iff any test in this test case should run.
Packit bd1cd8
  bool should_run_;
Packit bd1cd8
  // Elapsed time, in milliseconds.
Packit bd1cd8
  TimeInMillis elapsed_time_;
Packit bd1cd8
  // Holds test properties recorded during execution of SetUpTestCase and
Packit bd1cd8
  // TearDownTestCase.
Packit bd1cd8
  TestResult ad_hoc_test_result_;
Packit bd1cd8
Packit bd1cd8
  // We disallow copying TestCases.
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// An Environment object is capable of setting up and tearing down an
Packit bd1cd8
// environment.  You should subclass this to define your own
Packit bd1cd8
// environment(s).
Packit bd1cd8
//
Packit bd1cd8
// An Environment object does the set-up and tear-down in virtual
Packit bd1cd8
// methods SetUp() and TearDown() instead of the constructor and the
Packit bd1cd8
// destructor, as:
Packit bd1cd8
//
Packit bd1cd8
//   1. You cannot safely throw from a destructor.  This is a problem
Packit bd1cd8
//      as in some cases Google Test is used where exceptions are enabled, and
Packit bd1cd8
//      we may want to implement ASSERT_* using exceptions where they are
Packit bd1cd8
//      available.
Packit bd1cd8
//   2. You cannot use ASSERT_* directly in a constructor or
Packit bd1cd8
//      destructor.
Packit bd1cd8
class Environment {
Packit bd1cd8
 public:
Packit bd1cd8
  // The d'tor is virtual as we need to subclass Environment.
Packit bd1cd8
  virtual ~Environment() {}
Packit bd1cd8
Packit bd1cd8
  // Override this to define how to set up the environment.
Packit bd1cd8
  virtual void SetUp() {}
Packit bd1cd8
Packit bd1cd8
  // Override this to define how to tear down the environment.
Packit bd1cd8
  virtual void TearDown() {}
Packit bd1cd8
 private:
Packit bd1cd8
  // If you see an error about overriding the following function or
Packit bd1cd8
  // about it being private, you have mis-spelled SetUp() as Setup().
Packit bd1cd8
  struct Setup_should_be_spelled_SetUp {};
Packit bd1cd8
  virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// The interface for tracing execution of tests. The methods are organized in
Packit bd1cd8
// the order the corresponding events are fired.
Packit bd1cd8
class TestEventListener {
Packit bd1cd8
 public:
Packit bd1cd8
  virtual ~TestEventListener() {}
Packit bd1cd8
Packit bd1cd8
  // Fired before any test activity starts.
Packit bd1cd8
  virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired before each iteration of tests starts.  There may be more than
Packit bd1cd8
  // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
Packit bd1cd8
  // index, starting from 0.
Packit bd1cd8
  virtual void OnTestIterationStart(const UnitTest& unit_test,
Packit bd1cd8
                                    int iteration) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired before environment set-up for each iteration of tests starts.
Packit bd1cd8
  virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after environment set-up for each iteration of tests ends.
Packit bd1cd8
  virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired before the test case starts.
Packit bd1cd8
  virtual void OnTestCaseStart(const TestCase& test_case) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired before the test starts.
Packit bd1cd8
  virtual void OnTestStart(const TestInfo& test_info) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after a failed assertion or a SUCCEED() invocation.
Packit bd1cd8
  virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after the test ends.
Packit bd1cd8
  virtual void OnTestEnd(const TestInfo& test_info) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after the test case ends.
Packit bd1cd8
  virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired before environment tear-down for each iteration of tests starts.
Packit bd1cd8
  virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after environment tear-down for each iteration of tests ends.
Packit bd1cd8
  virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after each iteration of tests finishes.
Packit bd1cd8
  virtual void OnTestIterationEnd(const UnitTest& unit_test,
Packit bd1cd8
                                  int iteration) = 0;
Packit bd1cd8
Packit bd1cd8
  // Fired after all test activities have ended.
Packit bd1cd8
  virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// The convenience class for users who need to override just one or two
Packit bd1cd8
// methods and are not concerned that a possible change to a signature of
Packit bd1cd8
// the methods they override will not be caught during the build.  For
Packit bd1cd8
// comments about each method please see the definition of TestEventListener
Packit bd1cd8
// above.
Packit bd1cd8
class EmptyTestEventListener : public TestEventListener {
Packit bd1cd8
 public:
Packit bd1cd8
  virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
  virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
Packit bd1cd8
                                    int /*iteration*/) {}
Packit bd1cd8
  virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
  virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
  virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
Packit bd1cd8
  virtual void OnTestStart(const TestInfo& /*test_info*/) {}
Packit bd1cd8
  virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
Packit bd1cd8
  virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
Packit bd1cd8
  virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
Packit bd1cd8
  virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
  virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
  virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
Packit bd1cd8
                                  int /*iteration*/) {}
Packit bd1cd8
  virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// TestEventListeners lets users add listeners to track events in Google Test.
Packit bd1cd8
class GTEST_API_ TestEventListeners {
Packit bd1cd8
 public:
Packit bd1cd8
  TestEventListeners();
Packit bd1cd8
  ~TestEventListeners();
Packit bd1cd8
Packit bd1cd8
  // Appends an event listener to the end of the list. Google Test assumes
Packit bd1cd8
  // the ownership of the listener (i.e. it will delete the listener when
Packit bd1cd8
  // the test program finishes).
Packit bd1cd8
  void Append(TestEventListener* listener);
Packit bd1cd8
Packit bd1cd8
  // Removes the given event listener from the list and returns it.  It then
Packit bd1cd8
  // becomes the caller's responsibility to delete the listener. Returns
Packit bd1cd8
  // NULL if the listener is not found in the list.
Packit bd1cd8
  TestEventListener* Release(TestEventListener* listener);
Packit bd1cd8
Packit bd1cd8
  // Returns the standard listener responsible for the default console
Packit bd1cd8
  // output.  Can be removed from the listeners list to shut down default
Packit bd1cd8
  // console output.  Note that removing this object from the listener list
Packit bd1cd8
  // with Release transfers its ownership to the caller and makes this
Packit bd1cd8
  // function return NULL the next time.
Packit bd1cd8
  TestEventListener* default_result_printer() const {
Packit bd1cd8
    return default_result_printer_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the standard listener responsible for the default XML output
Packit bd1cd8
  // controlled by the --gtest_output=xml flag.  Can be removed from the
Packit bd1cd8
  // listeners list by users who want to shut down the default XML output
Packit bd1cd8
  // controlled by this flag and substitute it with custom one.  Note that
Packit bd1cd8
  // removing this object from the listener list with Release transfers its
Packit bd1cd8
  // ownership to the caller and makes this function return NULL the next
Packit bd1cd8
  // time.
Packit bd1cd8
  TestEventListener* default_xml_generator() const {
Packit bd1cd8
    return default_xml_generator_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  friend class TestCase;
Packit bd1cd8
  friend class TestInfo;
Packit bd1cd8
  friend class internal::DefaultGlobalTestPartResultReporter;
Packit bd1cd8
  friend class internal::NoExecDeathTest;
Packit bd1cd8
  friend class internal::TestEventListenersAccessor;
Packit bd1cd8
  friend class internal::UnitTestImpl;
Packit bd1cd8
Packit bd1cd8
  // Returns repeater that broadcasts the TestEventListener events to all
Packit bd1cd8
  // subscribers.
Packit bd1cd8
  TestEventListener* repeater();
Packit bd1cd8
Packit bd1cd8
  // Sets the default_result_printer attribute to the provided listener.
Packit bd1cd8
  // The listener is also added to the listener list and previous
Packit bd1cd8
  // default_result_printer is removed from it and deleted. The listener can
Packit bd1cd8
  // also be NULL in which case it will not be added to the list. Does
Packit bd1cd8
  // nothing if the previous and the current listener objects are the same.
Packit bd1cd8
  void SetDefaultResultPrinter(TestEventListener* listener);
Packit bd1cd8
Packit bd1cd8
  // Sets the default_xml_generator attribute to the provided listener.  The
Packit bd1cd8
  // listener is also added to the listener list and previous
Packit bd1cd8
  // default_xml_generator is removed from it and deleted. The listener can
Packit bd1cd8
  // also be NULL in which case it will not be added to the list. Does
Packit bd1cd8
  // nothing if the previous and the current listener objects are the same.
Packit bd1cd8
  void SetDefaultXmlGenerator(TestEventListener* listener);
Packit bd1cd8
Packit bd1cd8
  // Controls whether events will be forwarded by the repeater to the
Packit bd1cd8
  // listeners in the list.
Packit bd1cd8
  bool EventForwardingEnabled() const;
Packit bd1cd8
  void SuppressEventForwarding();
Packit bd1cd8
Packit bd1cd8
  // The actual list of listeners.
Packit bd1cd8
  internal::TestEventRepeater* repeater_;
Packit bd1cd8
  // Listener responsible for the standard result output.
Packit bd1cd8
  TestEventListener* default_result_printer_;
Packit bd1cd8
  // Listener responsible for the creation of the XML output file.
Packit bd1cd8
  TestEventListener* default_xml_generator_;
Packit bd1cd8
Packit bd1cd8
  // We disallow copying TestEventListeners.
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// A UnitTest consists of a vector of TestCases.
Packit bd1cd8
//
Packit bd1cd8
// This is a singleton class.  The only instance of UnitTest is
Packit bd1cd8
// created when UnitTest::GetInstance() is first called.  This
Packit bd1cd8
// instance is never deleted.
Packit bd1cd8
//
Packit bd1cd8
// UnitTest is not copyable.
Packit bd1cd8
//
Packit bd1cd8
// This class is thread-safe as long as the methods are called
Packit bd1cd8
// according to their specification.
Packit bd1cd8
class GTEST_API_ UnitTest {
Packit bd1cd8
 public:
Packit bd1cd8
  // Gets the singleton UnitTest object.  The first time this method
Packit bd1cd8
  // is called, a UnitTest object is constructed and returned.
Packit bd1cd8
  // Consecutive calls will return the same object.
Packit bd1cd8
  static UnitTest* GetInstance();
Packit bd1cd8
Packit bd1cd8
  // Runs all tests in this UnitTest object and prints the result.
Packit bd1cd8
  // Returns 0 if successful, or 1 otherwise.
Packit bd1cd8
  //
Packit bd1cd8
  // This method can only be called from the main thread.
Packit bd1cd8
  //
Packit bd1cd8
  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
  int Run() GTEST_MUST_USE_RESULT_;
Packit bd1cd8
Packit bd1cd8
  // Returns the working directory when the first TEST() or TEST_F()
Packit bd1cd8
  // was executed.  The UnitTest object owns the string.
Packit bd1cd8
  const char* original_working_dir() const;
Packit bd1cd8
Packit bd1cd8
  // Returns the TestCase object for the test that's currently running,
Packit bd1cd8
  // or NULL if no test is running.
Packit bd1cd8
  const TestCase* current_test_case() const
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
Packit bd1cd8
  // Returns the TestInfo object for the test that's currently running,
Packit bd1cd8
  // or NULL if no test is running.
Packit bd1cd8
  const TestInfo* current_test_info() const
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
Packit bd1cd8
  // Returns the random seed used at the start of the current test run.
Packit bd1cd8
  int random_seed() const;
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_PARAM_TEST
Packit bd1cd8
  // Returns the ParameterizedTestCaseRegistry object used to keep track of
Packit bd1cd8
  // value-parameterized tests and instantiate and register them.
Packit bd1cd8
  //
Packit bd1cd8
  // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
  internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
#endif  // GTEST_HAS_PARAM_TEST
Packit bd1cd8
Packit bd1cd8
  // Gets the number of successful test cases.
Packit bd1cd8
  int successful_test_case_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of failed test cases.
Packit bd1cd8
  int failed_test_case_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of all test cases.
Packit bd1cd8
  int total_test_case_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of all test cases that contain at least one test
Packit bd1cd8
  // that should run.
Packit bd1cd8
  int test_case_to_run_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of successful tests.
Packit bd1cd8
  int successful_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of failed tests.
Packit bd1cd8
  int failed_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of disabled tests that will be reported in the XML report.
Packit bd1cd8
  int reportable_disabled_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of disabled tests.
Packit bd1cd8
  int disabled_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of tests to be printed in the XML report.
Packit bd1cd8
  int reportable_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of all tests.
Packit bd1cd8
  int total_test_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the number of tests that should run.
Packit bd1cd8
  int test_to_run_count() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the time of the test program start, in ms from the start of the
Packit bd1cd8
  // UNIX epoch.
Packit bd1cd8
  TimeInMillis start_timestamp() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the elapsed time, in milliseconds.
Packit bd1cd8
  TimeInMillis elapsed_time() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the unit test passed (i.e. all test cases passed).
Packit bd1cd8
  bool Passed() const;
Packit bd1cd8
Packit bd1cd8
  // Returns true iff the unit test failed (i.e. some test case failed
Packit bd1cd8
  // or something outside of all tests failed).
Packit bd1cd8
  bool Failed() const;
Packit bd1cd8
Packit bd1cd8
  // Gets the i-th test case among all the test cases. i can range from 0 to
Packit bd1cd8
  // total_test_case_count() - 1. If i is not in that range, returns NULL.
Packit bd1cd8
  const TestCase* GetTestCase(int i) const;
Packit bd1cd8
Packit bd1cd8
  // Returns the TestResult containing information on test failures and
Packit bd1cd8
  // properties logged outside of individual test cases.
Packit bd1cd8
  const TestResult& ad_hoc_test_result() const;
Packit bd1cd8
Packit bd1cd8
  // Returns the list of event listeners that can be used to track events
Packit bd1cd8
  // inside Google Test.
Packit bd1cd8
  TestEventListeners& listeners();
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // Registers and returns a global test environment.  When a test
Packit bd1cd8
  // program is run, all global test environments will be set-up in
Packit bd1cd8
  // the order they were registered.  After all tests in the program
Packit bd1cd8
  // have finished, all global test environments will be torn-down in
Packit bd1cd8
  // the *reverse* order they were registered.
Packit bd1cd8
  //
Packit bd1cd8
  // The UnitTest object takes ownership of the given environment.
Packit bd1cd8
  //
Packit bd1cd8
  // This method can only be called from the main thread.
Packit bd1cd8
  Environment* AddEnvironment(Environment* env);
Packit bd1cd8
Packit bd1cd8
  // Adds a TestPartResult to the current TestResult object.  All
Packit bd1cd8
  // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
Packit bd1cd8
  // eventually call this to report their results.  The user code
Packit bd1cd8
  // should use the assertion macros instead of calling this directly.
Packit bd1cd8
  void AddTestPartResult(TestPartResult::Type result_type,
Packit bd1cd8
                         const char* file_name,
Packit bd1cd8
                         int line_number,
Packit bd1cd8
                         const std::string& message,
Packit bd1cd8
                         const std::string& os_stack_trace)
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
Packit bd1cd8
  // Adds a TestProperty to the current TestResult object when invoked from
Packit bd1cd8
  // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
Packit bd1cd8
  // from SetUpTestCase or TearDownTestCase, or to the global property set
Packit bd1cd8
  // when invoked elsewhere.  If the result already contains a property with
Packit bd1cd8
  // the same key, the value will be updated.
Packit bd1cd8
  void RecordProperty(const std::string& key, const std::string& value);
Packit bd1cd8
Packit bd1cd8
  // Gets the i-th test case among all the test cases. i can range from 0 to
Packit bd1cd8
  // total_test_case_count() - 1. If i is not in that range, returns NULL.
Packit bd1cd8
  TestCase* GetMutableTestCase(int i);
Packit bd1cd8
Packit bd1cd8
  // Accessors for the implementation object.
Packit bd1cd8
  internal::UnitTestImpl* impl() { return impl_; }
Packit bd1cd8
  const internal::UnitTestImpl* impl() const { return impl_; }
Packit bd1cd8
Packit bd1cd8
  // These classes and funcions are friends as they need to access private
Packit bd1cd8
  // members of UnitTest.
Packit bd1cd8
  friend class Test;
Packit bd1cd8
  friend class internal::AssertHelper;
Packit bd1cd8
  friend class internal::ScopedTrace;
Packit bd1cd8
  friend class internal::StreamingListenerTest;
Packit bd1cd8
  friend class internal::UnitTestRecordPropertyTestHelper;
Packit bd1cd8
  friend Environment* AddGlobalTestEnvironment(Environment* env);
Packit bd1cd8
  friend internal::UnitTestImpl* internal::GetUnitTestImpl();
Packit bd1cd8
  friend void internal::ReportFailureInUnknownLocation(
Packit bd1cd8
      TestPartResult::Type result_type,
Packit bd1cd8
      const std::string& message);
Packit bd1cd8
Packit bd1cd8
  // Creates an empty UnitTest.
Packit bd1cd8
  UnitTest();
Packit bd1cd8
Packit bd1cd8
  // D'tor
Packit bd1cd8
  virtual ~UnitTest();
Packit bd1cd8
Packit bd1cd8
  // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
Packit bd1cd8
  // Google Test trace stack.
Packit bd1cd8
  void PushGTestTrace(const internal::TraceInfo& trace)
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
Packit bd1cd8
  // Pops a trace from the per-thread Google Test trace stack.
Packit bd1cd8
  void PopGTestTrace()
Packit bd1cd8
      GTEST_LOCK_EXCLUDED_(mutex_);
Packit bd1cd8
Packit bd1cd8
  // Protects mutable state in *impl_.  This is mutable as some const
Packit bd1cd8
  // methods need to lock it too.
Packit bd1cd8
  mutable internal::Mutex mutex_;
Packit bd1cd8
Packit bd1cd8
  // Opaque implementation object.  This field is never changed once
Packit bd1cd8
  // the object is constructed.  We don't mark it as const here, as
Packit bd1cd8
  // doing so will cause a warning in the constructor of UnitTest.
Packit bd1cd8
  // Mutable state in *impl_ is protected by mutex_.
Packit bd1cd8
  internal::UnitTestImpl* impl_;
Packit bd1cd8
Packit bd1cd8
  // We disallow copying UnitTest.
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// A convenient wrapper for adding an environment for the test
Packit bd1cd8
// program.
Packit bd1cd8
//
Packit bd1cd8
// You should call this before RUN_ALL_TESTS() is called, probably in
Packit bd1cd8
// main().  If you use gtest_main, you need to call this before main()
Packit bd1cd8
// starts for it to take effect.  For example, you can define a global
Packit bd1cd8
// variable like this:
Packit bd1cd8
//
Packit bd1cd8
//   testing::Environment* const foo_env =
Packit bd1cd8
//       testing::AddGlobalTestEnvironment(new FooEnvironment);
Packit bd1cd8
//
Packit bd1cd8
// However, we strongly recommend you to write your own main() and
Packit bd1cd8
// call AddGlobalTestEnvironment() there, as relying on initialization
Packit bd1cd8
// of global variables makes the code harder to read and may cause
Packit bd1cd8
// problems when you register multiple environments from different
Packit bd1cd8
// translation units and the environments have dependencies among them
Packit bd1cd8
// (remember that the compiler doesn't guarantee the order in which
Packit bd1cd8
// global variables from different translation units are initialized).
Packit bd1cd8
inline Environment* AddGlobalTestEnvironment(Environment* env) {
Packit bd1cd8
  return UnitTest::GetInstance()->AddEnvironment(env);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Initializes Google Test.  This must be called before calling
Packit bd1cd8
// RUN_ALL_TESTS().  In particular, it parses a command line for the
Packit bd1cd8
// flags that Google Test recognizes.  Whenever a Google Test flag is
Packit bd1cd8
// seen, it is removed from argv, and *argc is decremented.
Packit bd1cd8
//
Packit bd1cd8
// No value is returned.  Instead, the Google Test flag variables are
Packit bd1cd8
// updated.
Packit bd1cd8
//
Packit bd1cd8
// Calling the function for the second time has no user-visible effect.
Packit bd1cd8
GTEST_API_ void InitGoogleTest(int* argc, char** argv);
Packit bd1cd8
Packit bd1cd8
// This overloaded version can be used in Windows programs compiled in
Packit bd1cd8
// UNICODE mode.
Packit bd1cd8
GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
Packit bd1cd8
Packit bd1cd8
namespace internal {
Packit bd1cd8
Packit bd1cd8
// Separate the error generating code from the code path to reduce the stack
Packit bd1cd8
// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
Packit bd1cd8
// when calling EXPECT_* in a tight loop.
Packit bd1cd8
template <typename T1, typename T2>
Packit bd1cd8
AssertionResult CmpHelperEQFailure(const char* lhs_expression,
Packit bd1cd8
                                   const char* rhs_expression,
Packit bd1cd8
                                   const T1& lhs, const T2& rhs) {
Packit bd1cd8
  return EqFailure(lhs_expression,
Packit bd1cd8
                   rhs_expression,
Packit bd1cd8
                   FormatForComparisonFailureMessage(lhs, rhs),
Packit bd1cd8
                   FormatForComparisonFailureMessage(rhs, lhs),
Packit bd1cd8
                   false);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// The helper function for {ASSERT|EXPECT}_EQ.
Packit bd1cd8
template <typename T1, typename T2>
Packit bd1cd8
AssertionResult CmpHelperEQ(const char* lhs_expression,
Packit bd1cd8
                            const char* rhs_expression,
Packit bd1cd8
                            const T1& lhs,
Packit bd1cd8
                            const T2& rhs) {
Packit bd1cd8
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
Packit bd1cd8
  if (lhs == rhs) {
Packit bd1cd8
    return AssertionSuccess();
Packit bd1cd8
  }
Packit bd1cd8
GTEST_DISABLE_MSC_WARNINGS_POP_()
Packit bd1cd8
Packit bd1cd8
  return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// With this overloaded version, we allow anonymous enums to be used
Packit bd1cd8
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
Packit bd1cd8
// can be implicitly cast to BiggestInt.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
Packit bd1cd8
                                       const char* rhs_expression,
Packit bd1cd8
                                       BiggestInt lhs,
Packit bd1cd8
                                       BiggestInt rhs);
Packit bd1cd8
Packit bd1cd8
// The helper class for {ASSERT|EXPECT}_EQ.  The template argument
Packit bd1cd8
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
Packit bd1cd8
// is a null pointer literal.  The following default implementation is
Packit bd1cd8
// for lhs_is_null_literal being false.
Packit bd1cd8
template <bool lhs_is_null_literal>
Packit bd1cd8
class EqHelper {
Packit bd1cd8
 public:
Packit bd1cd8
  // This templatized version is for the general case.
Packit bd1cd8
  template <typename T1, typename T2>
Packit bd1cd8
  static AssertionResult Compare(const char* lhs_expression,
Packit bd1cd8
                                 const char* rhs_expression,
Packit bd1cd8
                                 const T1& lhs,
Packit bd1cd8
                                 const T2& rhs) {
Packit bd1cd8
    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // With this overloaded version, we allow anonymous enums to be used
Packit bd1cd8
  // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
Packit bd1cd8
  // enums can be implicitly cast to BiggestInt.
Packit bd1cd8
  //
Packit bd1cd8
  // Even though its body looks the same as the above version, we
Packit bd1cd8
  // cannot merge the two, as it will make anonymous enums unhappy.
Packit bd1cd8
  static AssertionResult Compare(const char* lhs_expression,
Packit bd1cd8
                                 const char* rhs_expression,
Packit bd1cd8
                                 BiggestInt lhs,
Packit bd1cd8
                                 BiggestInt rhs) {
Packit bd1cd8
    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// This specialization is used when the first argument to ASSERT_EQ()
Packit bd1cd8
// is a null pointer literal, like NULL, false, or 0.
Packit bd1cd8
template <>
Packit bd1cd8
class EqHelper<true> {
Packit bd1cd8
 public:
Packit bd1cd8
  // We define two overloaded versions of Compare().  The first
Packit bd1cd8
  // version will be picked when the second argument to ASSERT_EQ() is
Packit bd1cd8
  // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
Packit bd1cd8
  // EXPECT_EQ(false, a_bool).
Packit bd1cd8
  template <typename T1, typename T2>
Packit bd1cd8
  static AssertionResult Compare(
Packit bd1cd8
      const char* lhs_expression,
Packit bd1cd8
      const char* rhs_expression,
Packit bd1cd8
      const T1& lhs,
Packit bd1cd8
      const T2& rhs,
Packit bd1cd8
      // The following line prevents this overload from being considered if T2
Packit bd1cd8
      // is not a pointer type.  We need this because ASSERT_EQ(NULL, my_ptr)
Packit bd1cd8
      // expands to Compare("", "", NULL, my_ptr), which requires a conversion
Packit bd1cd8
      // to match the Secret* in the other overload, which would otherwise make
Packit bd1cd8
      // this template match better.
Packit bd1cd8
      typename EnableIf::value>::type* = 0) {
Packit bd1cd8
    return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // This version will be picked when the second argument to ASSERT_EQ() is a
Packit bd1cd8
  // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
Packit bd1cd8
  template <typename T>
Packit bd1cd8
  static AssertionResult Compare(
Packit bd1cd8
      const char* lhs_expression,
Packit bd1cd8
      const char* rhs_expression,
Packit bd1cd8
      // We used to have a second template parameter instead of Secret*.  That
Packit bd1cd8
      // template parameter would deduce to 'long', making this a better match
Packit bd1cd8
      // than the first overload even without the first overload's EnableIf.
Packit bd1cd8
      // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
Packit bd1cd8
      // non-pointer argument" (even a deduced integral argument), so the old
Packit bd1cd8
      // implementation caused warnings in user code.
Packit bd1cd8
      Secret* /* lhs (NULL) */,
Packit bd1cd8
      T* rhs) {
Packit bd1cd8
    // We already know that 'lhs' is a null pointer.
Packit bd1cd8
    return CmpHelperEQ(lhs_expression, rhs_expression,
Packit bd1cd8
                       static_cast<T*>(NULL), rhs);
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Separate the error generating code from the code path to reduce the stack
Packit bd1cd8
// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
Packit bd1cd8
// when calling EXPECT_OP in a tight loop.
Packit bd1cd8
template <typename T1, typename T2>
Packit bd1cd8
AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
Packit bd1cd8
                                   const T1& val1, const T2& val2,
Packit bd1cd8
                                   const char* op) {
Packit bd1cd8
  return AssertionFailure()
Packit bd1cd8
         << "Expected: (" << expr1 << ") " << op << " (" << expr2
Packit bd1cd8
         << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
Packit bd1cd8
         << " vs " << FormatForComparisonFailureMessage(val2, val1);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// A macro for implementing the helper functions needed to implement
Packit bd1cd8
// ASSERT_?? and EXPECT_??.  It is here just to avoid copy-and-paste
Packit bd1cd8
// of similar code.
Packit bd1cd8
//
Packit bd1cd8
// For each templatized helper function, we also define an overloaded
Packit bd1cd8
// version for BiggestInt in order to reduce code bloat and allow
Packit bd1cd8
// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
Packit bd1cd8
// with gcc 4.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
Packit bd1cd8
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
Packit bd1cd8
template <typename T1, typename T2>\
Packit bd1cd8
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
Packit bd1cd8
                                   const T1& val1, const T2& val2) {\
Packit bd1cd8
  if (val1 op val2) {\
Packit bd1cd8
    return AssertionSuccess();\
Packit bd1cd8
  } else {\
Packit bd1cd8
    return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
Packit bd1cd8
  }\
Packit bd1cd8
}\
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelper##op_name(\
Packit bd1cd8
    const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
Packit bd1cd8
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
Packit bd1cd8
// Implements the helper function for {ASSERT|EXPECT}_NE
Packit bd1cd8
GTEST_IMPL_CMP_HELPER_(NE, !=);
Packit bd1cd8
// Implements the helper function for {ASSERT|EXPECT}_LE
Packit bd1cd8
GTEST_IMPL_CMP_HELPER_(LE, <=);
Packit bd1cd8
// Implements the helper function for {ASSERT|EXPECT}_LT
Packit bd1cd8
GTEST_IMPL_CMP_HELPER_(LT, <);
Packit bd1cd8
// Implements the helper function for {ASSERT|EXPECT}_GE
Packit bd1cd8
GTEST_IMPL_CMP_HELPER_(GE, >=);
Packit bd1cd8
// Implements the helper function for {ASSERT|EXPECT}_GT
Packit bd1cd8
GTEST_IMPL_CMP_HELPER_(GT, >);
Packit bd1cd8
Packit bd1cd8
#undef GTEST_IMPL_CMP_HELPER_
Packit bd1cd8
Packit bd1cd8
// The helper function for {ASSERT|EXPECT}_STREQ.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
Packit bd1cd8
                                          const char* s2_expression,
Packit bd1cd8
                                          const char* s1,
Packit bd1cd8
                                          const char* s2);
Packit bd1cd8
Packit bd1cd8
// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
Packit bd1cd8
                                              const char* s2_expression,
Packit bd1cd8
                                              const char* s1,
Packit bd1cd8
                                              const char* s2);
Packit bd1cd8
Packit bd1cd8
// The helper function for {ASSERT|EXPECT}_STRNE.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
Packit bd1cd8
                                          const char* s2_expression,
Packit bd1cd8
                                          const char* s1,
Packit bd1cd8
                                          const char* s2);
Packit bd1cd8
Packit bd1cd8
// The helper function for {ASSERT|EXPECT}_STRCASENE.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
Packit bd1cd8
                                              const char* s2_expression,
Packit bd1cd8
                                              const char* s1,
Packit bd1cd8
                                              const char* s2);
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
// Helper function for *_STREQ on wide strings.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
Packit bd1cd8
                                          const char* s2_expression,
Packit bd1cd8
                                          const wchar_t* s1,
Packit bd1cd8
                                          const wchar_t* s2);
Packit bd1cd8
Packit bd1cd8
// Helper function for *_STRNE on wide strings.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
Packit bd1cd8
                                          const char* s2_expression,
Packit bd1cd8
                                          const wchar_t* s1,
Packit bd1cd8
                                          const wchar_t* s2);
Packit bd1cd8
Packit bd1cd8
}  // namespace internal
Packit bd1cd8
Packit bd1cd8
// IsSubstring() and IsNotSubstring() are intended to be used as the
Packit bd1cd8
// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
Packit bd1cd8
// themselves.  They check whether needle is a substring of haystack
Packit bd1cd8
// (NULL is considered a substring of itself only), and return an
Packit bd1cd8
// appropriate error message when they fail.
Packit bd1cd8
//
Packit bd1cd8
// The {needle,haystack}_expr arguments are the stringified
Packit bd1cd8
// expressions that generated the two real arguments.
Packit bd1cd8
GTEST_API_ AssertionResult IsSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const char* needle, const char* haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const wchar_t* needle, const wchar_t* haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsNotSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const char* needle, const char* haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsNotSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const wchar_t* needle, const wchar_t* haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const ::std::string& needle, const ::std::string& haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsNotSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const ::std::string& needle, const ::std::string& haystack);
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_STD_WSTRING
Packit bd1cd8
GTEST_API_ AssertionResult IsSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const ::std::wstring& needle, const ::std::wstring& haystack);
Packit bd1cd8
GTEST_API_ AssertionResult IsNotSubstring(
Packit bd1cd8
    const char* needle_expr, const char* haystack_expr,
Packit bd1cd8
    const ::std::wstring& needle, const ::std::wstring& haystack);
Packit bd1cd8
#endif  // GTEST_HAS_STD_WSTRING
Packit bd1cd8
Packit bd1cd8
namespace internal {
Packit bd1cd8
Packit bd1cd8
// Helper template function for comparing floating-points.
Packit bd1cd8
//
Packit bd1cd8
// Template parameter:
Packit bd1cd8
//
Packit bd1cd8
//   RawType: the raw floating-point type (either float or double)
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
template <typename RawType>
Packit bd1cd8
AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
Packit bd1cd8
                                         const char* rhs_expression,
Packit bd1cd8
                                         RawType lhs_value,
Packit bd1cd8
                                         RawType rhs_value) {
Packit bd1cd8
  const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
Packit bd1cd8
Packit bd1cd8
  if (lhs.AlmostEquals(rhs)) {
Packit bd1cd8
    return AssertionSuccess();
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  ::std::stringstream lhs_ss;
Packit bd1cd8
  lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
Packit bd1cd8
         << lhs_value;
Packit bd1cd8
Packit bd1cd8
  ::std::stringstream rhs_ss;
Packit bd1cd8
  rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
Packit bd1cd8
         << rhs_value;
Packit bd1cd8
Packit bd1cd8
  return EqFailure(lhs_expression,
Packit bd1cd8
                   rhs_expression,
Packit bd1cd8
                   StringStreamToString(&lhs_ss),
Packit bd1cd8
                   StringStreamToString(&rhs_ss),
Packit bd1cd8
                   false);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Helper function for implementing ASSERT_NEAR.
Packit bd1cd8
//
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Packit bd1cd8
GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
Packit bd1cd8
                                                const char* expr2,
Packit bd1cd8
                                                const char* abs_error_expr,
Packit bd1cd8
                                                double val1,
Packit bd1cd8
                                                double val2,
Packit bd1cd8
                                                double abs_error);
Packit bd1cd8
Packit bd1cd8
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Packit bd1cd8
// A class that enables one to stream messages to assertion macros
Packit bd1cd8
class GTEST_API_ AssertHelper {
Packit bd1cd8
 public:
Packit bd1cd8
  // Constructor.
Packit bd1cd8
  AssertHelper(TestPartResult::Type type,
Packit bd1cd8
               const char* file,
Packit bd1cd8
               int line,
Packit bd1cd8
               const char* message);
Packit bd1cd8
  ~AssertHelper();
Packit bd1cd8
Packit bd1cd8
  // Message assignment is a semantic trick to enable assertion
Packit bd1cd8
  // streaming; see the GTEST_MESSAGE_ macro below.
Packit bd1cd8
  void operator=(const Message& message) const;
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // We put our data in a struct so that the size of the AssertHelper class can
Packit bd1cd8
  // be as small as possible.  This is important because gcc is incapable of
Packit bd1cd8
  // re-using stack space even for temporary variables, so every EXPECT_EQ
Packit bd1cd8
  // reserves stack space for another AssertHelper.
Packit bd1cd8
  struct AssertHelperData {
Packit bd1cd8
    AssertHelperData(TestPartResult::Type t,
Packit bd1cd8
                     const char* srcfile,
Packit bd1cd8
                     int line_num,
Packit bd1cd8
                     const char* msg)
Packit bd1cd8
        : type(t), file(srcfile), line(line_num), message(msg) { }
Packit bd1cd8
Packit bd1cd8
    TestPartResult::Type const type;
Packit bd1cd8
    const char* const file;
Packit bd1cd8
    int const line;
Packit bd1cd8
    std::string const message;
Packit bd1cd8
Packit bd1cd8
   private:
Packit bd1cd8
    GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
Packit bd1cd8
  };
Packit bd1cd8
Packit bd1cd8
  AssertHelperData* const data_;
Packit bd1cd8
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
}  // namespace internal
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_PARAM_TEST
Packit bd1cd8
// The pure interface class that all value-parameterized tests inherit from.
Packit bd1cd8
// A value-parameterized class must inherit from both ::testing::Test and
Packit bd1cd8
// ::testing::WithParamInterface. In most cases that just means inheriting
Packit bd1cd8
// from ::testing::TestWithParam, but more complicated test hierarchies
Packit bd1cd8
// may need to inherit from Test and WithParamInterface at different levels.
Packit bd1cd8
//
Packit bd1cd8
// This interface has support for accessing the test parameter value via
Packit bd1cd8
// the GetParam() method.
Packit bd1cd8
//
Packit bd1cd8
// Use it with one of the parameter generator defining functions, like Range(),
Packit bd1cd8
// Values(), ValuesIn(), Bool(), and Combine().
Packit bd1cd8
//
Packit bd1cd8
// class FooTest : public ::testing::TestWithParam<int> {
Packit bd1cd8
//  protected:
Packit bd1cd8
//   FooTest() {
Packit bd1cd8
//     // Can use GetParam() here.
Packit bd1cd8
//   }
Packit bd1cd8
//   virtual ~FooTest() {
Packit bd1cd8
//     // Can use GetParam() here.
Packit bd1cd8
//   }
Packit bd1cd8
//   virtual void SetUp() {
Packit bd1cd8
//     // Can use GetParam() here.
Packit bd1cd8
//   }
Packit bd1cd8
//   virtual void TearDown {
Packit bd1cd8
//     // Can use GetParam() here.
Packit bd1cd8
//   }
Packit bd1cd8
// };
Packit bd1cd8
// TEST_P(FooTest, DoesBar) {
Packit bd1cd8
//   // Can use GetParam() method here.
Packit bd1cd8
//   Foo foo;
Packit bd1cd8
//   ASSERT_TRUE(foo.DoesBar(GetParam()));
Packit bd1cd8
// }
Packit bd1cd8
// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
class WithParamInterface {
Packit bd1cd8
 public:
Packit bd1cd8
  typedef T ParamType;
Packit bd1cd8
  virtual ~WithParamInterface() {}
Packit bd1cd8
Packit bd1cd8
  // The current parameter value. Is also available in the test fixture's
Packit bd1cd8
  // constructor. This member function is non-static, even though it only
Packit bd1cd8
  // references static data, to reduce the opportunity for incorrect uses
Packit bd1cd8
  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
Packit bd1cd8
  // uses a fixture whose parameter type is int.
Packit bd1cd8
  const ParamType& GetParam() const {
Packit bd1cd8
    GTEST_CHECK_(parameter_ != NULL)
Packit bd1cd8
        << "GetParam() can only be called inside a value-parameterized test "
Packit bd1cd8
        << "-- did you intend to write TEST_P instead of TEST_F?";
Packit bd1cd8
    return *parameter_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // Sets parameter value. The caller is responsible for making sure the value
Packit bd1cd8
  // remains alive and unchanged throughout the current test.
Packit bd1cd8
  static void SetParam(const ParamType* parameter) {
Packit bd1cd8
    parameter_ = parameter;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Static value used for accessing parameter during a test lifetime.
Packit bd1cd8
  static const ParamType* parameter_;
Packit bd1cd8
Packit bd1cd8
  // TestClass must be a subclass of WithParamInterface<T> and Test.
Packit bd1cd8
  template <class TestClass> friend class internal::ParameterizedTestFactory;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
const T* WithParamInterface<T>::parameter_ = NULL;
Packit bd1cd8
Packit bd1cd8
// Most value-parameterized classes can ignore the existence of
Packit bd1cd8
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
class TestWithParam : public Test, public WithParamInterface<T> {
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_HAS_PARAM_TEST
Packit bd1cd8
Packit bd1cd8
// Macros for indicating success/failure in test code.
Packit bd1cd8
Packit bd1cd8
// ADD_FAILURE unconditionally adds a failure to the current test.
Packit bd1cd8
// SUCCEED generates a success - it doesn't automatically make the
Packit bd1cd8
// current test successful, as a test is only successful when it has
Packit bd1cd8
// no failure.
Packit bd1cd8
//
Packit bd1cd8
// EXPECT_* verifies that a certain condition is satisfied.  If not,
Packit bd1cd8
// it behaves like ADD_FAILURE.  In particular:
Packit bd1cd8
//
Packit bd1cd8
//   EXPECT_TRUE  verifies that a Boolean condition is true.
Packit bd1cd8
//   EXPECT_FALSE verifies that a Boolean condition is false.
Packit bd1cd8
//
Packit bd1cd8
// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
Packit bd1cd8
// that they will also abort the current function on failure.  People
Packit bd1cd8
// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
Packit bd1cd8
// writing data-driven tests often find themselves using ADD_FAILURE
Packit bd1cd8
// and EXPECT_* more.
Packit bd1cd8
Packit bd1cd8
// Generates a nonfatal failure with a generic message.
Packit bd1cd8
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
Packit bd1cd8
Packit bd1cd8
// Generates a nonfatal failure at the given source file location with
Packit bd1cd8
// a generic message.
Packit bd1cd8
#define ADD_FAILURE_AT(file, line) \
Packit bd1cd8
  GTEST_MESSAGE_AT_(file, line, "Failed", \
Packit bd1cd8
                    ::testing::TestPartResult::kNonFatalFailure)
Packit bd1cd8
Packit bd1cd8
// Generates a fatal failure with a generic message.
Packit bd1cd8
#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
Packit bd1cd8
Packit bd1cd8
// Define this macro to 1 to omit the definition of FAIL(), which is a
Packit bd1cd8
// generic name and clashes with some other libraries.
Packit bd1cd8
#if !GTEST_DONT_DEFINE_FAIL
Packit bd1cd8
# define FAIL() GTEST_FAIL()
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// Generates a success with a generic message.
Packit bd1cd8
#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
Packit bd1cd8
Packit bd1cd8
// Define this macro to 1 to omit the definition of SUCCEED(), which
Packit bd1cd8
// is a generic name and clashes with some other libraries.
Packit bd1cd8
#if !GTEST_DONT_DEFINE_SUCCEED
Packit bd1cd8
# define SUCCEED() GTEST_SUCCEED()
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// Macros for testing exceptions.
Packit bd1cd8
//
Packit bd1cd8
//    * {ASSERT|EXPECT}_THROW(statement, expected_exception):
Packit bd1cd8
//         Tests that the statement throws the expected exception.
Packit bd1cd8
//    * {ASSERT|EXPECT}_NO_THROW(statement):
Packit bd1cd8
//         Tests that the statement doesn't throw any exception.
Packit bd1cd8
//    * {ASSERT|EXPECT}_ANY_THROW(statement):
Packit bd1cd8
//         Tests that the statement throws an exception.
Packit bd1cd8
Packit bd1cd8
#define EXPECT_THROW(statement, expected_exception) \
Packit bd1cd8
  GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
#define EXPECT_NO_THROW(statement) \
Packit bd1cd8
  GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
#define EXPECT_ANY_THROW(statement) \
Packit bd1cd8
  GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
#define ASSERT_THROW(statement, expected_exception) \
Packit bd1cd8
  GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
Packit bd1cd8
#define ASSERT_NO_THROW(statement) \
Packit bd1cd8
  GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
Packit bd1cd8
#define ASSERT_ANY_THROW(statement) \
Packit bd1cd8
  GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
Packit bd1cd8
Packit bd1cd8
// Boolean assertions. Condition can be either a Boolean expression or an
Packit bd1cd8
// AssertionResult. For more information on how to use AssertionResult with
Packit bd1cd8
// these macros see comments on that class.
Packit bd1cd8
#define EXPECT_TRUE(condition) \
Packit bd1cd8
  GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
Packit bd1cd8
                      GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
#define EXPECT_FALSE(condition) \
Packit bd1cd8
  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
Packit bd1cd8
                      GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
#define ASSERT_TRUE(condition) \
Packit bd1cd8
  GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
Packit bd1cd8
                      GTEST_FATAL_FAILURE_)
Packit bd1cd8
#define ASSERT_FALSE(condition) \
Packit bd1cd8
  GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
Packit bd1cd8
                      GTEST_FATAL_FAILURE_)
Packit bd1cd8
Packit bd1cd8
// Includes the auto-generated header that implements a family of
Packit bd1cd8
// generic predicate assertion macros.
Packit bd1cd8
#include "gtest/gtest_pred_impl.h"
Packit bd1cd8
Packit bd1cd8
// Macros for testing equalities and inequalities.
Packit bd1cd8
//
Packit bd1cd8
//    * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
Packit bd1cd8
//    * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
Packit bd1cd8
//    * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
Packit bd1cd8
//    * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
Packit bd1cd8
//    * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
Packit bd1cd8
//    * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
Packit bd1cd8
//
Packit bd1cd8
// When they are not, Google Test prints both the tested expressions and
Packit bd1cd8
// their actual values.  The values must be compatible built-in types,
Packit bd1cd8
// or you will get a compiler error.  By "compatible" we mean that the
Packit bd1cd8
// values can be compared by the respective operator.
Packit bd1cd8
//
Packit bd1cd8
// Note:
Packit bd1cd8
//
Packit bd1cd8
//   1. It is possible to make a user-defined type work with
Packit bd1cd8
//   {ASSERT|EXPECT}_??(), but that requires overloading the
Packit bd1cd8
//   comparison operators and is thus discouraged by the Google C++
Packit bd1cd8
//   Usage Guide.  Therefore, you are advised to use the
Packit bd1cd8
//   {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
Packit bd1cd8
//   equal.
Packit bd1cd8
//
Packit bd1cd8
//   2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
Packit bd1cd8
//   pointers (in particular, C strings).  Therefore, if you use it
Packit bd1cd8
//   with two C strings, you are testing how their locations in memory
Packit bd1cd8
//   are related, not how their content is related.  To compare two C
Packit bd1cd8
//   strings by content, use {ASSERT|EXPECT}_STR*().
Packit bd1cd8
//
Packit bd1cd8
//   3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
Packit bd1cd8
//   {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
Packit bd1cd8
//   what the actual value is when it fails, and similarly for the
Packit bd1cd8
//   other comparisons.
Packit bd1cd8
//
Packit bd1cd8
//   4. Do not depend on the order in which {ASSERT|EXPECT}_??()
Packit bd1cd8
//   evaluate their arguments, which is undefined.
Packit bd1cd8
//
Packit bd1cd8
//   5. These macros evaluate their arguments exactly once.
Packit bd1cd8
//
Packit bd1cd8
// Examples:
Packit bd1cd8
//
Packit bd1cd8
//   EXPECT_NE(5, Foo());
Packit bd1cd8
//   EXPECT_EQ(NULL, a_pointer);
Packit bd1cd8
//   ASSERT_LT(i, array_size);
Packit bd1cd8
//   ASSERT_GT(records.size(), 0) << "There is no record left.";
Packit bd1cd8
Packit bd1cd8
#define EXPECT_EQ(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal:: \
Packit bd1cd8
                      EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
#define EXPECT_NE(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
Packit bd1cd8
#define EXPECT_LE(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
Packit bd1cd8
#define EXPECT_LT(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
Packit bd1cd8
#define EXPECT_GE(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
Packit bd1cd8
#define EXPECT_GT(val1, val2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
Packit bd1cd8
Packit bd1cd8
#define GTEST_ASSERT_EQ(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal:: \
Packit bd1cd8
                      EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
#define GTEST_ASSERT_NE(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
Packit bd1cd8
#define GTEST_ASSERT_LE(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
Packit bd1cd8
#define GTEST_ASSERT_LT(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
Packit bd1cd8
#define GTEST_ASSERT_GE(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
Packit bd1cd8
#define GTEST_ASSERT_GT(val1, val2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
Packit bd1cd8
Packit bd1cd8
// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
Packit bd1cd8
// ASSERT_XY(), which clashes with some users' own code.
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_EQ
Packit bd1cd8
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_NE
Packit bd1cd8
# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_LE
Packit bd1cd8
# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_LT
Packit bd1cd8
# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_GE
Packit bd1cd8
# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#if !GTEST_DONT_DEFINE_ASSERT_GT
Packit bd1cd8
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// C-string Comparisons.  All tests treat NULL and any non-NULL string
Packit bd1cd8
// as different.  Two NULLs are equal.
Packit bd1cd8
//
Packit bd1cd8
//    * {ASSERT|EXPECT}_STREQ(s1, s2):     Tests that s1 == s2
Packit bd1cd8
//    * {ASSERT|EXPECT}_STRNE(s1, s2):     Tests that s1 != s2
Packit bd1cd8
//    * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
Packit bd1cd8
//    * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
Packit bd1cd8
//
Packit bd1cd8
// For wide or narrow string objects, you can use the
Packit bd1cd8
// {ASSERT|EXPECT}_??() macros.
Packit bd1cd8
//
Packit bd1cd8
// Don't depend on the order in which the arguments are evaluated,
Packit bd1cd8
// which is undefined.
Packit bd1cd8
//
Packit bd1cd8
// These macros evaluate their arguments exactly once.
Packit bd1cd8
Packit bd1cd8
#define EXPECT_STREQ(s1, s2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
Packit bd1cd8
#define EXPECT_STRNE(s1, s2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
Packit bd1cd8
#define EXPECT_STRCASEEQ(s1, s2) \
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
Packit bd1cd8
#define EXPECT_STRCASENE(s1, s2)\
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
Packit bd1cd8
Packit bd1cd8
#define ASSERT_STREQ(s1, s2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
Packit bd1cd8
#define ASSERT_STRNE(s1, s2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
Packit bd1cd8
#define ASSERT_STRCASEEQ(s1, s2) \
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
Packit bd1cd8
#define ASSERT_STRCASENE(s1, s2)\
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
Packit bd1cd8
Packit bd1cd8
// Macros for comparing floating-point numbers.
Packit bd1cd8
//
Packit bd1cd8
//    * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
Packit bd1cd8
//         Tests that two float values are almost equal.
Packit bd1cd8
//    * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
Packit bd1cd8
//         Tests that two double values are almost equal.
Packit bd1cd8
//    * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
Packit bd1cd8
//         Tests that v1 and v2 are within the given distance to each other.
Packit bd1cd8
//
Packit bd1cd8
// Google Test uses ULP-based comparison to automatically pick a default
Packit bd1cd8
// error bound that is appropriate for the operands.  See the
Packit bd1cd8
// FloatingPoint template class in gtest-internal.h if you are
Packit bd1cd8
// interested in the implementation details.
Packit bd1cd8
Packit bd1cd8
#define EXPECT_FLOAT_EQ(val1, val2)\
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
Packit bd1cd8
#define EXPECT_DOUBLE_EQ(val1, val2)\
Packit bd1cd8
  EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
Packit bd1cd8
#define ASSERT_FLOAT_EQ(val1, val2)\
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
Packit bd1cd8
#define ASSERT_DOUBLE_EQ(val1, val2)\
Packit bd1cd8
  ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
Packit bd1cd8
                      val1, val2)
Packit bd1cd8
Packit bd1cd8
#define EXPECT_NEAR(val1, val2, abs_error)\
Packit bd1cd8
  EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
Packit bd1cd8
                      val1, val2, abs_error)
Packit bd1cd8
Packit bd1cd8
#define ASSERT_NEAR(val1, val2, abs_error)\
Packit bd1cd8
  ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
Packit bd1cd8
                      val1, val2, abs_error)
Packit bd1cd8
Packit bd1cd8
// These predicate format functions work on floating-point values, and
Packit bd1cd8
// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
Packit bd1cd8
//
Packit bd1cd8
//   EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
Packit bd1cd8
Packit bd1cd8
// Asserts that val1 is less than, or almost equal to, val2.  Fails
Packit bd1cd8
// otherwise.  In particular, it fails if either val1 or val2 is NaN.
Packit bd1cd8
GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
Packit bd1cd8
                                   float val1, float val2);
Packit bd1cd8
GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
Packit bd1cd8
                                    double val1, double val2);
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
#if GTEST_OS_WINDOWS
Packit bd1cd8
Packit bd1cd8
// Macros that test for HRESULT failure and success, these are only useful
Packit bd1cd8
// on Windows, and rely on Windows SDK macros and APIs to compile.
Packit bd1cd8
//
Packit bd1cd8
//    * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
Packit bd1cd8
//
Packit bd1cd8
// When expr unexpectedly fails or succeeds, Google Test prints the
Packit bd1cd8
// expected result and the actual result with both a human-readable
Packit bd1cd8
// string representation of the error, if available, as well as the
Packit bd1cd8
// hex result code.
Packit bd1cd8
# define EXPECT_HRESULT_SUCCEEDED(expr) \
Packit bd1cd8
    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
Packit bd1cd8
Packit bd1cd8
# define ASSERT_HRESULT_SUCCEEDED(expr) \
Packit bd1cd8
    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
Packit bd1cd8
Packit bd1cd8
# define EXPECT_HRESULT_FAILED(expr) \
Packit bd1cd8
    EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
Packit bd1cd8
Packit bd1cd8
# define ASSERT_HRESULT_FAILED(expr) \
Packit bd1cd8
    ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_OS_WINDOWS
Packit bd1cd8
Packit bd1cd8
// Macros that execute statement and check that it doesn't generate new fatal
Packit bd1cd8
// failures in the current thread.
Packit bd1cd8
//
Packit bd1cd8
//   * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
Packit bd1cd8
//
Packit bd1cd8
// Examples:
Packit bd1cd8
//
Packit bd1cd8
//   EXPECT_NO_FATAL_FAILURE(Process());
Packit bd1cd8
//   ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
Packit bd1cd8
//
Packit bd1cd8
#define ASSERT_NO_FATAL_FAILURE(statement) \
Packit bd1cd8
    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
Packit bd1cd8
#define EXPECT_NO_FATAL_FAILURE(statement) \
Packit bd1cd8
    GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
Packit bd1cd8
Packit bd1cd8
// Causes a trace (including the source file path, the current line
Packit bd1cd8
// number, and the given message) to be included in every test failure
Packit bd1cd8
// message generated by code in the current scope.  The effect is
Packit bd1cd8
// undone when the control leaves the current scope.
Packit bd1cd8
//
Packit bd1cd8
// The message argument can be anything streamable to std::ostream.
Packit bd1cd8
//
Packit bd1cd8
// In the implementation, we include the current line number as part
Packit bd1cd8
// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
Packit bd1cd8
// to appear in the same block - as long as they are on different
Packit bd1cd8
// lines.
Packit bd1cd8
#define SCOPED_TRACE(message) \
Packit bd1cd8
  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
Packit bd1cd8
    __FILE__, __LINE__, ::testing::Message() << (message))
Packit bd1cd8
Packit bd1cd8
// Compile-time assertion for type equality.
Packit bd1cd8
// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
Packit bd1cd8
// the same type.  The value it returns is not interesting.
Packit bd1cd8
//
Packit bd1cd8
// Instead of making StaticAssertTypeEq a class template, we make it a
Packit bd1cd8
// function template that invokes a helper class template.  This
Packit bd1cd8
// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
Packit bd1cd8
// defining objects of that type.
Packit bd1cd8
//
Packit bd1cd8
// CAVEAT:
Packit bd1cd8
//
Packit bd1cd8
// When used inside a method of a class template,
Packit bd1cd8
// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
Packit bd1cd8
// instantiated.  For example, given:
Packit bd1cd8
//
Packit bd1cd8
//   template <typename T> class Foo {
Packit bd1cd8
//    public:
Packit bd1cd8
//     void Bar() { testing::StaticAssertTypeEq<int, T>(); }
Packit bd1cd8
//   };
Packit bd1cd8
//
Packit bd1cd8
// the code:
Packit bd1cd8
//
Packit bd1cd8
//   void Test1() { Foo<bool> foo; }
Packit bd1cd8
//
Packit bd1cd8
// will NOT generate a compiler error, as Foo<bool>::Bar() is never
Packit bd1cd8
// actually instantiated.  Instead, you need:
Packit bd1cd8
//
Packit bd1cd8
//   void Test2() { Foo<bool> foo; foo.Bar(); }
Packit bd1cd8
//
Packit bd1cd8
// to cause a compiler error.
Packit bd1cd8
template <typename T1, typename T2>
Packit bd1cd8
bool StaticAssertTypeEq() {
Packit bd1cd8
  (void)internal::StaticAssertTypeEqHelper<T1, T2>();
Packit bd1cd8
  return true;
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Defines a test.
Packit bd1cd8
//
Packit bd1cd8
// The first parameter is the name of the test case, and the second
Packit bd1cd8
// parameter is the name of the test within the test case.
Packit bd1cd8
//
Packit bd1cd8
// The convention is to end the test case name with "Test".  For
Packit bd1cd8
// example, a test case for the Foo class can be named FooTest.
Packit bd1cd8
//
Packit bd1cd8
// Test code should appear between braces after an invocation of
Packit bd1cd8
// this macro.  Example:
Packit bd1cd8
//
Packit bd1cd8
//   TEST(FooTest, InitializesCorrectly) {
Packit bd1cd8
//     Foo foo;
Packit bd1cd8
//     EXPECT_TRUE(foo.StatusIsOK());
Packit bd1cd8
//   }
Packit bd1cd8
Packit bd1cd8
// Note that we call GetTestTypeId() instead of GetTypeId<
Packit bd1cd8
// ::testing::Test>() here to get the type ID of testing::Test.  This
Packit bd1cd8
// is to work around a suspected linker bug when using Google Test as
Packit bd1cd8
// a framework on Mac OS X.  The bug causes GetTypeId<
Packit bd1cd8
// ::testing::Test>() to return different values depending on whether
Packit bd1cd8
// the call is from the Google Test framework itself or from user test
Packit bd1cd8
// code.  GetTestTypeId() is guaranteed to always return the same
Packit bd1cd8
// value, as it always calls GetTypeId<>() from the Google Test
Packit bd1cd8
// framework.
Packit bd1cd8
#define GTEST_TEST(test_case_name, test_name)\
Packit bd1cd8
  GTEST_TEST_(test_case_name, test_name, \
Packit bd1cd8
              ::testing::Test, ::testing::internal::GetTestTypeId())
Packit bd1cd8
Packit bd1cd8
// Define this macro to 1 to omit the definition of TEST(), which
Packit bd1cd8
// is a generic name and clashes with some other libraries.
Packit bd1cd8
#if !GTEST_DONT_DEFINE_TEST
Packit bd1cd8
# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// Defines a test that uses a test fixture.
Packit bd1cd8
//
Packit bd1cd8
// The first parameter is the name of the test fixture class, which
Packit bd1cd8
// also doubles as the test case name.  The second parameter is the
Packit bd1cd8
// name of the test within the test case.
Packit bd1cd8
//
Packit bd1cd8
// A test fixture class must be declared earlier.  The user should put
Packit bd1cd8
// his test code between braces after using this macro.  Example:
Packit bd1cd8
//
Packit bd1cd8
//   class FooTest : public testing::Test {
Packit bd1cd8
//    protected:
Packit bd1cd8
//     virtual void SetUp() { b_.AddElement(3); }
Packit bd1cd8
//
Packit bd1cd8
//     Foo a_;
Packit bd1cd8
//     Foo b_;
Packit bd1cd8
//   };
Packit bd1cd8
//
Packit bd1cd8
//   TEST_F(FooTest, InitializesCorrectly) {
Packit bd1cd8
//     EXPECT_TRUE(a_.StatusIsOK());
Packit bd1cd8
//   }
Packit bd1cd8
//
Packit bd1cd8
//   TEST_F(FooTest, ReturnsElementCountCorrectly) {
Packit bd1cd8
//     EXPECT_EQ(0, a_.size());
Packit bd1cd8
//     EXPECT_EQ(1, b_.size());
Packit bd1cd8
//   }
Packit bd1cd8
Packit bd1cd8
#define TEST_F(test_fixture, test_name)\
Packit bd1cd8
  GTEST_TEST_(test_fixture, test_name, test_fixture, \
Packit bd1cd8
              ::testing::internal::GetTypeId<test_fixture>())
Packit bd1cd8
Packit bd1cd8
}  // namespace testing
Packit bd1cd8
Packit bd1cd8
// Use this function in main() to run all tests.  It returns 0 if all
Packit bd1cd8
// tests are successful, or 1 otherwise.
Packit bd1cd8
//
Packit bd1cd8
// RUN_ALL_TESTS() should be invoked after the command line has been
Packit bd1cd8
// parsed by InitGoogleTest().
Packit bd1cd8
//
Packit bd1cd8
// This function was formerly a macro; thus, it is in the global
Packit bd1cd8
// namespace and has an all-caps name.
Packit bd1cd8
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
Packit bd1cd8
Packit bd1cd8
inline int RUN_ALL_TESTS() {
Packit bd1cd8
  return ::testing::UnitTest::GetInstance()->Run();
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_INCLUDE_GTEST_GTEST_H_