From d201456903f3ecae1f7794edfab0d5678e642265 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 3 Jul 2008 22:38:12 +0000 Subject: Initial import. --- include/gtest/internal/gtest-internal.h | 569 ++++++++++++++++++++++++++++++++ 1 file changed, 569 insertions(+) create mode 100644 include/gtest/internal/gtest-internal.h (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h new file mode 100644 index 00000000..2be1b4ac --- /dev/null +++ b/include/gtest/internal/gtest-internal.h @@ -0,0 +1,569 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file declares functions and macros used internally by +// Google Test. They are subject to change without notice. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ + +#if defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) +// When using Google Test on the Mac as a framework, all the includes will be +// in the framework headers folder along with gtest.h. +// Define GTEST_NOT_MAC_FRAMEWORK_MODE if you are building Google Test on +// the Mac and are not using it as a framework. +// More info on frameworks available here: +// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/ +// Concepts/WhatAreFrameworks.html. +#include "gtest-port.h" // NOLINT +#else +#include +#endif // defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) + +#ifdef GTEST_OS_LINUX +#include +#include +#include +#include +#endif // GTEST_OS_LINUX + +#include // NOLINT +#include // NOLINT + +#if defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) +// When using Google Test on the Mac as a framework, all the includes will be +// in the framework headers folder along with gtest.h. +// Define GTEST_NOT_MAC_FRAMEWORK_MODE if you are building Google Test on +// the Mac and are not using it as a framework. +// More info on frameworks available here: +// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/ +// Concepts/WhatAreFrameworks.html. +#include "gtest-string.h" // NOLINT +#include "gtest-filepath.h" // NOLINT +#else +#include +#include +#endif // defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) + +// Due to C++ preprocessor weirdness, we need double indirection to +// concatenate two tokens when one of them is __LINE__. Writing +// +// foo ## __LINE__ +// +// will result in the token foo__LINE__, instead of foo followed by +// the current line number. For more details, see +// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +#define GTEST_CONCAT_TOKEN(foo, bar) GTEST_CONCAT_TOKEN_IMPL(foo, bar) +#define GTEST_CONCAT_TOKEN_IMPL(foo, bar) foo ## bar + +// Google Test defines the testing::Message class to allow construction of +// test messages via the << operator. The idea is that anything +// streamable to std::ostream can be streamed to a testing::Message. +// This allows a user to use his own types in Google Test assertions by +// overloading the << operator. +// +// util/gtl/stl_logging-inl.h overloads << for STL containers. These +// overloads cannot be defined in the std namespace, as that will be +// undefined behavior. Therefore, they are defined in the global +// namespace instead. +// +// C++'s symbol lookup rule (i.e. Koenig lookup) says that these +// overloads are visible in either the std namespace or the global +// namespace, but not other namespaces, including the testing +// namespace which Google Test's Message class is in. +// +// To allow STL containers (and other types that has a << operator +// defined in the global namespace) to be used in Google Test assertions, +// testing::Message must access the custom << operator from the global +// namespace. Hence this helper function. +// +// Note: Jeffrey Yasskin suggested an alternative fix by "using +// ::operator<<;" in the definition of Message's operator<<. That fix +// doesn't require a helper function, but unfortunately doesn't +// compile with MSVC. +template +inline void GTestStreamToHelper(std::ostream* os, const T& val) { + *os << val; +} + +namespace testing { + +// Forward declaration of classes. + +class Message; // Represents a failure message. +class TestCase; // A collection of related tests. +class TestPartResult; // Result of a test part. +class TestInfo; // Information about a test. +class UnitTest; // A collection of test cases. +class UnitTestEventListenerInterface; // Listens to Google Test events. +class AssertionResult; // Result of an assertion. + +namespace internal { + +struct TraceInfo; // Information about a trace point. +class ScopedTrace; // Implements scoped trace. +class TestInfoImpl; // Opaque implementation of TestInfo +class TestResult; // Result of a single Test. +class UnitTestImpl; // Opaque implementation of UnitTest + +template class List; // A generic list. +template class ListNode; // A node in a generic list. + +// A secret type that Google Test users don't know about. It has no +// definition on purpose. Therefore it's impossible to create a +// Secret object, which is what we want. +class Secret; + +// Two overloaded helpers for checking at compile time whether an +// expression is a null pointer literal (i.e. NULL or any 0-valued +// compile-time integral constant). Their return values have +// different sizes, so we can use sizeof() to test which version is +// picked by the compiler. These helpers have no implementations, as +// we only need their signatures. +// +// Given IsNullLiteralHelper(x), the compiler will pick the first +// version if x can be implicitly converted to Secret*, and pick the +// second version otherwise. Since Secret is a secret and incomplete +// type, the only expression a user can write that has type Secret* is +// a null pointer literal. Therefore, we know that x is a null +// pointer literal if and only if the first version is picked by the +// compiler. +char IsNullLiteralHelper(Secret* p); +char (&IsNullLiteralHelper(...))[2]; // NOLINT + +// A compile-time bool constant that is true if and only if x is a +// null pointer literal (i.e. NULL or any 0-valued compile-time +// integral constant). +#ifdef __SYMBIAN32__ // Symbian +// Passing non-POD classes through ellipsis (...) crashes the ARM compiler. +// The Nokia Symbian compiler tries to instantiate a copy constructor for +// objects passed through ellipsis (...), failing for uncopyable objects. +// Hence we define this to false (and lose support for NULL detection). +#define GTEST_IS_NULL_LITERAL(x) false +#else // ! __SYMBIAN32__ +#define GTEST_IS_NULL_LITERAL(x) \ + (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) +#endif // __SYMBIAN32__ + +// Appends the user-supplied message to the Google-Test-generated message. +String AppendUserMessage(const String& gtest_msg, + const Message& user_msg); + +// A helper class for creating scoped traces in user programs. +class ScopedTrace { + public: + // The c'tor pushes the given source file location and message onto + // a trace stack maintained by Google Test. + ScopedTrace(const char* file, int line, const Message& message); + + // The d'tor pops the info pushed by the c'tor. + // + // Note that the d'tor is not virtual in order to be efficient. + // Don't inherit from ScopedTrace! + ~ScopedTrace(); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN(ScopedTrace); +} GTEST_ATTRIBUTE_UNUSED; // A ScopedTrace object does its job in its + // c'tor and d'tor. Therefore it doesn't + // need to be used otherwise. + +// Converts a streamable value to a String. A NULL pointer is +// converted to "(null)". When the input value is a ::string, +// ::std::string, ::wstring, or ::std::wstring object, each NUL +// character in it is replaced with "\\0". +// Declared here but defined in gtest.h, so that it has access +// to the definition of the Message class, required by the ARM +// compiler. +template +String StreamableToString(const T& streamable); + +// Formats a value to be used in a failure message. + +#ifdef __SYMBIAN32__ + +// These are needed as the Nokia Symbian Compiler cannot decide between +// const T& and const T* in a function template. The Nokia compiler _can_ +// decide between class template specializations for T and T*, so a +// tr1::type_traits-like is_pointer works, and we can overload on that. + +// This overload makes sure that all pointers (including +// those to char or wchar_t) are printed as raw pointers. +template +inline String FormatValueForFailureMessage(internal::true_type dummy, + T* pointer) { + return StreamableToString(static_cast(pointer)); +} + +template +inline String FormatValueForFailureMessage(internal::false_type dummy, + const T& value) { + return StreamableToString(value); +} + +template +inline String FormatForFailureMessage(const T& value) { + return FormatValueForFailureMessage( + typename internal::is_pointer::type(), value); +} + +#else + +template +inline String FormatForFailureMessage(const T& value) { + return StreamableToString(value); +} + +// This overload makes sure that all pointers (including +// those to char or wchar_t) are printed as raw pointers. +template +inline String FormatForFailureMessage(T* pointer) { + return StreamableToString(static_cast(pointer)); +} + +#endif // __SYMBIAN32__ + +// These overloaded versions handle narrow and wide characters. +String FormatForFailureMessage(char ch); +String FormatForFailureMessage(wchar_t wchar); + +// When this operand is a const char* or char*, and the other operand +// is a ::std::string or ::string, we print this operand as a C string +// rather than a pointer. We do the same for wide strings. + +// This internal macro is used to avoid duplicated code. +#define GTEST_FORMAT_IMPL(operand2_type, operand1_printer)\ +inline String FormatForComparisonFailureMessage(\ + operand2_type::value_type* str, const operand2_type& operand2) {\ + return operand1_printer(str);\ +}\ +inline String FormatForComparisonFailureMessage(\ + const operand2_type::value_type* str, const operand2_type& operand2) {\ + return operand1_printer(str);\ +} + +#if GTEST_HAS_STD_STRING +GTEST_FORMAT_IMPL(::std::string, String::ShowCStringQuoted) +#endif // GTEST_HAS_STD_STRING +#if GTEST_HAS_STD_WSTRING +GTEST_FORMAT_IMPL(::std::wstring, String::ShowWideCStringQuoted) +#endif // GTEST_HAS_STD_WSTRING + +#if GTEST_HAS_GLOBAL_STRING +GTEST_FORMAT_IMPL(::string, String::ShowCStringQuoted) +#endif // GTEST_HAS_GLOBAL_STRING +#if GTEST_HAS_GLOBAL_WSTRING +GTEST_FORMAT_IMPL(::wstring, String::ShowWideCStringQuoted) +#endif // GTEST_HAS_GLOBAL_WSTRING + +#undef GTEST_FORMAT_IMPL + +// Constructs and returns the message for an equality assertion +// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. +// +// The first four parameters are the expressions used in the assertion +// and their values, as strings. For example, for ASSERT_EQ(foo, bar) +// where foo is 5 and bar is 6, we have: +// +// expected_expression: "foo" +// actual_expression: "bar" +// expected_value: "5" +// actual_value: "6" +// +// The ignoring_case parameter is true iff the assertion is a +// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will +// be inserted into the message. +AssertionResult EqFailure(const char* expected_expression, + const char* actual_expression, + const String& expected_value, + const String& actual_value, + bool ignoring_case); + + +// This template class represents an IEEE floating-point number +// (either single-precision or double-precision, depending on the +// template parameters). +// +// The purpose of this class is to do more sophisticated number +// comparison. (Due to round-off error, etc, it's very unlikely that +// two floating-points will be equal exactly. Hence a naive +// comparison by the == operation often doesn't work.) +// +// Format of IEEE floating-point: +// +// The most-significant bit being the leftmost, an IEEE +// floating-point looks like +// +// sign_bit exponent_bits fraction_bits +// +// Here, sign_bit is a single bit that designates the sign of the +// number. +// +// For float, there are 8 exponent bits and 23 fraction bits. +// +// For double, there are 11 exponent bits and 52 fraction bits. +// +// More details can be found at +// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. +// +// Template parameter: +// +// RawType: the raw floating-point type (either float or double) +template +class FloatingPoint { + public: + // Defines the unsigned integer type that has the same size as the + // floating point number. + typedef typename TypeWithSize::UInt Bits; + + // Constants. + + // # of bits in a number. + static const size_t kBitCount = 8*sizeof(RawType); + + // # of fraction bits in a number. + static const size_t kFractionBitCount = + std::numeric_limits::digits - 1; + + // # of exponent bits in a number. + static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; + + // The mask for the sign bit. + static const Bits kSignBitMask = static_cast(1) << (kBitCount - 1); + + // The mask for the fraction bits. + static const Bits kFractionBitMask = + ~static_cast(0) >> (kExponentBitCount + 1); + + // The mask for the exponent bits. + static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); + + // How many ULP's (Units in the Last Place) we want to tolerate when + // comparing two numbers. The larger the value, the more error we + // allow. A 0 value means that two numbers must be exactly the same + // to be considered equal. + // + // The maximum error of a single floating-point operation is 0.5 + // units in the last place. On Intel CPU's, all floating-point + // calculations are done with 80-bit precision, while double has 64 + // bits. Therefore, 4 should be enough for ordinary use. + // + // See the following article for more details on ULP: + // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm. + static const size_t kMaxUlps = 4; + + // Constructs a FloatingPoint from a raw floating-point number. + // + // On an Intel CPU, passing a non-normalized NAN (Not a Number) + // around may change its bits, although the new value is guaranteed + // to be also a NAN. Therefore, don't expect this constructor to + // preserve the bits in x when x is a NAN. + explicit FloatingPoint(const RawType& x) : value_(x) {} + + // Static methods + + // Reinterprets a bit pattern as a floating-point number. + // + // This function is needed to test the AlmostEquals() method. + static RawType ReinterpretBits(const Bits bits) { + FloatingPoint fp(0); + fp.bits_ = bits; + return fp.value_; + } + + // Returns the floating-point number that represent positive infinity. + static RawType Infinity() { + return ReinterpretBits(kExponentBitMask); + } + + // Non-static methods + + // Returns the bits that represents this number. + const Bits &bits() const { return bits_; } + + // Returns the exponent bits of this number. + Bits exponent_bits() const { return kExponentBitMask & bits_; } + + // Returns the fraction bits of this number. + Bits fraction_bits() const { return kFractionBitMask & bits_; } + + // Returns the sign bit of this number. + Bits sign_bit() const { return kSignBitMask & bits_; } + + // Returns true iff this is NAN (not a number). + bool is_nan() const { + // It's a NAN if the exponent bits are all ones and the fraction + // bits are not entirely zeros. + return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0); + } + + // Returns true iff this number is at most kMaxUlps ULP's away from + // rhs. In particular, this function: + // + // - returns false if either number is (or both are) NAN. + // - treats really large numbers as almost equal to infinity. + // - thinks +0.0 and -0.0 are 0 DLP's apart. + bool AlmostEquals(const FloatingPoint& rhs) const { + // The IEEE standard says that any comparison operation involving + // a NAN must return false. + if (is_nan() || rhs.is_nan()) return false; + + return DistanceBetweenSignAndMagnitudeNumbers(bits_, rhs.bits_) <= kMaxUlps; + } + + private: + // Converts an integer from the sign-and-magnitude representation to + // the biased representation. More precisely, let N be 2 to the + // power of (kBitCount - 1), an integer x is represented by the + // unsigned number x + N. + // + // For instance, + // + // -N + 1 (the most negative number representable using + // sign-and-magnitude) is represented by 1; + // 0 is represented by N; and + // N - 1 (the biggest number representable using + // sign-and-magnitude) is represented by 2N - 1. + // + // Read http://en.wikipedia.org/wiki/Signed_number_representations + // for more details on signed number representations. + static Bits SignAndMagnitudeToBiased(const Bits &sam) { + if (kSignBitMask & sam) { + // sam represents a negative number. + return ~sam + 1; + } else { + // sam represents a positive number. + return kSignBitMask | sam; + } + } + + // Given two numbers in the sign-and-magnitude representation, + // returns the distance between them as an unsigned number. + static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, + const Bits &sam2) { + const Bits biased1 = SignAndMagnitudeToBiased(sam1); + const Bits biased2 = SignAndMagnitudeToBiased(sam2); + return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); + } + + union { + RawType value_; // The raw floating-point number. + Bits bits_; // The bits that represent the number. + }; +}; + +// Typedefs the instances of the FloatingPoint template class that we +// care to use. +typedef FloatingPoint Float; +typedef FloatingPoint Double; + +// In order to catch the mistake of putting tests that use different +// test fixture classes in the same test case, we need to assign +// unique IDs to fixture classes and compare them. The TypeId type is +// used to hold such IDs. The user should treat TypeId as an opaque +// type: the only operation allowed on TypeId values is to compare +// them for equality using the == operator. +typedef void* TypeId; + +// GetTypeId() returns the ID of type T. Different values will be +// returned for different types. Calling the function twice with the +// same type argument is guaranteed to return the same ID. +template +inline TypeId GetTypeId() { + static bool dummy = false; + // The compiler is required to create an instance of the static + // variable dummy for each T used to instantiate the template. + // Therefore, the address of dummy is guaranteed to be unique. + return &dummy; +} + +#ifdef GTEST_OS_WINDOWS + +// Predicate-formatters for implementing the HRESULT checking macros +// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} +// We pass a long instead of HRESULT to avoid causing an +// include dependency for the HRESULT type. +AssertionResult IsHRESULTSuccess(const char* expr, long hr); // NOLINT +AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT + +#endif // GTEST_OS_WINDOWS + +} // namespace internal +} // namespace testing + +#define GTEST_MESSAGE(message, result_type) \ + ::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, message) \ + = ::testing::Message() + +#define GTEST_FATAL_FAILURE(message) \ + return GTEST_MESSAGE(message, ::testing::TPRT_FATAL_FAILURE) + +#define GTEST_NONFATAL_FAILURE(message) \ + GTEST_MESSAGE(message, ::testing::TPRT_NONFATAL_FAILURE) + +#define GTEST_SUCCESS(message) \ + GTEST_MESSAGE(message, ::testing::TPRT_SUCCESS) + +#define GTEST_TEST_BOOLEAN(boolexpr, booltext, actual, expected, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER \ + if (boolexpr) \ + ; \ + else \ + fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) + +// Helper macro for defining tests. +#define GTEST_TEST(test_case_name, test_name, parent_class)\ +class test_case_name##_##test_name##_Test : public parent_class {\ + public:\ + test_case_name##_##test_name##_Test() {}\ + static ::testing::Test* NewTest() {\ + return new test_case_name##_##test_name##_Test;\ + }\ + private:\ + virtual void TestBody();\ + static ::testing::TestInfo* const test_info_;\ + GTEST_DISALLOW_COPY_AND_ASSIGN(test_case_name##_##test_name##_Test);\ +};\ +\ +::testing::TestInfo* const test_case_name##_##test_name##_Test::test_info_ =\ + ::testing::TestInfo::MakeAndRegisterInstance(\ + #test_case_name, \ + #test_name, \ + ::testing::internal::GetTypeId< parent_class >(), \ + parent_class::SetUpTestCase, \ + parent_class::TearDownTestCase, \ + test_case_name##_##test_name##_Test::NewTest);\ +void test_case_name##_##test_name##_Test::TestBody() + + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ -- cgit v1.2.3 From e4e9a8bd7d2dbbad62030c8f80513e3c81b32213 Mon Sep 17 00:00:00 2001 From: shiqian Date: Tue, 8 Jul 2008 21:32:17 +0000 Subject: Makes the autotools scripts work on Mac OS X. Also hopefully makes gtest compile on Windows CE. --- include/gtest/internal/gtest-internal.h | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 2be1b4ac..0054bae3 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -37,18 +37,7 @@ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ -#if defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) -// When using Google Test on the Mac as a framework, all the includes will be -// in the framework headers folder along with gtest.h. -// Define GTEST_NOT_MAC_FRAMEWORK_MODE if you are building Google Test on -// the Mac and are not using it as a framework. -// More info on frameworks available here: -// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/ -// Concepts/WhatAreFrameworks.html. -#include "gtest-port.h" // NOLINT -#else #include -#endif // defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) #ifdef GTEST_OS_LINUX #include @@ -60,20 +49,8 @@ #include // NOLINT #include // NOLINT -#if defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) -// When using Google Test on the Mac as a framework, all the includes will be -// in the framework headers folder along with gtest.h. -// Define GTEST_NOT_MAC_FRAMEWORK_MODE if you are building Google Test on -// the Mac and are not using it as a framework. -// More info on frameworks available here: -// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/ -// Concepts/WhatAreFrameworks.html. -#include "gtest-string.h" // NOLINT -#include "gtest-filepath.h" // NOLINT -#else #include #include -#endif // defined(__APPLE__) && !defined(GTEST_NOT_MAC_FRAMEWORK_MODE) // Due to C++ preprocessor weirdness, we need double indirection to // concatenate two tokens when one of them is __LINE__. Writing -- cgit v1.2.3 From b75872639683cf572253f20863982324b113205e Mon Sep 17 00:00:00 2001 From: shiqian Date: Wed, 23 Jul 2008 20:28:27 +0000 Subject: Fixes some style nits; also fixes minor bugs in gtest-death-test.cc. --- include/gtest/internal/gtest-internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 0054bae3..2eefc7bf 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -241,11 +241,11 @@ String FormatForFailureMessage(wchar_t wchar); // This internal macro is used to avoid duplicated code. #define GTEST_FORMAT_IMPL(operand2_type, operand1_printer)\ inline String FormatForComparisonFailureMessage(\ - operand2_type::value_type* str, const operand2_type& operand2) {\ + operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ }\ inline String FormatForComparisonFailureMessage(\ - const operand2_type::value_type* str, const operand2_type& operand2) {\ + const operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ } -- cgit v1.2.3 From d5f13d4a257b6bfc43068f3a918989cf89af75ec Mon Sep 17 00:00:00 2001 From: shiqian Date: Wed, 6 Aug 2008 21:44:19 +0000 Subject: Changes test creation functions to factories. By Vlad Losev. --- include/gtest/internal/gtest-internal.h | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 2eefc7bf..dc6154b6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -98,6 +98,7 @@ namespace testing { // Forward declaration of classes. class Message; // Represents a failure message. +class Test; // Represents a test. class TestCase; // A collection of related tests. class TestPartResult; // Result of a test part. class TestInfo; // Information about a test. @@ -484,6 +485,31 @@ inline TypeId GetTypeId() { return &dummy; } +// Defines the abstract factory interface that creates instances +// of a Test object. +class TestFactoryBase { + public: + virtual ~TestFactoryBase() {} + + // Creates a test instance to run. The instance is both created and destroyed + // within TestInfoImpl::Run() + virtual Test* CreateTest() = 0; + + protected: + TestFactoryBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN(TestFactoryBase); +}; + +// This class provides implementation of TeastFactoryBase interface. +// It is used in TEST and TEST_F macros. +template +class TestFactoryImpl : public TestFactoryBase { + public: + virtual Test* CreateTest() { return new TestClass; } +}; + #ifdef GTEST_OS_WINDOWS // Predicate-formatters for implementing the HRESULT checking macros @@ -523,9 +549,6 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT class test_case_name##_##test_name##_Test : public parent_class {\ public:\ test_case_name##_##test_name##_Test() {}\ - static ::testing::Test* NewTest() {\ - return new test_case_name##_##test_name##_Test;\ - }\ private:\ virtual void TestBody();\ static ::testing::TestInfo* const test_info_;\ @@ -533,13 +556,14 @@ class test_case_name##_##test_name##_Test : public parent_class {\ };\ \ ::testing::TestInfo* const test_case_name##_##test_name##_Test::test_info_ =\ - ::testing::TestInfo::MakeAndRegisterInstance(\ - #test_case_name, \ - #test_name, \ - ::testing::internal::GetTypeId< parent_class >(), \ - parent_class::SetUpTestCase, \ - parent_class::TearDownTestCase, \ - test_case_name##_##test_name##_Test::NewTest);\ + ::testing::TestInfo::MakeAndRegisterInstance(\ + #test_case_name, \ + #test_name, \ + ::testing::internal::GetTypeId< parent_class >(), \ + parent_class::SetUpTestCase, \ + parent_class::TearDownTestCase, \ + new ::testing::internal::TestFactoryImpl<\ + test_case_name##_##test_name##_Test>);\ void test_case_name##_##test_name##_Test::TestBody() -- cgit v1.2.3 From a2b1a8556ea64014606d78b09333d9c522430a25 Mon Sep 17 00:00:00 2001 From: shiqian Date: Mon, 8 Sep 2008 17:55:52 +0000 Subject: Adds support for type-parameterized tests (by Zhanyong Wan); also adds case-insensitive wide string comparison to the String class (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 207 ++++++++++++++++++++++++++++++-- 1 file changed, 196 insertions(+), 11 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index dc6154b6..8adf13e4 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -46,11 +46,15 @@ #include #endif // GTEST_OS_LINUX -#include // NOLINT -#include // NOLINT +#include +#include +#include +#include +#include #include #include +#include // Due to C++ preprocessor weirdness, we need double indirection to // concatenate two tokens when one of them is __LINE__. Writing @@ -521,6 +525,182 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT #endif // GTEST_OS_WINDOWS +// Formats a source file path and a line number as they would appear +// in a compiler error message. +inline String FormatFileLocation(const char* file, int line) { + const char* const file_name = file == NULL ? "unknown file" : file; + if (line < 0) { + return String::Format("%s:", file_name); + } +#ifdef _MSC_VER + return String::Format("%s(%d):", file_name, line); +#else + return String::Format("%s:%d:", file_name, line); +#endif // _MSC_VER +} + +// Types of SetUpTestCase() and TearDownTestCase() functions. +typedef void (*SetUpTestCaseFunc)(); +typedef void (*TearDownTestCaseFunc)(); + +// Creates a new TestInfo object and registers it with Google Test; +// returns the created object. +// +// Arguments: +// +// test_case_name: name of the test case +// name: name of the test +// test_case_comment: a comment on the test case that will be included in +// the test output +// comment: a comment on the test that will be included in the +// test output +// fixture_class_id: ID of the test fixture class +// set_up_tc: pointer to the function that sets up the test case +// tear_down_tc: pointer to the function that tears down the test case +// factory: pointer to the factory that creates a test object. +// The newly created TestInfo instance will assume +// ownership of the factory object. +TestInfo* MakeAndRegisterTestInfo( + const char* test_case_name, const char* name, + const char* test_case_comment, const char* comment, + TypeId fixture_class_id, + SetUpTestCaseFunc set_up_tc, + TearDownTestCaseFunc tear_down_tc, + TestFactoryBase* factory); + +#if defined(GTEST_HAS_TYPED_TEST) || defined(GTEST_HAS_TYPED_TEST_P) + +// State of the definition of a type-parameterized test case. +class TypedTestCasePState { + public: + TypedTestCasePState() : registered_(false) {} + + // Adds the given test name to defined_test_names_ and return true + // if the test case hasn't been registered; otherwise aborts the + // program. + bool AddTestName(const char* file, int line, const char* case_name, + const char* test_name) { + if (registered_) { + fprintf(stderr, "%s Test %s must be defined before " + "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", + FormatFileLocation(file, line).c_str(), test_name, case_name); + abort(); + } + defined_test_names_.insert(test_name); + return true; + } + + // Verifies that registered_tests match the test names in + // defined_test_names_; returns registered_tests if successful, or + // aborts the program otherwise. + const char* VerifyRegisteredTestNames( + const char* file, int line, const char* registered_tests); + + private: + bool registered_; + ::std::set defined_test_names_; +}; + +// Skips to the first non-space char after the first comma in 'str'; +// returns NULL if no comma is found in 'str'. +inline const char* SkipComma(const char* str) { + const char* comma = strchr(str, ','); + if (comma == NULL) { + return NULL; + } + while (isspace(*(++comma))) {} + return comma; +} + +// Returns the prefix of 'str' before the first comma in it; returns +// the entire string if it contains no comma. +inline String GetPrefixUntilComma(const char* str) { + const char* comma = strchr(str, ','); + return comma == NULL ? String(str) : String(str, comma - str); +} + +// TypeParameterizedTest::Register() +// registers a list of type-parameterized tests with Google Test. The +// return value is insignificant - we just need to return something +// such that we can call this function in a namespace scope. +// +// Implementation note: The GTEST_TEMPLATE_ macro declares a template +// template parameter. It's defined in gtest-type-util.h. +template +class TypeParameterizedTest { + public: + // 'index' is the index of the test in the type list 'Types' + // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase, + // Types). Valid values for 'index' are [0, N - 1] where N is the + // length of Types. + static bool Register(const char* prefix, const char* case_name, + const char* test_names, int index) { + typedef typename Types::Head Type; + typedef Fixture FixtureClass; + typedef typename GTEST_BIND_(TestSel, Type) TestClass; + + // First, registers the first type-parameterized test in the type + // list. + MakeAndRegisterTestInfo( + String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", + case_name, index).c_str(), + GetPrefixUntilComma(test_names).c_str(), + String::Format("TypeParam = %s", GetTypeName().c_str()).c_str(), + "", + GetTypeId(), + TestClass::SetUpTestCase, + TestClass::TearDownTestCase, + new TestFactoryImpl); + + // Next, recurses (at compile time) with the tail of the type list. + return TypeParameterizedTest + ::Register(prefix, case_name, test_names, index + 1); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTest { + public: + static bool Register(const char* /*prefix*/, const char* /*case_name*/, + const char* /*test_names*/, int /*index*/) { + return true; + } +}; + +// TypeParameterizedTestCase::Register() +// registers *all combinations* of 'Tests' and 'Types' with Google +// Test. The return value is insignificant - we just need to return +// something such that we can call this function in a namespace scope. +template +class TypeParameterizedTestCase { + public: + static bool Register(const char* prefix, const char* case_name, + const char* test_names) { + typedef typename Tests::Head Head; + + // First, register the first test in 'Test' for each type in 'Types'. + TypeParameterizedTest::Register( + prefix, case_name, test_names, 0); + + // Next, recurses (at compile time) with the tail of the test list. + return TypeParameterizedTestCase + ::Register(prefix, case_name, SkipComma(test_names)); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTestCase { + public: + static bool Register(const char* prefix, const char* case_name, + const char* test_names) { + return true; + } +}; + +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + } // namespace internal } // namespace testing @@ -544,27 +724,32 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT else \ fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) +// Expands to the name of the class that implements the given test. +#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ + test_case_name##_##test_name##_Test + // Helper macro for defining tests. #define GTEST_TEST(test_case_name, test_name, parent_class)\ -class test_case_name##_##test_name##_Test : public parent_class {\ +class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ public:\ - test_case_name##_##test_name##_Test() {}\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ private:\ virtual void TestBody();\ static ::testing::TestInfo* const test_info_;\ - GTEST_DISALLOW_COPY_AND_ASSIGN(test_case_name##_##test_name##_Test);\ + GTEST_DISALLOW_COPY_AND_ASSIGN(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ };\ \ -::testing::TestInfo* const test_case_name##_##test_name##_Test::test_info_ =\ - ::testing::TestInfo::MakeAndRegisterInstance(\ - #test_case_name, \ - #test_name, \ +::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ + ::test_info_ =\ + ::testing::internal::MakeAndRegisterTestInfo(\ + #test_case_name, #test_name, "", "", \ ::testing::internal::GetTypeId< parent_class >(), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ new ::testing::internal::TestFactoryImpl<\ - test_case_name##_##test_name##_Test>);\ -void test_case_name##_##test_name##_Test::TestBody() + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ +void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ -- cgit v1.2.3 From 36865d8d354465e3461eedf2949a4b7799985d5d Mon Sep 17 00:00:00 2001 From: shiqian Date: Fri, 12 Sep 2008 20:57:22 +0000 Subject: Adds exception assertions. By balaz.dan@gmail.com. --- include/gtest/internal/gtest-internal.h | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 8adf13e4..898047e8 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -717,6 +717,67 @@ class TypeParameterizedTestCase { #define GTEST_SUCCESS(message) \ GTEST_MESSAGE(message, ::testing::TPRT_SUCCESS) + +#define GTEST_TEST_THROW(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER \ + if (const char* gtest_msg = "") { \ + bool gtest_caught_expected = false; \ + try { \ + statement; \ + } \ + catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + } \ + catch (...) { \ + gtest_msg = "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws a different " \ + "type."; \ + goto GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__); \ + } \ + if (!gtest_caught_expected) { \ + gtest_msg = "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ + goto GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__): \ + fail(gtest_msg) + +#define GTEST_TEST_NO_THROW(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER \ + if (const char* gtest_msg = "") { \ + try { \ + statement; \ + } \ + catch (...) { \ + gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws."; \ + goto GTEST_CONCAT_TOKEN(gtest_label_testnothrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN(gtest_label_testnothrow_, __LINE__): \ + fail(gtest_msg) + +#define GTEST_TEST_ANY_THROW(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER \ + if (const char* gtest_msg = "") { \ + bool gtest_caught_any = false; \ + try { \ + statement; \ + } \ + catch (...) { \ + gtest_caught_any = true; \ + } \ + if (!gtest_caught_any) { \ + gtest_msg = "Expected: " #statement " throws an exception.\n" \ + " Actual: it doesn't."; \ + goto GTEST_CONCAT_TOKEN(gtest_label_testanythrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN(gtest_label_testanythrow_, __LINE__): \ + fail(gtest_msg) + + #define GTEST_TEST_BOOLEAN(boolexpr, booltext, actual, expected, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER \ if (boolexpr) \ -- cgit v1.2.3 From e0865dd9199e8fffd5c2f95a68de6c1851f77c15 Mon Sep 17 00:00:00 2001 From: shiqian Date: Sat, 11 Oct 2008 07:20:02 +0000 Subject: Many changes: - appends "_" to internal macro names (by Markus Heule). - makes Google Test work with newer versions of tools on Symbian and Windows CE (by Mika Raento). - adds the (ASSERT|EXPECT)_NO_FATAL_FAILURE macros (by Markus Heule). - changes EXPECT_(NON|)FATAL_FAILURE to catch failures in the current thread only (by Markus Heule). - adds the EXPECT_(NON|)FATAL_FAILURE_ON_ALL_THREADS macros (by Markus Heule). - adds GTEST_HAS_PTHREAD and GTEST_IS_THREADSAFE to indicate the availability of and Google Test's thread-safety (by Zhanyong Wan). - adds scons/SConscript for building with scons (by Joi Sigurdsson). - adds src/gtest-all.cc for building Google Test from a single file (by Markus Heule). - updates the xcode project to include new tests (by Preston Jackson). --- include/gtest/internal/gtest-internal.h | 105 +++++++++++++++++++------------- 1 file changed, 62 insertions(+), 43 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 898047e8..7128a51d 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -64,8 +64,8 @@ // will result in the token foo__LINE__, instead of foo followed by // the current line number. For more details, see // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 -#define GTEST_CONCAT_TOKEN(foo, bar) GTEST_CONCAT_TOKEN_IMPL(foo, bar) -#define GTEST_CONCAT_TOKEN_IMPL(foo, bar) foo ## bar +#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) +#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar // Google Test defines the testing::Message class to allow construction of // test messages via the << operator. The idea is that anything @@ -121,6 +121,10 @@ class UnitTestImpl; // Opaque implementation of UnitTest template class List; // A generic list. template class ListNode; // A node in a generic list. +// The text used in failure messages to indicate the start of the +// stack trace. +extern const char kStackTraceMarker[]; + // A secret type that Google Test users don't know about. It has no // definition on purpose. Therefore it's impossible to create a // Secret object, which is what we want. @@ -151,11 +155,11 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT // The Nokia Symbian compiler tries to instantiate a copy constructor for // objects passed through ellipsis (...), failing for uncopyable objects. // Hence we define this to false (and lose support for NULL detection). -#define GTEST_IS_NULL_LITERAL(x) false -#else // ! __SYMBIAN32__ -#define GTEST_IS_NULL_LITERAL(x) \ +#define GTEST_IS_NULL_LITERAL_(x) false +#else // ! GTEST_OS_SYMBIAN +#define GTEST_IS_NULL_LITERAL_(x) \ (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) -#endif // __SYMBIAN32__ +#endif // GTEST_OS_SYMBIAN // Appends the user-supplied message to the Google-Test-generated message. String AppendUserMessage(const String& gtest_msg, @@ -175,10 +179,10 @@ class ScopedTrace { ~ScopedTrace(); private: - GTEST_DISALLOW_COPY_AND_ASSIGN(ScopedTrace); -} GTEST_ATTRIBUTE_UNUSED; // A ScopedTrace object does its job in its - // c'tor and d'tor. Therefore it doesn't - // need to be used otherwise. + GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace); +} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its + // c'tor and d'tor. Therefore it doesn't + // need to be used otherwise. // Converts a streamable value to a String. A NULL pointer is // converted to "(null)". When the input value is a ::string, @@ -192,7 +196,7 @@ String StreamableToString(const T& streamable); // Formats a value to be used in a failure message. -#ifdef __SYMBIAN32__ +#ifdef GTEST_OS_SYMBIAN // These are needed as the Nokia Symbian Compiler cannot decide between // const T& and const T* in a function template. The Nokia compiler _can_ @@ -233,7 +237,7 @@ inline String FormatForFailureMessage(T* pointer) { return StreamableToString(static_cast(pointer)); } -#endif // __SYMBIAN32__ +#endif // GTEST_OS_SYMBIAN // These overloaded versions handle narrow and wide characters. String FormatForFailureMessage(char ch); @@ -244,7 +248,7 @@ String FormatForFailureMessage(wchar_t wchar); // rather than a pointer. We do the same for wide strings. // This internal macro is used to avoid duplicated code. -#define GTEST_FORMAT_IMPL(operand2_type, operand1_printer)\ +#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ inline String FormatForComparisonFailureMessage(\ operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ @@ -255,20 +259,20 @@ inline String FormatForComparisonFailureMessage(\ } #if GTEST_HAS_STD_STRING -GTEST_FORMAT_IMPL(::std::string, String::ShowCStringQuoted) +GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) #endif // GTEST_HAS_STD_STRING #if GTEST_HAS_STD_WSTRING -GTEST_FORMAT_IMPL(::std::wstring, String::ShowWideCStringQuoted) +GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted) #endif // GTEST_HAS_STD_WSTRING #if GTEST_HAS_GLOBAL_STRING -GTEST_FORMAT_IMPL(::string, String::ShowCStringQuoted) +GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted) #endif // GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_WSTRING -GTEST_FORMAT_IMPL(::wstring, String::ShowWideCStringQuoted) +GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) #endif // GTEST_HAS_GLOBAL_WSTRING -#undef GTEST_FORMAT_IMPL +#undef GTEST_FORMAT_IMPL_ // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. @@ -503,7 +507,7 @@ class TestFactoryBase { TestFactoryBase() {} private: - GTEST_DISALLOW_COPY_AND_ASSIGN(TestFactoryBase); + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase); }; // This class provides implementation of TeastFactoryBase interface. @@ -704,22 +708,22 @@ class TypeParameterizedTestCase { } // namespace internal } // namespace testing -#define GTEST_MESSAGE(message, result_type) \ +#define GTEST_MESSAGE_(message, result_type) \ ::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, message) \ = ::testing::Message() -#define GTEST_FATAL_FAILURE(message) \ - return GTEST_MESSAGE(message, ::testing::TPRT_FATAL_FAILURE) +#define GTEST_FATAL_FAILURE_(message) \ + return GTEST_MESSAGE_(message, ::testing::TPRT_FATAL_FAILURE) -#define GTEST_NONFATAL_FAILURE(message) \ - GTEST_MESSAGE(message, ::testing::TPRT_NONFATAL_FAILURE) +#define GTEST_NONFATAL_FAILURE_(message) \ + GTEST_MESSAGE_(message, ::testing::TPRT_NONFATAL_FAILURE) -#define GTEST_SUCCESS(message) \ - GTEST_MESSAGE(message, ::testing::TPRT_SUCCESS) +#define GTEST_SUCCESS_(message) \ + GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) -#define GTEST_TEST_THROW(statement, expected_exception, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER \ +#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ @@ -732,19 +736,19 @@ class TypeParameterizedTestCase { gtest_msg = "Expected: " #statement " throws an exception of type " \ #expected_exception ".\n Actual: it throws a different " \ "type."; \ - goto GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ if (!gtest_caught_expected) { \ gtest_msg = "Expected: " #statement " throws an exception of type " \ #expected_exception ".\n Actual: it throws nothing."; \ - goto GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ - GTEST_CONCAT_TOKEN(gtest_label_testthrow_, __LINE__): \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ fail(gtest_msg) -#define GTEST_TEST_NO_THROW(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER \ +#define GTEST_TEST_NO_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ try { \ statement; \ @@ -752,14 +756,14 @@ class TypeParameterizedTestCase { catch (...) { \ gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ " Actual: it throws."; \ - goto GTEST_CONCAT_TOKEN(gtest_label_testnothrow_, __LINE__); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ } else \ - GTEST_CONCAT_TOKEN(gtest_label_testnothrow_, __LINE__): \ + GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ fail(gtest_msg) -#define GTEST_TEST_ANY_THROW(statement, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER \ +#define GTEST_TEST_ANY_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ bool gtest_caught_any = false; \ try { \ @@ -771,33 +775,48 @@ class TypeParameterizedTestCase { if (!gtest_caught_any) { \ gtest_msg = "Expected: " #statement " throws an exception.\n" \ " Actual: it doesn't."; \ - goto GTEST_CONCAT_TOKEN(gtest_label_testanythrow_, __LINE__); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ } \ } else \ - GTEST_CONCAT_TOKEN(gtest_label_testanythrow_, __LINE__): \ + GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ fail(gtest_msg) -#define GTEST_TEST_BOOLEAN(boolexpr, booltext, actual, expected, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER \ +#define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (boolexpr) \ ; \ else \ fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) +#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (const char* gtest_msg = "") { \ + ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ + { statement; } \ + if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ + gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ + "failures in the current thread.\n" \ + " Actual: it does."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ + fail(gtest_msg) + // Expands to the name of the class that implements the given test. #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ test_case_name##_##test_name##_Test // Helper macro for defining tests. -#define GTEST_TEST(test_case_name, test_name, parent_class)\ +#define GTEST_TEST_(test_case_name, test_name, parent_class)\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ public:\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ private:\ virtual void TestBody();\ static ::testing::TestInfo* const test_info_;\ - GTEST_DISALLOW_COPY_AND_ASSIGN(\ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ };\ \ -- cgit v1.2.3 From d2849f573052ba8431a887e0034b1be353a0d9b4 Mon Sep 17 00:00:00 2001 From: shiqian Date: Mon, 10 Nov 2008 18:27:46 +0000 Subject: Makes Google Test compile on Solaris and z/OS. By Rainer Klaffenboeck. --- include/gtest/internal/gtest-internal.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 7128a51d..a1e43e4c 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -150,16 +150,17 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT // A compile-time bool constant that is true if and only if x is a // null pointer literal (i.e. NULL or any 0-valued compile-time // integral constant). -#ifdef __SYMBIAN32__ // Symbian -// Passing non-POD classes through ellipsis (...) crashes the ARM compiler. -// The Nokia Symbian compiler tries to instantiate a copy constructor for -// objects passed through ellipsis (...), failing for uncopyable objects. -// Hence we define this to false (and lose support for NULL detection). +#ifdef GTEST_ELLIPSIS_NEEDS_COPY_ +// Passing non-POD classes through ellipsis (...) crashes the ARM +// compiler. The Nokia Symbian and the IBM XL C/C++ compiler try to +// instantiate a copy constructor for objects passed through ellipsis +// (...), failing for uncopyable objects. Hence we define this to +// false (and lose support for NULL detection). #define GTEST_IS_NULL_LITERAL_(x) false -#else // ! GTEST_OS_SYMBIAN +#else #define GTEST_IS_NULL_LITERAL_(x) \ (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) -#endif // GTEST_OS_SYMBIAN +#endif // GTEST_ELLIPSIS_NEEDS_COPY_ // Appends the user-supplied message to the Google-Test-generated message. String AppendUserMessage(const String& gtest_msg, @@ -196,12 +197,13 @@ String StreamableToString(const T& streamable); // Formats a value to be used in a failure message. -#ifdef GTEST_OS_SYMBIAN +#ifdef GTEST_NEEDS_IS_POINTER_ -// These are needed as the Nokia Symbian Compiler cannot decide between -// const T& and const T* in a function template. The Nokia compiler _can_ -// decide between class template specializations for T and T*, so a -// tr1::type_traits-like is_pointer works, and we can overload on that. +// These are needed as the Nokia Symbian and IBM XL C/C++ compilers +// cannot decide between const T& and const T* in a function template. +// These compilers _can_ decide between class template specializations +// for T and T*, so a tr1::type_traits-like is_pointer works, and we +// can overload on that. // This overload makes sure that all pointers (including // those to char or wchar_t) are printed as raw pointers. @@ -225,6 +227,10 @@ inline String FormatForFailureMessage(const T& value) { #else +// These are needed as the above solution using is_pointer has the +// limitation that T cannot be a type without external linkage, when +// compiled using MSVC. + template inline String FormatForFailureMessage(const T& value) { return StreamableToString(value); @@ -237,7 +243,7 @@ inline String FormatForFailureMessage(T* pointer) { return StreamableToString(static_cast(pointer)); } -#endif // GTEST_OS_SYMBIAN +#endif // GTEST_NEEDS_IS_POINTER_ // These overloaded versions handle narrow and wide characters. String FormatForFailureMessage(char ch); -- cgit v1.2.3 From 3d7042176307f0d7700a3640f3b3bcc8790b8fcd Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 20 Nov 2008 01:40:35 +0000 Subject: Value-parameterized tests and many bugfixes --- include/gtest/internal/gtest-internal.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index a1e43e4c..d439c00b 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -711,6 +711,21 @@ class TypeParameterizedTestCase { #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P +// Returns the current OS stack trace as a String. +// +// The maximum number of stack frames to be included is specified by +// the gtest_stack_trace_depth flag. The skip_count parameter +// specifies the number of top frames to be skipped, which doesn't +// count against the number of frames to be included. +// +// For example, if Foo() calls Bar(), which in turn calls +// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in +// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. +String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); + +// Returns the number of failed test parts in the given test result object. +int GetFailedPartCount(const TestResult* result); + } // namespace internal } // namespace testing @@ -727,7 +742,6 @@ class TypeParameterizedTestCase { #define GTEST_SUCCESS_(message) \ GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) - #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ @@ -837,5 +851,4 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() - #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ -- cgit v1.2.3 From c440a6923aa65d5be64134a6f430a5867a63df3f Mon Sep 17 00:00:00 2001 From: shiqian Date: Mon, 24 Nov 2008 20:13:22 +0000 Subject: Enables the Python tests to run with 2.3 (necessary for testing on Mac OS X Tiger); also fixes gtest_output_test when built with xcode. --- include/gtest/internal/gtest-internal.h | 37 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d439c00b..9e353b63 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -485,20 +485,39 @@ typedef FloatingPoint Double; // used to hold such IDs. The user should treat TypeId as an opaque // type: the only operation allowed on TypeId values is to compare // them for equality using the == operator. -typedef void* TypeId; +typedef const void* TypeId; + +template +class TypeIdHelper { + public: + // dummy_ must not have a const type. Otherwise an overly eager + // compiler (e.g. MSVC 7.1 & 8.0) may try to merge + // TypeIdHelper::dummy_ for different Ts as an "optimization". + static bool dummy_; +}; + +template +bool TypeIdHelper::dummy_ = false; // GetTypeId() returns the ID of type T. Different values will be // returned for different types. Calling the function twice with the // same type argument is guaranteed to return the same ID. template -inline TypeId GetTypeId() { - static bool dummy = false; - // The compiler is required to create an instance of the static - // variable dummy for each T used to instantiate the template. - // Therefore, the address of dummy is guaranteed to be unique. - return &dummy; +TypeId GetTypeId() { + // The compiler is required to allocate a different + // TypeIdHelper::dummy_ variable for each T used to instantiate + // the template. Therefore, the address of dummy_ is guaranteed to + // be unique. + return &(TypeIdHelper::dummy_); } +// Returns the type ID of ::testing::Test. Always call this instead +// of GetTypeId< ::testing::Test>() to get the type ID of +// ::testing::Test, as the latter may give the wrong result due to a +// suspected linker bug when compiling Google Test as a Mac OS X +// framework. +TypeId GetTestTypeId(); + // Defines the abstract factory interface that creates instances // of a Test object. class TestFactoryBase { @@ -829,7 +848,7 @@ int GetFailedPartCount(const TestResult* result); test_case_name##_##test_name##_Test // Helper macro for defining tests. -#define GTEST_TEST_(test_case_name, test_name, parent_class)\ +#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ public:\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ @@ -844,7 +863,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ ::test_info_ =\ ::testing::internal::MakeAndRegisterTestInfo(\ #test_case_name, #test_name, "", "", \ - ::testing::internal::GetTypeId< parent_class >(), \ + (parent_id), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ new ::testing::internal::TestFactoryImpl<\ -- cgit v1.2.3 From 1998cf5d32a19aaffe8652545802744d9133022d Mon Sep 17 00:00:00 2001 From: vladlosev Date: Wed, 26 Nov 2008 20:48:45 +0000 Subject: Allow Google Mock to initialize Google Test --- include/gtest/internal/gtest-internal.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 9e353b63..37faaaeb 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -121,6 +121,9 @@ class UnitTestImpl; // Opaque implementation of UnitTest template class List; // A generic list. template class ListNode; // A node in a generic list. +// How many times InitGoogleTest() has been called. +extern int g_init_gtest_count; + // The text used in failure messages to indicate the start of the // stack trace. extern const char kStackTraceMarker[]; -- cgit v1.2.3 From 4b83461e9772cce62e84310060fe84172e9bf4ba Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 29 Jan 2009 06:49:00 +0000 Subject: Fixes some warnings when compiled with MSVC at warning level 4. --- include/gtest/internal/gtest-internal.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 37faaaeb..541c89b8 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -748,6 +748,9 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); // Returns the number of failed test parts in the given test result object. int GetFailedPartCount(const TestResult* result); +// A helper for suppressing warnings on unreachable code in some macros. +inline bool True() { return true; } + } // namespace internal } // namespace testing @@ -835,7 +838,7 @@ int GetFailedPartCount(const TestResult* result); GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - { statement; } \ + if (::testing::internal::True()) { statement; } \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ "failures in the current thread.\n" \ -- cgit v1.2.3 From 37504994338c114247519331237831f88a9a7c40 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 6 Feb 2009 00:47:20 +0000 Subject: Adds tests for EXPECT_FATAL_FAILURE and reduces the golden file bloat (by Zhanyong Wan). Fixes more warnings on Windows (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 541c89b8..b28da96e 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -749,7 +749,7 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); int GetFailedPartCount(const TestResult* result); // A helper for suppressing warnings on unreachable code in some macros. -inline bool True() { return true; } +bool AlwaysTrue(); } // namespace internal } // namespace testing @@ -767,12 +767,18 @@ inline bool True() { return true; } #define GTEST_SUCCESS_(message) \ GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) +// Suppresses MSVC warnings 4072 (unreachable code) for the code following +// statement if it returns or throws (or doesn't return or throw in some +// situations). +#define GTEST_HIDE_UNREACHABLE_CODE_(statement) \ + if (::testing::internal::AlwaysTrue()) { statement; } + #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (expected_exception const&) { \ gtest_caught_expected = true; \ @@ -796,7 +802,7 @@ inline bool True() { return true; } GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (...) { \ gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ @@ -812,7 +818,7 @@ inline bool True() { return true; } if (const char* gtest_msg = "") { \ bool gtest_caught_any = false; \ try { \ - statement; \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ } \ catch (...) { \ gtest_caught_any = true; \ @@ -838,7 +844,7 @@ inline bool True() { return true; } GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - if (::testing::internal::True()) { statement; } \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ "failures in the current thread.\n" \ -- cgit v1.2.3 From 0af0709b02899f9177db55eba7929e65e5834b29 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 23 Feb 2009 23:21:55 +0000 Subject: Cleans up macro definitions. --- include/gtest/internal/gtest-internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index b28da96e..5908b760 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -39,7 +39,7 @@ #include -#ifdef GTEST_OS_LINUX +#if GTEST_OS_LINUX #include #include #include @@ -546,7 +546,7 @@ class TestFactoryImpl : public TestFactoryBase { virtual Test* CreateTest() { return new TestClass; } }; -#ifdef GTEST_OS_WINDOWS +#if GTEST_OS_WINDOWS // Predicate-formatters for implementing the HRESULT checking macros // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} @@ -600,7 +600,7 @@ TestInfo* MakeAndRegisterTestInfo( TearDownTestCaseFunc tear_down_tc, TestFactoryBase* factory); -#if defined(GTEST_HAS_TYPED_TEST) || defined(GTEST_HAS_TYPED_TEST_P) +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P // State of the definition of a type-parameterized test case. class TypedTestCasePState { -- cgit v1.2.3 From 44a041b711ff4a5b5f341f21127aed46dbfe38ad Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 11 Mar 2009 18:31:26 +0000 Subject: Fixes death-test-related tests on Windows, by Vlad Losev. --- include/gtest/internal/gtest-internal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 5908b760..f61d502f 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -616,6 +616,7 @@ class TypedTestCasePState { fprintf(stderr, "%s Test %s must be defined before " "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", FormatFileLocation(file, line).c_str(), test_name, case_name); + fflush(stderr); abort(); } defined_test_names_.insert(test_name); -- cgit v1.2.3 From c78ae6196dc9c24380b5cf86f8fd75a4d3edc704 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 28 Apr 2009 00:28:09 +0000 Subject: Ports gtest to C++Builder, by Josh Kelley. --- include/gtest/internal/gtest-internal.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index f61d502f..d596b3a6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -383,7 +383,7 @@ class FloatingPoint { // around may change its bits, although the new value is guaranteed // to be also a NAN. Therefore, don't expect this constructor to // preserve the bits in x when x is a NAN. - explicit FloatingPoint(const RawType& x) : value_(x) {} + explicit FloatingPoint(const RawType& x) { u_.value_ = x; } // Static methods @@ -392,8 +392,8 @@ class FloatingPoint { // This function is needed to test the AlmostEquals() method. static RawType ReinterpretBits(const Bits bits) { FloatingPoint fp(0); - fp.bits_ = bits; - return fp.value_; + fp.u_.bits_ = bits; + return fp.u_.value_; } // Returns the floating-point number that represent positive infinity. @@ -404,16 +404,16 @@ class FloatingPoint { // Non-static methods // Returns the bits that represents this number. - const Bits &bits() const { return bits_; } + const Bits &bits() const { return u_.bits_; } // Returns the exponent bits of this number. - Bits exponent_bits() const { return kExponentBitMask & bits_; } + Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } // Returns the fraction bits of this number. - Bits fraction_bits() const { return kFractionBitMask & bits_; } + Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } // Returns the sign bit of this number. - Bits sign_bit() const { return kSignBitMask & bits_; } + Bits sign_bit() const { return kSignBitMask & u_.bits_; } // Returns true iff this is NAN (not a number). bool is_nan() const { @@ -433,10 +433,17 @@ class FloatingPoint { // a NAN must return false. if (is_nan() || rhs.is_nan()) return false; - return DistanceBetweenSignAndMagnitudeNumbers(bits_, rhs.bits_) <= kMaxUlps; + return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) + <= kMaxUlps; } private: + // The data type used to store the actual floating-point number. + union FloatingPointUnion { + RawType value_; // The raw floating-point number. + Bits bits_; // The bits that represent the number. + }; + // Converts an integer from the sign-and-magnitude representation to // the biased representation. More precisely, let N be 2 to the // power of (kBitCount - 1), an integer x is represented by the @@ -471,10 +478,7 @@ class FloatingPoint { return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); } - union { - RawType value_; // The raw floating-point number. - Bits bits_; // The bits that represent the number. - }; + FloatingPointUnion u_; }; // Typedefs the instances of the FloatingPoint template class that we -- cgit v1.2.3 From 4853a503371f39aa22e14adcdecea71c09841e34 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 19 Jun 2009 17:23:54 +0000 Subject: Fixes compatibility with Windows CE and Symbian (By Tim Baverstock and Mika). --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d596b3a6..6e605e04 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -621,7 +621,7 @@ class TypedTestCasePState { "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", FormatFileLocation(file, line).c_str(), test_name, case_name); fflush(stderr); - abort(); + posix::Abort(); } defined_test_names_.insert(test_name); return true; -- cgit v1.2.3 From ef29ce3576240e51f289e49b2c4e156b414d6685 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 22 Jun 2009 23:29:24 +0000 Subject: Turns on exceptions when compiling gtest_output_test (by Vlad Losev); moves TestCase to gtest.h to prepare for the event listener API (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 6e605e04..a4c37364 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -103,7 +103,6 @@ namespace testing { class Message; // Represents a failure message. class Test; // Represents a test. -class TestCase; // A collection of related tests. class TestPartResult; // Result of a test part. class TestInfo; // Information about a test. class UnitTest; // A collection of test cases. -- cgit v1.2.3 From 600105ee3ac48a01143486e5536a5b8fff5b5b25 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 1 Jul 2009 22:55:05 +0000 Subject: Makes List a random-access data structure. This simplifies the implementation and makes it easier to implement test shuffling. --- include/gtest/internal/gtest-internal.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index a4c37364..91b386f0 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -116,9 +116,7 @@ class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo class TestResult; // Result of a single Test. class UnitTestImpl; // Opaque implementation of UnitTest - template class List; // A generic list. -template class ListNode; // A node in a generic list. // How many times InitGoogleTest() has been called. extern int g_init_gtest_count; -- cgit v1.2.3 From 89080477aee9bd91536c9fb47bc31c62ea7d75bb Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 13 Jul 2009 19:25:02 +0000 Subject: Adds color support for TERM=linux (by Alexander Demin); renames List to Vector (by Zhanyong Wan); implements Vector::Erase (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 91b386f0..76945551 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -116,7 +116,7 @@ class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo class TestResult; // Result of a single Test. class UnitTestImpl; // Opaque implementation of UnitTest -template class List; // A generic list. +template class Vector; // A generic vector. // How many times InitGoogleTest() has been called. extern int g_init_gtest_count; @@ -208,13 +208,13 @@ String StreamableToString(const T& streamable); // This overload makes sure that all pointers (including // those to char or wchar_t) are printed as raw pointers. template -inline String FormatValueForFailureMessage(internal::true_type dummy, +inline String FormatValueForFailureMessage(internal::true_type /*dummy*/, T* pointer) { return StreamableToString(static_cast(pointer)); } template -inline String FormatValueForFailureMessage(internal::false_type dummy, +inline String FormatValueForFailureMessage(internal::false_type /*dummy*/, const T& value) { return StreamableToString(value); } -- cgit v1.2.3 From c214ebc830aa918d54e535c6caa2da6317877e12 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 16 Jul 2009 00:36:55 +0000 Subject: More refactoring for the event listener API, by Vlad Losev. --- include/gtest/internal/gtest-internal.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 76945551..be37726a 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -101,20 +101,19 @@ namespace testing { // Forward declaration of classes. +class AssertionResult; // Result of an assertion. class Message; // Represents a failure message. class Test; // Represents a test. -class TestPartResult; // Result of a test part. class TestInfo; // Information about a test. +class TestPartResult; // Result of a test part. class UnitTest; // A collection of test cases. class UnitTestEventListenerInterface; // Listens to Google Test events. -class AssertionResult; // Result of an assertion. namespace internal { struct TraceInfo; // Information about a trace point. class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo -class TestResult; // Result of a single Test. class UnitTestImpl; // Opaque implementation of UnitTest template class Vector; // A generic vector. @@ -747,9 +746,6 @@ class TypeParameterizedTestCase { // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); -// Returns the number of failed test parts in the given test result object. -int GetFailedPartCount(const TestResult* result); - // A helper for suppressing warnings on unreachable code in some macros. bool AlwaysTrue(); -- cgit v1.2.3 From 16e9dd6e28a8a7fb2d611011e7353e042fcb282f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 4 Sep 2009 18:30:25 +0000 Subject: More implementation of the event listener interface (by Vlad Losev); Reduces the stack space usage of assertions by moving AssertHelper's fields to the heap (by Jorg Brown); Makes String faster, smaller, and simpler (by Zhanyong Wan); Fixes a bug in String::Format() (by Chandler); Adds the /MD version of VC projects to the distribution (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index be37726a..f0a7966b 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -107,7 +107,6 @@ class Test; // Represents a test. class TestInfo; // Information about a test. class TestPartResult; // Result of a test part. class UnitTest; // A collection of test cases. -class UnitTestEventListenerInterface; // Listens to Google Test events. namespace internal { -- cgit v1.2.3 From 866f4a94461d765f7f9514b6cb6e82d7b9ea12d2 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 16 Sep 2009 06:59:17 +0000 Subject: Simplifies the implementation of GTEST_LOG_ & GTEST_LOG_; renames GTEST_HIDE_UNREACHABLE_CODE_ to GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index f0a7966b..72272d91 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -767,7 +767,7 @@ bool AlwaysTrue(); // Suppresses MSVC warnings 4072 (unreachable code) for the code following // statement if it returns or throws (or doesn't return or throw in some // situations). -#define GTEST_HIDE_UNREACHABLE_CODE_(statement) \ +#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ if (::testing::internal::AlwaysTrue()) { statement; } #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ @@ -775,7 +775,7 @@ bool AlwaysTrue(); if (const char* gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (expected_exception const&) { \ gtest_caught_expected = true; \ @@ -799,7 +799,7 @@ bool AlwaysTrue(); GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (...) { \ gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ @@ -815,7 +815,7 @@ bool AlwaysTrue(); if (const char* gtest_msg = "") { \ bool gtest_caught_any = false; \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (...) { \ gtest_caught_any = true; \ @@ -841,7 +841,7 @@ bool AlwaysTrue(); GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ "failures in the current thread.\n" \ -- cgit v1.2.3 From 12d740faef11779b27b17c558ca92622bc0d2b54 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 17 Sep 2009 05:04:08 +0000 Subject: Makes gtest compile clean with MSVC's warning 4100 (unused formal parameter) enabled. --- include/gtest/internal/gtest-internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 72272d91..49e104af 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -725,8 +725,8 @@ class TypeParameterizedTestCase { template class TypeParameterizedTestCase { public: - static bool Register(const char* prefix, const char* case_name, - const char* test_names) { + static bool Register(const char* /*prefix*/, const char* /*case_name*/, + const char* /*test_names*/) { return true; } }; -- cgit v1.2.3 From e5373af0cb9cae249e7bc618cae3483397332895 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 18 Sep 2009 18:16:20 +0000 Subject: Renames the TestPartResult type enums and adjusts the order of methods in the event listener interface (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 49e104af..47755243 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -756,13 +756,13 @@ bool AlwaysTrue(); = ::testing::Message() #define GTEST_FATAL_FAILURE_(message) \ - return GTEST_MESSAGE_(message, ::testing::TPRT_FATAL_FAILURE) + return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) #define GTEST_NONFATAL_FAILURE_(message) \ - GTEST_MESSAGE_(message, ::testing::TPRT_NONFATAL_FAILURE) + GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) #define GTEST_SUCCESS_(message) \ - GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) + GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) // Suppresses MSVC warnings 4072 (unreachable code) for the code following // statement if it returns or throws (or doesn't return or throw in some -- cgit v1.2.3 From 2534ae201e47986d36d5fab0e523a7f046b8ec1e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 21 Sep 2009 19:42:03 +0000 Subject: Adds a Random class to support --gtest_shuffle (by Josh Kelley); Makes the scons script build in a deterministic order (by Zhanyong Wan). --- include/gtest/internal/gtest-internal.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 47755243..f5c30fb5 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -748,6 +748,28 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); // A helper for suppressing warnings on unreachable code in some macros. bool AlwaysTrue(); +// A simple Linear Congruential Generator for generating random +// numbers with a uniform distribution. Unlike rand() and srand(), it +// doesn't use global state (and therefore can't interfere with user +// code). Unlike rand_r(), it's portable. An LCG isn't very random, +// but it's good enough for our purposes. +class Random { + public: + static const UInt32 kMaxRange = 1u << 31; + + explicit Random(UInt32 seed) : state_(seed) {} + + void Reseed(UInt32 seed) { state_ = seed; } + + // Generates a random number from [0, range). Crashes if 'range' is + // 0 or greater than kMaxRange. + UInt32 Generate(UInt32 range); + + private: + UInt32 state_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); +}; + } // namespace internal } // namespace testing -- cgit v1.2.3 From f8b268ee86ca74bba3276352f1e7de53d1336c3e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 30 Sep 2009 20:23:50 +0000 Subject: Makes gtest compile cleanly with MSVC's /W4 (by Zhanyong Wan). Renames EventListenrs to TestEventListeners (by Zhanyong Wan). Fixes invalid characters in XML report (by Vlad Losev). Refacotrs SConscript (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index f5c30fb5..7033b0ca 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -745,9 +745,15 @@ class TypeParameterizedTestCase { // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); -// A helper for suppressing warnings on unreachable code in some macros. +// Helpers for suppressing warnings on unreachable code or constant +// condition. + +// Always returns true. bool AlwaysTrue(); +// Always returns false. +inline bool AlwaysFalse() { return !AlwaysTrue(); } + // A simple Linear Congruential Generator for generating random // numbers with a uniform distribution. Unlike rand() and srand(), it // doesn't use global state (and therefore can't interfere with user @@ -854,7 +860,7 @@ class Random { #define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (boolexpr) \ + if (::testing::internal::IsTrue(boolexpr)) \ ; \ else \ fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) -- cgit v1.2.3 From bad778caa39a88b7c11b159e20730aeec4fd711e Mon Sep 17 00:00:00 2001 From: vladlosev Date: Tue, 20 Oct 2009 21:03:10 +0000 Subject: Implements support for AssertionResult in Boolean assertions such as EXPECT_TRUE; Fixes Google Tests's tuple implementation to default-initialize its fields in the default constructor (by Zhanyong Wan); Populates gtest_stress_test.cc with actual tests. --- include/gtest/internal/gtest-internal.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 7033b0ca..08cf67d6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -299,6 +299,11 @@ AssertionResult EqFailure(const char* expected_expression, const String& actual_value, bool ignoring_case); +// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. +String GetBoolAssertionFailureMessage(const AssertionResult& assertion_result, + const char* expression_text, + const char* actual_predicate_value, + const char* expected_predicate_value); // This template class represents an IEEE floating-point number // (either single-precision or double-precision, depending on the @@ -858,12 +863,17 @@ class Random { fail(gtest_msg) -#define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \ +// Implements Boolean test assertions such as EXPECT_TRUE. expression can be +// either a boolean expression or an AssertionResult. text is a textual +// represenation of expression as it was passed into the EXPECT_TRUE. +#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::IsTrue(boolexpr)) \ + if (const ::testing::AssertionResult gtest_ar_ = \ + ::testing::AssertionResult(expression)) \ ; \ else \ - fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) + fail(::testing::internal::GetBoolAssertionFailureMessage(\ + gtest_ar_, text, #actual, #expected).c_str()) #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ -- cgit v1.2.3 From 891b3716c4b6e4bd7fdbd642ecaab37776eb5935 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 1 Dec 2009 19:39:52 +0000 Subject: Exposes SkipPrefix s.t. it can be used by gmock (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 08cf67d6..43e5f97e 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -604,6 +604,11 @@ TestInfo* MakeAndRegisterTestInfo( TearDownTestCaseFunc tear_down_tc, TestFactoryBase* factory); +// If *pstr starts with the given prefix, modifies *pstr to be right +// past the prefix and returns true; otherwise leaves *pstr unchanged +// and returns false. None of pstr, *pstr, and prefix can be NULL. +bool SkipPrefix(const char* prefix, const char** pstr); + #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P // State of the definition of a type-parameterized test case. -- cgit v1.2.3 From 44bafcb62d0f33fbc9aafb5492b245c949850df8 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 7 Dec 2009 20:45:16 +0000 Subject: Fixes the "passing non-POD to ellipsis" warning in Sun Studio. Based on Alexander Demin's patch. --- include/gtest/internal/gtest-internal.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 43e5f97e..e9f8e7cf 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -148,17 +148,14 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT // A compile-time bool constant that is true if and only if x is a // null pointer literal (i.e. NULL or any 0-valued compile-time // integral constant). -#ifdef GTEST_ELLIPSIS_NEEDS_COPY_ -// Passing non-POD classes through ellipsis (...) crashes the ARM -// compiler. The Nokia Symbian and the IBM XL C/C++ compiler try to -// instantiate a copy constructor for objects passed through ellipsis -// (...), failing for uncopyable objects. Hence we define this to -// false (and lose support for NULL detection). +#ifdef GTEST_ELLIPSIS_NEEDS_POD_ +// We lose support for NULL detection where the compiler doesn't like +// passing non-POD classes through ellipsis (...). #define GTEST_IS_NULL_LITERAL_(x) false #else #define GTEST_IS_NULL_LITERAL_(x) \ (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) -#endif // GTEST_ELLIPSIS_NEEDS_COPY_ +#endif // GTEST_ELLIPSIS_NEEDS_POD_ // Appends the user-supplied message to the Google-Test-generated message. String AppendUserMessage(const String& gtest_msg, -- cgit v1.2.3 From 88e97c822c988eaa9f8bcbaa1ea5d702ffd7d384 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 16 Dec 2009 23:34:59 +0000 Subject: Removes uses of GTEST_HAS_STD_STRING. --- include/gtest/internal/gtest-internal.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index e9f8e7cf..50f9fdf8 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -259,9 +259,7 @@ inline String FormatForComparisonFailureMessage(\ return operand1_printer(str);\ } -#if GTEST_HAS_STD_STRING GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) -#endif // GTEST_HAS_STD_STRING #if GTEST_HAS_STD_WSTRING GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted) #endif // GTEST_HAS_STD_WSTRING -- cgit v1.2.3 From 0d27868d0faef474594682f25336229daa89d6d7 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 25 Feb 2010 01:09:07 +0000 Subject: Simplifies the implementation by using std::vector instead of Vector. --- include/gtest/internal/gtest-internal.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 50f9fdf8..a7858f9a 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -114,7 +114,6 @@ struct TraceInfo; // Information about a trace point. class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo class UnitTestImpl; // Opaque implementation of UnitTest -template class Vector; // A generic vector. // How many times InitGoogleTest() has been called. extern int g_init_gtest_count; -- cgit v1.2.3 From 83589cca345d2f03d93b0555437aa480e0ed6699 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 5 Mar 2010 21:21:06 +0000 Subject: Supports building gtest as a DLL (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index a7858f9a..7bc35e20 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -161,7 +161,7 @@ String AppendUserMessage(const String& gtest_msg, const Message& user_msg); // A helper class for creating scoped traces in user programs. -class ScopedTrace { +class GTEST_API_ ScopedTrace { public: // The c'tor pushes the given source file location and message onto // a trace stack maintained by Google Test. @@ -240,8 +240,8 @@ inline String FormatForFailureMessage(T* pointer) { #endif // GTEST_NEEDS_IS_POINTER_ // These overloaded versions handle narrow and wide characters. -String FormatForFailureMessage(char ch); -String FormatForFailureMessage(wchar_t wchar); +GTEST_API_ String FormatForFailureMessage(char ch); +GTEST_API_ String FormatForFailureMessage(wchar_t wchar); // When this operand is a const char* or char*, and the other operand // is a ::std::string or ::string, we print this operand as a C string @@ -287,17 +287,18 @@ GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) // The ignoring_case parameter is true iff the assertion is a // *_STRCASEEQ*. When it's true, the string " (ignoring case)" will // be inserted into the message. -AssertionResult EqFailure(const char* expected_expression, - const char* actual_expression, - const String& expected_value, - const String& actual_value, - bool ignoring_case); +GTEST_API_ AssertionResult EqFailure(const char* expected_expression, + const char* actual_expression, + const String& expected_value, + const String& actual_value, + bool ignoring_case); // Constructs a failure message for Boolean assertions such as EXPECT_TRUE. -String GetBoolAssertionFailureMessage(const AssertionResult& assertion_result, - const char* expression_text, - const char* actual_predicate_value, - const char* expected_predicate_value); +GTEST_API_ String GetBoolAssertionFailureMessage( + const AssertionResult& assertion_result, + const char* expression_text, + const char* actual_predicate_value, + const char* expected_predicate_value); // This template class represents an IEEE floating-point number // (either single-precision or double-precision, depending on the @@ -517,7 +518,7 @@ TypeId GetTypeId() { // ::testing::Test, as the latter may give the wrong result due to a // suspected linker bug when compiling Google Test as a Mac OS X // framework. -TypeId GetTestTypeId(); +GTEST_API_ TypeId GetTestTypeId(); // Defines the abstract factory interface that creates instances // of a Test object. @@ -550,8 +551,10 @@ class TestFactoryImpl : public TestFactoryBase { // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} // We pass a long instead of HRESULT to avoid causing an // include dependency for the HRESULT type. -AssertionResult IsHRESULTSuccess(const char* expr, long hr); // NOLINT -AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT +GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr, + long hr); // NOLINT +GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, + long hr); // NOLINT #endif // GTEST_OS_WINDOWS @@ -590,7 +593,7 @@ typedef void (*TearDownTestCaseFunc)(); // factory: pointer to the factory that creates a test object. // The newly created TestInfo instance will assume // ownership of the factory object. -TestInfo* MakeAndRegisterTestInfo( +GTEST_API_ TestInfo* MakeAndRegisterTestInfo( const char* test_case_name, const char* name, const char* test_case_comment, const char* comment, TypeId fixture_class_id, @@ -606,7 +609,7 @@ bool SkipPrefix(const char* prefix, const char** pstr); #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P // State of the definition of a type-parameterized test case. -class TypedTestCasePState { +class GTEST_API_ TypedTestCasePState { public: TypedTestCasePState() : registered_(false) {} @@ -753,7 +756,7 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); // condition. // Always returns true. -bool AlwaysTrue(); +GTEST_API_ bool AlwaysTrue(); // Always returns false. inline bool AlwaysFalse() { return !AlwaysTrue(); } -- cgit v1.2.3 From 9f0824b0a61b50fd40e47da2387cd9b3f872ce47 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 22 Mar 2010 21:23:51 +0000 Subject: Adds missing gtest DLL exports. --- include/gtest/internal/gtest-internal.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 7bc35e20..31a66e99 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -120,7 +120,7 @@ extern int g_init_gtest_count; // The text used in failure messages to indicate the start of the // stack trace. -extern const char kStackTraceMarker[]; +GTEST_API_ extern const char kStackTraceMarker[]; // A secret type that Google Test users don't know about. It has no // definition on purpose. Therefore it's impossible to create a @@ -157,8 +157,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT #endif // GTEST_ELLIPSIS_NEEDS_POD_ // Appends the user-supplied message to the Google-Test-generated message. -String AppendUserMessage(const String& gtest_msg, - const Message& user_msg); +GTEST_API_ String AppendUserMessage(const String& gtest_msg, + const Message& user_msg); // A helper class for creating scoped traces in user programs. class GTEST_API_ ScopedTrace { @@ -750,7 +750,8 @@ class TypeParameterizedTestCase { // For example, if Foo() calls Bar(), which in turn calls // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. -String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); +GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, + int skip_count); // Helpers for suppressing warnings on unreachable code or constant // condition. @@ -766,7 +767,7 @@ inline bool AlwaysFalse() { return !AlwaysTrue(); } // doesn't use global state (and therefore can't interfere with user // code). Unlike rand_r(), it's portable. An LCG isn't very random, // but it's good enough for our purposes. -class Random { +class GTEST_API_ Random { public: static const UInt32 kMaxRange = 1u << 31; -- cgit v1.2.3 From 2ccea88c99d1ae23383d1b8eb3680a4a4d2edd66 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 10 May 2010 17:11:58 +0000 Subject: Moves the universal printer from gmock to gtest and refactors the cmake script for reusing in gmock (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 289 ++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 31a66e99..dc486017 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -97,6 +97,9 @@ inline void GTestStreamToHelper(std::ostream* os, const T& val) { *os << val; } +class ProtocolMessage; +namespace proto2 { class Message; } + namespace testing { // Forward declaration of classes. @@ -784,6 +787,292 @@ class GTEST_API_ Random { GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); }; +// Defining a variable of type CompileAssertTypesEqual will cause a +// compiler error iff T1 and T2 are different types. +template +struct CompileAssertTypesEqual; + +template +struct CompileAssertTypesEqual { +}; + +// Removes the reference from a type if it is a reference type, +// otherwise leaves it unchanged. This is the same as +// tr1::remove_reference, which is not widely available yet. +template +struct RemoveReference { typedef T type; }; // NOLINT +template +struct RemoveReference { typedef T type; }; // NOLINT + +// A handy wrapper around RemoveReference that works when the argument +// T depends on template parameters. +#define GTEST_REMOVE_REFERENCE_(T) \ + typename ::testing::internal::RemoveReference::type + +// Removes const from a type if it is a const type, otherwise leaves +// it unchanged. This is the same as tr1::remove_const, which is not +// widely available yet. +template +struct RemoveConst { typedef T type; }; // NOLINT +template +struct RemoveConst { typedef T type; }; // NOLINT + +// MSVC 8.0 has a bug which causes the above definition to fail to +// remove the const in 'const int[3]'. The following specialization +// works around the bug. However, it causes trouble with gcc and thus +// needs to be conditionally compiled. +#ifdef _MSC_VER +template +struct RemoveConst { + typedef typename RemoveConst::type type[N]; +}; +#endif // _MSC_VER + +// A handy wrapper around RemoveConst that works when the argument +// T depends on template parameters. +#define GTEST_REMOVE_CONST_(T) \ + typename ::testing::internal::RemoveConst::type + +// Adds reference to a type if it is not a reference type, +// otherwise leaves it unchanged. This is the same as +// tr1::add_reference, which is not widely available yet. +template +struct AddReference { typedef T& type; }; // NOLINT +template +struct AddReference { typedef T& type; }; // NOLINT + +// A handy wrapper around AddReference that works when the argument T +// depends on template parameters. +#define GTEST_ADD_REFERENCE_(T) \ + typename ::testing::internal::AddReference::type + +// Adds a reference to const on top of T as necessary. For example, +// it transforms +// +// char ==> const char& +// const char ==> const char& +// char& ==> const char& +// const char& ==> const char& +// +// The argument T must depend on some template parameters. +#define GTEST_REFERENCE_TO_CONST_(T) \ + GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T)) + +// ImplicitlyConvertible::value is a compile-time bool +// constant that's true iff type From can be implicitly converted to +// type To. +template +class ImplicitlyConvertible { + private: + // We need the following helper functions only for their types. + // They have no implementations. + + // MakeFrom() is an expression whose type is From. We cannot simply + // use From(), as the type From may not have a public default + // constructor. + static From MakeFrom(); + + // These two functions are overloaded. Given an expression + // Helper(x), the compiler will pick the first version if x can be + // implicitly converted to type To; otherwise it will pick the + // second version. + // + // The first version returns a value of size 1, and the second + // version returns a value of size 2. Therefore, by checking the + // size of Helper(x), which can be done at compile time, we can tell + // which version of Helper() is used, and hence whether x can be + // implicitly converted to type To. + static char Helper(To); + static char (&Helper(...))[2]; // NOLINT + + // We have to put the 'public' section after the 'private' section, + // or MSVC refuses to compile the code. + public: + // MSVC warns about implicitly converting from double to int for + // possible loss of data, so we need to temporarily disable the + // warning. +#ifdef _MSC_VER +#pragma warning(push) // Saves the current warning state. +#pragma warning(disable:4244) // Temporarily disables warning 4244. + static const bool value = + sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; +#pragma warning(pop) // Restores the warning state. +#else + static const bool value = + sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; +#endif // _MSV_VER +}; +template +const bool ImplicitlyConvertible::value; + +// IsAProtocolMessage::value is a compile-time bool constant that's +// true iff T is type ProtocolMessage, proto2::Message, or a subclass +// of those. +template +struct IsAProtocolMessage + : public bool_constant< + ImplicitlyConvertible::value || + ImplicitlyConvertible::value> { +}; + +// When the compiler sees expression IsContainerTest(0), the first +// overload of IsContainerTest will be picked if C is an STL-style +// container class (since C::const_iterator* is a valid type and 0 can +// be converted to it), while the second overload will be picked +// otherwise (since C::const_iterator will be an invalid type in this +// case). Therefore, we can determine whether C is a container class +// by checking the type of IsContainerTest(0). The value of the +// expression is insignificant. +typedef int IsContainer; +template +IsContainer IsContainerTest(typename C::const_iterator*) { return 0; } + +typedef char IsNotContainer; +template +IsNotContainer IsContainerTest(...) { return '\0'; } + +// Utilities for native arrays. + +// ArrayEq() compares two k-dimensional native arrays using the +// elements' operator==, where k can be any integer >= 0. When k is +// 0, ArrayEq() degenerates into comparing a single pair of values. + +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs); + +// This generic version is used when k is 0. +template +inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } + +// This overload is used when k >= 1. +template +inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { + return internal::ArrayEq(lhs, N, rhs); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous ArrayEq() function, arrays with different sizes would +// lead to different copies of the template code. +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs) { + for (size_t i = 0; i != size; i++) { + if (!internal::ArrayEq(lhs[i], rhs[i])) + return false; + } + return true; +} + +// Finds the first element in the iterator range [begin, end) that +// equals elem. Element may be a native array type itself. +template +Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { + for (Iter it = begin; it != end; ++it) { + if (internal::ArrayEq(*it, elem)) + return it; + } + return end; +} + +// CopyArray() copies a k-dimensional native array using the elements' +// operator=, where k can be any integer >= 0. When k is 0, +// CopyArray() degenerates into copying a single value. + +template +void CopyArray(const T* from, size_t size, U* to); + +// This generic version is used when k is 0. +template +inline void CopyArray(const T& from, U* to) { *to = from; } + +// This overload is used when k >= 1. +template +inline void CopyArray(const T(&from)[N], U(*to)[N]) { + internal::CopyArray(from, N, *to); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous CopyArray() function, arrays with different sizes +// would lead to different copies of the template code. +template +void CopyArray(const T* from, size_t size, U* to) { + for (size_t i = 0; i != size; i++) { + internal::CopyArray(from[i], to + i); + } +} + +// The relation between an NativeArray object (see below) and the +// native array it represents. +enum RelationToSource { + kReference, // The NativeArray references the native array. + kCopy // The NativeArray makes a copy of the native array and + // owns the copy. +}; + +// Adapts a native array to a read-only STL-style container. Instead +// of the complete STL container concept, this adaptor only implements +// members useful for Google Mock's container matchers. New members +// should be added as needed. To simplify the implementation, we only +// support Element being a raw type (i.e. having no top-level const or +// reference modifier). It's the client's responsibility to satisfy +// this requirement. Element can be an array type itself (hence +// multi-dimensional arrays are supported). +template +class NativeArray { + public: + // STL-style container typedefs. + typedef Element value_type; + typedef const Element* const_iterator; + + // Constructs from a native array. + NativeArray(const Element* array, size_t count, RelationToSource relation) { + Init(array, count, relation); + } + + // Copy constructor. + NativeArray(const NativeArray& rhs) { + Init(rhs.array_, rhs.size_, rhs.relation_to_source_); + } + + ~NativeArray() { + // Ensures that the user doesn't instantiate NativeArray with a + // const or reference type. + static_cast(StaticAssertTypeEqHelper()); + if (relation_to_source_ == kCopy) + delete[] array_; + } + + // STL-style container methods. + size_t size() const { return size_; } + const_iterator begin() const { return array_; } + const_iterator end() const { return array_ + size_; } + bool operator==(const NativeArray& rhs) const { + return size() == rhs.size() && + ArrayEq(begin(), size(), rhs.begin()); + } + + private: + // Initializes this object; makes a copy of the input array if + // 'relation' is kCopy. + void Init(const Element* array, size_t a_size, RelationToSource relation) { + if (relation == kReference) { + array_ = array; + } else { + Element* const copy = new Element[a_size]; + CopyArray(array, a_size, copy); + array_ = copy; + } + size_ = a_size; + relation_to_source_ = relation; + } + + const Element* array_; + size_t size_; + RelationToSource relation_to_source_; + + GTEST_DISALLOW_ASSIGN_(NativeArray); +}; + } // namespace internal } // namespace testing -- cgit v1.2.3 From 61baf319bbb928707a21d78d7ad8fd0bd04e714d Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 10 May 2010 17:23:54 +0000 Subject: Suppresses some Clang warnings (by Chandler Carruth, Jeffrey Yasskin, and Zhanyong Wan). --- include/gtest/internal/gtest-internal.h | 47 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index dc486017..3c5d1f76 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -765,6 +765,15 @@ GTEST_API_ bool AlwaysTrue(); // Always returns false. inline bool AlwaysFalse() { return !AlwaysTrue(); } +// Helper for suppressing false warning from Clang on a const char* +// variable declared in a conditional expression always being NULL in +// the else branch. +struct GTEST_API_ ConstCharPtr { + ConstCharPtr(const char* str) : value(str) {} + operator bool() const { return true; } + const char* value; +}; + // A simple Linear Congruential Generator for generating random // numbers with a uniform distribution. Unlike rand() and srand(), it // doesn't use global state (and therefore can't interfere with user @@ -1097,7 +1106,7 @@ class NativeArray { #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const char* gtest_msg = "") { \ + if (::testing::internal::ConstCharPtr gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ @@ -1106,38 +1115,38 @@ class NativeArray { gtest_caught_expected = true; \ } \ catch (...) { \ - gtest_msg = "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws a different " \ - "type."; \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws a different type."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ if (!gtest_caught_expected) { \ - gtest_msg = "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws nothing."; \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(gtest_msg) + fail(gtest_msg.value) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const char* gtest_msg = "") { \ + if (::testing::internal::AlwaysTrue()) { \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (...) { \ - gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ - " Actual: it throws."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail(gtest_msg) + fail("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws.") #define GTEST_TEST_ANY_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const char* gtest_msg = "") { \ + if (::testing::internal::AlwaysTrue()) { \ bool gtest_caught_any = false; \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ @@ -1146,13 +1155,12 @@ class NativeArray { gtest_caught_any = true; \ } \ if (!gtest_caught_any) { \ - gtest_msg = "Expected: " #statement " throws an exception.\n" \ - " Actual: it doesn't."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ - fail(gtest_msg) + fail("Expected: " #statement " throws an exception.\n" \ + " Actual: it doesn't.") // Implements Boolean test assertions such as EXPECT_TRUE. expression can be @@ -1169,18 +1177,17 @@ class NativeArray { #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const char* gtest_msg = "") { \ + if (::testing::internal::AlwaysTrue()) { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ - gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ - "failures in the current thread.\n" \ - " Actual: it does."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ - fail(gtest_msg) + fail("Expected: " #statement " doesn't generate new fatal " \ + "failures in the current thread.\n" \ + " Actual: it does.") // Expands to the name of the class that implements the given test. #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ -- cgit v1.2.3 From 55d166a2228d7e3b3500b8651ab9b8e56fb43b7e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 17 May 2010 19:31:00 +0000 Subject: Adds GTEST_REMOVE_REFERENCE_AND_CONST_. --- include/gtest/internal/gtest-internal.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 3c5d1f76..bf8412b9 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -842,6 +842,10 @@ struct RemoveConst { #define GTEST_REMOVE_CONST_(T) \ typename ::testing::internal::RemoveConst::type +// Turns const U&, U&, const U, and U all into U. +#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ + GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) + // Adds reference to a type if it is not a reference type, // otherwise leaves it unchanged. This is the same as // tr1::add_reference, which is not widely available yet. @@ -1046,7 +1050,7 @@ class NativeArray { // Ensures that the user doesn't instantiate NativeArray with a // const or reference type. static_cast(StaticAssertTypeEqHelper()); + GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>()); if (relation_to_source_ == kCopy) delete[] array_; } -- cgit v1.2.3 From 985a30360ce4824b65cb35ad55faa0d7c1ad1104 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 8 Jun 2010 22:51:46 +0000 Subject: Adds tests for SkipPrefix(). --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index bf8412b9..b57d0595 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -607,7 +607,7 @@ GTEST_API_ TestInfo* MakeAndRegisterTestInfo( // If *pstr starts with the given prefix, modifies *pstr to be right // past the prefix and returns true; otherwise leaves *pstr unchanged // and returns false. None of pstr, *pstr, and prefix can be NULL. -bool SkipPrefix(const char* prefix, const char** pstr); +GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr); #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P -- cgit v1.2.3 From e2a7f03b80fc0e9e6a6f36acb43776509486a6d4 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 21 Jul 2010 22:15:17 +0000 Subject: Allows EXPECT_EQ to accept arguments that don't have operator << (by Zhanyong Wan). Allows a user to customize how the universal printer prints a pointer of a specific type by overloading << (by Zhanyong Wan). Works around a bug in Cymbian's C++ compiler (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 93 ++++++++++++--------------------- 1 file changed, 34 insertions(+), 59 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index b57d0595..4a20c53c 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -102,7 +102,7 @@ namespace proto2 { class Message; } namespace testing { -// Forward declaration of classes. +// Forward declarations. class AssertionResult; // Result of an assertion. class Message; // Represents a failure message. @@ -111,6 +111,9 @@ class TestInfo; // Information about a test. class TestPartResult; // Result of a test part. class UnitTest; // A collection of test cases. +template +::std::string PrintToString(const T& value); + namespace internal { struct TraceInfo; // Information about a trace point. @@ -192,72 +195,23 @@ class GTEST_API_ ScopedTrace { template String StreamableToString(const T& streamable); -// Formats a value to be used in a failure message. - -#ifdef GTEST_NEEDS_IS_POINTER_ - -// These are needed as the Nokia Symbian and IBM XL C/C++ compilers -// cannot decide between const T& and const T* in a function template. -// These compilers _can_ decide between class template specializations -// for T and T*, so a tr1::type_traits-like is_pointer works, and we -// can overload on that. - -// This overload makes sure that all pointers (including -// those to char or wchar_t) are printed as raw pointers. -template -inline String FormatValueForFailureMessage(internal::true_type /*dummy*/, - T* pointer) { - return StreamableToString(static_cast(pointer)); -} - -template -inline String FormatValueForFailureMessage(internal::false_type /*dummy*/, - const T& value) { - return StreamableToString(value); -} - -template -inline String FormatForFailureMessage(const T& value) { - return FormatValueForFailureMessage( - typename internal::is_pointer::type(), value); -} - -#else - -// These are needed as the above solution using is_pointer has the -// limitation that T cannot be a type without external linkage, when -// compiled using MSVC. - -template -inline String FormatForFailureMessage(const T& value) { - return StreamableToString(value); -} - -// This overload makes sure that all pointers (including -// those to char or wchar_t) are printed as raw pointers. -template -inline String FormatForFailureMessage(T* pointer) { - return StreamableToString(static_cast(pointer)); -} - -#endif // GTEST_NEEDS_IS_POINTER_ - -// These overloaded versions handle narrow and wide characters. -GTEST_API_ String FormatForFailureMessage(char ch); -GTEST_API_ String FormatForFailureMessage(wchar_t wchar); - -// When this operand is a const char* or char*, and the other operand +// When this operand is a const char* or char*, if the other operand // is a ::std::string or ::string, we print this operand as a C string -// rather than a pointer. We do the same for wide strings. +// rather than a pointer (we do the same for wide strings); otherwise +// we print it as a pointer to be safe. // This internal macro is used to avoid duplicated code. +// Making the first operand const reference works around a bug in the +// Symbian compiler which is unable to select the correct specialization of +// FormatForComparisonFailureMessage. #define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ inline String FormatForComparisonFailureMessage(\ - operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ + operand2_type::value_type* const& str, const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ }\ inline String FormatForComparisonFailureMessage(\ - const operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ + const operand2_type::value_type* const& str, \ + const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ } @@ -275,6 +229,27 @@ GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) #undef GTEST_FORMAT_IMPL_ +// The next four overloads handle the case where the operand being +// printed is a char/wchar_t pointer and the other operand is not a +// string/wstring object. In such cases, we just print the operand as +// a pointer to be safe. +// +// Making the first operand const reference works around a bug in the +// Symbian compiler which is unable to select the correct specialization of +// FormatForComparisonFailureMessage. +#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \ + template \ + String FormatForComparisonFailureMessage(CharType* const& p, const T&) { \ + return PrintToString(static_cast(p)); \ + } + +GTEST_FORMAT_CHAR_PTR_IMPL_(char) +GTEST_FORMAT_CHAR_PTR_IMPL_(const char) +GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t) +GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t) + +#undef GTEST_FORMAT_CHAR_PTR_IMPL_ + // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // -- cgit v1.2.3 From 7c598c4f1a44fdda5f97587484c85bef9e93fa98 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 26 Jul 2010 21:59:50 +0000 Subject: Adds ADD_FAILURE_AT (by Zhanyong Wan); disables -Wswitch-default (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 4a20c53c..1e453df6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -1064,10 +1064,13 @@ class NativeArray { } // namespace internal } // namespace testing -#define GTEST_MESSAGE_(message, result_type) \ - ::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, message) \ +#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ + ::testing::internal::AssertHelper(result_type, file, line, message) \ = ::testing::Message() +#define GTEST_MESSAGE_(message, result_type) \ + GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) + #define GTEST_FATAL_FAILURE_(message) \ return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) -- cgit v1.2.3 From 35c39756495bea5959de5778aaaf33a94f8c1e2e Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 31 Aug 2010 18:21:13 +0000 Subject: Casts char to unsigned char before calling isspace() etc to avoid undefined behavior (by Zhanyong Wan); removes conditional #includes keyed on GTEST_HAS_PROTOBUF_ (by Zhanyong Wan); publishes GTEST_HAS_STREAM_REDIRECTION (by Vlad Losev); forward declares some classes properly (by Samuel Benzaquen); honors the --gtest_catch_exceptions flag (by Vlad Losev). --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 1e453df6..9cf9dd84 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -625,7 +625,7 @@ inline const char* SkipComma(const char* str) { if (comma == NULL) { return NULL; } - while (isspace(*(++comma))) {} + while (IsSpace(*(++comma))) {} return comma; } -- cgit v1.2.3 From dac3e879c56a50696a36f53e1e5e353e48fa665f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 14 Sep 2010 05:35:59 +0000 Subject: Include gtest headers as user headers instead of system headers. --- include/gtest/internal/gtest-internal.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 9cf9dd84..33078555 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -37,7 +37,7 @@ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ -#include +#include "gtest/internal/gtest-port.h" #if GTEST_OS_LINUX #include @@ -52,9 +52,9 @@ #include #include -#include -#include -#include +#include "gtest/internal/gtest-string.h" +#include "gtest/internal/gtest-filepath.h" +#include "gtest/internal/gtest-type-util.h" // Due to C++ preprocessor weirdness, we need double indirection to // concatenate two tokens when one of them is __LINE__. Writing -- cgit v1.2.3 From 48b1315108cdba8f37394aedb8098102ca00e8b9 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 10 Jan 2011 18:17:59 +0000 Subject: Fixes GCC 4.6 warnings (patch by Jeffrey Yasskin). --- include/gtest/internal/gtest-internal.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 33078555..2c082382 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -919,6 +919,13 @@ typedef char IsNotContainer; template IsNotContainer IsContainerTest(...) { return '\0'; } +// EnableIf::type is void when 'Cond' is true, and +// undefined when 'Cond' is false. To use SFINAE to make a function +// overload only apply when a particular expression is true, add +// "typename EnableIf::type* = 0" as the last parameter. +template struct EnableIf; +template<> struct EnableIf { typedef void type; }; // NOLINT + // Utilities for native arrays. // ArrayEq() compares two k-dimensional native arrays using the @@ -1182,7 +1189,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ private:\ virtual void TestBody();\ - static ::testing::TestInfo* const test_info_;\ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ GTEST_DISALLOW_COPY_AND_ASSIGN_(\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ };\ -- cgit v1.2.3 From 9bcf4d0a654b27732e2fa901fe98c09aba71773a Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 2 Feb 2011 00:49:33 +0000 Subject: Adds type_param and value_param as attributes to the XML report; also removes the comment() and test_case_comment() fields of TestInfo. Proposed and initally implemented by Joey Oravec. Re-implemented by Vlad Losev. --- include/gtest/internal/gtest-internal.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 2c082382..23fcef78 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -561,10 +561,10 @@ typedef void (*TearDownTestCaseFunc)(); // // test_case_name: name of the test case // name: name of the test -// test_case_comment: a comment on the test case that will be included in -// the test output -// comment: a comment on the test that will be included in the -// test output +// type_param the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param text representation of the test's value parameter, +// or NULL if this is not a type-parameterized test. // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case @@ -573,7 +573,8 @@ typedef void (*TearDownTestCaseFunc)(); // ownership of the factory object. GTEST_API_ TestInfo* MakeAndRegisterTestInfo( const char* test_case_name, const char* name, - const char* test_case_comment, const char* comment, + const char* type_param, + const char* value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, @@ -662,8 +663,8 @@ class TypeParameterizedTest { String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", case_name, index).c_str(), GetPrefixUntilComma(test_names).c_str(), - String::Format("TypeParam = %s", GetTypeName().c_str()).c_str(), - "", + GetTypeName().c_str(), + NULL, // No value parameter. GetTypeId(), TestClass::SetUpTestCase, TestClass::TearDownTestCase, @@ -1197,7 +1198,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ ::test_info_ =\ ::testing::internal::MakeAndRegisterTestInfo(\ - #test_case_name, #test_name, "", "", \ + #test_case_name, #test_name, NULL, NULL, \ (parent_id), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ -- cgit v1.2.3 From 9d7455f9844e293dff8b7902f0c2553094f2f976 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Wed, 2 Feb 2011 10:07:04 +0000 Subject: Adds null check for file locations in XML output printer. --- include/gtest/internal/gtest-internal.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 23fcef78..9f890faa 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -536,20 +536,6 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, #endif // GTEST_OS_WINDOWS -// Formats a source file path and a line number as they would appear -// in a compiler error message. -inline String FormatFileLocation(const char* file, int line) { - const char* const file_name = file == NULL ? "unknown file" : file; - if (line < 0) { - return String::Format("%s:", file_name); - } -#ifdef _MSC_VER - return String::Format("%s(%d):", file_name, line); -#else - return String::Format("%s:%d:", file_name, line); -#endif // _MSC_VER -} - // Types of SetUpTestCase() and TearDownTestCase() functions. typedef void (*SetUpTestCaseFunc)(); typedef void (*TearDownTestCaseFunc)(); -- cgit v1.2.3 From ffeb11d14a890b902dbb26ff2296cda7bf2d31df Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 22 Feb 2011 22:08:59 +0000 Subject: Indents preprocessor directives. --- include/gtest/internal/gtest-internal.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 9f890faa..db098a49 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -40,10 +40,10 @@ #include "gtest/internal/gtest-port.h" #if GTEST_OS_LINUX -#include -#include -#include -#include +# include +# include +# include +# include #endif // GTEST_OS_LINUX #include @@ -156,9 +156,9 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT #ifdef GTEST_ELLIPSIS_NEEDS_POD_ // We lose support for NULL detection where the compiler doesn't like // passing non-POD classes through ellipsis (...). -#define GTEST_IS_NULL_LITERAL_(x) false +# define GTEST_IS_NULL_LITERAL_(x) false #else -#define GTEST_IS_NULL_LITERAL_(x) \ +# define GTEST_IS_NULL_LITERAL_(x) \ (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) #endif // GTEST_ELLIPSIS_NEEDS_POD_ @@ -867,11 +867,12 @@ class ImplicitlyConvertible { // possible loss of data, so we need to temporarily disable the // warning. #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4244) // Temporarily disables warning 4244. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4244) // Temporarily disables warning 4244. + static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #else static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; -- cgit v1.2.3 From 603533a0a4dcfc2ef33051b9ae8237568a19adc4 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Sat, 5 Mar 2011 08:04:01 +0000 Subject: Fixes compatibility with Borland C++Builder. Original patch by Josh Kelley. Simplified by Zhanyong Wan. --- include/gtest/internal/gtest-internal.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index db098a49..947b1625 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -873,6 +873,11 @@ class ImplicitlyConvertible { static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; # pragma warning(pop) // Restores the warning state. +#elif defined(__BORLANDC__) + // C++Builder cannot use member overload resolution during template + // instantiation. The simplest workaround is to use its C++0x type traits + // functions (C++Builder 2009 and above only). + static const bool value = __is_convertible(From, To); #else static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; -- cgit v1.2.3 From 5451ffe816cafe4f0f51813eb8ddedb3543f0fea Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 9 Mar 2011 01:13:19 +0000 Subject: Makes IsContainerTest compatible with Sun C++ and Visual Age C++, based on Hady Zalek's report and experiment; also fixes a bug that causes it to think that a class named const_iterator is a container; also clarifies the Borland C++ compatibility fix in the comments based on Josh Kelley's suggestion. --- include/gtest/internal/gtest-internal.h | 38 ++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 947b1625..cfa3885c 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -896,21 +896,38 @@ struct IsAProtocolMessage ImplicitlyConvertible::value> { }; -// When the compiler sees expression IsContainerTest(0), the first -// overload of IsContainerTest will be picked if C is an STL-style -// container class (since C::const_iterator* is a valid type and 0 can -// be converted to it), while the second overload will be picked -// otherwise (since C::const_iterator will be an invalid type in this -// case). Therefore, we can determine whether C is a container class -// by checking the type of IsContainerTest(0). The value of the -// expression is insignificant. +// When the compiler sees expression IsContainerTest(0), if C is an +// STL-style container class, the first overload of IsContainerTest +// will be viable (since both C::iterator* and C::const_iterator* are +// valid types and NULL can be implicitly converted to them). It will +// be picked over the second overload as 'int' is a perfect match for +// the type of argument 0. If C::iterator or C::const_iterator is not +// a valid type, the first overload is not viable, and the second +// overload will be picked. Therefore, we can determine whether C is +// a container class by checking the type of IsContainerTest(0). +// The value of the expression is insignificant. +// +// Note that we look for both C::iterator and C::const_iterator. The +// reason is that C++ injects the name of a class as a member of the +// class itself (e.g. you can refer to class iterator as either +// 'iterator' or 'iterator::iterator'). If we look for C::iterator +// only, for example, we would mistakenly think that a class named +// iterator is an STL container. +// +// Also note that the simpler approach of overloading +// IsContainerTest(typename C::const_iterator*) and +// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++. typedef int IsContainer; template -IsContainer IsContainerTest(typename C::const_iterator*) { return 0; } +IsContainer IsContainerTest(int /* dummy */, + typename C::iterator* /* it */ = NULL, + typename C::const_iterator* /* const_it */ = NULL) { + return 0; +} typedef char IsNotContainer; template -IsNotContainer IsContainerTest(...) { return '\0'; } +IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } // EnableIf::type is void when 'Cond' is true, and // undefined when 'Cond' is false. To use SFINAE to make a function @@ -1009,6 +1026,7 @@ class NativeArray { public: // STL-style container typedefs. typedef Element value_type; + typedef Element* iterator; typedef const Element* const_iterator; // Constructs from a native array. -- cgit v1.2.3 From 5017fe0090e8902d028ba38753c00d73f16d83f0 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 11 Mar 2011 23:05:00 +0000 Subject: Fixes compatibility with Sun C++ (by Hady Zalek); fixes compatibility with Android (by Zachary Vorhies). --- include/gtest/internal/gtest-internal.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index cfa3885c..fcf4c717 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -788,16 +788,16 @@ struct RemoveConst { typedef T type; }; // NOLINT template struct RemoveConst { typedef T type; }; // NOLINT -// MSVC 8.0 has a bug which causes the above definition to fail to -// remove the const in 'const int[3]'. The following specialization -// works around the bug. However, it causes trouble with gcc and thus -// needs to be conditionally compiled. -#ifdef _MSC_VER +// MSVC 8.0 and Sun C++ have a bug which causes the above definition +// to fail to remove the const in 'const int[3]'. The following +// specialization works around the bug. However, it causes trouble +// with GCC and thus needs to be conditionally compiled. +#if defined(_MSC_VER) || defined(__SUNPRO_CC) template struct RemoveConst { typedef typename RemoveConst::type type[N]; }; -#endif // _MSC_VER +#endif // A handy wrapper around RemoveConst that works when the argument // T depends on template parameters. -- cgit v1.2.3 From 6323646e196fc0c9a7ef5c67143acf2180ec906f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 8 Apr 2011 02:42:59 +0000 Subject: fixes XL C++ compiler errors (by Pasi Valminen) --- include/gtest/internal/gtest-internal.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index fcf4c717..cd6fd79b 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -788,13 +788,14 @@ struct RemoveConst { typedef T type; }; // NOLINT template struct RemoveConst { typedef T type; }; // NOLINT -// MSVC 8.0 and Sun C++ have a bug which causes the above definition -// to fail to remove the const in 'const int[3]'. The following -// specialization works around the bug. However, it causes trouble -// with GCC and thus needs to be conditionally compiled. -#if defined(_MSC_VER) || defined(__SUNPRO_CC) +// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above +// definition to fail to remove the const in 'const int[3]' and 'const +// char[3][4]'. The following specialization works around the bug. +// However, it causes trouble with GCC and thus needs to be +// conditionally compiled. +#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__) template -struct RemoveConst { +struct RemoveConst { typedef typename RemoveConst::type type[N]; }; #endif -- cgit v1.2.3 From c91a353c47ea13244550037918ff8dc423063012 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 15 Apr 2011 19:50:39 +0000 Subject: Fixes XL C++ 10.1 compiler errors (based on patch by Hady Zalek); cleans up formatting of GTEST_NO_INLINE_. --- include/gtest/internal/gtest-internal.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index cd6fd79b..7aa1197f 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -195,22 +195,31 @@ class GTEST_API_ ScopedTrace { template String StreamableToString(const T& streamable); +// The Symbian compiler has a bug that prevents it from selecting the +// correct overload of FormatForComparisonFailureMessage (see below) +// unless we pass the first argument by reference. If we do that, +// however, Visual Age C++ 10.1 generates a compiler error. Therefore +// we only apply the work-around for Symbian. +#if defined(__SYMBIAN32__) +# define GTEST_CREF_WORKAROUND_ const& +#else +# define GTEST_CREF_WORKAROUND_ +#endif + // When this operand is a const char* or char*, if the other operand // is a ::std::string or ::string, we print this operand as a C string // rather than a pointer (we do the same for wide strings); otherwise // we print it as a pointer to be safe. // This internal macro is used to avoid duplicated code. -// Making the first operand const reference works around a bug in the -// Symbian compiler which is unable to select the correct specialization of -// FormatForComparisonFailureMessage. #define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ inline String FormatForComparisonFailureMessage(\ - operand2_type::value_type* const& str, const operand2_type& /*operand2*/) {\ + operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ + const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ }\ inline String FormatForComparisonFailureMessage(\ - const operand2_type::value_type* const& str, \ + const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ const operand2_type& /*operand2*/) {\ return operand1_printer(str);\ } @@ -233,13 +242,10 @@ GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) // printed is a char/wchar_t pointer and the other operand is not a // string/wstring object. In such cases, we just print the operand as // a pointer to be safe. -// -// Making the first operand const reference works around a bug in the -// Symbian compiler which is unable to select the correct specialization of -// FormatForComparisonFailureMessage. #define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \ template \ - String FormatForComparisonFailureMessage(CharType* const& p, const T&) { \ + String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \ + const T&) { \ return PrintToString(static_cast(p)); \ } -- cgit v1.2.3 From ee2f8caecc3199c8fdb03d07f0c6c653334f75b3 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 12 May 2011 17:32:42 +0000 Subject: Simplifies the code by removing condfitional section that is no longer necessary. --- include/gtest/internal/gtest-internal.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 7aa1197f..227d8189 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -797,14 +797,10 @@ struct RemoveConst { typedef T type; }; // NOLINT // MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above // definition to fail to remove the const in 'const int[3]' and 'const // char[3][4]'. The following specialization works around the bug. -// However, it causes trouble with GCC and thus needs to be -// conditionally compiled. -#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__) template struct RemoveConst { typedef typename RemoveConst::type type[N]; }; -#endif // A handy wrapper around RemoveConst that works when the argument // T depends on template parameters. -- cgit v1.2.3 From 7e29bb7f7ebc2a1734415cb64395d87fc87d12be Mon Sep 17 00:00:00 2001 From: vladlosev Date: Fri, 20 May 2011 00:38:55 +0000 Subject: Adds support for building Google Mock as a shared library (DLL). --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 227d8189..d0fe5f79 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -122,7 +122,7 @@ class TestInfoImpl; // Opaque implementation of TestInfo class UnitTestImpl; // Opaque implementation of UnitTest // How many times InitGoogleTest() has been called. -extern int g_init_gtest_count; +GTEST_API_ extern int g_init_gtest_count; // The text used in failure messages to indicate the start of the // stack trace. -- cgit v1.2.3 From cc265df8b44e613ca118ce5da145f91d66f6c440 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Mon, 13 Jun 2011 19:00:37 +0000 Subject: Fixes broken build on VC++ 7.1. --- include/gtest/internal/gtest-internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d0fe5f79..d8834500 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -802,6 +802,16 @@ struct RemoveConst { typedef typename RemoveConst::type type[N]; }; +#if defined(_MSC_VER) && _MSC_VER < 1400 +// This is the only specialization that allows VC++ 7.1 to remove const in +// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC +// and thus needs to be conditionally compiled. +template +struct RemoveConst { + typedef typename RemoveConst::type type[N]; +}; +#endif + // A handy wrapper around RemoveConst that works when the argument // T depends on template parameters. #define GTEST_REMOVE_CONST_(T) \ -- cgit v1.2.3 From a88c9a88e49e90ec414175543b2b7ff2f70866a7 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 7 Jun 2012 20:34:34 +0000 Subject: Improves gtest's failure messages. In particulars, char pointers and char arrays are not escapped properly. --- include/gtest/internal/gtest-internal.h | 61 --------------------------------- 1 file changed, 61 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index d8834500..a4d18396 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -195,67 +195,6 @@ class GTEST_API_ ScopedTrace { template String StreamableToString(const T& streamable); -// The Symbian compiler has a bug that prevents it from selecting the -// correct overload of FormatForComparisonFailureMessage (see below) -// unless we pass the first argument by reference. If we do that, -// however, Visual Age C++ 10.1 generates a compiler error. Therefore -// we only apply the work-around for Symbian. -#if defined(__SYMBIAN32__) -# define GTEST_CREF_WORKAROUND_ const& -#else -# define GTEST_CREF_WORKAROUND_ -#endif - -// When this operand is a const char* or char*, if the other operand -// is a ::std::string or ::string, we print this operand as a C string -// rather than a pointer (we do the same for wide strings); otherwise -// we print it as a pointer to be safe. - -// This internal macro is used to avoid duplicated code. -#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ -inline String FormatForComparisonFailureMessage(\ - operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ - const operand2_type& /*operand2*/) {\ - return operand1_printer(str);\ -}\ -inline String FormatForComparisonFailureMessage(\ - const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \ - const operand2_type& /*operand2*/) {\ - return operand1_printer(str);\ -} - -GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) -#if GTEST_HAS_STD_WSTRING -GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted) -#endif // GTEST_HAS_STD_WSTRING - -#if GTEST_HAS_GLOBAL_STRING -GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted) -#endif // GTEST_HAS_GLOBAL_STRING -#if GTEST_HAS_GLOBAL_WSTRING -GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) -#endif // GTEST_HAS_GLOBAL_WSTRING - -#undef GTEST_FORMAT_IMPL_ - -// The next four overloads handle the case where the operand being -// printed is a char/wchar_t pointer and the other operand is not a -// string/wstring object. In such cases, we just print the operand as -// a pointer to be safe. -#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \ - template \ - String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \ - const T&) { \ - return PrintToString(static_cast(p)); \ - } - -GTEST_FORMAT_CHAR_PTR_IMPL_(char) -GTEST_FORMAT_CHAR_PTR_IMPL_(const char) -GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t) -GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t) - -#undef GTEST_FORMAT_CHAR_PTR_IMPL_ - // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // -- cgit v1.2.3 From b535c1767e7ec4e9675bb7257d9bc34a84949741 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 6 Sep 2012 17:09:27 +0000 Subject: Removes obsolete debug code. --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index a4d18396..ede95f50 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -73,7 +73,7 @@ // This allows a user to use his own types in Google Test assertions by // overloading the << operator. // -// util/gtl/stl_logging-inl.h overloads << for STL containers. These +// util/gtl/stl_logging.h overloads << for STL containers. These // overloads cannot be defined in the std namespace, as that will be // undefined behavior. Therefore, they are defined in the global // namespace instead. -- cgit v1.2.3 From 87fdda2cf24d953f3cbec1e0c266b2db9928f406 Mon Sep 17 00:00:00 2001 From: jgm Date: Thu, 15 Nov 2012 15:47:38 +0000 Subject: Unfortunately, the svn repo is a bit out of date. This commit contains 8 changes that haven't made it to svn. The descriptions of each change are listed below. - Fixes some python shebang lines. - Add ElementsAreArray overloads to gmock. ElementsAreArray now makes a copy of its input elements before the conversion to a Matcher. ElementsAreArray can now take a vector as input. ElementsAreArray can now take an iterator pair as input. - Templatize MatchAndExplain to allow independent string types for the matcher and matchee. I also templatized the ConstCharPointer version of MatchAndExplain to avoid calls with "char*" from using the new templated MatchAndExplain. - Fixes the bug where the constructor of the return type of ElementsAre() saves a reference instead of a copy of the arguments. - Extends ElementsAre() to accept arrays whose sizes aren't known. - Switches gTest's internal FilePath class from testing::internal::String to std::string. testing::internal::String was introduced when gTest couldn't depend on std::string. It's now deprecated. - Switches gTest & gMock from using testing::internal::String objects to std::string. Some static methods of String are still in use. We may be able to remove some but not all of them. In particular, String::Format() should eventually be removed as it truncates the result at 4096 characters, often causing problems. --- include/gtest/internal/gtest-internal.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ede95f50..6e3dd66b 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -163,8 +163,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT #endif // GTEST_ELLIPSIS_NEEDS_POD_ // Appends the user-supplied message to the Google-Test-generated message. -GTEST_API_ String AppendUserMessage(const String& gtest_msg, - const Message& user_msg); +GTEST_API_ std::string AppendUserMessage( + const std::string& gtest_msg, const Message& user_msg); // A helper class for creating scoped traces in user programs. class GTEST_API_ ScopedTrace { @@ -185,7 +185,7 @@ class GTEST_API_ ScopedTrace { // c'tor and d'tor. Therefore it doesn't // need to be used otherwise. -// Converts a streamable value to a String. A NULL pointer is +// Converts a streamable value to an std::string. A NULL pointer is // converted to "(null)". When the input value is a ::string, // ::std::string, ::wstring, or ::std::wstring object, each NUL // character in it is replaced with "\\0". @@ -193,7 +193,7 @@ class GTEST_API_ ScopedTrace { // to the definition of the Message class, required by the ARM // compiler. template -String StreamableToString(const T& streamable); +std::string StreamableToString(const T& streamable); // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. @@ -212,12 +212,12 @@ String StreamableToString(const T& streamable); // be inserted into the message. GTEST_API_ AssertionResult EqFailure(const char* expected_expression, const char* actual_expression, - const String& expected_value, - const String& actual_value, + const std::string& expected_value, + const std::string& actual_value, bool ignoring_case); // Constructs a failure message for Boolean assertions such as EXPECT_TRUE. -GTEST_API_ String GetBoolAssertionFailureMessage( +GTEST_API_ std::string GetBoolAssertionFailureMessage( const AssertionResult& assertion_result, const char* expression_text, const char* actual_predicate_value, @@ -563,9 +563,9 @@ inline const char* SkipComma(const char* str) { // Returns the prefix of 'str' before the first comma in it; returns // the entire string if it contains no comma. -inline String GetPrefixUntilComma(const char* str) { +inline std::string GetPrefixUntilComma(const char* str) { const char* comma = strchr(str, ','); - return comma == NULL ? String(str) : String(str, comma - str); + return comma == NULL ? str : std::string(str, comma); } // TypeParameterizedTest::Register() @@ -650,7 +650,7 @@ class TypeParameterizedTestCase { #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P -// Returns the current OS stack trace as a String. +// Returns the current OS stack trace as an std::string. // // The maximum number of stack frames to be included is specified by // the gtest_stack_trace_depth flag. The skip_count parameter @@ -660,8 +660,8 @@ class TypeParameterizedTestCase { // For example, if Foo() calls Bar(), which in turn calls // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. -GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, - int skip_count); +GTEST_API_ std::string GetCurrentOsStackTraceExceptTop( + UnitTest* unit_test, int skip_count); // Helpers for suppressing warnings on unreachable code or constant // condition. -- cgit v1.2.3 From 65b5c22436fab922ea791b9b39a8fe154f0849f8 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Sat, 2 Feb 2013 18:45:13 +0000 Subject: Fixes an out-dated URL. --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 6e3dd66b..4e57d3ca 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -292,7 +292,7 @@ class FloatingPoint { // bits. Therefore, 4 should be enough for ordinary use. // // See the following article for more details on ULP: - // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm. + // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ static const size_t kMaxUlps = 4; // Constructs a FloatingPoint from a raw floating-point number. -- cgit v1.2.3 From cc1fdb58caf8d5ac9b858f615d3c42267fc5e258 Mon Sep 17 00:00:00 2001 From: kosak Date: Fri, 22 Feb 2013 20:10:40 +0000 Subject: Removes testing::internal::String::Format(), which causes problems as it truncates the result at 4096 chars. Also update an obsolete link in comment. --- include/gtest/internal/gtest-internal.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 4e57d3ca..ca4e1fdb 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -493,7 +493,7 @@ typedef void (*TearDownTestCaseFunc)(); // test_case_name: name of the test case // name: name of the test // type_param the name of the test's type parameter, or NULL if -// this is not a typed or a type-parameterized test. +// this is not a typed or a type-parameterized test. // value_param text representation of the test's value parameter, // or NULL if this is not a type-parameterized test. // fixture_class_id: ID of the test fixture class @@ -503,7 +503,8 @@ typedef void (*TearDownTestCaseFunc)(); // The newly created TestInfo instance will assume // ownership of the factory object. GTEST_API_ TestInfo* MakeAndRegisterTestInfo( - const char* test_case_name, const char* name, + const char* test_case_name, + const char* name, const char* type_param, const char* value_param, TypeId fixture_class_id, @@ -591,8 +592,8 @@ class TypeParameterizedTest { // First, registers the first type-parameterized test in the type // list. MakeAndRegisterTestInfo( - String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", - case_name, index).c_str(), + (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/" + + StreamableToString(index)).c_str(), GetPrefixUntilComma(test_names).c_str(), GetTypeName().c_str(), NULL, // No value parameter. -- cgit v1.2.3 From 1b89db97058ced81a116d6a03714fec9bd8fc721 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 28 Feb 2013 22:55:25 +0000 Subject: Removes an unused variable; also refactors to support an up-coming googlemock change. --- include/gtest/internal/gtest-internal.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ca4e1fdb..892ddecd 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -46,6 +46,10 @@ # include #endif // GTEST_OS_LINUX +#if GTEST_HAS_EXCEPTIONS +# include +#endif + #include #include #include @@ -166,6 +170,21 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT GTEST_API_ std::string AppendUserMessage( const std::string& gtest_msg, const Message& user_msg); +#if GTEST_HAS_EXCEPTIONS + +// This exception is thrown by (and only by) a failed Google Test +// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions +// are enabled). We derive it from std::runtime_error, which is for +// errors presumably detectable only at run time. Since +// std::runtime_error inherits from std::exception, many testing +// frameworks know how to extract and print the message inside it. +class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error { + public: + explicit GoogleTestFailureException(const TestPartResult& failure); +}; + +#endif // GTEST_HAS_EXCEPTIONS + // A helper class for creating scoped traces in user programs. class GTEST_API_ ScopedTrace { public: -- cgit v1.2.3 From 6a036a5c8c7613e888fad39d92fc3fd84a96fbc7 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 28 Feb 2013 23:46:07 +0000 Subject: Fixes a nasty issue in gtest's template instantiation. --- include/gtest/internal/gtest-internal.h | 46 +-------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 892ddecd..16047258 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -56,6 +56,7 @@ #include #include +#include "gtest/gtest-message.h" #include "gtest/internal/gtest-string.h" #include "gtest/internal/gtest-filepath.h" #include "gtest/internal/gtest-type-util.h" @@ -71,36 +72,6 @@ #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar -// Google Test defines the testing::Message class to allow construction of -// test messages via the << operator. The idea is that anything -// streamable to std::ostream can be streamed to a testing::Message. -// This allows a user to use his own types in Google Test assertions by -// overloading the << operator. -// -// util/gtl/stl_logging.h overloads << for STL containers. These -// overloads cannot be defined in the std namespace, as that will be -// undefined behavior. Therefore, they are defined in the global -// namespace instead. -// -// C++'s symbol lookup rule (i.e. Koenig lookup) says that these -// overloads are visible in either the std namespace or the global -// namespace, but not other namespaces, including the testing -// namespace which Google Test's Message class is in. -// -// To allow STL containers (and other types that has a << operator -// defined in the global namespace) to be used in Google Test assertions, -// testing::Message must access the custom << operator from the global -// namespace. Hence this helper function. -// -// Note: Jeffrey Yasskin suggested an alternative fix by "using -// ::operator<<;" in the definition of Message's operator<<. That fix -// doesn't require a helper function, but unfortunately doesn't -// compile with MSVC. -template -inline void GTestStreamToHelper(std::ostream* os, const T& val) { - *os << val; -} - class ProtocolMessage; namespace proto2 { class Message; } @@ -132,11 +103,6 @@ GTEST_API_ extern int g_init_gtest_count; // stack trace. GTEST_API_ extern const char kStackTraceMarker[]; -// A secret type that Google Test users don't know about. It has no -// definition on purpose. Therefore it's impossible to create a -// Secret object, which is what we want. -class Secret; - // Two overloaded helpers for checking at compile time whether an // expression is a null pointer literal (i.e. NULL or any 0-valued // compile-time integral constant). Their return values have @@ -204,16 +170,6 @@ class GTEST_API_ ScopedTrace { // c'tor and d'tor. Therefore it doesn't // need to be used otherwise. -// Converts a streamable value to an std::string. A NULL pointer is -// converted to "(null)". When the input value is a ::string, -// ::std::string, ::wstring, or ::std::wstring object, each NUL -// character in it is replaced with "\\0". -// Declared here but defined in gtest.h, so that it has access -// to the definition of the Message class, required by the ARM -// compiler. -template -std::string StreamableToString(const T& streamable); - // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // -- cgit v1.2.3 From 2d3543f81d6d4583332f8b60768ade18e0f96220 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 18 Sep 2013 17:49:56 +0000 Subject: avoids clash with the max() macro on Windows --- include/gtest/internal/gtest-internal.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 16047258..0dcc3a31 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -51,6 +51,7 @@ #endif #include +#include #include #include #include @@ -294,6 +295,9 @@ class FloatingPoint { return ReinterpretBits(kExponentBitMask); } + // Returns the maximum representable finite floating-point number. + static RawType Max(); + // Non-static methods // Returns the bits that represents this number. @@ -374,6 +378,13 @@ class FloatingPoint { FloatingPointUnion u_; }; +// We cannot use std::numeric_limits::max() as it clashes with the max() +// macro defined by . +template <> +inline float FloatingPoint::Max() { return FLT_MAX; } +template <> +inline double FloatingPoint::Max() { return DBL_MAX; } + // Typedefs the instances of the FloatingPoint template class that we // care to use. typedef FloatingPoint Float; -- cgit v1.2.3 From aa34ae250800af7e98499abba44636503cf99b16 Mon Sep 17 00:00:00 2001 From: kosak Date: Tue, 3 Dec 2013 01:36:29 +0000 Subject: Delete whitespace, and change the return type of ImplicitlyConvertible::MakeFrom() to From&. --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 0dcc3a31..f58f65f6 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -784,7 +784,7 @@ class ImplicitlyConvertible { // MakeFrom() is an expression whose type is From. We cannot simply // use From(), as the type From may not have a public default // constructor. - static From MakeFrom(); + static typename AddReference::type MakeFrom(); // These two functions are overloaded. Given an expression // Helper(x), the compiler will pick the first version if x can be -- cgit v1.2.3 From 8120f66c3249e253f03fdb48bee7e528bc038d31 Mon Sep 17 00:00:00 2001 From: billydonahue Date: Thu, 15 May 2014 19:42:15 +0000 Subject: Push upstream to SVN. --- include/gtest/internal/gtest-internal.h | 79 +++++++++++++++++---------------- 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index f58f65f6..ff8f6298 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -802,25 +802,20 @@ class ImplicitlyConvertible { // We have to put the 'public' section after the 'private' section, // or MSVC refuses to compile the code. public: - // MSVC warns about implicitly converting from double to int for - // possible loss of data, so we need to temporarily disable the - // warning. -#ifdef _MSC_VER -# pragma warning(push) // Saves the current warning state. -# pragma warning(disable:4244) // Temporarily disables warning 4244. - - static const bool value = - sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; -# pragma warning(pop) // Restores the warning state. -#elif defined(__BORLANDC__) +#if defined(__BORLANDC__) // C++Builder cannot use member overload resolution during template // instantiation. The simplest workaround is to use its C++0x type traits // functions (C++Builder 2009 and above only). static const bool value = __is_convertible(From, To); #else + // MSVC warns about implicitly converting from double to int for + // possible loss of data, so we need to temporarily disable the + // warning. + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244) static const bool value = sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; -#endif // _MSV_VER + GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif // __BORLANDC__ }; template const bool ImplicitlyConvertible::value; @@ -946,11 +941,10 @@ void CopyArray(const T* from, size_t size, U* to) { // The relation between an NativeArray object (see below) and the // native array it represents. -enum RelationToSource { - kReference, // The NativeArray references the native array. - kCopy // The NativeArray makes a copy of the native array and - // owns the copy. -}; +// We use 2 different structs to allow non-copyable types to be used, as long +// as RelationToSourceReference() is passed. +struct RelationToSourceReference {}; +struct RelationToSourceCopy {}; // Adapts a native array to a read-only STL-style container. Instead // of the complete STL container concept, this adaptor only implements @@ -968,22 +962,23 @@ class NativeArray { typedef Element* iterator; typedef const Element* const_iterator; - // Constructs from a native array. - NativeArray(const Element* array, size_t count, RelationToSource relation) { - Init(array, count, relation); + // Constructs from a native array. References the source. + NativeArray(const Element* array, size_t count, RelationToSourceReference) { + InitRef(array, count); + } + + // Constructs from a native array. Copies the source. + NativeArray(const Element* array, size_t count, RelationToSourceCopy) { + InitCopy(array, count); } // Copy constructor. NativeArray(const NativeArray& rhs) { - Init(rhs.array_, rhs.size_, rhs.relation_to_source_); + (this->*rhs.clone_)(rhs.array_, rhs.size_); } ~NativeArray() { - // Ensures that the user doesn't instantiate NativeArray with a - // const or reference type. - static_cast(StaticAssertTypeEqHelper()); - if (relation_to_source_ == kCopy) + if (clone_ != &NativeArray::InitRef) delete[] array_; } @@ -997,23 +992,30 @@ class NativeArray { } private: - // Initializes this object; makes a copy of the input array if - // 'relation' is kCopy. - void Init(const Element* array, size_t a_size, RelationToSource relation) { - if (relation == kReference) { - array_ = array; - } else { - Element* const copy = new Element[a_size]; - CopyArray(array, a_size, copy); - array_ = copy; - } + enum { + kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper< + Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value, + }; + + // Initializes this object with a copy of the input. + void InitCopy(const Element* array, size_t a_size) { + Element* const copy = new Element[a_size]; + CopyArray(array, a_size, copy); + array_ = copy; size_ = a_size; - relation_to_source_ = relation; + clone_ = &NativeArray::InitCopy; + } + + // Initializes this object with a reference of the input. + void InitRef(const Element* array, size_t a_size) { + array_ = array; + size_ = a_size; + clone_ = &NativeArray::InitRef; } const Element* array_; size_t size_; - RelationToSource relation_to_source_; + void (NativeArray::*clone_)(const Element*, size_t); GTEST_DISALLOW_ASSIGN_(NativeArray); }; @@ -1156,3 +1158,4 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ + -- cgit v1.2.3 From b54098a9abade957ab3c4e94ae5e5225ef0015a4 Mon Sep 17 00:00:00 2001 From: kosak Date: Mon, 28 Jul 2014 21:54:50 +0000 Subject: Expand equality failure messages with a by-line diff. --- include/gtest/internal/gtest-internal.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ff8f6298..21a0f567 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include "gtest/gtest-message.h" #include "gtest/internal/gtest-string.h" @@ -171,6 +173,36 @@ class GTEST_API_ ScopedTrace { // c'tor and d'tor. Therefore it doesn't // need to be used otherwise. +namespace edit_distance { +// Returns the optimal edits to go from 'left' to 'right'. +// All edits cost the same, with replace having lower priority than +// add/remove. +// Simple implementation of the Wagner–Fischer algorithm. +// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm +enum EditType { kMatch, kAdd, kRemove, kReplace }; +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, const std::vector& right); + +// Same as above, but the input is represented as strings. +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, + const std::vector& right); + +// Create a diff of the input strings in Unified diff format. +GTEST_API_ std::string CreateUnifiedDiff(const std::vector& left, + const std::vector& right, + size_t context = 2); + +} // namespace edit_distance + +// Calculate the diff between 'left' and 'right' and return it in unified diff +// format. +// If not null, stores in 'total_line_count' the total number of lines found +// in left + right. +GTEST_API_ std::string DiffStrings(const std::string& left, + const std::string& right, + size_t* total_line_count); + // Constructs and returns the message for an equality assertion // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // -- cgit v1.2.3 From e330b754cbd4b23a160521e05ff1014ed576378b Mon Sep 17 00:00:00 2001 From: kosak Date: Mon, 17 Nov 2014 02:28:09 +0000 Subject: Strip trailing whitespace when stringifying type lists. --- include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 21a0f567..ba7175cf 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -612,7 +612,7 @@ class TypeParameterizedTest { MakeAndRegisterTestInfo( (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/" + StreamableToString(index)).c_str(), - GetPrefixUntilComma(test_names).c_str(), + StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), GetTypeName().c_str(), NULL, // No value parameter. GetTypeId(), -- cgit v1.2.3 From 195610d30c2234b76bef70a85426ac8d7dbdf9f3 Mon Sep 17 00:00:00 2001 From: kosak Date: Fri, 17 Jul 2015 21:56:19 +0000 Subject: Add support for --gtest_flagfile --- include/gtest/internal/gtest-internal.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ba7175cf..b48075c5 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -587,6 +587,11 @@ inline std::string GetPrefixUntilComma(const char* str) { return comma == NULL ? str : std::string(str, comma); } +// Splits a given string on a given delimiter, populating a given +// vector with the fields. +void SplitString(const ::std::string& str, char delimiter, + ::std::vector< ::std::string>* dest); + // TypeParameterizedTest::Register() // registers a list of type-parameterized tests with Google Test. The // return value is insignificant - we just need to return something -- cgit v1.2.3 From 4f8dc917ebce062f75defee3d4890bbcd07e277b Mon Sep 17 00:00:00 2001 From: kosak Date: Fri, 17 Jul 2015 22:11:58 +0000 Subject: Add support for --gtest_flagfile. --- include/gtest/internal/gtest-internal.h | 69 ++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index b48075c5..ee2dc4a1 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -503,6 +504,13 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, typedef void (*SetUpTestCaseFunc)(); typedef void (*TearDownTestCaseFunc)(); +struct CodeLocation { + CodeLocation(const string& a_file, int a_line) : file(a_file), line(a_line) {} + + string file; + int line; +}; + // Creates a new TestInfo object and registers it with Google Test; // returns the created object. // @@ -514,6 +522,7 @@ typedef void (*TearDownTestCaseFunc)(); // this is not a typed or a type-parameterized test. // value_param text representation of the test's value parameter, // or NULL if this is not a type-parameterized test. +// code_location: code location where the test is defined // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case @@ -525,6 +534,7 @@ GTEST_API_ TestInfo* MakeAndRegisterTestInfo( const char* name, const char* type_param, const char* value_param, + CodeLocation code_location, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, @@ -554,10 +564,21 @@ class GTEST_API_ TypedTestCasePState { fflush(stderr); posix::Abort(); } - defined_test_names_.insert(test_name); + registered_tests_.insert( + ::std::make_pair(test_name, CodeLocation(file, line))); return true; } + bool TestExists(const std::string& test_name) const { + return registered_tests_.count(test_name) > 0; + } + + const CodeLocation& GetCodeLocation(const std::string& test_name) const { + RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name); + GTEST_CHECK_(it != registered_tests_.end()); + return it->second; + } + // Verifies that registered_tests match the test names in // defined_test_names_; returns registered_tests if successful, or // aborts the program otherwise. @@ -565,8 +586,10 @@ class GTEST_API_ TypedTestCasePState { const char* file, int line, const char* registered_tests); private: + typedef ::std::map RegisteredTestsMap; + bool registered_; - ::std::set defined_test_names_; + RegisteredTestsMap registered_tests_; }; // Skips to the first non-space char after the first comma in 'str'; @@ -606,8 +629,10 @@ class TypeParameterizedTest { // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase, // Types). Valid values for 'index' are [0, N - 1] where N is the // length of Types. - static bool Register(const char* prefix, const char* case_name, - const char* test_names, int index) { + static bool Register(const char* prefix, + CodeLocation code_location, + const char* case_name, const char* test_names, + int index) { typedef typename Types::Head Type; typedef Fixture FixtureClass; typedef typename GTEST_BIND_(TestSel, Type) TestClass; @@ -620,6 +645,7 @@ class TypeParameterizedTest { StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), GetTypeName().c_str(), NULL, // No value parameter. + code_location, GetTypeId(), TestClass::SetUpTestCase, TestClass::TearDownTestCase, @@ -627,7 +653,7 @@ class TypeParameterizedTest { // Next, recurses (at compile time) with the tail of the type list. return TypeParameterizedTest - ::Register(prefix, case_name, test_names, index + 1); + ::Register(prefix, code_location, case_name, test_names, index + 1); } }; @@ -635,8 +661,9 @@ class TypeParameterizedTest { template class TypeParameterizedTest { public: - static bool Register(const char* /*prefix*/, const char* /*case_name*/, - const char* /*test_names*/, int /*index*/) { + static bool Register(const char* /*prefix*/, CodeLocation, + const char* /*case_name*/, const char* /*test_names*/, + int /*index*/) { return true; } }; @@ -648,17 +675,31 @@ class TypeParameterizedTest { template class TypeParameterizedTestCase { public: - static bool Register(const char* prefix, const char* case_name, - const char* test_names) { + static bool Register(const char* prefix, CodeLocation code_location, + const TypedTestCasePState* state, + const char* case_name, const char* test_names) { + std::string test_name = StripTrailingSpaces( + GetPrefixUntilComma(test_names)); + if (!state->TestExists(test_name)) { + fprintf(stderr, "Failed to get code location for test %s.%s at %s.", + case_name, test_name.c_str(), + FormatFileLocation(code_location.file.c_str(), + code_location.line).c_str()); + fflush(stderr); + posix::Abort(); + } + const CodeLocation& test_location = state->GetCodeLocation(test_name); + typedef typename Tests::Head Head; // First, register the first test in 'Test' for each type in 'Types'. TypeParameterizedTest::Register( - prefix, case_name, test_names, 0); + prefix, test_location, case_name, test_names, 0); // Next, recurses (at compile time) with the tail of the test list. return TypeParameterizedTestCase - ::Register(prefix, case_name, SkipComma(test_names)); + ::Register(prefix, code_location, state, + case_name, SkipComma(test_names)); } }; @@ -666,8 +707,9 @@ class TypeParameterizedTestCase { template class TypeParameterizedTestCase { public: - static bool Register(const char* /*prefix*/, const char* /*case_name*/, - const char* /*test_names*/) { + static bool Register(const char* /*prefix*/, CodeLocation, + const TypedTestCasePState* /*state*/, + const char* /*case_name*/, const char* /*test_names*/) { return true; } }; @@ -1187,6 +1229,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ ::test_info_ =\ ::testing::internal::MakeAndRegisterTestInfo(\ #test_case_name, #test_name, NULL, NULL, \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), \ (parent_id), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ -- cgit v1.2.3 From f972f1680aa5de3230dac197b223336f30210f69 Mon Sep 17 00:00:00 2001 From: kosak Date: Fri, 24 Jul 2015 20:43:09 +0000 Subject: Inject GetArgvs() with a macro from custom/gtest-port.h. --- include/gtest/internal/gtest-internal.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/gtest/internal/gtest-internal.h') diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index ee2dc4a1..ebd1cf61 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -100,9 +100,6 @@ class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo class UnitTestImpl; // Opaque implementation of UnitTest -// How many times InitGoogleTest() has been called. -GTEST_API_ extern int g_init_gtest_count; - // The text used in failure messages to indicate the start of the // stack trace. GTEST_API_ extern const char kStackTraceMarker[]; -- cgit v1.2.3