gtest-internal.h
Go to the documentation of this file.
00001 // Copyright 2005, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
00031 //
00032 // The Google C++ Testing Framework (Google Test)
00033 //
00034 // This header file declares functions and macros used internally by
00035 // Google Test.  They are subject to change without notice.
00036 
00037 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
00038 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
00039 
00040 #include "gtest/internal/gtest-port.h"
00041 
00042 #if GTEST_OS_LINUX
00043 # include <stdlib.h>
00044 # include <sys/types.h>
00045 # include <sys/wait.h>
00046 # include <unistd.h>
00047 #endif  // GTEST_OS_LINUX
00048 
00049 #if GTEST_HAS_EXCEPTIONS
00050 # include <stdexcept>
00051 #endif
00052 
00053 #include <ctype.h>
00054 #include <float.h>
00055 #include <string.h>
00056 #include <iomanip>
00057 #include <limits>
00058 #include <set>
00059 #include <string>
00060 #include <vector>
00061 
00062 #include "gtest/gtest-message.h"
00063 #include "gtest/internal/gtest-string.h"
00064 #include "gtest/internal/gtest-filepath.h"
00065 #include "gtest/internal/gtest-type-util.h"
00066 
00067 // Due to C++ preprocessor weirdness, we need double indirection to
00068 // concatenate two tokens when one of them is __LINE__.  Writing
00069 //
00070 //   foo ## __LINE__
00071 //
00072 // will result in the token foo__LINE__, instead of foo followed by
00073 // the current line number.  For more details, see
00074 // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
00075 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
00076 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
00077 
00078 class ProtocolMessage;
00079 namespace proto2 { class Message; }
00080 
00081 namespace testing {
00082 
00083 // Forward declarations.
00084 
00085 class AssertionResult;                 // Result of an assertion.
00086 class Message;                         // Represents a failure message.
00087 class Test;                            // Represents a test.
00088 class TestInfo;                        // Information about a test.
00089 class TestPartResult;                  // Result of a test part.
00090 class UnitTest;                        // A collection of test cases.
00091 
00092 template <typename T>
00093 ::std::string PrintToString(const T& value);
00094 
00095 namespace internal {
00096 
00097 struct TraceInfo;                      // Information about a trace point.
00098 class ScopedTrace;                     // Implements scoped trace.
00099 class TestInfoImpl;                    // Opaque implementation of TestInfo
00100 class UnitTestImpl;                    // Opaque implementation of UnitTest
00101 
00102 // How many times InitGoogleTest() has been called.
00103 GTEST_API_ extern int g_init_gtest_count;
00104 
00105 // The text used in failure messages to indicate the start of the
00106 // stack trace.
00107 GTEST_API_ extern const char kStackTraceMarker[];
00108 
00109 // Two overloaded helpers for checking at compile time whether an
00110 // expression is a null pointer literal (i.e. NULL or any 0-valued
00111 // compile-time integral constant).  Their return values have
00112 // different sizes, so we can use sizeof() to test which version is
00113 // picked by the compiler.  These helpers have no implementations, as
00114 // we only need their signatures.
00115 //
00116 // Given IsNullLiteralHelper(x), the compiler will pick the first
00117 // version if x can be implicitly converted to Secret*, and pick the
00118 // second version otherwise.  Since Secret is a secret and incomplete
00119 // type, the only expression a user can write that has type Secret* is
00120 // a null pointer literal.  Therefore, we know that x is a null
00121 // pointer literal if and only if the first version is picked by the
00122 // compiler.
00123 char IsNullLiteralHelper(Secret* p);
00124 char (&IsNullLiteralHelper(...))[2];  // NOLINT
00125 
00126 // A compile-time bool constant that is true if and only if x is a
00127 // null pointer literal (i.e. NULL or any 0-valued compile-time
00128 // integral constant).
00129 #ifdef GTEST_ELLIPSIS_NEEDS_POD_
00130 // We lose support for NULL detection where the compiler doesn't like
00131 // passing non-POD classes through ellipsis (...).
00132 # define GTEST_IS_NULL_LITERAL_(x) false
00133 #else
00134 # define GTEST_IS_NULL_LITERAL_(x) \
00135     (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
00136 #endif  // GTEST_ELLIPSIS_NEEDS_POD_
00137 
00138 // Appends the user-supplied message to the Google-Test-generated message.
00139 GTEST_API_ std::string AppendUserMessage(
00140     const std::string& gtest_msg, const Message& user_msg);
00141 
00142 #if GTEST_HAS_EXCEPTIONS
00143 
00144 // This exception is thrown by (and only by) a failed Google Test
00145 // assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
00146 // are enabled).  We derive it from std::runtime_error, which is for
00147 // errors presumably detectable only at run time.  Since
00148 // std::runtime_error inherits from std::exception, many testing
00149 // frameworks know how to extract and print the message inside it.
00150 class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
00151  public:
00152   explicit GoogleTestFailureException(const TestPartResult& failure);
00153 };
00154 
00155 #endif  // GTEST_HAS_EXCEPTIONS
00156 
00157 // A helper class for creating scoped traces in user programs.
00158 class GTEST_API_ ScopedTrace {
00159  public:
00160   // The c'tor pushes the given source file location and message onto
00161   // a trace stack maintained by Google Test.
00162   ScopedTrace(const char* file, int line, const Message& message);
00163 
00164   // The d'tor pops the info pushed by the c'tor.
00165   //
00166   // Note that the d'tor is not virtual in order to be efficient.
00167   // Don't inherit from ScopedTrace!
00168   ~ScopedTrace();
00169 
00170  private:
00171   GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
00172 } GTEST_ATTRIBUTE_UNUSED_;  // A ScopedTrace object does its job in its
00173                             // c'tor and d'tor.  Therefore it doesn't
00174                             // need to be used otherwise.
00175 
00176 namespace edit_distance {
00177 // Returns the optimal edits to go from 'left' to 'right'.
00178 // All edits cost the same, with replace having lower priority than
00179 // add/remove.
00180 // Simple implementation of the Wagner–Fischer algorithm.
00181 // See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
00182 enum EditType { kMatch, kAdd, kRemove, kReplace };
00183 GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
00184     const std::vector<size_t>& left, const std::vector<size_t>& right);
00185 
00186 // Same as above, but the input is represented as strings.
00187 GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
00188     const std::vector<std::string>& left,
00189     const std::vector<std::string>& right);
00190 
00191 // Create a diff of the input strings in Unified diff format.
00192 GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
00193                                          const std::vector<std::string>& right,
00194                                          size_t context = 2);
00195 
00196 }  // namespace edit_distance
00197 
00198 // Calculate the diff between 'left' and 'right' and return it in unified diff
00199 // format.
00200 // If not null, stores in 'total_line_count' the total number of lines found
00201 // in left + right.
00202 GTEST_API_ std::string DiffStrings(const std::string& left,
00203                                    const std::string& right,
00204                                    size_t* total_line_count);
00205 
00206 // Constructs and returns the message for an equality assertion
00207 // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
00208 //
00209 // The first four parameters are the expressions used in the assertion
00210 // and their values, as strings.  For example, for ASSERT_EQ(foo, bar)
00211 // where foo is 5 and bar is 6, we have:
00212 //
00213 //   expected_expression: "foo"
00214 //   actual_expression:   "bar"
00215 //   expected_value:      "5"
00216 //   actual_value:        "6"
00217 //
00218 // The ignoring_case parameter is true iff the assertion is a
00219 // *_STRCASEEQ*.  When it's true, the string " (ignoring case)" will
00220 // be inserted into the message.
00221 GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
00222                                      const char* actual_expression,
00223                                      const std::string& expected_value,
00224                                      const std::string& actual_value,
00225                                      bool ignoring_case);
00226 
00227 // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
00228 GTEST_API_ std::string GetBoolAssertionFailureMessage(
00229     const AssertionResult& assertion_result,
00230     const char* expression_text,
00231     const char* actual_predicate_value,
00232     const char* expected_predicate_value);
00233 
00234 // This template class represents an IEEE floating-point number
00235 // (either single-precision or double-precision, depending on the
00236 // template parameters).
00237 //
00238 // The purpose of this class is to do more sophisticated number
00239 // comparison.  (Due to round-off error, etc, it's very unlikely that
00240 // two floating-points will be equal exactly.  Hence a naive
00241 // comparison by the == operation often doesn't work.)
00242 //
00243 // Format of IEEE floating-point:
00244 //
00245 //   The most-significant bit being the leftmost, an IEEE
00246 //   floating-point looks like
00247 //
00248 //     sign_bit exponent_bits fraction_bits
00249 //
00250 //   Here, sign_bit is a single bit that designates the sign of the
00251 //   number.
00252 //
00253 //   For float, there are 8 exponent bits and 23 fraction bits.
00254 //
00255 //   For double, there are 11 exponent bits and 52 fraction bits.
00256 //
00257 //   More details can be found at
00258 //   http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
00259 //
00260 // Template parameter:
00261 //
00262 //   RawType: the raw floating-point type (either float or double)
00263 template <typename RawType>
00264 class FloatingPoint {
00265  public:
00266   // Defines the unsigned integer type that has the same size as the
00267   // floating point number.
00268   typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
00269 
00270   // Constants.
00271 
00272   // # of bits in a number.
00273   static const size_t kBitCount = 8*sizeof(RawType);
00274 
00275   // # of fraction bits in a number.
00276   static const size_t kFractionBitCount =
00277     std::numeric_limits<RawType>::digits - 1;
00278 
00279   // # of exponent bits in a number.
00280   static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
00281 
00282   // The mask for the sign bit.
00283   static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
00284 
00285   // The mask for the fraction bits.
00286   static const Bits kFractionBitMask =
00287     ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
00288 
00289   // The mask for the exponent bits.
00290   static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
00291 
00292   // How many ULP's (Units in the Last Place) we want to tolerate when
00293   // comparing two numbers.  The larger the value, the more error we
00294   // allow.  A 0 value means that two numbers must be exactly the same
00295   // to be considered equal.
00296   //
00297   // The maximum error of a single floating-point operation is 0.5
00298   // units in the last place.  On Intel CPU's, all floating-point
00299   // calculations are done with 80-bit precision, while double has 64
00300   // bits.  Therefore, 4 should be enough for ordinary use.
00301   //
00302   // See the following article for more details on ULP:
00303   // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
00304   static const size_t kMaxUlps = 4;
00305 
00306   // Constructs a FloatingPoint from a raw floating-point number.
00307   //
00308   // On an Intel CPU, passing a non-normalized NAN (Not a Number)
00309   // around may change its bits, although the new value is guaranteed
00310   // to be also a NAN.  Therefore, don't expect this constructor to
00311   // preserve the bits in x when x is a NAN.
00312   explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
00313 
00314   // Static methods
00315 
00316   // Reinterprets a bit pattern as a floating-point number.
00317   //
00318   // This function is needed to test the AlmostEquals() method.
00319   static RawType ReinterpretBits(const Bits bits) {
00320     FloatingPoint fp(0);
00321     fp.u_.bits_ = bits;
00322     return fp.u_.value_;
00323   }
00324 
00325   // Returns the floating-point number that represent positive infinity.
00326   static RawType Infinity() {
00327     return ReinterpretBits(kExponentBitMask);
00328   }
00329 
00330   // Returns the maximum representable finite floating-point number.
00331   static RawType Max();
00332 
00333   // Non-static methods
00334 
00335   // Returns the bits that represents this number.
00336   const Bits &bits() const { return u_.bits_; }
00337 
00338   // Returns the exponent bits of this number.
00339   Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
00340 
00341   // Returns the fraction bits of this number.
00342   Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
00343 
00344   // Returns the sign bit of this number.
00345   Bits sign_bit() const { return kSignBitMask & u_.bits_; }
00346 
00347   // Returns true iff this is NAN (not a number).
00348   bool is_nan() const {
00349     // It's a NAN if the exponent bits are all ones and the fraction
00350     // bits are not entirely zeros.
00351     return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
00352   }
00353 
00354   // Returns true iff this number is at most kMaxUlps ULP's away from
00355   // rhs.  In particular, this function:
00356   //
00357   //   - returns false if either number is (or both are) NAN.
00358   //   - treats really large numbers as almost equal to infinity.
00359   //   - thinks +0.0 and -0.0 are 0 DLP's apart.
00360   bool AlmostEquals(const FloatingPoint& rhs) const {
00361     // The IEEE standard says that any comparison operation involving
00362     // a NAN must return false.
00363     if (is_nan() || rhs.is_nan()) return false;
00364 
00365     return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
00366         <= kMaxUlps;
00367   }
00368 
00369  private:
00370   // The data type used to store the actual floating-point number.
00371   union FloatingPointUnion {
00372     RawType value_;  // The raw floating-point number.
00373     Bits bits_;      // The bits that represent the number.
00374   };
00375 
00376   // Converts an integer from the sign-and-magnitude representation to
00377   // the biased representation.  More precisely, let N be 2 to the
00378   // power of (kBitCount - 1), an integer x is represented by the
00379   // unsigned number x + N.
00380   //
00381   // For instance,
00382   //
00383   //   -N + 1 (the most negative number representable using
00384   //          sign-and-magnitude) is represented by 1;
00385   //   0      is represented by N; and
00386   //   N - 1  (the biggest number representable using
00387   //          sign-and-magnitude) is represented by 2N - 1.
00388   //
00389   // Read http://en.wikipedia.org/wiki/Signed_number_representations
00390   // for more details on signed number representations.
00391   static Bits SignAndMagnitudeToBiased(const Bits &sam) {
00392     if (kSignBitMask & sam) {
00393       // sam represents a negative number.
00394       return ~sam + 1;
00395     } else {
00396       // sam represents a positive number.
00397       return kSignBitMask | sam;
00398     }
00399   }
00400 
00401   // Given two numbers in the sign-and-magnitude representation,
00402   // returns the distance between them as an unsigned number.
00403   static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
00404                                                      const Bits &sam2) {
00405     const Bits biased1 = SignAndMagnitudeToBiased(sam1);
00406     const Bits biased2 = SignAndMagnitudeToBiased(sam2);
00407     return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
00408   }
00409 
00410   FloatingPointUnion u_;
00411 };
00412 
00413 // We cannot use std::numeric_limits<T>::max() as it clashes with the max()
00414 // macro defined by <windows.h>.
00415 template <>
00416 inline float FloatingPoint<float>::Max() { return FLT_MAX; }
00417 template <>
00418 inline double FloatingPoint<double>::Max() { return DBL_MAX; }
00419 
00420 // Typedefs the instances of the FloatingPoint template class that we
00421 // care to use.
00422 typedef FloatingPoint<float> Float;
00423 typedef FloatingPoint<double> Double;
00424 
00425 // In order to catch the mistake of putting tests that use different
00426 // test fixture classes in the same test case, we need to assign
00427 // unique IDs to fixture classes and compare them.  The TypeId type is
00428 // used to hold such IDs.  The user should treat TypeId as an opaque
00429 // type: the only operation allowed on TypeId values is to compare
00430 // them for equality using the == operator.
00431 typedef const void* TypeId;
00432 
00433 template <typename T>
00434 class TypeIdHelper {
00435  public:
00436   // dummy_ must not have a const type.  Otherwise an overly eager
00437   // compiler (e.g. MSVC 7.1 & 8.0) may try to merge
00438   // TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
00439   static bool dummy_;
00440 };
00441 
00442 template <typename T>
00443 bool TypeIdHelper<T>::dummy_ = false;
00444 
00445 // GetTypeId<T>() returns the ID of type T.  Different values will be
00446 // returned for different types.  Calling the function twice with the
00447 // same type argument is guaranteed to return the same ID.
00448 template <typename T>
00449 TypeId GetTypeId() {
00450   // The compiler is required to allocate a different
00451   // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
00452   // the template.  Therefore, the address of dummy_ is guaranteed to
00453   // be unique.
00454   return &(TypeIdHelper<T>::dummy_);
00455 }
00456 
00457 // Returns the type ID of ::testing::Test.  Always call this instead
00458 // of GetTypeId< ::testing::Test>() to get the type ID of
00459 // ::testing::Test, as the latter may give the wrong result due to a
00460 // suspected linker bug when compiling Google Test as a Mac OS X
00461 // framework.
00462 GTEST_API_ TypeId GetTestTypeId();
00463 
00464 // Defines the abstract factory interface that creates instances
00465 // of a Test object.
00466 class TestFactoryBase {
00467  public:
00468   virtual ~TestFactoryBase() {}
00469 
00470   // Creates a test instance to run. The instance is both created and destroyed
00471   // within TestInfoImpl::Run()
00472   virtual Test* CreateTest() = 0;
00473 
00474  protected:
00475   TestFactoryBase() {}
00476 
00477  private:
00478   GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
00479 };
00480 
00481 // This class provides implementation of TeastFactoryBase interface.
00482 // It is used in TEST and TEST_F macros.
00483 template <class TestClass>
00484 class TestFactoryImpl : public TestFactoryBase {
00485  public:
00486   virtual Test* CreateTest() { return new TestClass; }
00487 };
00488 
00489 #if GTEST_OS_WINDOWS
00490 
00491 // Predicate-formatters for implementing the HRESULT checking macros
00492 // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
00493 // We pass a long instead of HRESULT to avoid causing an
00494 // include dependency for the HRESULT type.
00495 GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
00496                                             long hr);  // NOLINT
00497 GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
00498                                             long hr);  // NOLINT
00499 
00500 #endif  // GTEST_OS_WINDOWS
00501 
00502 // Types of SetUpTestCase() and TearDownTestCase() functions.
00503 typedef void (*SetUpTestCaseFunc)();
00504 typedef void (*TearDownTestCaseFunc)();
00505 
00506 // Creates a new TestInfo object and registers it with Google Test;
00507 // returns the created object.
00508 //
00509 // Arguments:
00510 //
00511 //   test_case_name:   name of the test case
00512 //   name:             name of the test
00513 //   type_param        the name of the test's type parameter, or NULL if
00514 //                     this is not a typed or a type-parameterized test.
00515 //   value_param       text representation of the test's value parameter,
00516 //                     or NULL if this is not a type-parameterized test.
00517 //   fixture_class_id: ID of the test fixture class
00518 //   set_up_tc:        pointer to the function that sets up the test case
00519 //   tear_down_tc:     pointer to the function that tears down the test case
00520 //   factory:          pointer to the factory that creates a test object.
00521 //                     The newly created TestInfo instance will assume
00522 //                     ownership of the factory object.
00523 GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
00524     const char* test_case_name,
00525     const char* name,
00526     const char* type_param,
00527     const char* value_param,
00528     TypeId fixture_class_id,
00529     SetUpTestCaseFunc set_up_tc,
00530     TearDownTestCaseFunc tear_down_tc,
00531     TestFactoryBase* factory);
00532 
00533 // If *pstr starts with the given prefix, modifies *pstr to be right
00534 // past the prefix and returns true; otherwise leaves *pstr unchanged
00535 // and returns false.  None of pstr, *pstr, and prefix can be NULL.
00536 GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
00537 
00538 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
00539 
00540 // State of the definition of a type-parameterized test case.
00541 class GTEST_API_ TypedTestCasePState {
00542  public:
00543   TypedTestCasePState() : registered_(false) {}
00544 
00545   // Adds the given test name to defined_test_names_ and return true
00546   // if the test case hasn't been registered; otherwise aborts the
00547   // program.
00548   bool AddTestName(const char* file, int line, const char* case_name,
00549                    const char* test_name) {
00550     if (registered_) {
00551       fprintf(stderr, "%s Test %s must be defined before "
00552               "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
00553               FormatFileLocation(file, line).c_str(), test_name, case_name);
00554       fflush(stderr);
00555       posix::Abort();
00556     }
00557     defined_test_names_.insert(test_name);
00558     return true;
00559   }
00560 
00561   // Verifies that registered_tests match the test names in
00562   // defined_test_names_; returns registered_tests if successful, or
00563   // aborts the program otherwise.
00564   const char* VerifyRegisteredTestNames(
00565       const char* file, int line, const char* registered_tests);
00566 
00567  private:
00568   bool registered_;
00569   ::std::set<const char*> defined_test_names_;
00570 };
00571 
00572 // Skips to the first non-space char after the first comma in 'str';
00573 // returns NULL if no comma is found in 'str'.
00574 inline const char* SkipComma(const char* str) {
00575   const char* comma = strchr(str, ',');
00576   if (comma == NULL) {
00577     return NULL;
00578   }
00579   while (IsSpace(*(++comma))) {}
00580   return comma;
00581 }
00582 
00583 // Returns the prefix of 'str' before the first comma in it; returns
00584 // the entire string if it contains no comma.
00585 inline std::string GetPrefixUntilComma(const char* str) {
00586   const char* comma = strchr(str, ',');
00587   return comma == NULL ? str : std::string(str, comma);
00588 }
00589 
00590 // TypeParameterizedTest<Fixture, TestSel, Types>::Register()
00591 // registers a list of type-parameterized tests with Google Test.  The
00592 // return value is insignificant - we just need to return something
00593 // such that we can call this function in a namespace scope.
00594 //
00595 // Implementation note: The GTEST_TEMPLATE_ macro declares a template
00596 // template parameter.  It's defined in gtest-type-util.h.
00597 template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
00598 class TypeParameterizedTest {
00599  public:
00600   // 'index' is the index of the test in the type list 'Types'
00601   // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
00602   // Types).  Valid values for 'index' are [0, N - 1] where N is the
00603   // length of Types.
00604   static bool Register(const char* prefix, const char* case_name,
00605                        const char* test_names, int index) {
00606     typedef typename Types::Head Type;
00607     typedef Fixture<Type> FixtureClass;
00608     typedef typename GTEST_BIND_(TestSel, Type) TestClass;
00609 
00610     // First, registers the first type-parameterized test in the type
00611     // list.
00612     MakeAndRegisterTestInfo(
00613         (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
00614          + StreamableToString(index)).c_str(),
00615         StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
00616         GetTypeName<Type>().c_str(),
00617         NULL,  // No value parameter.
00618         GetTypeId<FixtureClass>(),
00619         TestClass::SetUpTestCase,
00620         TestClass::TearDownTestCase,
00621         new TestFactoryImpl<TestClass>);
00622 
00623     // Next, recurses (at compile time) with the tail of the type list.
00624     return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
00625         ::Register(prefix, case_name, test_names, index + 1);
00626   }
00627 };
00628 
00629 // The base case for the compile time recursion.
00630 template <GTEST_TEMPLATE_ Fixture, class TestSel>
00631 class TypeParameterizedTest<Fixture, TestSel, Types0> {
00632  public:
00633   static bool Register(const char* /*prefix*/, const char* /*case_name*/,
00634                        const char* /*test_names*/, int /*index*/) {
00635     return true;
00636   }
00637 };
00638 
00639 // TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
00640 // registers *all combinations* of 'Tests' and 'Types' with Google
00641 // Test.  The return value is insignificant - we just need to return
00642 // something such that we can call this function in a namespace scope.
00643 template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
00644 class TypeParameterizedTestCase {
00645  public:
00646   static bool Register(const char* prefix, const char* case_name,
00647                        const char* test_names) {
00648     typedef typename Tests::Head Head;
00649 
00650     // First, register the first test in 'Test' for each type in 'Types'.
00651     TypeParameterizedTest<Fixture, Head, Types>::Register(
00652         prefix, case_name, test_names, 0);
00653 
00654     // Next, recurses (at compile time) with the tail of the test list.
00655     return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
00656         ::Register(prefix, case_name, SkipComma(test_names));
00657   }
00658 };
00659 
00660 // The base case for the compile time recursion.
00661 template <GTEST_TEMPLATE_ Fixture, typename Types>
00662 class TypeParameterizedTestCase<Fixture, Templates0, Types> {
00663  public:
00664   static bool Register(const char* /*prefix*/, const char* /*case_name*/,
00665                        const char* /*test_names*/) {
00666     return true;
00667   }
00668 };
00669 
00670 #endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
00671 
00672 // Returns the current OS stack trace as an std::string.
00673 //
00674 // The maximum number of stack frames to be included is specified by
00675 // the gtest_stack_trace_depth flag.  The skip_count parameter
00676 // specifies the number of top frames to be skipped, which doesn't
00677 // count against the number of frames to be included.
00678 //
00679 // For example, if Foo() calls Bar(), which in turn calls
00680 // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
00681 // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
00682 GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
00683     UnitTest* unit_test, int skip_count);
00684 
00685 // Helpers for suppressing warnings on unreachable code or constant
00686 // condition.
00687 
00688 // Always returns true.
00689 GTEST_API_ bool AlwaysTrue();
00690 
00691 // Always returns false.
00692 inline bool AlwaysFalse() { return !AlwaysTrue(); }
00693 
00694 // Helper for suppressing false warning from Clang on a const char*
00695 // variable declared in a conditional expression always being NULL in
00696 // the else branch.
00697 struct GTEST_API_ ConstCharPtr {
00698   ConstCharPtr(const char* str) : value(str) {}
00699   operator bool() const { return true; }
00700   const char* value;
00701 };
00702 
00703 // A simple Linear Congruential Generator for generating random
00704 // numbers with a uniform distribution.  Unlike rand() and srand(), it
00705 // doesn't use global state (and therefore can't interfere with user
00706 // code).  Unlike rand_r(), it's portable.  An LCG isn't very random,
00707 // but it's good enough for our purposes.
00708 class GTEST_API_ Random {
00709  public:
00710   static const UInt32 kMaxRange = 1u << 31;
00711 
00712   explicit Random(UInt32 seed) : state_(seed) {}
00713 
00714   void Reseed(UInt32 seed) { state_ = seed; }
00715 
00716   // Generates a random number from [0, range).  Crashes if 'range' is
00717   // 0 or greater than kMaxRange.
00718   UInt32 Generate(UInt32 range);
00719 
00720  private:
00721   UInt32 state_;
00722   GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
00723 };
00724 
00725 // Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
00726 // compiler error iff T1 and T2 are different types.
00727 template <typename T1, typename T2>
00728 struct CompileAssertTypesEqual;
00729 
00730 template <typename T>
00731 struct CompileAssertTypesEqual<T, T> {
00732 };
00733 
00734 // Removes the reference from a type if it is a reference type,
00735 // otherwise leaves it unchanged.  This is the same as
00736 // tr1::remove_reference, which is not widely available yet.
00737 template <typename T>
00738 struct RemoveReference { typedef T type; };  // NOLINT
00739 template <typename T>
00740 struct RemoveReference<T&> { typedef T type; };  // NOLINT
00741 
00742 // A handy wrapper around RemoveReference that works when the argument
00743 // T depends on template parameters.
00744 #define GTEST_REMOVE_REFERENCE_(T) \
00745     typename ::testing::internal::RemoveReference<T>::type
00746 
00747 // Removes const from a type if it is a const type, otherwise leaves
00748 // it unchanged.  This is the same as tr1::remove_const, which is not
00749 // widely available yet.
00750 template <typename T>
00751 struct RemoveConst { typedef T type; };  // NOLINT
00752 template <typename T>
00753 struct RemoveConst<const T> { typedef T type; };  // NOLINT
00754 
00755 // MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
00756 // definition to fail to remove the const in 'const int[3]' and 'const
00757 // char[3][4]'.  The following specialization works around the bug.
00758 template <typename T, size_t N>
00759 struct RemoveConst<const T[N]> {
00760   typedef typename RemoveConst<T>::type type[N];
00761 };
00762 
00763 #if defined(_MSC_VER) && _MSC_VER < 1400
00764 // This is the only specialization that allows VC++ 7.1 to remove const in
00765 // 'const int[3] and 'const int[3][4]'.  However, it causes trouble with GCC
00766 // and thus needs to be conditionally compiled.
00767 template <typename T, size_t N>
00768 struct RemoveConst<T[N]> {
00769   typedef typename RemoveConst<T>::type type[N];
00770 };
00771 #endif
00772 
00773 // A handy wrapper around RemoveConst that works when the argument
00774 // T depends on template parameters.
00775 #define GTEST_REMOVE_CONST_(T) \
00776     typename ::testing::internal::RemoveConst<T>::type
00777 
00778 // Turns const U&, U&, const U, and U all into U.
00779 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
00780     GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
00781 
00782 // Adds reference to a type if it is not a reference type,
00783 // otherwise leaves it unchanged.  This is the same as
00784 // tr1::add_reference, which is not widely available yet.
00785 template <typename T>
00786 struct AddReference { typedef T& type; };  // NOLINT
00787 template <typename T>
00788 struct AddReference<T&> { typedef T& type; };  // NOLINT
00789 
00790 // A handy wrapper around AddReference that works when the argument T
00791 // depends on template parameters.
00792 #define GTEST_ADD_REFERENCE_(T) \
00793     typename ::testing::internal::AddReference<T>::type
00794 
00795 // Adds a reference to const on top of T as necessary.  For example,
00796 // it transforms
00797 //
00798 //   char         ==> const char&
00799 //   const char   ==> const char&
00800 //   char&        ==> const char&
00801 //   const char&  ==> const char&
00802 //
00803 // The argument T must depend on some template parameters.
00804 #define GTEST_REFERENCE_TO_CONST_(T) \
00805     GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
00806 
00807 // ImplicitlyConvertible<From, To>::value is a compile-time bool
00808 // constant that's true iff type From can be implicitly converted to
00809 // type To.
00810 template <typename From, typename To>
00811 class ImplicitlyConvertible {
00812  private:
00813   // We need the following helper functions only for their types.
00814   // They have no implementations.
00815 
00816   // MakeFrom() is an expression whose type is From.  We cannot simply
00817   // use From(), as the type From may not have a public default
00818   // constructor.
00819   static typename AddReference<From>::type MakeFrom();
00820 
00821   // These two functions are overloaded.  Given an expression
00822   // Helper(x), the compiler will pick the first version if x can be
00823   // implicitly converted to type To; otherwise it will pick the
00824   // second version.
00825   //
00826   // The first version returns a value of size 1, and the second
00827   // version returns a value of size 2.  Therefore, by checking the
00828   // size of Helper(x), which can be done at compile time, we can tell
00829   // which version of Helper() is used, and hence whether x can be
00830   // implicitly converted to type To.
00831   static char Helper(To);
00832   static char (&Helper(...))[2];  // NOLINT
00833 
00834   // We have to put the 'public' section after the 'private' section,
00835   // or MSVC refuses to compile the code.
00836  public:
00837 #if defined(__BORLANDC__)
00838   // C++Builder cannot use member overload resolution during template
00839   // instantiation.  The simplest workaround is to use its C++0x type traits
00840   // functions (C++Builder 2009 and above only).
00841   static const bool value = __is_convertible(From, To);
00842 #else
00843   // MSVC warns about implicitly converting from double to int for
00844   // possible loss of data, so we need to temporarily disable the
00845   // warning.
00846   GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244)
00847   static const bool value =
00848       sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
00849   GTEST_DISABLE_MSC_WARNINGS_POP_()
00850 #endif  // __BORLANDC__
00851 };
00852 template <typename From, typename To>
00853 const bool ImplicitlyConvertible<From, To>::value;
00854 
00855 // IsAProtocolMessage<T>::value is a compile-time bool constant that's
00856 // true iff T is type ProtocolMessage, proto2::Message, or a subclass
00857 // of those.
00858 template <typename T>
00859 struct IsAProtocolMessage
00860     : public bool_constant<
00861   ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
00862   ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
00863 };
00864 
00865 // When the compiler sees expression IsContainerTest<C>(0), if C is an
00866 // STL-style container class, the first overload of IsContainerTest
00867 // will be viable (since both C::iterator* and C::const_iterator* are
00868 // valid types and NULL can be implicitly converted to them).  It will
00869 // be picked over the second overload as 'int' is a perfect match for
00870 // the type of argument 0.  If C::iterator or C::const_iterator is not
00871 // a valid type, the first overload is not viable, and the second
00872 // overload will be picked.  Therefore, we can determine whether C is
00873 // a container class by checking the type of IsContainerTest<C>(0).
00874 // The value of the expression is insignificant.
00875 //
00876 // Note that we look for both C::iterator and C::const_iterator.  The
00877 // reason is that C++ injects the name of a class as a member of the
00878 // class itself (e.g. you can refer to class iterator as either
00879 // 'iterator' or 'iterator::iterator').  If we look for C::iterator
00880 // only, for example, we would mistakenly think that a class named
00881 // iterator is an STL container.
00882 //
00883 // Also note that the simpler approach of overloading
00884 // IsContainerTest(typename C::const_iterator*) and
00885 // IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
00886 typedef int IsContainer;
00887 template <class C>
00888 IsContainer IsContainerTest(int /* dummy */,
00889                             typename C::iterator* /* it */ = NULL,
00890                             typename C::const_iterator* /* const_it */ = NULL) {
00891   return 0;
00892 }
00893 
00894 typedef char IsNotContainer;
00895 template <class C>
00896 IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
00897 
00898 // EnableIf<condition>::type is void when 'Cond' is true, and
00899 // undefined when 'Cond' is false.  To use SFINAE to make a function
00900 // overload only apply when a particular expression is true, add
00901 // "typename EnableIf<expression>::type* = 0" as the last parameter.
00902 template<bool> struct EnableIf;
00903 template<> struct EnableIf<true> { typedef void type; };  // NOLINT
00904 
00905 // Utilities for native arrays.
00906 
00907 // ArrayEq() compares two k-dimensional native arrays using the
00908 // elements' operator==, where k can be any integer >= 0.  When k is
00909 // 0, ArrayEq() degenerates into comparing a single pair of values.
00910 
00911 template <typename T, typename U>
00912 bool ArrayEq(const T* lhs, size_t size, const U* rhs);
00913 
00914 // This generic version is used when k is 0.
00915 template <typename T, typename U>
00916 inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
00917 
00918 // This overload is used when k >= 1.
00919 template <typename T, typename U, size_t N>
00920 inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
00921   return internal::ArrayEq(lhs, N, rhs);
00922 }
00923 
00924 // This helper reduces code bloat.  If we instead put its logic inside
00925 // the previous ArrayEq() function, arrays with different sizes would
00926 // lead to different copies of the template code.
00927 template <typename T, typename U>
00928 bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
00929   for (size_t i = 0; i != size; i++) {
00930     if (!internal::ArrayEq(lhs[i], rhs[i]))
00931       return false;
00932   }
00933   return true;
00934 }
00935 
00936 // Finds the first element in the iterator range [begin, end) that
00937 // equals elem.  Element may be a native array type itself.
00938 template <typename Iter, typename Element>
00939 Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
00940   for (Iter it = begin; it != end; ++it) {
00941     if (internal::ArrayEq(*it, elem))
00942       return it;
00943   }
00944   return end;
00945 }
00946 
00947 // CopyArray() copies a k-dimensional native array using the elements'
00948 // operator=, where k can be any integer >= 0.  When k is 0,
00949 // CopyArray() degenerates into copying a single value.
00950 
00951 template <typename T, typename U>
00952 void CopyArray(const T* from, size_t size, U* to);
00953 
00954 // This generic version is used when k is 0.
00955 template <typename T, typename U>
00956 inline void CopyArray(const T& from, U* to) { *to = from; }
00957 
00958 // This overload is used when k >= 1.
00959 template <typename T, typename U, size_t N>
00960 inline void CopyArray(const T(&from)[N], U(*to)[N]) {
00961   internal::CopyArray(from, N, *to);
00962 }
00963 
00964 // This helper reduces code bloat.  If we instead put its logic inside
00965 // the previous CopyArray() function, arrays with different sizes
00966 // would lead to different copies of the template code.
00967 template <typename T, typename U>
00968 void CopyArray(const T* from, size_t size, U* to) {
00969   for (size_t i = 0; i != size; i++) {
00970     internal::CopyArray(from[i], to + i);
00971   }
00972 }
00973 
00974 // The relation between an NativeArray object (see below) and the
00975 // native array it represents.
00976 // We use 2 different structs to allow non-copyable types to be used, as long
00977 // as RelationToSourceReference() is passed.
00978 struct RelationToSourceReference {};
00979 struct RelationToSourceCopy {};
00980 
00981 // Adapts a native array to a read-only STL-style container.  Instead
00982 // of the complete STL container concept, this adaptor only implements
00983 // members useful for Google Mock's container matchers.  New members
00984 // should be added as needed.  To simplify the implementation, we only
00985 // support Element being a raw type (i.e. having no top-level const or
00986 // reference modifier).  It's the client's responsibility to satisfy
00987 // this requirement.  Element can be an array type itself (hence
00988 // multi-dimensional arrays are supported).
00989 template <typename Element>
00990 class NativeArray {
00991  public:
00992   // STL-style container typedefs.
00993   typedef Element value_type;
00994   typedef Element* iterator;
00995   typedef const Element* const_iterator;
00996 
00997   // Constructs from a native array. References the source.
00998   NativeArray(const Element* array, size_t count, RelationToSourceReference) {
00999     InitRef(array, count);
01000   }
01001 
01002   // Constructs from a native array. Copies the source.
01003   NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
01004     InitCopy(array, count);
01005   }
01006 
01007   // Copy constructor.
01008   NativeArray(const NativeArray& rhs) {
01009     (this->*rhs.clone_)(rhs.array_, rhs.size_);
01010   }
01011 
01012   ~NativeArray() {
01013     if (clone_ != &NativeArray::InitRef)
01014       delete[] array_;
01015   }
01016 
01017   // STL-style container methods.
01018   size_t size() const { return size_; }
01019   const_iterator begin() const { return array_; }
01020   const_iterator end() const { return array_ + size_; }
01021   bool operator==(const NativeArray& rhs) const {
01022     return size() == rhs.size() &&
01023         ArrayEq(begin(), size(), rhs.begin());
01024   }
01025 
01026  private:
01027   enum {
01028     kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
01029         Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value,
01030   };
01031 
01032   // Initializes this object with a copy of the input.
01033   void InitCopy(const Element* array, size_t a_size) {
01034     Element* const copy = new Element[a_size];
01035     CopyArray(array, a_size, copy);
01036     array_ = copy;
01037     size_ = a_size;
01038     clone_ = &NativeArray::InitCopy;
01039   }
01040 
01041   // Initializes this object with a reference of the input.
01042   void InitRef(const Element* array, size_t a_size) {
01043     array_ = array;
01044     size_ = a_size;
01045     clone_ = &NativeArray::InitRef;
01046   }
01047 
01048   const Element* array_;
01049   size_t size_;
01050   void (NativeArray::*clone_)(const Element*, size_t);
01051 
01052   GTEST_DISALLOW_ASSIGN_(NativeArray);
01053 };
01054 
01055 }  // namespace internal
01056 }  // namespace testing
01057 
01058 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
01059   ::testing::internal::AssertHelper(result_type, file, line, message) \
01060     = ::testing::Message()
01061 
01062 #define GTEST_MESSAGE_(message, result_type) \
01063   GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
01064 
01065 #define GTEST_FATAL_FAILURE_(message) \
01066   return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
01067 
01068 #define GTEST_NONFATAL_FAILURE_(message) \
01069   GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
01070 
01071 #define GTEST_SUCCESS_(message) \
01072   GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
01073 
01074 // Suppresses MSVC warnings 4072 (unreachable code) for the code following
01075 // statement if it returns or throws (or doesn't return or throw in some
01076 // situations).
01077 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
01078   if (::testing::internal::AlwaysTrue()) { statement; }
01079 
01080 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
01081   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01082   if (::testing::internal::ConstCharPtr gtest_msg = "") { \
01083     bool gtest_caught_expected = false; \
01084     try { \
01085       GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01086     } \
01087     catch (expected_exception const&) { \
01088       gtest_caught_expected = true; \
01089     } \
01090     catch (...) { \
01091       gtest_msg.value = \
01092           "Expected: " #statement " throws an exception of type " \
01093           #expected_exception ".\n  Actual: it throws a different type."; \
01094       goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
01095     } \
01096     if (!gtest_caught_expected) { \
01097       gtest_msg.value = \
01098           "Expected: " #statement " throws an exception of type " \
01099           #expected_exception ".\n  Actual: it throws nothing."; \
01100       goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
01101     } \
01102   } else \
01103     GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
01104       fail(gtest_msg.value)
01105 
01106 #define GTEST_TEST_NO_THROW_(statement, fail) \
01107   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01108   if (::testing::internal::AlwaysTrue()) { \
01109     try { \
01110       GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01111     } \
01112     catch (...) { \
01113       goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
01114     } \
01115   } else \
01116     GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
01117       fail("Expected: " #statement " doesn't throw an exception.\n" \
01118            "  Actual: it throws.")
01119 
01120 #define GTEST_TEST_ANY_THROW_(statement, fail) \
01121   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01122   if (::testing::internal::AlwaysTrue()) { \
01123     bool gtest_caught_any = false; \
01124     try { \
01125       GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01126     } \
01127     catch (...) { \
01128       gtest_caught_any = true; \
01129     } \
01130     if (!gtest_caught_any) { \
01131       goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
01132     } \
01133   } else \
01134     GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
01135       fail("Expected: " #statement " throws an exception.\n" \
01136            "  Actual: it doesn't.")
01137 
01138 
01139 // Implements Boolean test assertions such as EXPECT_TRUE. expression can be
01140 // either a boolean expression or an AssertionResult. text is a textual
01141 // represenation of expression as it was passed into the EXPECT_TRUE.
01142 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
01143   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01144   if (const ::testing::AssertionResult gtest_ar_ = \
01145       ::testing::AssertionResult(expression)) \
01146     ; \
01147   else \
01148     fail(::testing::internal::GetBoolAssertionFailureMessage(\
01149         gtest_ar_, text, #actual, #expected).c_str())
01150 
01151 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
01152   GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
01153   if (::testing::internal::AlwaysTrue()) { \
01154     ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
01155     GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
01156     if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
01157       goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
01158     } \
01159   } else \
01160     GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
01161       fail("Expected: " #statement " doesn't generate new fatal " \
01162            "failures in the current thread.\n" \
01163            "  Actual: it does.")
01164 
01165 // Expands to the name of the class that implements the given test.
01166 #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
01167   test_case_name##_##test_name##_Test
01168 
01169 // Helper macro for defining tests.
01170 #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
01171 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
01172  public:\
01173   GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
01174  private:\
01175   virtual void TestBody();\
01176   static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
01177   GTEST_DISALLOW_COPY_AND_ASSIGN_(\
01178       GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
01179 };\
01180 \
01181 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
01182   ::test_info_ =\
01183     ::testing::internal::MakeAndRegisterTestInfo(\
01184         #test_case_name, #test_name, NULL, NULL, \
01185         (parent_id), \
01186         parent_class::SetUpTestCase, \
01187         parent_class::TearDownTestCase, \
01188         new ::testing::internal::TestFactoryImpl<\
01189             GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
01190 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
01191 
01192 #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
01193 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:03