Blame googletest/include/gtest/internal/gtest-internal.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
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
Packit bd1cd8
//
Packit bd1cd8
// The Google C++ Testing Framework (Google Test)
Packit bd1cd8
//
Packit bd1cd8
// This header file declares functions and macros used internally by
Packit bd1cd8
// Google Test.  They are subject to change without notice.
Packit bd1cd8
Packit bd1cd8
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
Packit bd1cd8
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
Packit bd1cd8
Packit bd1cd8
#include "gtest/internal/gtest-port.h"
Packit bd1cd8
Packit bd1cd8
#if GTEST_OS_LINUX
Packit bd1cd8
# include <stdlib.h>
Packit bd1cd8
# include <sys/types.h>
Packit bd1cd8
# include <sys/wait.h>
Packit bd1cd8
# include <unistd.h>
Packit bd1cd8
#endif  // GTEST_OS_LINUX
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_EXCEPTIONS
Packit bd1cd8
# include <stdexcept>
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
#include <ctype.h>
Packit bd1cd8
#include <float.h>
Packit bd1cd8
#include <string.h>
Packit bd1cd8
#include <iomanip>
Packit bd1cd8
#include <limits>
Packit bd1cd8
#include <map>
Packit bd1cd8
#include <set>
Packit bd1cd8
#include <string>
Packit bd1cd8
#include <vector>
Packit bd1cd8
Packit bd1cd8
#include "gtest/gtest-message.h"
Packit bd1cd8
#include "gtest/internal/gtest-string.h"
Packit bd1cd8
#include "gtest/internal/gtest-filepath.h"
Packit bd1cd8
#include "gtest/internal/gtest-type-util.h"
Packit bd1cd8
Packit bd1cd8
// Due to C++ preprocessor weirdness, we need double indirection to
Packit bd1cd8
// concatenate two tokens when one of them is __LINE__.  Writing
Packit bd1cd8
//
Packit bd1cd8
//   foo ## __LINE__
Packit bd1cd8
//
Packit bd1cd8
// will result in the token foo__LINE__, instead of foo followed by
Packit bd1cd8
// the current line number.  For more details, see
Packit bd1cd8
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
Packit bd1cd8
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
Packit bd1cd8
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
Packit bd1cd8
Packit bd1cd8
class ProtocolMessage;
Packit bd1cd8
namespace proto2 { class Message; }
Packit bd1cd8
Packit bd1cd8
namespace testing {
Packit bd1cd8
Packit bd1cd8
// Forward declarations.
Packit bd1cd8
Packit bd1cd8
class AssertionResult;                 // Result of an assertion.
Packit bd1cd8
class Message;                         // Represents a failure message.
Packit bd1cd8
class Test;                            // Represents a test.
Packit bd1cd8
class TestInfo;                        // Information about a test.
Packit bd1cd8
class TestPartResult;                  // Result of a test part.
Packit bd1cd8
class UnitTest;                        // A collection of test cases.
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
::std::string PrintToString(const T& value);
Packit bd1cd8
Packit bd1cd8
namespace internal {
Packit bd1cd8
Packit bd1cd8
struct TraceInfo;                      // Information about a trace point.
Packit bd1cd8
class ScopedTrace;                     // Implements scoped trace.
Packit bd1cd8
class TestInfoImpl;                    // Opaque implementation of TestInfo
Packit bd1cd8
class UnitTestImpl;                    // Opaque implementation of UnitTest
Packit bd1cd8
Packit bd1cd8
// The text used in failure messages to indicate the start of the
Packit bd1cd8
// stack trace.
Packit bd1cd8
GTEST_API_ extern const char kStackTraceMarker[];
Packit bd1cd8
Packit bd1cd8
// Two overloaded helpers for checking at compile time whether an
Packit bd1cd8
// expression is a null pointer literal (i.e. NULL or any 0-valued
Packit bd1cd8
// compile-time integral constant).  Their return values have
Packit bd1cd8
// different sizes, so we can use sizeof() to test which version is
Packit bd1cd8
// picked by the compiler.  These helpers have no implementations, as
Packit bd1cd8
// we only need their signatures.
Packit bd1cd8
//
Packit bd1cd8
// Given IsNullLiteralHelper(x), the compiler will pick the first
Packit bd1cd8
// version if x can be implicitly converted to Secret*, and pick the
Packit bd1cd8
// second version otherwise.  Since Secret is a secret and incomplete
Packit bd1cd8
// type, the only expression a user can write that has type Secret* is
Packit bd1cd8
// a null pointer literal.  Therefore, we know that x is a null
Packit bd1cd8
// pointer literal if and only if the first version is picked by the
Packit bd1cd8
// compiler.
Packit bd1cd8
char IsNullLiteralHelper(Secret* p);
Packit bd1cd8
char (&IsNullLiteralHelper(...))[2];  // NOLINT
Packit bd1cd8
Packit bd1cd8
// A compile-time bool constant that is true if and only if x is a
Packit bd1cd8
// null pointer literal (i.e. NULL or any 0-valued compile-time
Packit bd1cd8
// integral constant).
Packit bd1cd8
#ifdef GTEST_ELLIPSIS_NEEDS_POD_
Packit bd1cd8
// We lose support for NULL detection where the compiler doesn't like
Packit bd1cd8
// passing non-POD classes through ellipsis (...).
Packit bd1cd8
# define GTEST_IS_NULL_LITERAL_(x) false
Packit bd1cd8
#else
Packit bd1cd8
# define GTEST_IS_NULL_LITERAL_(x) \
Packit bd1cd8
    (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
Packit bd1cd8
#endif  // GTEST_ELLIPSIS_NEEDS_POD_
Packit bd1cd8
Packit bd1cd8
// Appends the user-supplied message to the Google-Test-generated message.
Packit bd1cd8
GTEST_API_ std::string AppendUserMessage(
Packit bd1cd8
    const std::string& gtest_msg, const Message& user_msg);
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_EXCEPTIONS
Packit bd1cd8
Packit bd1cd8
// This exception is thrown by (and only by) a failed Google Test
Packit bd1cd8
// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
Packit bd1cd8
// are enabled).  We derive it from std::runtime_error, which is for
Packit bd1cd8
// errors presumably detectable only at run time.  Since
Packit bd1cd8
// std::runtime_error inherits from std::exception, many testing
Packit bd1cd8
// frameworks know how to extract and print the message inside it.
Packit bd1cd8
class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
Packit bd1cd8
 public:
Packit bd1cd8
  explicit GoogleTestFailureException(const TestPartResult& failure);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_HAS_EXCEPTIONS
Packit bd1cd8
Packit bd1cd8
// A helper class for creating scoped traces in user programs.
Packit bd1cd8
class GTEST_API_ ScopedTrace {
Packit bd1cd8
 public:
Packit bd1cd8
  // The c'tor pushes the given source file location and message onto
Packit bd1cd8
  // a trace stack maintained by Google Test.
Packit bd1cd8
  ScopedTrace(const char* file, int line, const Message& message);
Packit bd1cd8
Packit bd1cd8
  // The d'tor pops the info pushed by the c'tor.
Packit bd1cd8
  //
Packit bd1cd8
  // Note that the d'tor is not virtual in order to be efficient.
Packit bd1cd8
  // Don't inherit from ScopedTrace!
Packit bd1cd8
  ~ScopedTrace();
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
Packit bd1cd8
} GTEST_ATTRIBUTE_UNUSED_;  // A ScopedTrace object does its job in its
Packit bd1cd8
                            // c'tor and d'tor.  Therefore it doesn't
Packit bd1cd8
                            // need to be used otherwise.
Packit bd1cd8
Packit bd1cd8
namespace edit_distance {
Packit bd1cd8
// Returns the optimal edits to go from 'left' to 'right'.
Packit bd1cd8
// All edits cost the same, with replace having lower priority than
Packit bd1cd8
// add/remove.
Packit bd1cd8
// Simple implementation of the Wagner–Fischer algorithm.
Packit bd1cd8
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
Packit bd1cd8
enum EditType { kMatch, kAdd, kRemove, kReplace };
Packit bd1cd8
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
Packit bd1cd8
    const std::vector<size_t>& left, const std::vector<size_t>& right);
Packit bd1cd8
Packit bd1cd8
// Same as above, but the input is represented as strings.
Packit bd1cd8
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
Packit bd1cd8
    const std::vector<std::string>& left,
Packit bd1cd8
    const std::vector<std::string>& right);
Packit bd1cd8
Packit bd1cd8
// Create a diff of the input strings in Unified diff format.
Packit bd1cd8
GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
Packit bd1cd8
                                         const std::vector<std::string>& right,
Packit bd1cd8
                                         size_t context = 2);
Packit bd1cd8
Packit bd1cd8
}  // namespace edit_distance
Packit bd1cd8
Packit bd1cd8
// Calculate the diff between 'left' and 'right' and return it in unified diff
Packit bd1cd8
// format.
Packit bd1cd8
// If not null, stores in 'total_line_count' the total number of lines found
Packit bd1cd8
// in left + right.
Packit bd1cd8
GTEST_API_ std::string DiffStrings(const std::string& left,
Packit bd1cd8
                                   const std::string& right,
Packit bd1cd8
                                   size_t* total_line_count);
Packit bd1cd8
Packit bd1cd8
// Constructs and returns the message for an equality assertion
Packit bd1cd8
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
Packit bd1cd8
//
Packit bd1cd8
// The first four parameters are the expressions used in the assertion
Packit bd1cd8
// and their values, as strings.  For example, for ASSERT_EQ(foo, bar)
Packit bd1cd8
// where foo is 5 and bar is 6, we have:
Packit bd1cd8
//
Packit bd1cd8
//   expected_expression: "foo"
Packit bd1cd8
//   actual_expression:   "bar"
Packit bd1cd8
//   expected_value:      "5"
Packit bd1cd8
//   actual_value:        "6"
Packit bd1cd8
//
Packit bd1cd8
// The ignoring_case parameter is true iff the assertion is a
Packit bd1cd8
// *_STRCASEEQ*.  When it's true, the string " (ignoring case)" will
Packit bd1cd8
// be inserted into the message.
Packit bd1cd8
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
Packit bd1cd8
                                     const char* actual_expression,
Packit bd1cd8
                                     const std::string& expected_value,
Packit bd1cd8
                                     const std::string& actual_value,
Packit bd1cd8
                                     bool ignoring_case);
Packit bd1cd8
Packit bd1cd8
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
Packit bd1cd8
GTEST_API_ std::string GetBoolAssertionFailureMessage(
Packit bd1cd8
    const AssertionResult& assertion_result,
Packit bd1cd8
    const char* expression_text,
Packit bd1cd8
    const char* actual_predicate_value,
Packit bd1cd8
    const char* expected_predicate_value);
Packit bd1cd8
Packit bd1cd8
// This template class represents an IEEE floating-point number
Packit bd1cd8
// (either single-precision or double-precision, depending on the
Packit bd1cd8
// template parameters).
Packit bd1cd8
//
Packit bd1cd8
// The purpose of this class is to do more sophisticated number
Packit bd1cd8
// comparison.  (Due to round-off error, etc, it's very unlikely that
Packit bd1cd8
// two floating-points will be equal exactly.  Hence a naive
Packit bd1cd8
// comparison by the == operation often doesn't work.)
Packit bd1cd8
//
Packit bd1cd8
// Format of IEEE floating-point:
Packit bd1cd8
//
Packit bd1cd8
//   The most-significant bit being the leftmost, an IEEE
Packit bd1cd8
//   floating-point looks like
Packit bd1cd8
//
Packit bd1cd8
//     sign_bit exponent_bits fraction_bits
Packit bd1cd8
//
Packit bd1cd8
//   Here, sign_bit is a single bit that designates the sign of the
Packit bd1cd8
//   number.
Packit bd1cd8
//
Packit bd1cd8
//   For float, there are 8 exponent bits and 23 fraction bits.
Packit bd1cd8
//
Packit bd1cd8
//   For double, there are 11 exponent bits and 52 fraction bits.
Packit bd1cd8
//
Packit bd1cd8
//   More details can be found at
Packit bd1cd8
//   http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
Packit bd1cd8
//
Packit bd1cd8
// Template parameter:
Packit bd1cd8
//
Packit bd1cd8
//   RawType: the raw floating-point type (either float or double)
Packit bd1cd8
template <typename RawType>
Packit bd1cd8
class FloatingPoint {
Packit bd1cd8
 public:
Packit bd1cd8
  // Defines the unsigned integer type that has the same size as the
Packit bd1cd8
  // floating point number.
Packit bd1cd8
  typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
Packit bd1cd8
Packit bd1cd8
  // Constants.
Packit bd1cd8
Packit bd1cd8
  // # of bits in a number.
Packit bd1cd8
  static const size_t kBitCount = 8*sizeof(RawType);
Packit bd1cd8
Packit bd1cd8
  // # of fraction bits in a number.
Packit bd1cd8
  static const size_t kFractionBitCount =
Packit bd1cd8
    std::numeric_limits<RawType>::digits - 1;
Packit bd1cd8
Packit bd1cd8
  // # of exponent bits in a number.
Packit bd1cd8
  static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
Packit bd1cd8
Packit bd1cd8
  // The mask for the sign bit.
Packit bd1cd8
  static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
Packit bd1cd8
Packit bd1cd8
  // The mask for the fraction bits.
Packit bd1cd8
  static const Bits kFractionBitMask =
Packit bd1cd8
    ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
Packit bd1cd8
Packit bd1cd8
  // The mask for the exponent bits.
Packit bd1cd8
  static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
Packit bd1cd8
Packit bd1cd8
  // How many ULP's (Units in the Last Place) we want to tolerate when
Packit bd1cd8
  // comparing two numbers.  The larger the value, the more error we
Packit bd1cd8
  // allow.  A 0 value means that two numbers must be exactly the same
Packit bd1cd8
  // to be considered equal.
Packit bd1cd8
  //
Packit bd1cd8
  // The maximum error of a single floating-point operation is 0.5
Packit bd1cd8
  // units in the last place.  On Intel CPU's, all floating-point
Packit bd1cd8
  // calculations are done with 80-bit precision, while double has 64
Packit bd1cd8
  // bits.  Therefore, 4 should be enough for ordinary use.
Packit bd1cd8
  //
Packit bd1cd8
  // See the following article for more details on ULP:
Packit bd1cd8
  // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
Packit bd1cd8
  static const size_t kMaxUlps = 4;
Packit bd1cd8
Packit bd1cd8
  // Constructs a FloatingPoint from a raw floating-point number.
Packit bd1cd8
  //
Packit bd1cd8
  // On an Intel CPU, passing a non-normalized NAN (Not a Number)
Packit bd1cd8
  // around may change its bits, although the new value is guaranteed
Packit bd1cd8
  // to be also a NAN.  Therefore, don't expect this constructor to
Packit bd1cd8
  // preserve the bits in x when x is a NAN.
Packit bd1cd8
  explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
Packit bd1cd8
Packit bd1cd8
  // Static methods
Packit bd1cd8
Packit bd1cd8
  // Reinterprets a bit pattern as a floating-point number.
Packit bd1cd8
  //
Packit bd1cd8
  // This function is needed to test the AlmostEquals() method.
Packit bd1cd8
  static RawType ReinterpretBits(const Bits bits) {
Packit bd1cd8
    FloatingPoint fp(0);
Packit bd1cd8
    fp.u_.bits_ = bits;
Packit bd1cd8
    return fp.u_.value_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the floating-point number that represent positive infinity.
Packit bd1cd8
  static RawType Infinity() {
Packit bd1cd8
    return ReinterpretBits(kExponentBitMask);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns the maximum representable finite floating-point number.
Packit bd1cd8
  static RawType Max();
Packit bd1cd8
Packit bd1cd8
  // Non-static methods
Packit bd1cd8
Packit bd1cd8
  // Returns the bits that represents this number.
Packit bd1cd8
  const Bits &bits() const { return u_.bits_; }
Packit bd1cd8
Packit bd1cd8
  // Returns the exponent bits of this number.
Packit bd1cd8
  Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
Packit bd1cd8
Packit bd1cd8
  // Returns the fraction bits of this number.
Packit bd1cd8
  Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
Packit bd1cd8
Packit bd1cd8
  // Returns the sign bit of this number.
Packit bd1cd8
  Bits sign_bit() const { return kSignBitMask & u_.bits_; }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff this is NAN (not a number).
Packit bd1cd8
  bool is_nan() const {
Packit bd1cd8
    // It's a NAN if the exponent bits are all ones and the fraction
Packit bd1cd8
    // bits are not entirely zeros.
Packit bd1cd8
    return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Returns true iff this number is at most kMaxUlps ULP's away from
Packit bd1cd8
  // rhs.  In particular, this function:
Packit bd1cd8
  //
Packit bd1cd8
  //   - returns false if either number is (or both are) NAN.
Packit bd1cd8
  //   - treats really large numbers as almost equal to infinity.
Packit bd1cd8
  //   - thinks +0.0 and -0.0 are 0 DLP's apart.
Packit bd1cd8
  bool AlmostEquals(const FloatingPoint& rhs) const {
Packit bd1cd8
    // The IEEE standard says that any comparison operation involving
Packit bd1cd8
    // a NAN must return false.
Packit bd1cd8
    if (is_nan() || rhs.is_nan()) return false;
Packit bd1cd8
Packit bd1cd8
    return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
Packit bd1cd8
        <= kMaxUlps;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  // The data type used to store the actual floating-point number.
Packit bd1cd8
  union FloatingPointUnion {
Packit bd1cd8
    RawType value_;  // The raw floating-point number.
Packit bd1cd8
    Bits bits_;      // The bits that represent the number.
Packit bd1cd8
  };
Packit bd1cd8
Packit bd1cd8
  // Converts an integer from the sign-and-magnitude representation to
Packit bd1cd8
  // the biased representation.  More precisely, let N be 2 to the
Packit bd1cd8
  // power of (kBitCount - 1), an integer x is represented by the
Packit bd1cd8
  // unsigned number x + N.
Packit bd1cd8
  //
Packit bd1cd8
  // For instance,
Packit bd1cd8
  //
Packit bd1cd8
  //   -N + 1 (the most negative number representable using
Packit bd1cd8
  //          sign-and-magnitude) is represented by 1;
Packit bd1cd8
  //   0      is represented by N; and
Packit bd1cd8
  //   N - 1  (the biggest number representable using
Packit bd1cd8
  //          sign-and-magnitude) is represented by 2N - 1.
Packit bd1cd8
  //
Packit bd1cd8
  // Read http://en.wikipedia.org/wiki/Signed_number_representations
Packit bd1cd8
  // for more details on signed number representations.
Packit bd1cd8
  static Bits SignAndMagnitudeToBiased(const Bits &sam) {
Packit bd1cd8
    if (kSignBitMask & sam) {
Packit bd1cd8
      // sam represents a negative number.
Packit bd1cd8
      return ~sam + 1;
Packit bd1cd8
    } else {
Packit bd1cd8
      // sam represents a positive number.
Packit bd1cd8
      return kSignBitMask | sam;
Packit bd1cd8
    }
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Given two numbers in the sign-and-magnitude representation,
Packit bd1cd8
  // returns the distance between them as an unsigned number.
Packit bd1cd8
  static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
Packit bd1cd8
                                                     const Bits &sam2) {
Packit bd1cd8
    const Bits biased1 = SignAndMagnitudeToBiased(sam1);
Packit bd1cd8
    const Bits biased2 = SignAndMagnitudeToBiased(sam2);
Packit bd1cd8
    return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  FloatingPointUnion u_;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// We cannot use std::numeric_limits<T>::max() as it clashes with the max()
Packit bd1cd8
// macro defined by <windows.h>.
Packit bd1cd8
template <>
Packit bd1cd8
inline float FloatingPoint<float>::Max() { return FLT_MAX; }
Packit bd1cd8
template <>
Packit bd1cd8
inline double FloatingPoint<double>::Max() { return DBL_MAX; }
Packit bd1cd8
Packit bd1cd8
// Typedefs the instances of the FloatingPoint template class that we
Packit bd1cd8
// care to use.
Packit bd1cd8
typedef FloatingPoint<float> Float;
Packit bd1cd8
typedef FloatingPoint<double> Double;
Packit bd1cd8
Packit bd1cd8
// In order to catch the mistake of putting tests that use different
Packit bd1cd8
// test fixture classes in the same test case, we need to assign
Packit bd1cd8
// unique IDs to fixture classes and compare them.  The TypeId type is
Packit bd1cd8
// used to hold such IDs.  The user should treat TypeId as an opaque
Packit bd1cd8
// type: the only operation allowed on TypeId values is to compare
Packit bd1cd8
// them for equality using the == operator.
Packit bd1cd8
typedef const void* TypeId;
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
class TypeIdHelper {
Packit bd1cd8
 public:
Packit bd1cd8
  // dummy_ must not have a const type.  Otherwise an overly eager
Packit bd1cd8
  // compiler (e.g. MSVC 7.1 & 8.0) may try to merge
Packit bd1cd8
  // TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
Packit bd1cd8
  static bool dummy_;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
bool TypeIdHelper<T>::dummy_ = false;
Packit bd1cd8
Packit bd1cd8
// GetTypeId<T>() returns the ID of type T.  Different values will be
Packit bd1cd8
// returned for different types.  Calling the function twice with the
Packit bd1cd8
// same type argument is guaranteed to return the same ID.
Packit bd1cd8
template <typename T>
Packit bd1cd8
TypeId GetTypeId() {
Packit bd1cd8
  // The compiler is required to allocate a different
Packit bd1cd8
  // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
Packit bd1cd8
  // the template.  Therefore, the address of dummy_ is guaranteed to
Packit bd1cd8
  // be unique.
Packit bd1cd8
  return &(TypeIdHelper<T>::dummy_);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Returns the type ID of ::testing::Test.  Always call this instead
Packit bd1cd8
// of GetTypeId< ::testing::Test>() to get the type ID of
Packit bd1cd8
// ::testing::Test, as the latter may give the wrong result due to a
Packit bd1cd8
// suspected linker bug when compiling Google Test as a Mac OS X
Packit bd1cd8
// framework.
Packit bd1cd8
GTEST_API_ TypeId GetTestTypeId();
Packit bd1cd8
Packit bd1cd8
// Defines the abstract factory interface that creates instances
Packit bd1cd8
// of a Test object.
Packit bd1cd8
class TestFactoryBase {
Packit bd1cd8
 public:
Packit bd1cd8
  virtual ~TestFactoryBase() {}
Packit bd1cd8
Packit bd1cd8
  // Creates a test instance to run. The instance is both created and destroyed
Packit bd1cd8
  // within TestInfoImpl::Run()
Packit bd1cd8
  virtual Test* CreateTest() = 0;
Packit bd1cd8
Packit bd1cd8
 protected:
Packit bd1cd8
  TestFactoryBase() {}
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// This class provides implementation of TeastFactoryBase interface.
Packit bd1cd8
// It is used in TEST and TEST_F macros.
Packit bd1cd8
template <class TestClass>
Packit bd1cd8
class TestFactoryImpl : public TestFactoryBase {
Packit bd1cd8
 public:
Packit bd1cd8
  virtual Test* CreateTest() { return new TestClass; }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
#if GTEST_OS_WINDOWS
Packit bd1cd8
Packit bd1cd8
// Predicate-formatters for implementing the HRESULT checking macros
Packit bd1cd8
// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
Packit bd1cd8
// We pass a long instead of HRESULT to avoid causing an
Packit bd1cd8
// include dependency for the HRESULT type.
Packit bd1cd8
GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
Packit bd1cd8
                                            long hr);  // NOLINT
Packit bd1cd8
GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
Packit bd1cd8
                                            long hr);  // NOLINT
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_OS_WINDOWS
Packit bd1cd8
Packit bd1cd8
// Types of SetUpTestCase() and TearDownTestCase() functions.
Packit bd1cd8
typedef void (*SetUpTestCaseFunc)();
Packit bd1cd8
typedef void (*TearDownTestCaseFunc)();
Packit bd1cd8
Packit bd1cd8
struct CodeLocation {
Packit bd1cd8
  CodeLocation(const string& a_file, int a_line) : file(a_file), line(a_line) {}
Packit bd1cd8
Packit bd1cd8
  string file;
Packit bd1cd8
  int line;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Creates a new TestInfo object and registers it with Google Test;
Packit bd1cd8
// returns the created object.
Packit bd1cd8
//
Packit bd1cd8
// Arguments:
Packit bd1cd8
//
Packit bd1cd8
//   test_case_name:   name of the test case
Packit bd1cd8
//   name:             name of the test
Packit bd1cd8
//   type_param        the name of the test's type parameter, or NULL if
Packit bd1cd8
//                     this is not a typed or a type-parameterized test.
Packit bd1cd8
//   value_param       text representation of the test's value parameter,
Packit bd1cd8
//                     or NULL if this is not a type-parameterized test.
Packit bd1cd8
//   code_location:    code location where the test is defined
Packit bd1cd8
//   fixture_class_id: ID of the test fixture class
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
//   factory:          pointer to the factory that creates a test object.
Packit bd1cd8
//                     The newly created TestInfo instance will assume
Packit bd1cd8
//                     ownership of the factory object.
Packit bd1cd8
GTEST_API_ TestInfo* 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
    CodeLocation code_location,
Packit bd1cd8
    TypeId fixture_class_id,
Packit bd1cd8
    SetUpTestCaseFunc set_up_tc,
Packit bd1cd8
    TearDownTestCaseFunc tear_down_tc,
Packit bd1cd8
    TestFactoryBase* factory);
Packit bd1cd8
Packit bd1cd8
// If *pstr starts with the given prefix, modifies *pstr to be right
Packit bd1cd8
// past the prefix and returns true; otherwise leaves *pstr unchanged
Packit bd1cd8
// and returns false.  None of pstr, *pstr, and prefix can be NULL.
Packit bd1cd8
GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
Packit bd1cd8
Packit bd1cd8
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
Packit bd1cd8
Packit bd1cd8
// State of the definition of a type-parameterized test case.
Packit bd1cd8
class GTEST_API_ TypedTestCasePState {
Packit bd1cd8
 public:
Packit bd1cd8
  TypedTestCasePState() : registered_(false) {}
Packit bd1cd8
Packit bd1cd8
  // Adds the given test name to defined_test_names_ and return true
Packit bd1cd8
  // if the test case hasn't been registered; otherwise aborts the
Packit bd1cd8
  // program.
Packit bd1cd8
  bool AddTestName(const char* file, int line, const char* case_name,
Packit bd1cd8
                   const char* test_name) {
Packit bd1cd8
    if (registered_) {
Packit bd1cd8
      fprintf(stderr, "%s Test %s must be defined before "
Packit bd1cd8
              "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
Packit bd1cd8
              FormatFileLocation(file, line).c_str(), test_name, case_name);
Packit bd1cd8
      fflush(stderr);
Packit bd1cd8
      posix::Abort();
Packit bd1cd8
    }
Packit bd1cd8
    registered_tests_.insert(
Packit bd1cd8
        ::std::make_pair(test_name, CodeLocation(file, line)));
Packit bd1cd8
    return true;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  bool TestExists(const std::string& test_name) const {
Packit bd1cd8
    return registered_tests_.count(test_name) > 0;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  const CodeLocation& GetCodeLocation(const std::string& test_name) const {
Packit bd1cd8
    RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
Packit bd1cd8
    GTEST_CHECK_(it != registered_tests_.end());
Packit bd1cd8
    return it->second;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Verifies that registered_tests match the test names in
Packit bd1cd8
  // defined_test_names_; returns registered_tests if successful, or
Packit bd1cd8
  // aborts the program otherwise.
Packit bd1cd8
  const char* VerifyRegisteredTestNames(
Packit bd1cd8
      const char* file, int line, const char* registered_tests);
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap;
Packit bd1cd8
Packit bd1cd8
  bool registered_;
Packit bd1cd8
  RegisteredTestsMap registered_tests_;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Skips to the first non-space char after the first comma in 'str';
Packit bd1cd8
// returns NULL if no comma is found in 'str'.
Packit bd1cd8
inline const char* SkipComma(const char* str) {
Packit bd1cd8
  const char* comma = strchr(str, ',');
Packit bd1cd8
  if (comma == NULL) {
Packit bd1cd8
    return NULL;
Packit bd1cd8
  }
Packit bd1cd8
  while (IsSpace(*(++comma))) {}
Packit bd1cd8
  return comma;
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Returns the prefix of 'str' before the first comma in it; returns
Packit bd1cd8
// the entire string if it contains no comma.
Packit bd1cd8
inline std::string GetPrefixUntilComma(const char* str) {
Packit bd1cd8
  const char* comma = strchr(str, ',');
Packit bd1cd8
  return comma == NULL ? str : std::string(str, comma);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Splits a given string on a given delimiter, populating a given
Packit bd1cd8
// vector with the fields.
Packit bd1cd8
void SplitString(const ::std::string& str, char delimiter,
Packit bd1cd8
                 ::std::vector< ::std::string>* dest);
Packit bd1cd8
Packit bd1cd8
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
Packit bd1cd8
// registers a list of type-parameterized tests with Google Test.  The
Packit bd1cd8
// return value is insignificant - we just need to return something
Packit bd1cd8
// such that we can call this function in a namespace scope.
Packit bd1cd8
//
Packit bd1cd8
// Implementation note: The GTEST_TEMPLATE_ macro declares a template
Packit bd1cd8
// template parameter.  It's defined in gtest-type-util.h.
Packit bd1cd8
template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
Packit bd1cd8
class TypeParameterizedTest {
Packit bd1cd8
 public:
Packit bd1cd8
  // 'index' is the index of the test in the type list 'Types'
Packit bd1cd8
  // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
Packit bd1cd8
  // Types).  Valid values for 'index' are [0, N - 1] where N is the
Packit bd1cd8
  // length of Types.
Packit bd1cd8
  static bool Register(const char* prefix,
Packit bd1cd8
                       CodeLocation code_location,
Packit bd1cd8
                       const char* case_name, const char* test_names,
Packit bd1cd8
                       int index) {
Packit bd1cd8
    typedef typename Types::Head Type;
Packit bd1cd8
    typedef Fixture<Type> FixtureClass;
Packit bd1cd8
    typedef typename GTEST_BIND_(TestSel, Type) TestClass;
Packit bd1cd8
Packit bd1cd8
    // First, registers the first type-parameterized test in the type
Packit bd1cd8
    // list.
Packit bd1cd8
    MakeAndRegisterTestInfo(
Packit bd1cd8
        (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
Packit bd1cd8
         + StreamableToString(index)).c_str(),
Packit bd1cd8
        StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
Packit bd1cd8
        GetTypeName<Type>().c_str(),
Packit bd1cd8
        NULL,  // No value parameter.
Packit bd1cd8
        code_location,
Packit bd1cd8
        GetTypeId<FixtureClass>(),
Packit bd1cd8
        TestClass::SetUpTestCase,
Packit bd1cd8
        TestClass::TearDownTestCase,
Packit bd1cd8
        new TestFactoryImpl<TestClass>);
Packit bd1cd8
Packit bd1cd8
    // Next, recurses (at compile time) with the tail of the type list.
Packit bd1cd8
    return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
Packit bd1cd8
        ::Register(prefix, code_location, case_name, test_names, index + 1);
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// The base case for the compile time recursion.
Packit bd1cd8
template <GTEST_TEMPLATE_ Fixture, class TestSel>
Packit bd1cd8
class TypeParameterizedTest<Fixture, TestSel, Types0> {
Packit bd1cd8
 public:
Packit bd1cd8
  static bool Register(const char* /*prefix*/, CodeLocation,
Packit bd1cd8
                       const char* /*case_name*/, const char* /*test_names*/,
Packit bd1cd8
                       int /*index*/) {
Packit bd1cd8
    return true;
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
Packit bd1cd8
// registers *all combinations* of 'Tests' and 'Types' with Google
Packit bd1cd8
// Test.  The return value is insignificant - we just need to return
Packit bd1cd8
// something such that we can call this function in a namespace scope.
Packit bd1cd8
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
Packit bd1cd8
class TypeParameterizedTestCase {
Packit bd1cd8
 public:
Packit bd1cd8
  static bool Register(const char* prefix, CodeLocation code_location,
Packit bd1cd8
                       const TypedTestCasePState* state,
Packit bd1cd8
                       const char* case_name, const char* test_names) {
Packit bd1cd8
    std::string test_name = StripTrailingSpaces(
Packit bd1cd8
        GetPrefixUntilComma(test_names));
Packit bd1cd8
    if (!state->TestExists(test_name)) {
Packit bd1cd8
      fprintf(stderr, "Failed to get code location for test %s.%s at %s.",
Packit bd1cd8
              case_name, test_name.c_str(),
Packit bd1cd8
              FormatFileLocation(code_location.file.c_str(),
Packit bd1cd8
                                 code_location.line).c_str());
Packit bd1cd8
      fflush(stderr);
Packit bd1cd8
      posix::Abort();
Packit bd1cd8
    }
Packit bd1cd8
    const CodeLocation& test_location = state->GetCodeLocation(test_name);
Packit bd1cd8
Packit bd1cd8
    typedef typename Tests::Head Head;
Packit bd1cd8
Packit bd1cd8
    // First, register the first test in 'Test' for each type in 'Types'.
Packit bd1cd8
    TypeParameterizedTest<Fixture, Head, Types>::Register(
Packit bd1cd8
        prefix, test_location, case_name, test_names, 0);
Packit bd1cd8
Packit bd1cd8
    // Next, recurses (at compile time) with the tail of the test list.
Packit bd1cd8
    return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
Packit bd1cd8
        ::Register(prefix, code_location, state,
Packit bd1cd8
                   case_name, SkipComma(test_names));
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// The base case for the compile time recursion.
Packit bd1cd8
template <GTEST_TEMPLATE_ Fixture, typename Types>
Packit bd1cd8
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
Packit bd1cd8
 public:
Packit bd1cd8
  static bool Register(const char* /*prefix*/, CodeLocation,
Packit bd1cd8
                       const TypedTestCasePState* /*state*/,
Packit bd1cd8
                       const char* /*case_name*/, const char* /*test_names*/) {
Packit bd1cd8
    return true;
Packit bd1cd8
  }
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
Packit bd1cd8
Packit bd1cd8
// Returns the current OS stack trace as an std::string.
Packit bd1cd8
//
Packit bd1cd8
// The maximum number of stack frames to be included is specified by
Packit bd1cd8
// the gtest_stack_trace_depth flag.  The skip_count parameter
Packit bd1cd8
// specifies the number of top frames to be skipped, which doesn't
Packit bd1cd8
// count against the number of frames to be included.
Packit bd1cd8
//
Packit bd1cd8
// For example, if Foo() calls Bar(), which in turn calls
Packit bd1cd8
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
Packit bd1cd8
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
Packit bd1cd8
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
Packit bd1cd8
    UnitTest* unit_test, int skip_count);
Packit bd1cd8
Packit bd1cd8
// Helpers for suppressing warnings on unreachable code or constant
Packit bd1cd8
// condition.
Packit bd1cd8
Packit bd1cd8
// Always returns true.
Packit bd1cd8
GTEST_API_ bool AlwaysTrue();
Packit bd1cd8
Packit bd1cd8
// Always returns false.
Packit bd1cd8
inline bool AlwaysFalse() { return !AlwaysTrue(); }
Packit bd1cd8
Packit bd1cd8
// Helper for suppressing false warning from Clang on a const char*
Packit bd1cd8
// variable declared in a conditional expression always being NULL in
Packit bd1cd8
// the else branch.
Packit bd1cd8
struct GTEST_API_ ConstCharPtr {
Packit bd1cd8
  ConstCharPtr(const char* str) : value(str) {}
Packit bd1cd8
  operator bool() const { return true; }
Packit bd1cd8
  const char* value;
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// A simple Linear Congruential Generator for generating random
Packit bd1cd8
// numbers with a uniform distribution.  Unlike rand() and srand(), it
Packit bd1cd8
// doesn't use global state (and therefore can't interfere with user
Packit bd1cd8
// code).  Unlike rand_r(), it's portable.  An LCG isn't very random,
Packit bd1cd8
// but it's good enough for our purposes.
Packit bd1cd8
class GTEST_API_ Random {
Packit bd1cd8
 public:
Packit bd1cd8
  static const UInt32 kMaxRange = 1u << 31;
Packit bd1cd8
Packit bd1cd8
  explicit Random(UInt32 seed) : state_(seed) {}
Packit bd1cd8
Packit bd1cd8
  void Reseed(UInt32 seed) { state_ = seed; }
Packit bd1cd8
Packit bd1cd8
  // Generates a random number from [0, range).  Crashes if 'range' is
Packit bd1cd8
  // 0 or greater than kMaxRange.
Packit bd1cd8
  UInt32 Generate(UInt32 range);
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  UInt32 state_;
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
Packit bd1cd8
// compiler error iff T1 and T2 are different types.
Packit bd1cd8
template <typename T1, typename T2>
Packit bd1cd8
struct CompileAssertTypesEqual;
Packit bd1cd8
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct CompileAssertTypesEqual<T, T> {
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// Removes the reference from a type if it is a reference type,
Packit bd1cd8
// otherwise leaves it unchanged.  This is the same as
Packit bd1cd8
// tr1::remove_reference, which is not widely available yet.
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct RemoveReference { typedef T type; };  // NOLINT
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct RemoveReference<T&> { typedef T type; };  // NOLINT
Packit bd1cd8
Packit bd1cd8
// A handy wrapper around RemoveReference that works when the argument
Packit bd1cd8
// T depends on template parameters.
Packit bd1cd8
#define GTEST_REMOVE_REFERENCE_(T) \
Packit bd1cd8
    typename ::testing::internal::RemoveReference<T>::type
Packit bd1cd8
Packit bd1cd8
// Removes const from a type if it is a const type, otherwise leaves
Packit bd1cd8
// it unchanged.  This is the same as tr1::remove_const, which is not
Packit bd1cd8
// widely available yet.
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct RemoveConst { typedef T type; };  // NOLINT
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct RemoveConst<const T> { typedef T type; };  // NOLINT
Packit bd1cd8
Packit bd1cd8
// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
Packit bd1cd8
// definition to fail to remove the const in 'const int[3]' and 'const
Packit bd1cd8
// char[3][4]'.  The following specialization works around the bug.
Packit bd1cd8
template <typename T, size_t N>
Packit bd1cd8
struct RemoveConst<const T[N]> {
Packit bd1cd8
  typedef typename RemoveConst<T>::type type[N];
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
#if defined(_MSC_VER) && _MSC_VER < 1400
Packit bd1cd8
// This is the only specialization that allows VC++ 7.1 to remove const in
Packit bd1cd8
// 'const int[3] and 'const int[3][4]'.  However, it causes trouble with GCC
Packit bd1cd8
// and thus needs to be conditionally compiled.
Packit bd1cd8
template <typename T, size_t N>
Packit bd1cd8
struct RemoveConst<T[N]> {
Packit bd1cd8
  typedef typename RemoveConst<T>::type type[N];
Packit bd1cd8
};
Packit bd1cd8
#endif
Packit bd1cd8
Packit bd1cd8
// A handy wrapper around RemoveConst that works when the argument
Packit bd1cd8
// T depends on template parameters.
Packit bd1cd8
#define GTEST_REMOVE_CONST_(T) \
Packit bd1cd8
    typename ::testing::internal::RemoveConst<T>::type
Packit bd1cd8
Packit bd1cd8
// Turns const U&, U&, const U, and U all into U.
Packit bd1cd8
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
Packit bd1cd8
    GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
Packit bd1cd8
Packit bd1cd8
// Adds reference to a type if it is not a reference type,
Packit bd1cd8
// otherwise leaves it unchanged.  This is the same as
Packit bd1cd8
// tr1::add_reference, which is not widely available yet.
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct AddReference { typedef T& type; };  // NOLINT
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct AddReference<T&> { typedef T& type; };  // NOLINT
Packit bd1cd8
Packit bd1cd8
// A handy wrapper around AddReference that works when the argument T
Packit bd1cd8
// depends on template parameters.
Packit bd1cd8
#define GTEST_ADD_REFERENCE_(T) \
Packit bd1cd8
    typename ::testing::internal::AddReference<T>::type
Packit bd1cd8
Packit bd1cd8
// Adds a reference to const on top of T as necessary.  For example,
Packit bd1cd8
// it transforms
Packit bd1cd8
//
Packit bd1cd8
//   char         ==> const char&
Packit bd1cd8
//   const char   ==> const char&
Packit bd1cd8
//   char&        ==> const char&
Packit bd1cd8
//   const char&  ==> const char&
Packit bd1cd8
//
Packit bd1cd8
// The argument T must depend on some template parameters.
Packit bd1cd8
#define GTEST_REFERENCE_TO_CONST_(T) \
Packit bd1cd8
    GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
Packit bd1cd8
Packit bd1cd8
// ImplicitlyConvertible<From, To>::value is a compile-time bool
Packit bd1cd8
// constant that's true iff type From can be implicitly converted to
Packit bd1cd8
// type To.
Packit bd1cd8
template <typename From, typename To>
Packit bd1cd8
class ImplicitlyConvertible {
Packit bd1cd8
 private:
Packit bd1cd8
  // We need the following helper functions only for their types.
Packit bd1cd8
  // They have no implementations.
Packit bd1cd8
Packit bd1cd8
  // MakeFrom() is an expression whose type is From.  We cannot simply
Packit bd1cd8
  // use From(), as the type From may not have a public default
Packit bd1cd8
  // constructor.
Packit bd1cd8
  static typename AddReference<From>::type MakeFrom();
Packit bd1cd8
Packit bd1cd8
  // These two functions are overloaded.  Given an expression
Packit bd1cd8
  // Helper(x), the compiler will pick the first version if x can be
Packit bd1cd8
  // implicitly converted to type To; otherwise it will pick the
Packit bd1cd8
  // second version.
Packit bd1cd8
  //
Packit bd1cd8
  // The first version returns a value of size 1, and the second
Packit bd1cd8
  // version returns a value of size 2.  Therefore, by checking the
Packit bd1cd8
  // size of Helper(x), which can be done at compile time, we can tell
Packit bd1cd8
  // which version of Helper() is used, and hence whether x can be
Packit bd1cd8
  // implicitly converted to type To.
Packit bd1cd8
  static char Helper(To);
Packit bd1cd8
  static char (&Helper(...))[2];  // NOLINT
Packit bd1cd8
Packit bd1cd8
  // We have to put the 'public' section after the 'private' section,
Packit bd1cd8
  // or MSVC refuses to compile the code.
Packit bd1cd8
 public:
Packit bd1cd8
#if defined(__BORLANDC__)
Packit bd1cd8
  // C++Builder cannot use member overload resolution during template
Packit bd1cd8
  // instantiation.  The simplest workaround is to use its C++0x type traits
Packit bd1cd8
  // functions (C++Builder 2009 and above only).
Packit bd1cd8
  static const bool value = __is_convertible(From, To);
Packit bd1cd8
#else
Packit bd1cd8
  // MSVC warns about implicitly converting from double to int for
Packit bd1cd8
  // possible loss of data, so we need to temporarily disable the
Packit bd1cd8
  // warning.
Packit bd1cd8
  GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244)
Packit bd1cd8
  static const bool value =
Packit bd1cd8
      sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
Packit bd1cd8
  GTEST_DISABLE_MSC_WARNINGS_POP_()
Packit bd1cd8
#endif  // __BORLANDC__
Packit bd1cd8
};
Packit bd1cd8
template <typename From, typename To>
Packit bd1cd8
const bool ImplicitlyConvertible<From, To>::value;
Packit bd1cd8
Packit bd1cd8
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
Packit bd1cd8
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
Packit bd1cd8
// of those.
Packit bd1cd8
template <typename T>
Packit bd1cd8
struct IsAProtocolMessage
Packit bd1cd8
    : public bool_constant<
Packit bd1cd8
  ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
Packit bd1cd8
  ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
// When the compiler sees expression IsContainerTest<C>(0), if C is an
Packit bd1cd8
// STL-style container class, the first overload of IsContainerTest
Packit bd1cd8
// will be viable (since both C::iterator* and C::const_iterator* are
Packit bd1cd8
// valid types and NULL can be implicitly converted to them).  It will
Packit bd1cd8
// be picked over the second overload as 'int' is a perfect match for
Packit bd1cd8
// the type of argument 0.  If C::iterator or C::const_iterator is not
Packit bd1cd8
// a valid type, the first overload is not viable, and the second
Packit bd1cd8
// overload will be picked.  Therefore, we can determine whether C is
Packit bd1cd8
// a container class by checking the type of IsContainerTest<C>(0).
Packit bd1cd8
// The value of the expression is insignificant.
Packit bd1cd8
//
Packit bd1cd8
// Note that we look for both C::iterator and C::const_iterator.  The
Packit bd1cd8
// reason is that C++ injects the name of a class as a member of the
Packit bd1cd8
// class itself (e.g. you can refer to class iterator as either
Packit bd1cd8
// 'iterator' or 'iterator::iterator').  If we look for C::iterator
Packit bd1cd8
// only, for example, we would mistakenly think that a class named
Packit bd1cd8
// iterator is an STL container.
Packit bd1cd8
//
Packit bd1cd8
// Also note that the simpler approach of overloading
Packit bd1cd8
// IsContainerTest(typename C::const_iterator*) and
Packit bd1cd8
// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
Packit bd1cd8
typedef int IsContainer;
Packit bd1cd8
template <class C>
Packit bd1cd8
IsContainer IsContainerTest(int /* dummy */,
Packit bd1cd8
                            typename C::iterator* /* it */ = NULL,
Packit bd1cd8
                            typename C::const_iterator* /* const_it */ = NULL) {
Packit bd1cd8
  return 0;
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
typedef char IsNotContainer;
Packit bd1cd8
template <class C>
Packit bd1cd8
IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
Packit bd1cd8
Packit bd1cd8
// EnableIf<condition>::type is void when 'Cond' is true, and
Packit bd1cd8
// undefined when 'Cond' is false.  To use SFINAE to make a function
Packit bd1cd8
// overload only apply when a particular expression is true, add
Packit bd1cd8
// "typename EnableIf<expression>::type* = 0" as the last parameter.
Packit bd1cd8
template<bool> struct EnableIf;
Packit bd1cd8
template<> struct EnableIf<true> { typedef void type; };  // NOLINT
Packit bd1cd8
Packit bd1cd8
// Utilities for native arrays.
Packit bd1cd8
Packit bd1cd8
// ArrayEq() compares two k-dimensional native arrays using the
Packit bd1cd8
// elements' operator==, where k can be any integer >= 0.  When k is
Packit bd1cd8
// 0, ArrayEq() degenerates into comparing a single pair of values.
Packit bd1cd8
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
bool ArrayEq(const T* lhs, size_t size, const U* rhs);
Packit bd1cd8
Packit bd1cd8
// This generic version is used when k is 0.
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
Packit bd1cd8
Packit bd1cd8
// This overload is used when k >= 1.
Packit bd1cd8
template <typename T, typename U, size_t N>
Packit bd1cd8
inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
Packit bd1cd8
  return internal::ArrayEq(lhs, N, rhs);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// This helper reduces code bloat.  If we instead put its logic inside
Packit bd1cd8
// the previous ArrayEq() function, arrays with different sizes would
Packit bd1cd8
// lead to different copies of the template code.
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
Packit bd1cd8
  for (size_t i = 0; i != size; i++) {
Packit bd1cd8
    if (!internal::ArrayEq(lhs[i], rhs[i]))
Packit bd1cd8
      return false;
Packit bd1cd8
  }
Packit bd1cd8
  return true;
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// Finds the first element in the iterator range [begin, end) that
Packit bd1cd8
// equals elem.  Element may be a native array type itself.
Packit bd1cd8
template <typename Iter, typename Element>
Packit bd1cd8
Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
Packit bd1cd8
  for (Iter it = begin; it != end; ++it) {
Packit bd1cd8
    if (internal::ArrayEq(*it, elem))
Packit bd1cd8
      return it;
Packit bd1cd8
  }
Packit bd1cd8
  return end;
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// CopyArray() copies a k-dimensional native array using the elements'
Packit bd1cd8
// operator=, where k can be any integer >= 0.  When k is 0,
Packit bd1cd8
// CopyArray() degenerates into copying a single value.
Packit bd1cd8
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
void CopyArray(const T* from, size_t size, U* to);
Packit bd1cd8
Packit bd1cd8
// This generic version is used when k is 0.
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
inline void CopyArray(const T& from, U* to) { *to = from; }
Packit bd1cd8
Packit bd1cd8
// This overload is used when k >= 1.
Packit bd1cd8
template <typename T, typename U, size_t N>
Packit bd1cd8
inline void CopyArray(const T(&from)[N], U(*to)[N]) {
Packit bd1cd8
  internal::CopyArray(from, N, *to);
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// This helper reduces code bloat.  If we instead put its logic inside
Packit bd1cd8
// the previous CopyArray() function, arrays with different sizes
Packit bd1cd8
// would lead to different copies of the template code.
Packit bd1cd8
template <typename T, typename U>
Packit bd1cd8
void CopyArray(const T* from, size_t size, U* to) {
Packit bd1cd8
  for (size_t i = 0; i != size; i++) {
Packit bd1cd8
    internal::CopyArray(from[i], to + i);
Packit bd1cd8
  }
Packit bd1cd8
}
Packit bd1cd8
Packit bd1cd8
// The relation between an NativeArray object (see below) and the
Packit bd1cd8
// native array it represents.
Packit bd1cd8
// We use 2 different structs to allow non-copyable types to be used, as long
Packit bd1cd8
// as RelationToSourceReference() is passed.
Packit bd1cd8
struct RelationToSourceReference {};
Packit bd1cd8
struct RelationToSourceCopy {};
Packit bd1cd8
Packit bd1cd8
// Adapts a native array to a read-only STL-style container.  Instead
Packit bd1cd8
// of the complete STL container concept, this adaptor only implements
Packit bd1cd8
// members useful for Google Mock's container matchers.  New members
Packit bd1cd8
// should be added as needed.  To simplify the implementation, we only
Packit bd1cd8
// support Element being a raw type (i.e. having no top-level const or
Packit bd1cd8
// reference modifier).  It's the client's responsibility to satisfy
Packit bd1cd8
// this requirement.  Element can be an array type itself (hence
Packit bd1cd8
// multi-dimensional arrays are supported).
Packit bd1cd8
template <typename Element>
Packit bd1cd8
class NativeArray {
Packit bd1cd8
 public:
Packit bd1cd8
  // STL-style container typedefs.
Packit bd1cd8
  typedef Element value_type;
Packit bd1cd8
  typedef Element* iterator;
Packit bd1cd8
  typedef const Element* const_iterator;
Packit bd1cd8
Packit bd1cd8
  // Constructs from a native array. References the source.
Packit bd1cd8
  NativeArray(const Element* array, size_t count, RelationToSourceReference) {
Packit bd1cd8
    InitRef(array, count);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Constructs from a native array. Copies the source.
Packit bd1cd8
  NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
Packit bd1cd8
    InitCopy(array, count);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Copy constructor.
Packit bd1cd8
  NativeArray(const NativeArray& rhs) {
Packit bd1cd8
    (this->*rhs.clone_)(rhs.array_, rhs.size_);
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  ~NativeArray() {
Packit bd1cd8
    if (clone_ != &NativeArray::InitRef)
Packit bd1cd8
      delete[] array_;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // STL-style container methods.
Packit bd1cd8
  size_t size() const { return size_; }
Packit bd1cd8
  const_iterator begin() const { return array_; }
Packit bd1cd8
  const_iterator end() const { return array_ + size_; }
Packit bd1cd8
  bool operator==(const NativeArray& rhs) const {
Packit bd1cd8
    return size() == rhs.size() &&
Packit bd1cd8
        ArrayEq(begin(), size(), rhs.begin());
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
 private:
Packit bd1cd8
  enum {
Packit bd1cd8
    kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
Packit bd1cd8
        Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value,
Packit bd1cd8
  };
Packit bd1cd8
Packit bd1cd8
  // Initializes this object with a copy of the input.
Packit bd1cd8
  void InitCopy(const Element* array, size_t a_size) {
Packit bd1cd8
    Element* const copy = new Element[a_size];
Packit bd1cd8
    CopyArray(array, a_size, copy);
Packit bd1cd8
    array_ = copy;
Packit bd1cd8
    size_ = a_size;
Packit bd1cd8
    clone_ = &NativeArray::InitCopy;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  // Initializes this object with a reference of the input.
Packit bd1cd8
  void InitRef(const Element* array, size_t a_size) {
Packit bd1cd8
    array_ = array;
Packit bd1cd8
    size_ = a_size;
Packit bd1cd8
    clone_ = &NativeArray::InitRef;
Packit bd1cd8
  }
Packit bd1cd8
Packit bd1cd8
  const Element* array_;
Packit bd1cd8
  size_t size_;
Packit bd1cd8
  void (NativeArray::*clone_)(const Element*, size_t);
Packit bd1cd8
Packit bd1cd8
  GTEST_DISALLOW_ASSIGN_(NativeArray);
Packit bd1cd8
};
Packit bd1cd8
Packit bd1cd8
}  // namespace internal
Packit bd1cd8
}  // namespace testing
Packit bd1cd8
Packit bd1cd8
#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
Packit bd1cd8
  ::testing::internal::AssertHelper(result_type, file, line, message) \
Packit bd1cd8
    = ::testing::Message()
Packit bd1cd8
Packit bd1cd8
#define GTEST_MESSAGE_(message, result_type) \
Packit bd1cd8
  GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
Packit bd1cd8
Packit bd1cd8
#define GTEST_FATAL_FAILURE_(message) \
Packit bd1cd8
  return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
Packit bd1cd8
Packit bd1cd8
#define GTEST_NONFATAL_FAILURE_(message) \
Packit bd1cd8
  GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
Packit bd1cd8
Packit bd1cd8
#define GTEST_SUCCESS_(message) \
Packit bd1cd8
  GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
Packit bd1cd8
Packit bd1cd8
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
Packit bd1cd8
// statement if it returns or throws (or doesn't return or throw in some
Packit bd1cd8
// situations).
Packit bd1cd8
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
Packit bd1cd8
  if (::testing::internal::AlwaysTrue()) { statement; }
Packit bd1cd8
Packit bd1cd8
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
Packit bd1cd8
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
Packit bd1cd8
  if (::testing::internal::ConstCharPtr gtest_msg = "") { \
Packit bd1cd8
    bool gtest_caught_expected = false; \
Packit bd1cd8
    try { \
Packit bd1cd8
      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
Packit bd1cd8
    } \
Packit bd1cd8
    catch (expected_exception const&) { \
Packit bd1cd8
      gtest_caught_expected = true; \
Packit bd1cd8
    } \
Packit bd1cd8
    catch (...) { \
Packit bd1cd8
      gtest_msg.value = \
Packit bd1cd8
          "Expected: " #statement " throws an exception of type " \
Packit bd1cd8
          #expected_exception ".\n  Actual: it throws a different type."; \
Packit bd1cd8
      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
Packit bd1cd8
    } \
Packit bd1cd8
    if (!gtest_caught_expected) { \
Packit bd1cd8
      gtest_msg.value = \
Packit bd1cd8
          "Expected: " #statement " throws an exception of type " \
Packit bd1cd8
          #expected_exception ".\n  Actual: it throws nothing."; \
Packit bd1cd8
      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
Packit bd1cd8
    } \
Packit bd1cd8
  } else \
Packit bd1cd8
    GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
Packit bd1cd8
      fail(gtest_msg.value)
Packit bd1cd8
Packit bd1cd8
#define GTEST_TEST_NO_THROW_(statement, fail) \
Packit bd1cd8
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
Packit bd1cd8
  if (::testing::internal::AlwaysTrue()) { \
Packit bd1cd8
    try { \
Packit bd1cd8
      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
Packit bd1cd8
    } \
Packit bd1cd8
    catch (...) { \
Packit bd1cd8
      goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
Packit bd1cd8
    } \
Packit bd1cd8
  } else \
Packit bd1cd8
    GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
Packit bd1cd8
      fail("Expected: " #statement " doesn't throw an exception.\n" \
Packit bd1cd8
           "  Actual: it throws.")
Packit bd1cd8
Packit bd1cd8
#define GTEST_TEST_ANY_THROW_(statement, fail) \
Packit bd1cd8
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
Packit bd1cd8
  if (::testing::internal::AlwaysTrue()) { \
Packit bd1cd8
    bool gtest_caught_any = false; \
Packit bd1cd8
    try { \
Packit bd1cd8
      GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
Packit bd1cd8
    } \
Packit bd1cd8
    catch (...) { \
Packit bd1cd8
      gtest_caught_any = true; \
Packit bd1cd8
    } \
Packit bd1cd8
    if (!gtest_caught_any) { \
Packit bd1cd8
      goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
Packit bd1cd8
    } \
Packit bd1cd8
  } else \
Packit bd1cd8
    GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
Packit bd1cd8
      fail("Expected: " #statement " throws an exception.\n" \
Packit bd1cd8
           "  Actual: it doesn't.")
Packit bd1cd8
Packit bd1cd8
Packit bd1cd8
// Implements Boolean test assertions such as EXPECT_TRUE. expression can be
Packit bd1cd8
// either a boolean expression or an AssertionResult. text is a textual
Packit bd1cd8
// represenation of expression as it was passed into the EXPECT_TRUE.
Packit bd1cd8
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
Packit bd1cd8
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
Packit bd1cd8
  if (const ::testing::AssertionResult gtest_ar_ = \
Packit bd1cd8
      ::testing::AssertionResult(expression)) \
Packit bd1cd8
    ; \
Packit bd1cd8
  else \
Packit bd1cd8
    fail(::testing::internal::GetBoolAssertionFailureMessage(\
Packit bd1cd8
        gtest_ar_, text, #actual, #expected).c_str())
Packit bd1cd8
Packit bd1cd8
#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
Packit bd1cd8
  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
Packit bd1cd8
  if (::testing::internal::AlwaysTrue()) { \
Packit bd1cd8
    ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
Packit bd1cd8
    GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
Packit bd1cd8
    if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
Packit bd1cd8
      goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
Packit bd1cd8
    } \
Packit bd1cd8
  } else \
Packit bd1cd8
    GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
Packit bd1cd8
      fail("Expected: " #statement " doesn't generate new fatal " \
Packit bd1cd8
           "failures in the current thread.\n" \
Packit bd1cd8
           "  Actual: it does.")
Packit bd1cd8
Packit bd1cd8
// Expands to the name of the class that implements the given test.
Packit bd1cd8
#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
Packit bd1cd8
  test_case_name##_##test_name##_Test
Packit bd1cd8
Packit bd1cd8
// Helper macro for defining tests.
Packit bd1cd8
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
Packit bd1cd8
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
Packit bd1cd8
 public:\
Packit bd1cd8
  GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
Packit bd1cd8
 private:\
Packit bd1cd8
  virtual void TestBody();\
Packit bd1cd8
  static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
Packit bd1cd8
  GTEST_DISALLOW_COPY_AND_ASSIGN_(\
Packit bd1cd8
      GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
Packit bd1cd8
};\
Packit bd1cd8
\
Packit bd1cd8
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
Packit bd1cd8
  ::test_info_ =\
Packit bd1cd8
    ::testing::internal::MakeAndRegisterTestInfo(\
Packit bd1cd8
        #test_case_name, #test_name, NULL, NULL, \
Packit bd1cd8
        ::testing::internal::CodeLocation(__FILE__, __LINE__), \
Packit bd1cd8
        (parent_id), \
Packit bd1cd8
        parent_class::SetUpTestCase, \
Packit bd1cd8
        parent_class::TearDownTestCase, \
Packit bd1cd8
        new ::testing::internal::TestFactoryImpl<\
Packit bd1cd8
            GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
Packit bd1cd8
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
Packit bd1cd8
Packit bd1cd8
#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
Packit bd1cd8