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


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:24:39