diff options
author | Kristian Monsen <kristianm@google.com> | 2011-06-28 21:49:31 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-07-08 17:55:00 +0100 |
commit | ddb351dbec246cf1fab5ec20d2d5520909041de1 (patch) | |
tree | 158e3fb57bdcac07c7f1e767fde3c70687c9fbb1 /testing | |
parent | 6b92e04f5f151c896e3088e86f70db7081009308 (diff) | |
download | external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.zip external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.gz external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.bz2 |
Merge Chromium at r12.0.742.93: Initial merge by git
Change-Id: Ic5ee2fec31358bbee305f7e915442377bfa6cda6
Diffstat (limited to 'testing')
68 files changed, 1177 insertions, 775 deletions
diff --git a/testing/gmock/CHANGES b/testing/gmock/CHANGES index 21ab488..ba7cfc4 100644 --- a/testing/gmock/CHANGES +++ b/testing/gmock/CHANGES @@ -1,3 +1,27 @@ +Changes for 1.6.0: + +* Compilation is much faster and uses much less memory, especially + when the constructor and destructor of a mock class are moved out of + the class body. +* New matchers: Pointwise(), Each(). +* New actions: ReturnPointee() and ReturnRefOfCopy(). +* CMake support. +* Project files for Visual Studio 2010. +* AllOf() and AnyOf() can handle up-to 10 arguments now. +* Google Mock doctor understands Clang error messages now. +* SetArgPointee<> now accepts string literals. +* gmock_gen.py handles storage specifier macros and template return + types now. +* Compatibility fixes. +* Bug fixes and implementation clean-ups. + +Potentially breaking changes: + +* The description string for MATCHER*() changes from Python-style + interpolation to an ordinary C++ string expression. +* SetArgumentPointee is deprecated in favor of SetArgPointee. +* Some non-essential project files for Visual Studio 2005 are removed. + Changes for 1.5.0: * New feature: Google Mock can be safely used in multi-threaded tests diff --git a/testing/gmock/Makefile.am b/testing/gmock/Makefile.am index e02c07e..cf7dee9 100644 --- a/testing/gmock/Makefile.am +++ b/testing/gmock/Makefile.am @@ -153,6 +153,10 @@ EXTRA_DIST += \ scripts/generator/cpp/utils.py \ scripts/generator/gmock_gen.py +# CMake scripts. +EXTRA_DIST += \ + CMakeLists.txt + # Microsoft Visual Studio 2005 projects. EXTRA_DIST += \ msvc/2005/gmock.sln \ diff --git a/testing/gmock/configure.ac b/testing/gmock/configure.ac index 8498a6c..e8b65bd 100644 --- a/testing/gmock/configure.ac +++ b/testing/gmock/configure.ac @@ -1,7 +1,7 @@ m4_include(gtest/m4/acx_pthread.m4) AC_INIT([Google C++ Mocking Framework], - [1.5.0], + [1.6.0], [googlemock@googlegroups.com], [gmock]) @@ -101,7 +101,7 @@ AC_ARG_VAR([GTEST_VERSION], [The version of Google Test available.]) HAVE_BUILT_GTEST="no" -GTEST_MIN_VERSION="1.5.0" +GTEST_MIN_VERSION="1.6.0" AS_IF([test "x${enable_external_gtest}" = "xyes"], [# Begin filling in variables as we are able. diff --git a/testing/gmock/include/gmock/gmock-actions.h b/testing/gmock/include/gmock/gmock-actions.h index af3483f..d6a3e14 100644 --- a/testing/gmock/include/gmock/gmock-actions.h +++ b/testing/gmock/include/gmock/gmock-actions.h @@ -40,7 +40,7 @@ #include <string> #ifndef _WIN32_WCE -#include <errno.h> +# include <errno.h> #endif #include "gmock/internal/gmock-internal-utils.h" @@ -981,7 +981,11 @@ SetArgPointee(const T& x) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage<T>::value>(x)); } + +#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) // This overload allows SetArgPointee() to accept a string literal. +// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish +// this overload from the templated version and emit a compile error. template <size_t N> PolymorphicAction< internal::SetArgumentPointeeAction<N, const char*, false> > @@ -989,6 +993,16 @@ SetArgPointee(const char* p) { return MakePolymorphicAction(internal::SetArgumentPointeeAction< N, const char*, false>(p)); } + +template <size_t N> +PolymorphicAction< + internal::SetArgumentPointeeAction<N, const wchar_t*, false> > +SetArgPointee(const wchar_t* p) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, const wchar_t*, false>(p)); +} +#endif + // The following version is DEPRECATED. template <size_t N, typename T> PolymorphicAction< diff --git a/testing/gmock/include/gmock/gmock-generated-actions.h b/testing/gmock/include/gmock/gmock-generated-actions.h index 6ab014d..635bb59 100644 --- a/testing/gmock/include/gmock/gmock-generated-actions.h +++ b/testing/gmock/include/gmock/gmock-generated-actions.h @@ -2228,8 +2228,8 @@ namespace testing { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif // Various overloads for InvokeArgument<N>(). @@ -2411,7 +2411,7 @@ ACTION_TEMPLATE(ReturnNew, } #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif } // namespace testing diff --git a/testing/gmock/include/gmock/gmock-generated-actions.h.pump b/testing/gmock/include/gmock/gmock-generated-actions.h.pump index 4d7c5ce..001fd7d 100644 --- a/testing/gmock/include/gmock/gmock-generated-actions.h.pump +++ b/testing/gmock/include/gmock/gmock-generated-actions.h.pump @@ -751,8 +751,8 @@ namespace testing { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif // Various overloads for InvokeArgument<N>(). @@ -817,7 +817,7 @@ ACTION_TEMPLATE(ReturnNew, ]] #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif } // namespace testing diff --git a/testing/gmock/include/gmock/gmock-generated-matchers.h b/testing/gmock/include/gmock/gmock-generated-matchers.h index 68af306..6feaf1a 100644 --- a/testing/gmock/include/gmock/gmock-generated-matchers.h +++ b/testing/gmock/include/gmock/gmock-generated-matchers.h @@ -850,7 +850,7 @@ ElementsAreArray(const T (&array)[N]) { } // AllOf(m1, m2, ..., mk) matches any value that matches all of the given -// sub-matchers. +// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. template <typename Matcher1, typename Matcher2> inline internal::BothOfMatcher<Matcher1, Matcher2> @@ -862,7 +862,7 @@ template <typename Matcher1, typename Matcher2, typename Matcher3> inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, Matcher3> > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return AllOf(m1, AllOf(m2, m3)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -870,7 +870,7 @@ template <typename Matcher1, typename Matcher2, typename Matcher3, inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, internal::BothOfMatcher<Matcher3, Matcher4> > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return AllOf(m1, AllOf(m2, m3, m4)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -879,7 +879,7 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4, Matcher5> > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return AllOf(m1, AllOf(m2, m3, m4, m5)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -889,7 +889,7 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, internal::BothOfMatcher<Matcher5, Matcher6> > > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6) { - return AllOf(m1, AllOf(m2, m3, m4, m5, m6)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -900,7 +900,7 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, Matcher7> > > > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7) { - return AllOf(m1, AllOf(m2, m3, m4, m5, m6, m7)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -912,7 +912,7 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, internal::BothOfMatcher<Matcher7, Matcher8> > > > > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8) { - return AllOf(m1, AllOf(m2, m3, m4, m5, m6, m7, m8)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -925,7 +925,7 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, Matcher9> > > > > > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { - return AllOf(m1, AllOf(m2, m3, m4, m5, m6, m7, m8, m9)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -938,11 +938,12 @@ inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2, internal::BothOfMatcher<Matcher9, Matcher10> > > > > > > > > AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { - return AllOf(m1, AllOf(m2, m3, m4, m5, m6, m7, m8, m9, m10)); + return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8, m9, + m10)); } // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given -// sub-matchers. +// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. template <typename Matcher1, typename Matcher2> inline internal::EitherOfMatcher<Matcher1, Matcher2> @@ -954,7 +955,7 @@ template <typename Matcher1, typename Matcher2, typename Matcher3> inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, Matcher3> > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return AnyOf(m1, AnyOf(m2, m3)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -962,7 +963,7 @@ template <typename Matcher1, typename Matcher2, typename Matcher3, inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, internal::EitherOfMatcher<Matcher3, Matcher4> > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return AnyOf(m1, AnyOf(m2, m3, m4)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -971,7 +972,7 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4, Matcher5> > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -981,7 +982,7 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, internal::EitherOfMatcher<Matcher5, Matcher6> > > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5, m6)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -992,7 +993,7 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, Matcher7> > > > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5, m6, m7)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -1004,7 +1005,7 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, internal::EitherOfMatcher<Matcher7, Matcher8> > > > > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5, m6, m7, m8)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -1017,7 +1018,7 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, Matcher9> > > > > > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5, m6, m7, m8, m9)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9)); } template <typename Matcher1, typename Matcher2, typename Matcher3, @@ -1030,11 +1031,13 @@ inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matcher2, internal::EitherOfMatcher<Matcher9, Matcher10> > > > > > > > > AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5, Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) { - return AnyOf(m1, AnyOf(m2, m3, m4, m5, m6, m7, m8, m9, m10)); + return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8, m9, + m10)); } } // namespace testing + // The MATCHER* family of macros can be used in a namespace scope to // define custom matchers easily. // diff --git a/testing/gmock/include/gmock/gmock-generated-matchers.h.pump b/testing/gmock/include/gmock/gmock-generated-matchers.h.pump index cebdd0e..8c09444 100644 --- a/testing/gmock/include/gmock/gmock-generated-matchers.h.pump +++ b/testing/gmock/include/gmock/gmock-generated-matchers.h.pump @@ -303,7 +303,7 @@ ElementsAreArray(const T (&array)[N]) { } // AllOf(m1, m2, ..., mk) matches any value that matches all of the given -// sub-matchers. +// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. $range i 2..n $for i [[ @@ -318,7 +318,7 @@ AllOf($for j, [[Matcher$j m$j]]) { $if i == 2 [[ return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2); ]] $else [[ - return AllOf(m1, AllOf($for k, [[m$(k + 1)]])); + return ::testing::AllOf(m1, ::testing::AllOf($for k, [[m$(k + 1)]])); ]] } @@ -326,7 +326,7 @@ $if i == 2 [[ ]] // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given -// sub-matchers. +// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. $range i 2..n $for i [[ @@ -341,7 +341,7 @@ AnyOf($for j, [[Matcher$j m$j]]) { $if i == 2 [[ return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2); ]] $else [[ - return AnyOf(m1, AnyOf($for k, [[m$(k + 1)]])); + return ::testing::AnyOf(m1, ::testing::AnyOf($for k, [[m$(k + 1)]])); ]] } diff --git a/testing/gmock/include/gmock/gmock-matchers.h b/testing/gmock/include/gmock/gmock-matchers.h index 86c3db7..dfb7259 100644 --- a/testing/gmock/include/gmock/gmock-matchers.h +++ b/testing/gmock/include/gmock/gmock-matchers.h @@ -1394,12 +1394,12 @@ class TrulyMatcher { MatchResultListener* /* listener */) const { #if GTEST_OS_WINDOWS // MSVC warns about converting a value into bool (warning 4800). -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4800) // Temporarily disables warning 4800. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4800) // Temporarily disables warning 4800. #endif // GTEST_OS_WINDOWS return predicate_(x); #if GTEST_OS_WINDOWS -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif // GTEST_OS_WINDOWS } diff --git a/testing/gmock/include/gmock/gmock-more-actions.h b/testing/gmock/include/gmock/gmock-more-actions.h index a547a64..fc5e5ca 100644 --- a/testing/gmock/include/gmock/gmock-more-actions.h +++ b/testing/gmock/include/gmock/gmock-more-actions.h @@ -136,8 +136,8 @@ WithArg(const InnerAction& action) { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif // Action ReturnArg<k>() returns the k-th argument of the mock function. @@ -188,12 +188,12 @@ ACTION_TEMPLATE(SetArrayArgument, // Microsoft compiler deprecates ::std::copy, so we want to suppress warning // 4996 (Function call with parameters that may be unsafe) there. #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4996) // Temporarily disables warning 4996. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4996) // Temporarily disables warning 4996. #endif ::std::copy(first, last, ::std::tr1::get<k>(args)); #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif } @@ -213,19 +213,19 @@ ACTION_P(ReturnPointee, pointer) { return *pointer; } #if GTEST_HAS_EXCEPTIONS // Suppresses the 'unreachable code' warning that VC generates in opt modes. -#ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4702) // Temporarily disables warning 4702. -#endif +# ifdef _MSC_VER +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4702) // Temporarily disables warning 4702. +# endif ACTION_P(Throw, exception) { throw exception; } -#ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. -#endif +# ifdef _MSC_VER +# pragma warning(pop) // Restores the warning state. +# endif #endif // GTEST_HAS_EXCEPTIONS #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif } // namespace testing diff --git a/testing/gmock/include/gmock/gmock-spec-builders.h b/testing/gmock/include/gmock/gmock-spec-builders.h index 9e18508..6ae807a 100644 --- a/testing/gmock/include/gmock/gmock-spec-builders.h +++ b/testing/gmock/include/gmock/gmock-spec-builders.h @@ -1279,8 +1279,8 @@ class MockSpec { // the constructor only. #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4355) // Temporarily disables warning 4355. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4355) // Temporarily disables warning 4355. #endif // _MSV_VER // C++ treats the void type specially. For example, you cannot define @@ -1686,7 +1686,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { }; // class FunctionMockerBase #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif // _MSV_VER // Implements methods of FunctionMockerBase. diff --git a/testing/gmock/include/gmock/internal/gmock-internal-utils.h b/testing/gmock/include/gmock/internal/gmock-internal-utils.h index 7aaf6de..48fadba 100644 --- a/testing/gmock/include/gmock/internal/gmock-internal-utils.h +++ b/testing/gmock/include/gmock/internal/gmock-internal-utils.h @@ -101,7 +101,7 @@ struct LinkedPtrLessThan { (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) // wchar_t is a typedef. #else -#define GMOCK_WCHAR_T_IS_NATIVE_ 1 +# define GMOCK_WCHAR_T_IS_NATIVE_ 1 #endif // signed wchar_t and unsigned wchar_t are NOT in the C++ standard. @@ -114,7 +114,8 @@ struct LinkedPtrLessThan { // To gcc, // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int #ifdef __GNUC__ -#define GMOCK_HAS_SIGNED_WCHAR_T_ 1 // signed/unsigned wchar_t are valid types. +// signed/unsigned wchar_t are valid types. +# define GMOCK_HAS_SIGNED_WCHAR_T_ 1 #endif // In what follows, we use the term "kind" to indicate whether a type diff --git a/testing/gmock/include/gmock/internal/gmock-port.h b/testing/gmock/include/gmock/internal/gmock-port.h index bb3f583..3b9cc47 100644 --- a/testing/gmock/include/gmock/internal/gmock-port.h +++ b/testing/gmock/include/gmock/internal/gmock-port.h @@ -53,7 +53,7 @@ // For MS Visual C++, check the compiler version. At least VS 2003 is // required to compile Google Mock. #if defined(_MSC_VER) && _MSC_VER < 1310 -#error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." +# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." #endif // Macro for referencing flags. This is public as we want the user to diff --git a/testing/gmock/scripts/gmock_doctor.py b/testing/gmock/scripts/gmock_doctor.py index ab923ef..afd5910 100755 --- a/testing/gmock/scripts/gmock_doctor.py +++ b/testing/gmock/scripts/gmock_doctor.py @@ -463,7 +463,7 @@ def _TypeInTemplatedBaseDiagnoser(msg): _CLANG_FILE_LINE_RE + r'error: use of undeclared identifier \'(?P<type>.*)\'\n' r'(.*\n)*?' - r'(?P=file):(?P=line):(?P=column): error: ' + r'(?P=file):(?P=line):\d+: error: ' r'non-friend class member \'Result\' cannot have a qualified name' ) clang_regex_type_of_a_param = ( diff --git a/testing/gmock/src/gmock-spec-builders.cc b/testing/gmock/src/gmock-spec-builders.cc index a99caef..aa33cc4 100644 --- a/testing/gmock/src/gmock-spec-builders.cc +++ b/testing/gmock/src/gmock-spec-builders.cc @@ -45,7 +45,7 @@ #include "gtest/gtest.h" #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC -#include <unistd.h> // NOLINT +# include <unistd.h> // NOLINT #endif namespace testing { diff --git a/testing/gmock/src/gmock_main.cc b/testing/gmock/src/gmock_main.cc index 3725ae7..9d8aea2 100644 --- a/testing/gmock/src/gmock_main.cc +++ b/testing/gmock/src/gmock_main.cc @@ -39,7 +39,7 @@ // Windows. See the following link to track the current status of this bug: // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT #if GTEST_OS_WINDOWS_MOBILE -#include <tchar.h> // NOLINT +# include <tchar.h> // NOLINT int _tmain(int argc, TCHAR** argv) { #else diff --git a/testing/gmock/test/gmock-actions_test.cc b/testing/gmock/test/gmock-actions_test.cc index b3f8d52..b7803fe 100644 --- a/testing/gmock/test/gmock-actions_test.cc +++ b/testing/gmock/test/gmock-actions_test.cc @@ -714,23 +714,44 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) { EXPECT_EQ('a', ch); } +#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) // Tests that SetArgPointee<N>() accepts a string literal. +// GCC prior to v4.0 and the Symbian compiler do not support this. TEST(SetArgPointeeTest, AcceptsStringLiteral) { - typedef void MyFunction(bool, std::string*, const char**); - Action<MyFunction> a = SetArgPointee<1>("hi"); + typedef void MyFunction(std::string*, const char**); + Action<MyFunction> a = SetArgPointee<0>("hi"); std::string str; const char* ptr = NULL; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("hi", str); EXPECT_TRUE(ptr == NULL); - a = SetArgPointee<2>("world"); + a = SetArgPointee<1>("world"); str = ""; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("", str); EXPECT_STREQ("world", ptr); } +TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { + typedef void MyFunction(const wchar_t**); + Action<MyFunction> a = SetArgPointee<0>(L"world"); + const wchar_t* ptr = NULL; + a.Perform(make_tuple(&ptr)); + EXPECT_STREQ(L"world", ptr); + +# if GTEST_HAS_STD_WSTRING + + typedef void MyStringFunction(std::wstring*); + Action<MyStringFunction> a2 = SetArgPointee<0>(L"world"); + std::wstring str = L""; + a2.Perform(make_tuple(&str)); + EXPECT_EQ(L"world", str); + +# endif +} +#endif + // Tests that SetArgPointee<N>() accepts a char pointer. TEST(SetArgPointeeTest, AcceptsCharPointer) { typedef void MyFunction(bool, std::string*, const char**); @@ -751,6 +772,26 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { EXPECT_EQ(world, ptr); } +TEST(SetArgPointeeTest, AcceptsWideCharPointer) { + typedef void MyFunction(bool, const wchar_t**); + const wchar_t* const hi = L"hi"; + Action<MyFunction> a = SetArgPointee<1>(hi); + const wchar_t* ptr = NULL; + a.Perform(make_tuple(true, &ptr)); + EXPECT_EQ(hi, ptr); + +# if GTEST_HAS_STD_WSTRING + + typedef void MyStringFunction(bool, std::wstring*); + wchar_t world_array[] = L"world"; + wchar_t* const world = world_array; + Action<MyStringFunction> a2 = SetArgPointee<1>(world); + std::wstring str; + a2.Perform(make_tuple(true, &str)); + EXPECT_EQ(world_array, str); +# endif +} + #if GTEST_HAS_PROTOBUF_ // Tests that SetArgPointee<N>(proto_buffer) sets the v1 protobuf diff --git a/testing/gmock/test/gmock-generated-actions_test.cc b/testing/gmock/test/gmock-generated-actions_test.cc index 982be1b..436f1a2 100644 --- a/testing/gmock/test/gmock-generated-actions_test.cc +++ b/testing/gmock/test/gmock-generated-actions_test.cc @@ -593,8 +593,8 @@ TEST(DoAllTest, TenActions) { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif // Tests the ACTION*() macro family. @@ -1205,7 +1205,7 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) { } #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif } // namespace gmock_generated_actions_test diff --git a/testing/gmock/test/gmock-generated-function-mockers_test.cc b/testing/gmock/test/gmock-generated-function-mockers_test.cc index d000386..0d90ded 100644 --- a/testing/gmock/test/gmock-generated-function-mockers_test.cc +++ b/testing/gmock/test/gmock-generated-function-mockers_test.cc @@ -44,14 +44,14 @@ // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // we are getting compiler errors if we use basetyps.h, hence including // objbase.h for definition of STDMETHOD. -#include <objbase.h> +# include <objbase.h> #endif // GTEST_OS_WINDOWS // There is a bug in MSVC (fixed in VS 2008) that prevents creating a // mock for a function with const arguments, so we don't test such // cases for MSVC versions older than 2008. #if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) -#define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS +# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS #endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500) namespace testing { diff --git a/testing/gmock/test/gmock-generated-matchers_test.cc b/testing/gmock/test/gmock-generated-matchers_test.cc index 2a7f498..819f1a8 100644 --- a/testing/gmock/test/gmock-generated-matchers_test.cc +++ b/testing/gmock/test/gmock-generated-matchers_test.cc @@ -144,8 +144,8 @@ TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif MATCHER(SumIsZero, "") { @@ -1091,8 +1091,37 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) { EXPECT_THAT(a, Contains(Not(Contains(5)))); } +namespace adl_test { + +// Verifies that the implementation of ::testing::AllOf and ::testing::AnyOf +// don't issue unqualified recursive calls. If they do, the argument dependent +// name lookup will cause AllOf/AnyOf in the 'adl_test' namespace to be found +// as a candidate and the compilation will break due to an ambiguous overload. + +// The matcher must be in the same namespace as AllOf/AnyOf to make argument +// dependent lookup find those. +MATCHER(M, "") { return true; } + +template <typename T1, typename T2> +bool AllOf(const T1& t1, const T2& t2) { return true; } + +TEST(AllOfTest, DoesNotCallAllOfUnqualified) { + EXPECT_THAT(42, testing::AllOf( + M(), M(), M(), M(), M(), M(), M(), M(), M(), M())); +} + +template <typename T1, typename T2> bool +AnyOf(const T1& t1, const T2& t2) { return true; } + +TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) { + EXPECT_THAT(42, testing::AnyOf( + M(), M(), M(), M(), M(), M(), M(), M(), M(), M())); +} + +} // namespace adl_test + #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif } // namespace diff --git a/testing/gmock/test/gmock-internal-utils_test.cc b/testing/gmock/test/gmock-internal-utils_test.cc index 5b0e804..ae743c1 100644 --- a/testing/gmock/test/gmock-internal-utils_test.cc +++ b/testing/gmock/test/gmock-internal-utils_test.cc @@ -45,7 +45,7 @@ #include "gtest/gtest-spi.h" #if GTEST_OS_CYGWIN -#include <sys/types.h> // For ssize_t. NOLINT +# include <sys/types.h> // For ssize_t. NOLINT #endif class ProtocolMessage; @@ -416,18 +416,21 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) { CaptureStdout(); Log(WARNING, "Test log.\n", 100); const String log = GetCapturedStdout(); -#if defined(NDEBUG) && GTEST_GOOGLE3_MODE_ + +# if defined(NDEBUG) && GTEST_GOOGLE3_MODE_ + // In opt mode, no stack frame should be skipped. EXPECT_THAT(log, ContainsRegex("\nGMOCK WARNING:\n" "Test log\\.\n" "Stack trace:\n" ".+")); -#else +# else + // In dbg mode, the stack frames should be skipped. EXPECT_STREQ("\nGMOCK WARNING:\n" "Test log.\n" "Stack trace:\n", log.c_str()); -#endif +# endif } // Tests that all logs are printed when the value of the diff --git a/testing/gmock/test/gmock-matchers_test.cc b/testing/gmock/test/gmock-matchers_test.cc index deff9b2..6f93fbd 100644 --- a/testing/gmock/test/gmock-matchers_test.cc +++ b/testing/gmock/test/gmock-matchers_test.cc @@ -1004,8 +1004,8 @@ TEST(StrEqTest, MatchesEqualString) { } TEST(StrEqTest, CanDescribeSelf) { - Matcher<string> m = StrEq("Hi-\'\"\?\\\a\b\f\n\r\t\v\xD3"); - EXPECT_EQ("is equal to \"Hi-\'\\\"\\?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"", + Matcher<string> m = StrEq("Hi-\'\"?\\\a\b\f\n\r\t\v\xD3"); + EXPECT_EQ("is equal to \"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"", Describe(m)); string str("01204500800"); @@ -1393,8 +1393,8 @@ TEST(StdWideStrEqTest, MatchesEqual) { } TEST(StdWideStrEqTest, CanDescribeSelf) { - Matcher< ::std::wstring> m = StrEq(L"Hi-\'\"\?\\\a\b\f\n\r\t\v"); - EXPECT_EQ("is equal to L\"Hi-\'\\\"\\?\\\\\\a\\b\\f\\n\\r\\t\\v\"", + Matcher< ::std::wstring> m = StrEq(L"Hi-\'\"?\\\a\b\f\n\r\t\v"); + EXPECT_EQ("is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"", Describe(m)); Matcher< ::std::wstring> m2 = StrEq(L"\xD3\x576\x8D3\xC74D"); @@ -1584,8 +1584,8 @@ TEST(GlobalWideStrEqTest, MatchesEqual) { } TEST(GlobalWideStrEqTest, CanDescribeSelf) { - Matcher< ::wstring> m = StrEq(L"Hi-\'\"\?\\\a\b\f\n\r\t\v"); - EXPECT_EQ("is equal to L\"Hi-\'\\\"\\?\\\\\\a\\b\\f\\n\\r\\t\\v\"", + Matcher< ::wstring> m = StrEq(L"Hi-\'\"?\\\a\b\f\n\r\t\v"); + EXPECT_EQ("is equal to L\"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\"", Describe(m)); Matcher< ::wstring> m2 = StrEq(L"\xD3\x576\x8D3\xC74D"); diff --git a/testing/gmock/test/gmock-spec-builders_test.cc b/testing/gmock/test/gmock-spec-builders_test.cc index aea5228..29d47d1 100644 --- a/testing/gmock/test/gmock-spec-builders_test.cc +++ b/testing/gmock/test/gmock-spec-builders_test.cc @@ -1717,14 +1717,14 @@ TEST(DeletingMockEarlyTest, Success2) { // Suppresses warning on unreferenced formal parameter in MSVC with // -W4. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif ACTION_P(Delete, ptr) { delete ptr; } #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { @@ -1890,7 +1890,9 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) { const String output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsSubstring, "Stack trace:", output); -#ifndef NDEBUG + +# ifndef NDEBUG + // We check the stack trace content in dbg-mode only, as opt-mode // may inline the call we are interested in seeing. @@ -1904,7 +1906,8 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) { c.NonVoidMethod(); const String output2 = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "NonVoidMethod(", output2); -#endif // NDEBUG + +# endif // NDEBUG } // Tests that an uninteresting mock function call causes the function @@ -1949,14 +1952,14 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { const string& function_name) { if (should_print) { EXPECT_THAT(output.c_str(), HasSubstr(expected_substring)); -#ifndef NDEBUG +# ifndef NDEBUG // We check the stack trace content in dbg-mode only, as opt-mode // may inline the call we are interested in seeing. EXPECT_THAT(output.c_str(), HasSubstr(function_name)); -#else +# else // Suppresses 'unused function parameter' warnings. static_cast<void>(function_name); -#endif // NDEBUG +# endif // NDEBUG } else { EXPECT_STREQ("", output.c_str()); } diff --git a/testing/gmock/test/gmock_link_test.h b/testing/gmock/test/gmock_link_test.h index 499cc18..ab5af4b 100644 --- a/testing/gmock/test/gmock_link_test.h +++ b/testing/gmock/test/gmock_link_test.h @@ -117,7 +117,7 @@ #include "gmock/gmock.h" #if !GTEST_OS_WINDOWS_MOBILE -#include <errno.h> +# include <errno.h> #endif #include "gmock/internal/gmock-port.h" @@ -419,8 +419,8 @@ TEST(LinkTest, TestThrow) { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4100) +# pragma warning(push) +# pragma warning(disable:4100) #endif // Tests the linkage of actions created using ACTION macro. @@ -455,7 +455,7 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) { } #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif TEST(LinkTest, TestActionP2Macro) { diff --git a/testing/gmock_mutant.h b/testing/gmock_mutant.h index b90bf7b..7e991f0 100644 --- a/testing/gmock_mutant.h +++ b/testing/gmock_mutant.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -103,7 +103,7 @@ // CreateFunctor(&mock->demiurge_, &Demiurge::DecreaseMonsters)))); // -#include "base/linked_ptr.h" +#include "base/memory/linked_ptr.h" #include "base/tuple.h" // for Tuple namespace testing { diff --git a/testing/gtest/CHANGES b/testing/gtest/CHANGES index e574415..c2f8707 100644 --- a/testing/gtest/CHANGES +++ b/testing/gtest/CHANGES @@ -1,3 +1,32 @@ +Changes for 1.6.0: + +* New feature: ADD_FAILURE_AT() for reporting a test failure at the + given source location -- useful for writing testing utilities. +* New feature: the universal value printer is moved from Google Mock + to Google Test. +* New feature: type parameters and value parameters are reported in + the XML report now. +* A gtest_disable_pthreads CMake option. +* Colored output works in GNU Screen sessions now. +* Parameters of value-parameterized tests are now printed in the + textual output. +* Failures from ad hoc test assertions run before RUN_ALL_TESTS() are + now correctly reported. +* Arguments of ASSERT_XY and EXPECT_XY no longer need to support << to + ostream. +* More complete handling of exceptions. +* GTEST_ASSERT_XY can be used instead of ASSERT_XY in case the latter + name is already used by another library. +* --gtest_catch_exceptions is now true by default, allowing a test + program to continue after an exception is thrown. +* Value-parameterized test fixtures can now derive from Test and + WithParamInterface<T> separately, easing conversion of legacy tests. +* Death test messages are clearly marked to make them more + distinguishable from other messages. +* Compatibility fixes for Google Native Client, MinGW, Lucid + autotools, and C++0x. +* Bug fixes and implementation clean-ups. + Changes for 1.5.0: * New feature: assertions can be safely called in multiple threads diff --git a/testing/gtest/Makefile.am b/testing/gtest/Makefile.am index e4628aa..94912e0 100644 --- a/testing/gtest/Makefile.am +++ b/testing/gtest/Makefile.am @@ -44,6 +44,7 @@ EXTRA_DIST += \ # C++ test files that we don't compile directly. EXTRA_DIST += \ + test/gtest-death-test_ex_test.cc \ test/gtest-death-test_test.cc \ test/gtest-filepath_test.cc \ test/gtest-linked_ptr_test.cc \ @@ -112,7 +113,8 @@ EXTRA_DIST += \ # CMake script EXTRA_DIST += \ - CMakeLists.txt + CMakeLists.txt \ + cmake/internal_utils.cmake # MSVC project files EXTRA_DIST += \ diff --git a/testing/gtest/configure.ac b/testing/gtest/configure.ac index de2d1e7..fa66029 100644 --- a/testing/gtest/configure.ac +++ b/testing/gtest/configure.ac @@ -5,7 +5,7 @@ m4_include(m4/acx_pthread.m4) # "[1.0.1]"). It also asumes that there won't be any closing parenthesis # between "AC_INIT(" and the closing ")" including comments and strings. AC_INIT([Google C++ Testing Framework], - [1.5.0], + [1.6.0], [googletestframework@googlegroups.com], [gtest]) diff --git a/testing/gtest/include/gtest/gtest-death-test.h b/testing/gtest/include/gtest/gtest-death-test.h index 0d1cb36..a27883f 100644 --- a/testing/gtest/include/gtest/gtest-death-test.h +++ b/testing/gtest/include/gtest/gtest-death-test.h @@ -154,24 +154,24 @@ GTEST_DECLARE_string_(death_test_style); // Asserts that a given statement causes the program to exit, with an // integer exit status that satisfies predicate, and emitting error output // that matches regex. -#define ASSERT_EXIT(statement, predicate, regex) \ - GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) +# define ASSERT_EXIT(statement, predicate, regex) \ + GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) // Like ASSERT_EXIT, but continues on to successive tests in the // test case, if any: -#define EXPECT_EXIT(statement, predicate, regex) \ - GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) +# define EXPECT_EXIT(statement, predicate, regex) \ + GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) // Asserts that a given statement causes the program to exit, either by // explicitly exiting with a nonzero exit code or being killed by a // signal, and emitting error output that matches regex. -#define ASSERT_DEATH(statement, regex) \ - ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) +# define ASSERT_DEATH(statement, regex) \ + ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) // Like ASSERT_DEATH, but continues on to successive tests in the // test case, if any: -#define EXPECT_DEATH(statement, regex) \ - EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) +# define EXPECT_DEATH(statement, regex) \ + EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: @@ -187,7 +187,7 @@ class GTEST_API_ ExitedWithCode { const int exit_code_; }; -#if !GTEST_OS_WINDOWS +# if !GTEST_OS_WINDOWS // Tests that an exit code describes an exit due to termination by a // given signal. class GTEST_API_ KilledBySignal { @@ -197,7 +197,7 @@ class GTEST_API_ KilledBySignal { private: const int signum_; }; -#endif // !GTEST_OS_WINDOWS +# endif // !GTEST_OS_WINDOWS // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. // The death testing framework causes this to have interesting semantics, @@ -242,23 +242,23 @@ class GTEST_API_ KilledBySignal { // EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); // }, "death"); // -#ifdef NDEBUG +# ifdef NDEBUG -#define EXPECT_DEBUG_DEATH(statement, regex) \ +# define EXPECT_DEBUG_DEATH(statement, regex) \ do { statement; } while (::testing::internal::AlwaysFalse()) -#define ASSERT_DEBUG_DEATH(statement, regex) \ +# define ASSERT_DEBUG_DEATH(statement, regex) \ do { statement; } while (::testing::internal::AlwaysFalse()) -#else +# else -#define EXPECT_DEBUG_DEATH(statement, regex) \ +# define EXPECT_DEBUG_DEATH(statement, regex) \ EXPECT_DEATH(statement, regex) -#define ASSERT_DEBUG_DEATH(statement, regex) \ +# define ASSERT_DEBUG_DEATH(statement, regex) \ ASSERT_DEATH(statement, regex) -#endif // NDEBUG for EXPECT_DEBUG_DEATH +# endif // NDEBUG for EXPECT_DEBUG_DEATH #endif // GTEST_HAS_DEATH_TEST // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and @@ -267,14 +267,14 @@ class GTEST_API_ KilledBySignal { // useful when you are combining death test assertions with normal test // assertions in one test. #if GTEST_HAS_DEATH_TEST -#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ +# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ EXPECT_DEATH(statement, regex) -#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ +# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ ASSERT_DEATH(statement, regex) #else -#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ +# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, ) -#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ +# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return) #endif diff --git a/testing/gtest/include/gtest/gtest-message.h b/testing/gtest/include/gtest/gtest-message.h index ecc04e7..9b7142f 100644 --- a/testing/gtest/include/gtest/gtest-message.h +++ b/testing/gtest/include/gtest/gtest-message.h @@ -192,6 +192,7 @@ class GTEST_API_ Message { } private: + #if 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_ diff --git a/testing/gtest/include/gtest/gtest-param-test.h b/testing/gtest/include/gtest/gtest-param-test.h index 9a92303..62c7c00 100644 --- a/testing/gtest/include/gtest/gtest-param-test.h +++ b/testing/gtest/include/gtest/gtest-param-test.h @@ -182,7 +182,7 @@ TEST_P(DerivedTest, DoesBlah) { #include "gtest/internal/gtest-port.h" #if !GTEST_OS_SYMBIAN -#include <utility> +# include <utility> #endif // scripts/fuse_gtest.py depends on gtest's own header being #included @@ -1222,7 +1222,7 @@ inline internal::ParamGenerator<bool> Bool() { return Values(false, true); } -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // Combine() allows the user to combine two or more sequences to produce // values of a Cartesian product of those sequences' elements. // @@ -1374,11 +1374,11 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3, Generator10>( g1, g2, g3, g4, g5, g6, g7, g8, g9, g10); } -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE -#define TEST_P(test_case_name, test_name) \ +# define TEST_P(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ : public test_case_name { \ public: \ @@ -1404,7 +1404,7 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3, GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() -#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ +# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ ::testing::internal::ParamGenerator<test_case_name::ParamType> \ gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \ int gtest_##prefix##test_case_name##_dummy_ = \ diff --git a/testing/gtest/include/gtest/gtest-param-test.h.pump b/testing/gtest/include/gtest/gtest-param-test.h.pump index d73f24d..877126b 100644 --- a/testing/gtest/include/gtest/gtest-param-test.h.pump +++ b/testing/gtest/include/gtest/gtest-param-test.h.pump @@ -181,7 +181,7 @@ TEST_P(DerivedTest, DoesBlah) { #include "gtest/internal/gtest-port.h" #if !GTEST_OS_SYMBIAN -#include <utility> +# include <utility> #endif // scripts/fuse_gtest.py depends on gtest's own header being #included @@ -379,7 +379,7 @@ inline internal::ParamGenerator<bool> Bool() { return Values(false, true); } -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // Combine() allows the user to combine two or more sequences to produce // values of a Cartesian product of those sequences' elements. // @@ -440,11 +440,11 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( } ]] -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE -#define TEST_P(test_case_name, test_name) \ +# define TEST_P(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ : public test_case_name { \ public: \ @@ -470,7 +470,7 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() -#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ +# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ ::testing::internal::ParamGenerator<test_case_name::ParamType> \ gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \ int gtest_##prefix##test_case_name##_dummy_ = \ diff --git a/testing/gtest/include/gtest/gtest-printers.h b/testing/gtest/include/gtest/gtest-printers.h index c8daa29..9cbab3f 100644 --- a/testing/gtest/include/gtest/gtest-printers.h +++ b/testing/gtest/include/gtest/gtest-printers.h @@ -308,7 +308,10 @@ void DefaultPrintTo(IsNotContainer /* dummy */, } else { // C++ doesn't allow casting from a function pointer to any object // pointer. - if (ImplicitlyConvertible<T*, const void*>::value) { + // + // IsTrue() silences warnings: "Condition is always true", + // "unreachable code". + if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) { // T is not a function type. We just call << to print p, // relying on ADL to pick up user-defined << for their pointer // types, if any. @@ -578,8 +581,8 @@ class UniversalPrinter { // MSVC warns about adding const to a function type, so we want to // disable the warning. #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4180) // Temporarily disables warning 4180. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4180) // Temporarily disables warning 4180. #endif // _MSC_VER // Note: we deliberately don't call this PrintTo(), as that name @@ -598,7 +601,7 @@ class UniversalPrinter { } #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif // _MSC_VER }; @@ -649,8 +652,8 @@ class UniversalPrinter<T&> { // MSVC warns about adding const to a function type, so we want to // disable the warning. #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4180) // Temporarily disables warning 4180. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4180) // Temporarily disables warning 4180. #endif // _MSC_VER static void Print(const T& value, ::std::ostream* os) { @@ -663,7 +666,7 @@ class UniversalPrinter<T&> { } #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif // _MSC_VER }; @@ -736,12 +739,26 @@ struct TuplePrefixPrinter<0> { template <typename Tuple> static void TersePrintPrefixToStrings(const Tuple&, Strings*) {} }; +// We have to specialize the entire TuplePrefixPrinter<> class +// template here, even though the definition of +// TersePrintPrefixToStrings() is the same as the generic version, as +// Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't +// support specializing a method template of a class template. template <> -template <typename Tuple> -void TuplePrefixPrinter<1>::PrintPrefixTo(const Tuple& t, ::std::ostream* os) { - UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>:: - Print(::std::tr1::get<0>(t), os); -} +struct TuplePrefixPrinter<1> { + template <typename Tuple> + static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) { + UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>:: + Print(::std::tr1::get<0>(t), os); + } + + template <typename Tuple> + static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) { + ::std::stringstream ss; + UniversalTersePrint(::std::tr1::get<0>(t), &ss); + strings->push_back(ss.str()); + } +}; // Helper function for printing a tuple. T must be instantiated with // a tuple type. diff --git a/testing/gtest/include/gtest/gtest-typed-test.h b/testing/gtest/include/gtest/gtest-typed-test.h index 2d3b8bf..fe1e83b 100644 --- a/testing/gtest/include/gtest/gtest-typed-test.h +++ b/testing/gtest/include/gtest/gtest-typed-test.h @@ -157,16 +157,16 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); // // Expands to the name of the typedef for the type parameters of the // given test case. -#define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_ +# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_ // The 'Types' template argument below must have spaces around it // since some compilers may choke on '>>' when passing a template // instance (e.g. Types<int>) -#define TYPED_TEST_CASE(CaseName, Types) \ +# define TYPED_TEST_CASE(CaseName, Types) \ typedef ::testing::internal::TypeList< Types >::type \ GTEST_TYPE_PARAMS_(CaseName) -#define TYPED_TEST(CaseName, TestName) \ +# define TYPED_TEST(CaseName, TestName) \ template <typename gtest_TypeParam_> \ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ : public CaseName<gtest_TypeParam_> { \ @@ -196,31 +196,31 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); // Expands to the namespace name that the type-parameterized tests for // the given type-parameterized test case are defined in. The exact // name of the namespace is subject to change without notice. -#define GTEST_CASE_NAMESPACE_(TestCaseName) \ +# define GTEST_CASE_NAMESPACE_(TestCaseName) \ gtest_case_##TestCaseName##_ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // // Expands to the name of the variable used to remember the names of // the defined tests in the given test case. -#define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \ +# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \ gtest_typed_test_case_p_state_##TestCaseName##_ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY. // // Expands to the name of the variable used to remember the names of // the registered tests in the given test case. -#define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \ +# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \ gtest_registered_test_names_##TestCaseName##_ // The variables defined in the type-parameterized test macros are // static as typically these macros are used in a .h file that can be // #included in multiple translation units linked together. -#define TYPED_TEST_CASE_P(CaseName) \ +# define TYPED_TEST_CASE_P(CaseName) \ static ::testing::internal::TypedTestCasePState \ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName) -#define TYPED_TEST_P(CaseName, TestName) \ +# define TYPED_TEST_P(CaseName, TestName) \ namespace GTEST_CASE_NAMESPACE_(CaseName) { \ template <typename gtest_TypeParam_> \ class TestName : public CaseName<gtest_TypeParam_> { \ @@ -236,7 +236,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); template <typename gtest_TypeParam_> \ void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody() -#define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \ +# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \ namespace GTEST_CASE_NAMESPACE_(CaseName) { \ typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \ } \ @@ -247,7 +247,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); // The 'Types' template argument below must have spaces around it // since some compilers may choke on '>>' when passing a template // instance (e.g. Types<int>) -#define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ +# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \ ::testing::internal::TypeParameterizedTestCase<CaseName, \ GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \ diff --git a/testing/gtest/include/gtest/gtest.h b/testing/gtest/include/gtest/gtest.h index 741a360..cd01c7b 100644 --- a/testing/gtest/include/gtest/gtest.h +++ b/testing/gtest/include/gtest/gtest.h @@ -672,6 +672,7 @@ class GTEST_API_ TestInfo { const TestResult* result() const { return &result_; } private: + #if GTEST_HAS_DEATH_TEST friend class internal::DefaultDeathTestFactory; #endif // GTEST_HAS_DEATH_TEST @@ -1295,7 +1296,9 @@ namespace internal { template <typename T1, typename T2> String FormatForComparisonFailureMessage(const T1& value, const T2& /* other_operand */) { - return PrintToString(value); + // C++Builder compiles this incorrectly if the namespace isn't explicitly + // given. + return ::testing::PrintToString(value); } // The helper function for {ASSERT|EXPECT}_EQ. @@ -1305,8 +1308,8 @@ AssertionResult CmpHelperEQ(const char* expected_expression, const T1& expected, const T2& actual) { #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4389) // Temporarily disables warning on +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4389) // Temporarily disables warning on // signed/unsigned mismatch. #endif @@ -1315,7 +1318,7 @@ AssertionResult CmpHelperEQ(const char* expected_expression, } #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif return EqFailure(expected_expression, @@ -1740,7 +1743,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { // Define this macro to 1 to omit the definition of FAIL(), which is a // generic name and clashes with some other libraries. #if !GTEST_DONT_DEFINE_FAIL -#define FAIL() GTEST_FAIL() +# define FAIL() GTEST_FAIL() #endif // Generates a success with a generic message. @@ -1749,7 +1752,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { // Define this macro to 1 to omit the definition of SUCCEED(), which // is a generic name and clashes with some other libraries. #if !GTEST_DONT_DEFINE_SUCCEED -#define SUCCEED() GTEST_SUCCEED() +# define SUCCEED() GTEST_SUCCEED() #endif // Macros for testing exceptions. @@ -1874,27 +1877,27 @@ class TestWithParam : public Test, public WithParamInterface<T> { // ASSERT_XY(), which clashes with some users' own code. #if !GTEST_DONT_DEFINE_ASSERT_EQ -#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) +# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) #endif #if !GTEST_DONT_DEFINE_ASSERT_NE -#define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) +# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) #endif #if !GTEST_DONT_DEFINE_ASSERT_LE -#define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) +# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) #endif #if !GTEST_DONT_DEFINE_ASSERT_LT -#define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) +# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) #endif #if !GTEST_DONT_DEFINE_ASSERT_GE -#define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) +# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) #endif #if !GTEST_DONT_DEFINE_ASSERT_GT -#define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) +# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) #endif // C String Comparisons. All tests treat NULL and any non-NULL string @@ -1993,16 +1996,16 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, // expected result and the actual result with both a human-readable // string representation of the error, if available, as well as the // hex result code. -#define EXPECT_HRESULT_SUCCEEDED(expr) \ +# define EXPECT_HRESULT_SUCCEEDED(expr) \ EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) -#define ASSERT_HRESULT_SUCCEEDED(expr) \ +# define ASSERT_HRESULT_SUCCEEDED(expr) \ ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) -#define EXPECT_HRESULT_FAILED(expr) \ +# define EXPECT_HRESULT_FAILED(expr) \ EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) -#define ASSERT_HRESULT_FAILED(expr) \ +# define ASSERT_HRESULT_FAILED(expr) \ ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) #endif // GTEST_OS_WINDOWS @@ -2105,7 +2108,7 @@ bool StaticAssertTypeEq() { // Define this macro to 1 to omit the definition of TEST(), which // is a generic name and clashes with some other libraries. #if !GTEST_DONT_DEFINE_TEST -#define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name) +# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name) #endif // Defines a test that uses a test fixture. diff --git a/testing/gtest/include/gtest/gtest_pred_impl.h b/testing/gtest/include/gtest/gtest_pred_impl.h index d33f5d5..3805f85 100644 --- a/testing/gtest/include/gtest/gtest_pred_impl.h +++ b/testing/gtest/include/gtest/gtest_pred_impl.h @@ -37,7 +37,7 @@ // Makes sure this header is not included before gtest.h. #ifndef GTEST_INCLUDE_GTEST_GTEST_H_ -#error Do not include gtest_pred_impl.h directly. Include gtest.h instead. +# error Do not include gtest_pred_impl.h directly. Include gtest.h instead. #endif // GTEST_INCLUDE_GTEST_GTEST_H_ // This header implements a family of generic predicate assertion diff --git a/testing/gtest/include/gtest/internal/gtest-death-test-internal.h b/testing/gtest/include/gtest/internal/gtest-death-test-internal.h index 2b2c98d..1d9f83b 100644 --- a/testing/gtest/include/gtest/internal/gtest-death-test-internal.h +++ b/testing/gtest/include/gtest/internal/gtest-death-test-internal.h @@ -157,8 +157,8 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status); // Traps C++ exceptions escaping statement and reports them as test // failures. Note that trapping SEH exceptions is not implemented here. -#if GTEST_HAS_EXCEPTIONS -#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ +# if GTEST_HAS_EXCEPTIONS +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } catch (const ::std::exception& gtest_exception) { \ @@ -173,14 +173,16 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status); } catch (...) { \ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ } -#else -#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + +# else +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) -#endif + +# endif // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, // ASSERT_EXIT*, and EXPECT_EXIT*. -#define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ +# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (::testing::internal::AlwaysTrue()) { \ const ::testing::internal::RE& gtest_regex = (regex); \ @@ -285,7 +287,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); // statement unconditionally returns or throws. The Message constructor at // the end allows the syntax of streaming additional messages into the // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. -#define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ +# define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (::testing::internal::AlwaysTrue()) { \ GTEST_LOG_(WARNING) \ diff --git a/testing/gtest/include/gtest/internal/gtest-internal.h b/testing/gtest/include/gtest/internal/gtest-internal.h index 23fcef7..fcf4c71 100644 --- a/testing/gtest/include/gtest/internal/gtest-internal.h +++ b/testing/gtest/include/gtest/internal/gtest-internal.h @@ -40,10 +40,10 @@ #include "gtest/internal/gtest-port.h" #if GTEST_OS_LINUX -#include <stdlib.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <unistd.h> +# include <stdlib.h> +# include <sys/types.h> +# include <sys/wait.h> +# include <unistd.h> #endif // GTEST_OS_LINUX #include <ctype.h> @@ -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_ @@ -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)(); @@ -802,16 +788,16 @@ struct RemoveConst { typedef T type; }; // NOLINT template <typename T> struct RemoveConst<const T> { 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 <typename T, size_t N> struct RemoveConst<T[N]> { typedef typename RemoveConst<T>::type type[N]; }; -#endif // _MSC_VER +#endif // A handy wrapper around RemoveConst that works when the argument // T depends on template parameters. @@ -881,11 +867,17 @@ 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. +#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; @@ -904,21 +896,38 @@ struct IsAProtocolMessage ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> { }; -// When the compiler sees expression IsContainerTest<C>(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<C>(0). The value of the -// expression is insignificant. +// When the compiler sees expression IsContainerTest<C>(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<C>(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 <class C> -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 <class C> -IsNotContainer IsContainerTest(...) { return '\0'; } +IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } // EnableIf<condition>::type is void when 'Cond' is true, and // undefined when 'Cond' is false. To use SFINAE to make a function @@ -1017,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. diff --git a/testing/gtest/include/gtest/internal/gtest-param-util-generated.h b/testing/gtest/include/gtest/internal/gtest-param-util-generated.h index 306a5e5..c6f0ce0 100644 --- a/testing/gtest/include/gtest/internal/gtest-param-util-generated.h +++ b/testing/gtest/include/gtest/internal/gtest-param-util-generated.h @@ -2826,7 +2826,7 @@ class ValueArray50 { const T50 v50_; }; -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // // Generates values from the Cartesian product of values produced @@ -4810,7 +4810,7 @@ CartesianProductHolder10(const Generator1& g1, const Generator2& g2, const Generator10 g10_; }; // class CartesianProductHolder10 -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE } // namespace internal } // namespace testing diff --git a/testing/gtest/include/gtest/internal/gtest-param-util-generated.h.pump b/testing/gtest/include/gtest/internal/gtest-param-util-generated.h.pump index f261eb7..c148bb1 100644 --- a/testing/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +++ b/testing/gtest/include/gtest/internal/gtest-param-util-generated.h.pump @@ -115,7 +115,7 @@ $for j [[ ]] -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // // Generates values from the Cartesian product of values produced @@ -291,7 +291,7 @@ $for j [[ ]] -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE } // namespace internal } // namespace testing diff --git a/testing/gtest/include/gtest/internal/gtest-param-util.h b/testing/gtest/include/gtest/internal/gtest-param-util.h index 61c3e37..0f7b331 100644 --- a/testing/gtest/include/gtest/internal/gtest-param-util.h +++ b/testing/gtest/include/gtest/internal/gtest-param-util.h @@ -579,7 +579,7 @@ class ParameterizedTestCaseRegistry { // and terminate the program since we cannot guaranty correct // test case setup and tear-down in this case. ReportInvalidTestCaseType(test_case_name, file, line); - abort(); + posix::Abort(); } else { // At this point we are sure that the object we found is of the same // type we are looking for, so we downcast it to that type diff --git a/testing/gtest/include/gtest/internal/gtest-port.h b/testing/gtest/include/gtest/internal/gtest-port.h index be2297e..24f2e6f 100644 --- a/testing/gtest/include/gtest/internal/gtest-port.h +++ b/testing/gtest/include/gtest/internal/gtest-port.h @@ -87,6 +87,7 @@ // GTEST_OS_AIX - IBM AIX // GTEST_OS_CYGWIN - Cygwin // GTEST_OS_LINUX - Linux +// GTEST_OS_LINUX_ANDROID - Google Android // GTEST_OS_MAC - Mac OS X // GTEST_OS_NACL - Google Native Client (NaCl) // GTEST_OS_SOLARIS - Sun Solaris @@ -185,8 +186,8 @@ #include <stdio.h> #include <string.h> #ifndef _WIN32_WCE -#include <sys/types.h> -#include <sys/stat.h> +# include <sys/types.h> +# include <sys/stat.h> #endif // !_WIN32_WCE #include <iostream> // NOLINT @@ -203,36 +204,39 @@ // Determines the version of gcc that is used to compile this. #ifdef __GNUC__ // 40302 means version 4.3.2. -#define GTEST_GCC_VER_ \ +# define GTEST_GCC_VER_ \ (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) #endif // __GNUC__ // Determines the platform on which Google Test is compiled. #ifdef __CYGWIN__ -#define GTEST_OS_CYGWIN 1 +# define GTEST_OS_CYGWIN 1 #elif defined __SYMBIAN32__ -#define GTEST_OS_SYMBIAN 1 +# define GTEST_OS_SYMBIAN 1 #elif defined _WIN32 -#define GTEST_OS_WINDOWS 1 -#ifdef _WIN32_WCE -#define GTEST_OS_WINDOWS_MOBILE 1 -#elif defined(__MINGW__) || defined(__MINGW32__) -#define GTEST_OS_WINDOWS_MINGW 1 -#else -#define GTEST_OS_WINDOWS_DESKTOP 1 -#endif // _WIN32_WCE +# define GTEST_OS_WINDOWS 1 +# ifdef _WIN32_WCE +# define GTEST_OS_WINDOWS_MOBILE 1 +# elif defined(__MINGW__) || defined(__MINGW32__) +# define GTEST_OS_WINDOWS_MINGW 1 +# else +# define GTEST_OS_WINDOWS_DESKTOP 1 +# endif // _WIN32_WCE #elif defined __APPLE__ -#define GTEST_OS_MAC 1 +# define GTEST_OS_MAC 1 #elif defined __linux__ -#define GTEST_OS_LINUX 1 +# define GTEST_OS_LINUX 1 +# ifdef ANDROID +# define GTEST_OS_LINUX_ANDROID 1 +# endif // ANDROID #elif defined __MVS__ -#define GTEST_OS_ZOS 1 +# define GTEST_OS_ZOS 1 #elif defined(__sun) && defined(__SVR4) -#define GTEST_OS_SOLARIS 1 +# define GTEST_OS_SOLARIS 1 #elif defined(_AIX) -#define GTEST_OS_AIX 1 +# define GTEST_OS_AIX 1 #elif defined __native_client__ -#define GTEST_OS_NACL 1 +# define GTEST_OS_NACL 1 #endif // __CYGWIN__ // Brings in definitions for functions used in the testing::internal::posix @@ -242,21 +246,21 @@ // This assumes that non-Windows OSes provide unistd.h. For OSes where this // is not the case, we need to include headers that provide the functions // mentioned above. -#include <unistd.h> -#if !GTEST_OS_NACL +# include <unistd.h> +# if !GTEST_OS_NACL // TODO(vladl@google.com): Remove this condition when Native Client SDK adds // strings.h (tracked in // http://code.google.com/p/nativeclient/issues/detail?id=1175). -#include <strings.h> // Native Client doesn't provide strings.h. -#endif +# include <strings.h> // Native Client doesn't provide strings.h. +# endif #elif !GTEST_OS_WINDOWS_MOBILE -#include <direct.h> -#include <io.h> +# include <direct.h> +# include <io.h> #endif // Defines this to true iff Google Test can use POSIX regular expressions. #ifndef GTEST_HAS_POSIX_RE -#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) +# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) #endif #if GTEST_HAS_POSIX_RE @@ -265,67 +269,67 @@ // won't compile otherwise. We can #include it here as we already // included <stdlib.h>, which is guaranteed to define size_t through // <stddef.h>. -#include <regex.h> // NOLINT +# include <regex.h> // NOLINT -#define GTEST_USES_POSIX_RE 1 +# define GTEST_USES_POSIX_RE 1 #elif GTEST_OS_WINDOWS // <regex.h> is not available on Windows. Use our own simple regex // implementation instead. -#define GTEST_USES_SIMPLE_RE 1 +# define GTEST_USES_SIMPLE_RE 1 #else // <regex.h> may not be available on this platform. Use our own // simple regex implementation instead. -#define GTEST_USES_SIMPLE_RE 1 +# define GTEST_USES_SIMPLE_RE 1 #endif // GTEST_HAS_POSIX_RE #ifndef GTEST_HAS_EXCEPTIONS // The user didn't tell us whether exceptions are enabled, so we need // to figure it out. -#if defined(_MSC_VER) || defined(__BORLANDC__) +# if defined(_MSC_VER) || defined(__BORLANDC__) // MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS // macro to enable exceptions, so we'll do the same. // Assumes that exceptions are enabled by default. -#ifndef _HAS_EXCEPTIONS -#define _HAS_EXCEPTIONS 1 -#endif // _HAS_EXCEPTIONS -#define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS -#elif defined(__GNUC__) && __EXCEPTIONS +# ifndef _HAS_EXCEPTIONS +# define _HAS_EXCEPTIONS 1 +# endif // _HAS_EXCEPTIONS +# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS +# elif defined(__GNUC__) && __EXCEPTIONS // gcc defines __EXCEPTIONS to 1 iff exceptions are enabled. -#define GTEST_HAS_EXCEPTIONS 1 -#elif defined(__SUNPRO_CC) +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__SUNPRO_CC) // Sun Pro CC supports exceptions. However, there is no compile-time way of // detecting whether they are enabled or not. Therefore, we assume that // they are enabled unless the user tells us otherwise. -#define GTEST_HAS_EXCEPTIONS 1 -#elif defined(__IBMCPP__) && __EXCEPTIONS +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__IBMCPP__) && __EXCEPTIONS // xlC defines __EXCEPTIONS to 1 iff exceptions are enabled. -#define GTEST_HAS_EXCEPTIONS 1 -#else +# define GTEST_HAS_EXCEPTIONS 1 +# else // For other compilers, we assume exceptions are disabled to be // conservative. -#define GTEST_HAS_EXCEPTIONS 0 -#endif // defined(_MSC_VER) || defined(__BORLANDC__) +# define GTEST_HAS_EXCEPTIONS 0 +# endif // defined(_MSC_VER) || defined(__BORLANDC__) #endif // GTEST_HAS_EXCEPTIONS #if !defined(GTEST_HAS_STD_STRING) // Even though we don't use this macro any longer, we keep it in case // some clients still depend on it. -#define GTEST_HAS_STD_STRING 1 +# define GTEST_HAS_STD_STRING 1 #elif !GTEST_HAS_STD_STRING // The user told us that ::std::string isn't available. -#error "Google Test cannot be used where ::std::string isn't available." +# error "Google Test cannot be used where ::std::string isn't available." #endif // !defined(GTEST_HAS_STD_STRING) #ifndef GTEST_HAS_GLOBAL_STRING // The user didn't tell us whether ::string is available, so we need // to figure it out. -#define GTEST_HAS_GLOBAL_STRING 0 +# define GTEST_HAS_GLOBAL_STRING 0 #endif // GTEST_HAS_GLOBAL_STRING @@ -336,15 +340,17 @@ // is available. // Cygwin 1.7 and below doesn't support ::std::wstring. -// Solaris' libc++ doesn't support it either. -#define GTEST_HAS_STD_WSTRING (!(GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) +// Solaris' libc++ doesn't support it either. Android has +// no support for it at least as recent as Froyo (2.2). +# define GTEST_HAS_STD_WSTRING \ + (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) #endif // GTEST_HAS_STD_WSTRING #ifndef GTEST_HAS_GLOBAL_WSTRING // The user didn't tell us whether ::wstring is available, so we need // to figure it out. -#define GTEST_HAS_GLOBAL_WSTRING \ +# define GTEST_HAS_GLOBAL_WSTRING \ (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING) #endif // GTEST_HAS_GLOBAL_WSTRING @@ -353,46 +359,46 @@ // The user didn't tell us whether RTTI is enabled, so we need to // figure it out. -#ifdef _MSC_VER +# ifdef _MSC_VER -#ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. -#define GTEST_HAS_RTTI 1 -#else -#define GTEST_HAS_RTTI 0 -#endif +# ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled. -#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) +# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) -#ifdef __GXX_RTTI -#define GTEST_HAS_RTTI 1 -#else -#define GTEST_HAS_RTTI 0 -#endif // __GXX_RTTI +# ifdef __GXX_RTTI +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif // __GXX_RTTI // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if // both the typeid and dynamic_cast features are present. -#elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) +# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) -#ifdef __RTTI_ALL__ -#define GTEST_HAS_RTTI 1 -#else -#define GTEST_HAS_RTTI 0 -#endif +# ifdef __RTTI_ALL__ +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif -#else +# else // For all other compilers, we assume RTTI is enabled. -#define GTEST_HAS_RTTI 1 +# define GTEST_HAS_RTTI 1 -#endif // _MSC_VER +# endif // _MSC_VER #endif // GTEST_HAS_RTTI // It's this header's responsibility to #include <typeinfo> when RTTI // is enabled. #if GTEST_HAS_RTTI -#include <typeinfo> +# include <typeinfo> #endif // Determines whether Google Test can use the pthreads library. @@ -402,16 +408,16 @@ // // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // to your compiler flags. -#define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC) +# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC) #endif // GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is // true. -#include <pthread.h> // NOLINT +# include <pthread.h> // NOLINT // For timespec and nanosleep, used below. -#include <time.h> // NOLINT +# include <time.h> // NOLINT #endif // Determines whether Google Test can use tr1/tuple. You can define @@ -419,7 +425,7 @@ // feature depending on tuple with be disabled in this mode). #ifndef GTEST_HAS_TR1_TUPLE // The user didn't tell us not to do it, so we assume it's OK. -#define GTEST_HAS_TR1_TUPLE 1 +# define GTEST_HAS_TR1_TUPLE 1 #endif // GTEST_HAS_TR1_TUPLE // Determines whether Google Test's own tr1 tuple implementation @@ -434,12 +440,12 @@ // defining __GNUC__ and friends, but cannot compile GCC's tuple // implementation. MSVC 2008 (9.0) provides TR1 tuple in a 323 MB // Feature Pack download, which we cannot assume the user has. -#if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \ +# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000)) \ || _MSC_VER >= 1600 -#define GTEST_USE_OWN_TR1_TUPLE 0 -#else -#define GTEST_USE_OWN_TR1_TUPLE 1 -#endif +# define GTEST_USE_OWN_TR1_TUPLE 0 +# else +# define GTEST_USE_OWN_TR1_TUPLE 1 +# endif #endif // GTEST_USE_OWN_TR1_TUPLE @@ -448,47 +454,47 @@ // tr1/tuple. #if GTEST_HAS_TR1_TUPLE -#if GTEST_USE_OWN_TR1_TUPLE -#include "gtest/internal/gtest-tuple.h" -#elif GTEST_OS_SYMBIAN +# if GTEST_USE_OWN_TR1_TUPLE +# include "gtest/internal/gtest-tuple.h" +# elif GTEST_OS_SYMBIAN // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to // use STLport's tuple implementation, which unfortunately doesn't // work as the copy of STLport distributed with Symbian is incomplete. // By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to // use its own tuple implementation. -#ifdef BOOST_HAS_TR1_TUPLE -#undef BOOST_HAS_TR1_TUPLE -#endif // BOOST_HAS_TR1_TUPLE +# ifdef BOOST_HAS_TR1_TUPLE +# undef BOOST_HAS_TR1_TUPLE +# endif // BOOST_HAS_TR1_TUPLE // This prevents <boost/tr1/detail/config.hpp>, which defines // BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>. -#define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED -#include <tuple> +# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED +# include <tuple> -#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) +# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does // not conform to the TR1 spec, which requires the header to be <tuple>. -#if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 +# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 // Until version 4.3.2, gcc has a bug that causes <tr1/functional>, // which is #included by <tr1/tuple>, to not compile when RTTI is // disabled. _TR1_FUNCTIONAL is the header guard for // <tr1/functional>. Hence the following #define is a hack to prevent // <tr1/functional> from being included. -#define _TR1_FUNCTIONAL 1 -#include <tr1/tuple> -#undef _TR1_FUNCTIONAL // Allows the user to #include +# define _TR1_FUNCTIONAL 1 +# include <tr1/tuple> +# undef _TR1_FUNCTIONAL // Allows the user to #include // <tr1/functional> if he chooses to. -#else -#include <tr1/tuple> // NOLINT -#endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 +# else +# include <tr1/tuple> // NOLINT +# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 -#else +# else // If the compiler is not GCC 4.0+, we assume the user is using a // spec-conforming TR1 implementation. -#include <tuple> // NOLINT -#endif // GTEST_USE_OWN_TR1_TUPLE +# include <tuple> // NOLINT +# endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE @@ -499,11 +505,11 @@ #ifndef GTEST_HAS_CLONE // The user didn't tell us, so we need to figure it out. -#if GTEST_OS_LINUX && !defined(__ia64__) -#define GTEST_HAS_CLONE 1 -#else -#define GTEST_HAS_CLONE 0 -#endif // GTEST_OS_LINUX && !defined(__ia64__) +# if GTEST_OS_LINUX && !defined(__ia64__) +# define GTEST_HAS_CLONE 1 +# else +# define GTEST_HAS_CLONE 0 +# endif // GTEST_OS_LINUX && !defined(__ia64__) #endif // GTEST_HAS_CLONE @@ -512,11 +518,11 @@ #ifndef GTEST_HAS_STREAM_REDIRECTION // By default, we assume that stream redirection is supported on all // platforms except known mobile ones. -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN -#define GTEST_HAS_STREAM_REDIRECTION 0 -#else -#define GTEST_HAS_STREAM_REDIRECTION 1 -#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN +# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN +# define GTEST_HAS_STREAM_REDIRECTION 0 +# else +# define GTEST_HAS_STREAM_REDIRECTION 1 +# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN #endif // GTEST_HAS_STREAM_REDIRECTION // Determines whether to support death tests. @@ -526,8 +532,8 @@ #if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX) -#define GTEST_HAS_DEATH_TEST 1 -#include <vector> // NOLINT +# define GTEST_HAS_DEATH_TEST 1 +# include <vector> // NOLINT #endif // We don't support MSVC 7.1 with exceptions disabled now. Therefore @@ -541,8 +547,8 @@ // Sun Pro CC, and IBM Visual Age support. #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \ defined(__IBMCPP__) -#define GTEST_HAS_TYPED_TEST 1 -#define GTEST_HAS_TYPED_TEST_P 1 +# define GTEST_HAS_TYPED_TEST 1 +# define GTEST_HAS_TYPED_TEST_P 1 #endif // Determines whether to support Combine(). This only makes sense when @@ -550,7 +556,7 @@ // work on Sun Studio since it doesn't understand templated conversion // operators. #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC) -#define GTEST_HAS_COMBINE 1 +# define GTEST_HAS_COMBINE 1 #endif // Determines whether the system compiler uses UTF-16 for encoding wide strings. @@ -559,7 +565,7 @@ // Determines whether test results can be streamed to a socket. #if GTEST_OS_LINUX -#define GTEST_CAN_STREAM_RESULTS_ 1 +# define GTEST_CAN_STREAM_RESULTS_ 1 #endif // Defines some utility macros. @@ -573,9 +579,9 @@ // // The "switch (0) case 0:" idiom is used to suppress this. #ifdef __INTEL_COMPILER -#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ #else -#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT #endif // Use this annotation at the end of a struct/class definition to @@ -590,9 +596,9 @@ // Also use it after a variable or parameter declaration to tell the // compiler the variable/parameter does not have to be used. #if defined(__GNUC__) && !defined(COMPILER_ICC) -#define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) +# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) #else -#define GTEST_ATTRIBUTE_UNUSED_ +# define GTEST_ATTRIBUTE_UNUSED_ #endif // A macro to disallow operator= @@ -612,9 +618,9 @@ // // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) -#define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) +# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) #else -#define GTEST_MUST_USE_RESULT_ +# define GTEST_MUST_USE_RESULT_ #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC // Determine whether the compiler supports Microsoft's Structured Exception @@ -623,28 +629,28 @@ #ifndef GTEST_HAS_SEH // The user didn't tell us, so we need to figure it out. -#if defined(_MSC_VER) || defined(__BORLANDC__) +# if defined(_MSC_VER) || defined(__BORLANDC__) // These two compilers are known to support SEH. -#define GTEST_HAS_SEH 1 -#else +# define GTEST_HAS_SEH 1 +# else // Assume no SEH. -#define GTEST_HAS_SEH 0 -#endif +# define GTEST_HAS_SEH 0 +# endif #endif // GTEST_HAS_SEH #ifdef _MSC_VER -#if GTEST_LINKED_AS_SHARED_LIBRARY -#define GTEST_API_ __declspec(dllimport) -#elif GTEST_CREATE_SHARED_LIBRARY -#define GTEST_API_ __declspec(dllexport) -#endif +# if GTEST_LINKED_AS_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllimport) +# elif GTEST_CREATE_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllexport) +# endif #endif // _MSC_VER #ifndef GTEST_API_ -#define GTEST_API_ +# define GTEST_API_ #endif namespace testing { @@ -794,7 +800,9 @@ class GTEST_API_ RE { RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT #if GTEST_HAS_GLOBAL_STRING + RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT + #endif // GTEST_HAS_GLOBAL_STRING RE(const char* regex) { Init(regex); } // NOLINT @@ -818,12 +826,14 @@ class GTEST_API_ RE { } #if GTEST_HAS_GLOBAL_STRING + static bool FullMatch(const ::string& str, const RE& re) { return FullMatch(str.c_str(), re); } static bool PartialMatch(const ::string& str, const RE& re) { return PartialMatch(str.c_str(), re); } + #endif // GTEST_HAS_GLOBAL_STRING static bool FullMatch(const char* str, const RE& re); @@ -838,16 +848,31 @@ class GTEST_API_ RE { // files. const char* pattern_; bool is_valid_; + #if GTEST_USES_POSIX_RE + regex_t full_regex_; // For FullMatch(). regex_t partial_regex_; // For PartialMatch(). + #else // GTEST_USES_SIMPLE_RE + const char* full_pattern_; // For FullMatch(); + #endif GTEST_DISALLOW_ASSIGN_(RE); }; +// Formats a source file path and a line number as they would appear +// in an error message from the compiler used to compile this code. +GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); + +// Formats a file location for compiler-independent XML output. +// Although this function is not platform dependent, we put it next to +// FormatFileLocation in order to contrast the two functions. +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, + int line); + // Defines logging utilities: // GTEST_LOG_(severity) - logs messages at the specified severity level. The // message itself is streamed into the macro. @@ -1195,11 +1220,11 @@ class MutexBase { }; // Forward-declares a static mutex. -#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ extern ::testing::internal::MutexBase mutex // Defines and statically (i.e. at link time) initializes a static mutex. -#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 } // The Mutex class can only be used for mutexes created at runtime. It @@ -1346,7 +1371,7 @@ class ThreadLocal { GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); }; -#define GTEST_IS_THREADSAFE 1 +# define GTEST_IS_THREADSAFE 1 #else // GTEST_HAS_PTHREAD @@ -1361,10 +1386,10 @@ class Mutex { void AssertHeld() const {} }; -#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ extern ::testing::internal::Mutex mutex -#define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex class GTestMutexLock { public: @@ -1388,7 +1413,7 @@ class ThreadLocal { // The above synchronization primitives have dummy implementations. // Therefore Google Test is not thread-safe. -#define GTEST_IS_THREADSAFE 0 +# define GTEST_IS_THREADSAFE 0 #endif // GTEST_HAS_PTHREAD @@ -1405,9 +1430,9 @@ GTEST_API_ size_t GetThreadCount(); #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) // We lose support for NULL detection where the compiler doesn't like // passing non-POD classes through ellipsis (...). -#define GTEST_ELLIPSIS_NEEDS_POD_ 1 +# define GTEST_ELLIPSIS_NEEDS_POD_ 1 #else -#define GTEST_CAN_COMPARE_NULL 1 +# define GTEST_CAN_COMPARE_NULL 1 #endif // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between @@ -1415,7 +1440,7 @@ GTEST_API_ size_t GetThreadCount(); // _can_ decide between class template specializations for T and T*, // so a tr1::type_traits-like is_pointer works. #if defined(__SYMBIAN32__) || defined(__IBMCPP__) -#define GTEST_NEEDS_IS_POINTER_ 1 +# define GTEST_NEEDS_IS_POINTER_ 1 #endif template <bool bool_value> @@ -1435,13 +1460,13 @@ template <typename T> struct is_pointer<T*> : public true_type {}; #if GTEST_OS_WINDOWS -#define GTEST_PATH_SEP_ "\\" -#define GTEST_HAS_ALT_PATH_SEP_ 1 +# define GTEST_PATH_SEP_ "\\" +# define GTEST_HAS_ALT_PATH_SEP_ 1 // The biggest signed integer type the compiler supports. typedef __int64 BiggestInt; #else -#define GTEST_PATH_SEP_ "/" -#define GTEST_HAS_ALT_PATH_SEP_ 0 +# define GTEST_PATH_SEP_ "/" +# define GTEST_HAS_ALT_PATH_SEP_ 0 typedef long long BiggestInt; // NOLINT #endif // GTEST_OS_WINDOWS @@ -1495,36 +1520,36 @@ namespace posix { typedef struct _stat StatStruct; -#ifdef __BORLANDC__ +# ifdef __BORLANDC__ inline int IsATTY(int fd) { return isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { return stricmp(s1, s2); } inline char* StrDup(const char* src) { return strdup(src); } -#else // !__BORLANDC__ -#if GTEST_OS_WINDOWS_MOBILE +# else // !__BORLANDC__ +# if GTEST_OS_WINDOWS_MOBILE inline int IsATTY(int /* fd */) { return 0; } -#else +# else inline int IsATTY(int fd) { return _isatty(fd); } -#endif // GTEST_OS_WINDOWS_MOBILE +# endif // GTEST_OS_WINDOWS_MOBILE inline int StrCaseCmp(const char* s1, const char* s2) { return _stricmp(s1, s2); } inline char* StrDup(const char* src) { return _strdup(src); } -#endif // __BORLANDC__ +# endif // __BORLANDC__ -#if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // time and thus not defined there. -#else +# else inline int FileNo(FILE* file) { return _fileno(file); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int RmDir(const char* dir) { return _rmdir(dir); } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } -#endif // GTEST_OS_WINDOWS_MOBILE +# endif // GTEST_OS_WINDOWS_MOBILE #else @@ -1546,8 +1571,8 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } #ifdef _MSC_VER // Temporarily disable warning 4996 (deprecated function). -#pragma warning(push) -#pragma warning(disable:4996) +# pragma warning(push) +# pragma warning(disable:4996) #endif inline const char* StrNCpy(char* dest, const char* src, size_t n) { @@ -1596,7 +1621,7 @@ inline const char* GetEnv(const char* name) { } #ifdef _MSC_VER -#pragma warning(pop) // Restores the warning state. +# pragma warning(pop) // Restores the warning state. #endif #if GTEST_OS_WINDOWS_MOBILE @@ -1662,6 +1687,7 @@ class TypeWithSize<4> { template <> class TypeWithSize<8> { public: + #if GTEST_OS_WINDOWS typedef __int64 Int; typedef unsigned __int64 UInt; diff --git a/testing/gtest/include/gtest/internal/gtest-string.h b/testing/gtest/include/gtest/internal/gtest-string.h index 8cbb797..dc3a07b 100644 --- a/testing/gtest/include/gtest/internal/gtest-string.h +++ b/testing/gtest/include/gtest/internal/gtest-string.h @@ -43,7 +43,7 @@ #ifdef __BORLANDC__ // string.h is not guaranteed to provide strcpy on C++ Builder. -#include <mem.h> +# include <mem.h> #endif #include <string.h> @@ -296,7 +296,7 @@ class GTEST_API_ String { private: // Constructs a non-NULL String from the given content. This - // function can only be called when data_ has not been allocated. + // function can only be called when c_str_ has not been allocated. // ConstructNonNull(NULL, 0) results in an empty string (""). // ConstructNonNull(NULL, non_zero) is undefined behavior. void ConstructNonNull(const char* buffer, size_t a_length) { diff --git a/testing/gtest/include/gtest/internal/gtest-tuple.h b/testing/gtest/include/gtest/internal/gtest-tuple.h index 16178fc..d1af50e 100644 --- a/testing/gtest/include/gtest/internal/gtest-tuple.h +++ b/testing/gtest/include/gtest/internal/gtest-tuple.h @@ -44,9 +44,9 @@ // private as public. // Sun Studio versions < 12 also have the above bug. #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) -#define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: #else -#define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ template <GTEST_10_TYPENAMES_(U)> friend class tuple; \ private: #endif diff --git a/testing/gtest/include/gtest/internal/gtest-tuple.h.pump b/testing/gtest/include/gtest/internal/gtest-tuple.h.pump index 85ebc80..ef51909 100644 --- a/testing/gtest/include/gtest/internal/gtest-tuple.h.pump +++ b/testing/gtest/include/gtest/internal/gtest-tuple.h.pump @@ -45,9 +45,9 @@ $$ This meta comment fixes auto-indentation in Emacs. }} // private as public. // Sun Studio versions < 12 also have the above bug. #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) -#define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: #else -#define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ template <GTEST_$(n)_TYPENAMES_(U)> friend class tuple; \ private: #endif diff --git a/testing/gtest/include/gtest/internal/gtest-type-util.h b/testing/gtest/include/gtest/internal/gtest-type-util.h index 7a98646..ec9315d 100644 --- a/testing/gtest/include/gtest/internal/gtest-type-util.h +++ b/testing/gtest/include/gtest/internal/gtest-type-util.h @@ -47,36 +47,24 @@ #include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-string.h" -#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P - // #ifdef __GNUC__ is too general here. It is possible to use gcc without using // libstdc++ (which is where cxxabi.h comes from). -#ifdef __GLIBCXX__ -#include <cxxabi.h> -#endif // __GLIBCXX__ +# ifdef __GLIBCXX__ +# include <cxxabi.h> +# endif // __GLIBCXX__ namespace testing { namespace internal { -// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same -// type. This can be used as a compile-time assertion to ensure that -// two types are equal. - -template <typename T1, typename T2> -struct AssertTypeEq; - -template <typename T> -struct AssertTypeEq<T, T> { - typedef bool type; -}; - // GetTypeName<T>() returns a human-readable name of type T. +// NB: This function is also used in Google Mock, so don't move it inside of +// the typed-test-only section below. template <typename T> String GetTypeName() { -#if GTEST_HAS_RTTI +# if GTEST_HAS_RTTI const char* const name = typeid(T).name(); -#ifdef __GLIBCXX__ +# ifdef __GLIBCXX__ int status = 0; // gcc's implementation of typeid(T).name() mangles the type name, // so we have to demangle it. @@ -84,15 +72,31 @@ String GetTypeName() { const String name_str(status == 0 ? readable_name : name); free(readable_name); return name_str; -#else +# else return name; -#endif // __GLIBCXX__ +# endif // __GLIBCXX__ + +# else -#else return "<type>"; -#endif // GTEST_HAS_RTTI + +# endif // GTEST_HAS_RTTI } +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same +// type. This can be used as a compile-time assertion to ensure that +// two types are equal. + +template <typename T1, typename T2> +struct AssertTypeEq; + +template <typename T> +struct AssertTypeEq<T, T> { + typedef bool type; +}; + // A unique type used as the default value for the arguments of class // template Types. This allows us to simulate variadic templates // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't @@ -1611,7 +1615,7 @@ struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, namespace internal { -#define GTEST_TEMPLATE_ template <typename T> class +# define GTEST_TEMPLATE_ template <typename T> class // The template "selector" struct TemplateSel<Tmpl> is used to // represent Tmpl, which must be a class template with one type @@ -1629,7 +1633,7 @@ struct TemplateSel { }; }; -#define GTEST_BIND_(TmplSel, T) \ +# define GTEST_BIND_(TmplSel, T) \ TmplSel::template Bind<T>::type // A unique struct template used as the default value for the @@ -3313,9 +3317,9 @@ struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type; }; +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + } // namespace internal } // namespace testing -#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P - #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ diff --git a/testing/gtest/include/gtest/internal/gtest-type-util.h.pump b/testing/gtest/include/gtest/internal/gtest-type-util.h.pump index 04906b7..b69ce6e 100644 --- a/testing/gtest/include/gtest/internal/gtest-type-util.h.pump +++ b/testing/gtest/include/gtest/internal/gtest-type-util.h.pump @@ -45,36 +45,24 @@ $var n = 50 $$ Maximum length of type lists we want to support. #include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-string.h" -#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P - // #ifdef __GNUC__ is too general here. It is possible to use gcc without using // libstdc++ (which is where cxxabi.h comes from). -#ifdef __GLIBCXX__ -#include <cxxabi.h> -#endif // __GLIBCXX__ +# ifdef __GLIBCXX__ +# include <cxxabi.h> +# endif // __GLIBCXX__ namespace testing { namespace internal { -// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same -// type. This can be used as a compile-time assertion to ensure that -// two types are equal. - -template <typename T1, typename T2> -struct AssertTypeEq; - -template <typename T> -struct AssertTypeEq<T, T> { - typedef bool type; -}; - // GetTypeName<T>() returns a human-readable name of type T. +// NB: This function is also used in Google Mock, so don't move it inside of +// the typed-test-only section below. template <typename T> String GetTypeName() { -#if GTEST_HAS_RTTI +# if GTEST_HAS_RTTI const char* const name = typeid(T).name(); -#ifdef __GLIBCXX__ +# ifdef __GLIBCXX__ int status = 0; // gcc's implementation of typeid(T).name() mangles the type name, // so we have to demangle it. @@ -82,15 +70,31 @@ String GetTypeName() { const String name_str(status == 0 ? readable_name : name); free(readable_name); return name_str; -#else +# else return name; -#endif // __GLIBCXX__ +# endif // __GLIBCXX__ + +# else -#else return "<type>"; -#endif // GTEST_HAS_RTTI + +# endif // GTEST_HAS_RTTI } +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same +// type. This can be used as a compile-time assertion to ensure that +// two types are equal. + +template <typename T1, typename T2> +struct AssertTypeEq; + +template <typename T> +struct AssertTypeEq<T, T> { + typedef bool type; +}; + // A unique type used as the default value for the arguments of class // template Types. This allows us to simulate variadic templates // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't @@ -169,7 +173,7 @@ struct Types<$for j, [[T$j]]$for k[[, internal::None]]> { namespace internal { -#define GTEST_TEMPLATE_ template <typename T> class +# define GTEST_TEMPLATE_ template <typename T> class // The template "selector" struct TemplateSel<Tmpl> is used to // represent Tmpl, which must be a class template with one type @@ -187,7 +191,7 @@ struct TemplateSel { }; }; -#define GTEST_BIND_(TmplSel, T) \ +# define GTEST_BIND_(TmplSel, T) \ TmplSel::template Bind<T>::type // A unique struct template used as the default value for the @@ -279,9 +283,9 @@ struct TypeList<Types<$for i, [[T$i]]> > { typedef typename Types<$for i, [[T$i]]>::type type; }; +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + } // namespace internal } // namespace testing -#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P - #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ diff --git a/testing/gtest/src/gtest-death-test.cc b/testing/gtest/src/gtest-death-test.cc index 3e65193..603fccc 100644 --- a/testing/gtest/src/gtest-death-test.cc +++ b/testing/gtest/src/gtest-death-test.cc @@ -36,21 +36,21 @@ #if GTEST_HAS_DEATH_TEST -#if GTEST_OS_MAC -#include <crt_externs.h> -#endif // GTEST_OS_MAC - -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <stdarg.h> - -#if GTEST_OS_WINDOWS -#include <windows.h> -#else -#include <sys/mman.h> -#include <sys/wait.h> -#endif // GTEST_OS_WINDOWS +# if GTEST_OS_MAC +# include <crt_externs.h> +# endif // GTEST_OS_MAC + +# include <errno.h> +# include <fcntl.h> +# include <limits.h> +# include <stdarg.h> + +# if GTEST_OS_WINDOWS +# include <windows.h> +# else +# include <sys/mman.h> +# include <sys/wait.h> +# endif // GTEST_OS_WINDOWS #endif // GTEST_HAS_DEATH_TEST @@ -113,14 +113,18 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) { // ExitedWithCode function-call operator. bool ExitedWithCode::operator()(int exit_status) const { -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS + return exit_status == exit_code_; -#else + +# else + return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_; -#endif // GTEST_OS_WINDOWS + +# endif // GTEST_OS_WINDOWS } -#if !GTEST_OS_WINDOWS +# if !GTEST_OS_WINDOWS // KilledBySignal constructor. KilledBySignal::KilledBySignal(int signum) : signum_(signum) { } @@ -129,7 +133,7 @@ KilledBySignal::KilledBySignal(int signum) : signum_(signum) { bool KilledBySignal::operator()(int exit_status) const { return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_; } -#endif // !GTEST_OS_WINDOWS +# endif // !GTEST_OS_WINDOWS namespace internal { @@ -139,20 +143,25 @@ namespace internal { // specified by wait(2). static String ExitSummary(int exit_code) { Message m; -#if GTEST_OS_WINDOWS + +# if GTEST_OS_WINDOWS + m << "Exited with exit status " << exit_code; -#else + +# else + if (WIFEXITED(exit_code)) { m << "Exited with exit status " << WEXITSTATUS(exit_code); } else if (WIFSIGNALED(exit_code)) { m << "Terminated by signal " << WTERMSIG(exit_code); } -#ifdef WCOREDUMP +# ifdef WCOREDUMP if (WCOREDUMP(exit_code)) { m << " (core dumped)"; } -#endif -#endif // GTEST_OS_WINDOWS +# endif +# endif // GTEST_OS_WINDOWS + return m.GetString(); } @@ -162,7 +171,7 @@ bool ExitedUnsuccessfully(int exit_status) { return !ExitedWithCode(0)(exit_status); } -#if !GTEST_OS_WINDOWS +# if !GTEST_OS_WINDOWS // Generates a textual failure message when a death test finds more than // one thread running, or cannot determine the number of threads, prior // to executing the given statement. It is the responsibility of the @@ -177,7 +186,7 @@ static String DeathTestThreadWarning(size_t thread_count) { msg << "detected " << thread_count << " threads."; return msg.GetString(); } -#endif // !GTEST_OS_WINDOWS +# endif // !GTEST_OS_WINDOWS // Flag characters for reporting a death test that did not die. static const char kDeathTestLived = 'L'; @@ -216,13 +225,13 @@ void DeathTestAbort(const String& message) { } else { fprintf(stderr, "%s", message.c_str()); fflush(stderr); - abort(); + posix::Abort(); } } // A replacement for CHECK that calls DeathTestAbort if the assertion // fails. -#define GTEST_DEATH_TEST_CHECK_(expression) \ +# define GTEST_DEATH_TEST_CHECK_(expression) \ do { \ if (!::testing::internal::IsTrue(expression)) { \ DeathTestAbort(::testing::internal::String::Format( \ @@ -238,7 +247,7 @@ void DeathTestAbort(const String& message) { // evaluates the expression as long as it evaluates to -1 and sets // errno to EINTR. If the expression evaluates to -1 but errno is // something other than EINTR, DeathTestAbort is called. -#define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ +# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ do { \ int gtest_retval; \ do { \ @@ -527,7 +536,7 @@ bool DeathTestImpl::Passed(bool status_ok) { return success; } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are // always threadsafe, and Google Test considers the @@ -723,7 +732,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { set_spawned(true); return OVERSEE_TEST; } -#else // We are not on Windows. +# else // We are not on Windows. // ForkingDeathTest provides implementations for most of the abstract // methods of the DeathTest interface. Only the AssumeRole method is @@ -871,19 +880,19 @@ struct ExecDeathTestArgs { int close_fd; // File descriptor to close; the read end of a pipe }; -#if GTEST_OS_MAC +# if GTEST_OS_MAC inline char** GetEnviron() { // When Google Test is built as a framework on MacOS X, the environ variable // is unavailable. Apple's documentation (man environ) recommends using // _NSGetEnviron() instead. return *_NSGetEnviron(); } -#else +# else // Some POSIX platforms expect you to declare environ. extern "C" makes // it reside in the global namespace. extern "C" char** environ; inline char** GetEnviron() { return environ; } -#endif // GTEST_OS_MAC +# endif // GTEST_OS_MAC // The main function for a threadsafe-style death test child process. // This function is called in a clone()-ed process and thus must avoid @@ -940,7 +949,7 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) { ExecDeathTestArgs args = { argv, close_fd }; pid_t child_pid = -1; -#if GTEST_HAS_CLONE +# if GTEST_HAS_CLONE const bool use_fork = GTEST_FLAG(death_test_use_fork); if (!use_fork) { @@ -957,9 +966,9 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) { GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1); } -#else +# else const bool use_fork = true; -#endif // GTEST_HAS_CLONE +# endif // GTEST_HAS_CLONE if (use_fork && (child_pid = fork()) == 0) { ExecDeathTestChildMain(&args); @@ -1020,7 +1029,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { return OVERSEE_TEST; } -#endif // !GTEST_OS_WINDOWS +# endif // !GTEST_OS_WINDOWS // Creates a concrete DeathTest-derived class that depends on the // --gtest_death_test_style flag, and sets the pointer pointed to @@ -1051,18 +1060,23 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, } } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS + if (GTEST_FLAG(death_test_style) == "threadsafe" || GTEST_FLAG(death_test_style) == "fast") { *test = new WindowsDeathTest(statement, regex, file, line); } -#else + +# else + if (GTEST_FLAG(death_test_style) == "threadsafe") { *test = new ExecDeathTest(statement, regex, file, line); } else if (GTEST_FLAG(death_test_style) == "fast") { *test = new NoExecDeathTest(statement, regex); } -#endif // GTEST_OS_WINDOWS + +# endif // GTEST_OS_WINDOWS + else { // NOLINT - this is more readable than unbalanced brackets inside #if. DeathTest::set_last_death_test_message(String::Format( "Unknown death test style \"%s\" encountered", @@ -1093,7 +1107,7 @@ static void SplitString(const ::std::string& str, char delimiter, dest->swap(parsed); } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // Recreates the pipe and event handles from the provided parameters, // signals the event, and returns a file descriptor wrapped around the pipe // handle. This function is called in the child process only. @@ -1157,7 +1171,7 @@ int GetStatusFileDescriptor(unsigned int parent_process_id, return write_fd; } -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS // Returns a newly created InternalRunDeathTestFlag object with fields // initialized from the GTEST_FLAG(internal_run_death_test) flag if @@ -1173,7 +1187,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields); int write_fd = -1; -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS + unsigned int parent_process_id = 0; size_t write_handle_as_size_t = 0; size_t event_handle_as_size_t = 0; @@ -1191,7 +1206,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, event_handle_as_size_t); -#else +# else + if (fields.size() != 4 || !ParseNaturalNumber(fields[1], &line) || !ParseNaturalNumber(fields[2], &index) @@ -1200,7 +1216,9 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { "Bad --gtest_internal_run_death_test flag: %s", GTEST_FLAG(internal_run_death_test).c_str())); } -#endif // GTEST_OS_WINDOWS + +# endif // GTEST_OS_WINDOWS + return new InternalRunDeathTestFlag(fields[0], line, index, write_fd); } diff --git a/testing/gtest/src/gtest-filepath.cc b/testing/gtest/src/gtest-filepath.cc index 118848a..91b2571 100644 --- a/testing/gtest/src/gtest-filepath.cc +++ b/testing/gtest/src/gtest-filepath.cc @@ -35,26 +35,26 @@ #include <stdlib.h> #if GTEST_OS_WINDOWS_MOBILE -#include <windows.h> +# include <windows.h> #elif GTEST_OS_WINDOWS -#include <direct.h> -#include <io.h> +# include <direct.h> +# include <io.h> #elif GTEST_OS_SYMBIAN || GTEST_OS_NACL // Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h -#include <sys/syslimits.h> +# include <sys/syslimits.h> #else -#include <limits.h> -#include <climits> // Some Linux distributions define PATH_MAX here. +# include <limits.h> +# include <climits> // Some Linux distributions define PATH_MAX here. #endif // GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS -#define GTEST_PATH_MAX_ _MAX_PATH +# define GTEST_PATH_MAX_ _MAX_PATH #elif defined(PATH_MAX) -#define GTEST_PATH_MAX_ PATH_MAX +# define GTEST_PATH_MAX_ PATH_MAX #elif defined(_XOPEN_PATH_MAX) -#define GTEST_PATH_MAX_ _XOPEN_PATH_MAX +# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX #else -#define GTEST_PATH_MAX_ _POSIX_PATH_MAX +# define GTEST_PATH_MAX_ _POSIX_PATH_MAX #endif // GTEST_OS_WINDOWS #include "gtest/internal/gtest-string.h" @@ -71,16 +71,16 @@ const char kPathSeparator = '\\'; const char kAlternatePathSeparator = '/'; const char kPathSeparatorString[] = "\\"; const char kAlternatePathSeparatorString[] = "/"; -#if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have a current directory. You should not use // the current directory in tests on Windows CE, but this at least // provides a reasonable fallback. const char kCurrentDirectoryString[] = "\\"; // Windows CE doesn't define INVALID_FILE_ATTRIBUTES const DWORD kInvalidFileAttributes = 0xffffffff; -#else +# else const char kCurrentDirectoryString[] = ".\\"; -#endif // GTEST_OS_WINDOWS_MOBILE +# endif // GTEST_OS_WINDOWS_MOBILE #else const char kPathSeparator = '/'; const char kPathSeparatorString[] = "/"; diff --git a/testing/gtest/src/gtest-internal-inl.h b/testing/gtest/src/gtest-internal-inl.h index 8629c6f..e45f452 100644 --- a/testing/gtest/src/gtest-internal-inl.h +++ b/testing/gtest/src/gtest-internal-inl.h @@ -41,12 +41,12 @@ // part of Google Test's implementation; otherwise it's undefined. #if !GTEST_IMPLEMENTATION_ // A user is trying to include this from his code - just say no. -#error "gtest-internal-inl.h is part of Google Test's internal implementation." -#error "It must not be included except by Google Test itself." +# error "gtest-internal-inl.h is part of Google Test's internal implementation." +# error "It must not be included except by Google Test itself." #endif // GTEST_IMPLEMENTATION_ #ifndef _WIN32_WCE -#include <errno.h> +# include <errno.h> #endif // !_WIN32_WCE #include <stddef.h> #include <stdlib.h> // For strtoll/_strtoul64/malloc/free. @@ -59,7 +59,7 @@ #include "gtest/internal/gtest-port.h" #if GTEST_OS_WINDOWS -#include <windows.h> // For DWORD. +# include <windows.h> // NOLINT #endif // GTEST_OS_WINDOWS #include "gtest/gtest.h" // NOLINT @@ -930,7 +930,7 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); // platform. GTEST_API_ String GetLastErrnoDescription(); -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // Provides leak-safe Windows kernel handle ownership. class AutoHandle { public: @@ -954,7 +954,7 @@ class AutoHandle { GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle); }; -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS // Attempts to parse a string into a positive integer pointed to by the // number parameter. Returns true if that is possible. @@ -973,14 +973,20 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) { char* end; // BiggestConvertible is the largest integer type that system-provided // string-to-number conversion routines can return. -#if GTEST_OS_WINDOWS && !defined(__GNUC__) + +# if GTEST_OS_WINDOWS && !defined(__GNUC__) + // MSVC and C++ Builder define __int64 instead of the standard long long. typedef unsigned __int64 BiggestConvertible; const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10); -#else + +# else + typedef unsigned long long BiggestConvertible; // NOLINT const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); -#endif // GTEST_OS_WINDOWS && !defined(__GNUC__) + +# endif // GTEST_OS_WINDOWS && !defined(__GNUC__) + const bool parse_success = *end == '\0' && errno == 0; // TODO(vladl@google.com): Convert this to compile time assertion when it is diff --git a/testing/gtest/src/gtest-port.cc b/testing/gtest/src/gtest-port.cc index da62fba..b860d48 100644 --- a/testing/gtest/src/gtest-port.cc +++ b/testing/gtest/src/gtest-port.cc @@ -37,18 +37,18 @@ #include <string.h> #if GTEST_OS_WINDOWS_MOBILE -#include <windows.h> // For TerminateProcess() +# include <windows.h> // For TerminateProcess() #elif GTEST_OS_WINDOWS -#include <io.h> -#include <sys/stat.h> +# include <io.h> +# include <sys/stat.h> #else -#include <unistd.h> +# include <unistd.h> #endif // GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_MAC -#include <mach/mach_init.h> -#include <mach/task.h> -#include <mach/vm_map.h> +# include <mach/mach_init.h> +# include <mach/task.h> +# include <mach/vm_map.h> #endif // GTEST_OS_MAC #include "gtest/gtest-spi.h" @@ -424,6 +424,38 @@ void RE::Init(const char* regex) { #endif // GTEST_USES_POSIX_RE +const char kUnknownFile[] = "unknown file"; + +// Formats a source file path and a line number as they would appear +// in an error message from the compiler used to compile this code. +GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) { + const char* const file_name = file == NULL ? kUnknownFile : file; + + if (line < 0) { + return String::Format("%s:", file_name).c_str(); + } +#ifdef _MSC_VER + return String::Format("%s(%d):", file_name, line).c_str(); +#else + return String::Format("%s:%d:", file_name, line).c_str(); +#endif // _MSC_VER +} + +// Formats a file location for compiler-independent XML output. +// Although this function is not platform dependent, we put it next to +// FormatFileLocation in order to contrast the two functions. +// Note that FormatCompilerIndependentFileLocation() does NOT append colon +// to the file location it produces, unlike FormatFileLocation(). +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation( + const char* file, int line) { + const char* const file_name = file == NULL ? kUnknownFile : file; + + if (line < 0) + return file_name; + else + return String::Format("%s:%d", file_name, line).c_str(); +} + GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line) : severity_(severity) { @@ -446,8 +478,8 @@ GTestLog::~GTestLog() { // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4996) +# pragma warning(push) +# pragma warning(disable: 4996) #endif // _MSC_VER #if GTEST_HAS_STREAM_REDIRECTION @@ -457,7 +489,8 @@ class CapturedStream { public: // The ctor redirects the stream to a temporary file. CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { -#if GTEST_OS_WINDOWS + +# if GTEST_OS_WINDOWS char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT @@ -472,14 +505,14 @@ class CapturedStream { GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file " << temp_file_path; filename_ = temp_file_path; -#else +# else // There's no guarantee that a test has write access to the // current directory, so we create the temporary file in the /tmp // directory instead. char name_template[] = "/tmp/captured_stream.XXXXXX"; const int captured_fd = mkstemp(name_template); filename_ = name_template; -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS fflush(NULL); dup2(captured_fd, fd_); close(captured_fd); @@ -548,9 +581,9 @@ String CapturedStream::ReadEntireFile(FILE* file) { return content; } -#ifdef _MSC_VER -#pragma warning(pop) -#endif // _MSC_VER +# ifdef _MSC_VER +# pragma warning(pop) +# endif // _MSC_VER static CapturedStream* g_captured_stderr = NULL; static CapturedStream* g_captured_stdout = NULL; diff --git a/testing/gtest/src/gtest-printers.cc b/testing/gtest/src/gtest-printers.cc index bfbca9c..e576ca4 100644 --- a/testing/gtest/src/gtest-printers.cc +++ b/testing/gtest/src/gtest-printers.cc @@ -56,11 +56,11 @@ namespace { using ::std::ostream; #if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s. -#define snprintf _snprintf +# define snprintf _snprintf #elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf. -#define snprintf _snprintf_s +# define snprintf _snprintf_s #elif _MSC_VER -#define snprintf _snprintf +# define snprintf _snprintf #endif // GTEST_OS_WINDOWS_MOBILE // Prints a segment of bytes in the given object. @@ -155,9 +155,6 @@ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) { case L'\'': *os << "\\'"; break; - case L'\?': - *os << "\\?"; - break; case L'\\': *os << "\\\\"; break; diff --git a/testing/gtest/src/gtest.cc b/testing/gtest/src/gtest.cc index 575a8a5..fc0f801 100644 --- a/testing/gtest/src/gtest.cc +++ b/testing/gtest/src/gtest.cc @@ -51,76 +51,76 @@ // TODO(kenton@google.com): Use autoconf to detect availability of // gettimeofday(). -#define GTEST_HAS_GETTIMEOFDAY_ 1 +# define GTEST_HAS_GETTIMEOFDAY_ 1 -#include <fcntl.h> // NOLINT -#include <limits.h> // NOLINT -#include <sched.h> // NOLINT +# include <fcntl.h> // NOLINT +# include <limits.h> // NOLINT +# include <sched.h> // NOLINT // Declares vsnprintf(). This header is not available on Windows. -#include <strings.h> // NOLINT -#include <sys/mman.h> // NOLINT -#include <sys/time.h> // NOLINT -#include <unistd.h> // NOLINT -#include <string> +# include <strings.h> // NOLINT +# include <sys/mman.h> // NOLINT +# include <sys/time.h> // NOLINT +# include <unistd.h> // NOLINT +# include <string> #elif GTEST_OS_SYMBIAN -#define GTEST_HAS_GETTIMEOFDAY_ 1 -#include <sys/time.h> // NOLINT +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include <sys/time.h> // NOLINT #elif GTEST_OS_ZOS -#define GTEST_HAS_GETTIMEOFDAY_ 1 -#include <sys/time.h> // NOLINT +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include <sys/time.h> // NOLINT // On z/OS we additionally need strings.h for strcasecmp. -#include <strings.h> // NOLINT +# include <strings.h> // NOLINT #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. -#include <windows.h> // NOLINT +# include <windows.h> // NOLINT #elif GTEST_OS_WINDOWS // We are on Windows proper. -#include <io.h> // NOLINT -#include <sys/timeb.h> // NOLINT -#include <sys/types.h> // NOLINT -#include <sys/stat.h> // NOLINT +# include <io.h> // NOLINT +# include <sys/timeb.h> // NOLINT +# include <sys/types.h> // NOLINT +# include <sys/stat.h> // NOLINT -#if GTEST_OS_WINDOWS_MINGW +# if GTEST_OS_WINDOWS_MINGW // MinGW has gettimeofday() but not _ftime64(). // TODO(kenton@google.com): Use autoconf to detect availability of // gettimeofday(). // TODO(kenton@google.com): There are other ways to get the time on // Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW // supports these. consider using them instead. -#define GTEST_HAS_GETTIMEOFDAY_ 1 -#include <sys/time.h> // NOLINT -#endif // GTEST_OS_WINDOWS_MINGW +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include <sys/time.h> // NOLINT +# endif // GTEST_OS_WINDOWS_MINGW // cpplint thinks that the header is already included, so we want to // silence it. -#include <windows.h> // NOLINT +# include <windows.h> // NOLINT #else // Assume other platforms have gettimeofday(). // TODO(kenton@google.com): Use autoconf to detect availability of // gettimeofday(). -#define GTEST_HAS_GETTIMEOFDAY_ 1 +# define GTEST_HAS_GETTIMEOFDAY_ 1 // cpplint thinks that the header is already included, so we want to // silence it. -#include <sys/time.h> // NOLINT -#include <unistd.h> // NOLINT +# include <sys/time.h> // NOLINT +# include <unistd.h> // NOLINT #endif // GTEST_OS_LINUX #if GTEST_HAS_EXCEPTIONS -#include <stdexcept> +# include <stdexcept> #endif #if GTEST_CAN_STREAM_RESULTS_ -#include <arpa/inet.h> // NOLINT -#include <netdb.h> // NOLINT +# include <arpa/inet.h> // NOLINT +# include <netdb.h> // NOLINT #endif // Indicates that this translation unit is part of Google Test's @@ -133,7 +133,7 @@ #undef GTEST_IMPLEMENTATION_ #if GTEST_OS_WINDOWS -#define vsnprintf _vsnprintf +# define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS namespace testing { @@ -786,25 +786,30 @@ TimeInMillis GetTimeInMillis() { return 0; #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ __timeb64 now; -#ifdef _MSC_VER + +# ifdef _MSC_VER + // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996 // (deprecated function) there. // TODO(kenton@google.com): Use GetTickCount()? Or use // SystemTimeToFileTime() -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4996) // Temporarily disables warning 4996. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4996) // Temporarily disables warning 4996. _ftime64(&now); -#pragma warning(pop) // Restores the warning state. -#else +# pragma warning(pop) // Restores the warning state. +# else + _ftime64(&now); -#endif // _MSC_VER + +# endif // _MSC_VER + return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm; #elif GTEST_HAS_GETTIMEOFDAY_ struct timeval now; gettimeofday(&now, NULL); return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000; #else -#error "Don't know how to get the current time on your system." +# error "Don't know how to get the current time on your system." #endif } @@ -1332,10 +1337,13 @@ namespace { AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -#if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE + // Windows CE doesn't support FormatMessage. const char error_text[] = ""; -#else + +# else + // Looks up the human-readable system message for the HRESULT code // and since we're not passing any params to FormatMessage, we don't // want inserts expanded. @@ -1356,7 +1364,8 @@ AssertionResult HRESULTFailureHelper(const char* expr, --message_length) { error_text[message_length - 1] = '\0'; } -#endif // GTEST_OS_WINDOWS_MOBILE + +# endif // GTEST_OS_WINDOWS_MOBILE const String error_hex(String::Format("0x%08X ", hr)); return ::testing::AssertionFailure() @@ -1612,11 +1621,11 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, #if GTEST_OS_WINDOWS return _wcsicmp(lhs, rhs) == 0; -#elif GTEST_OS_LINUX +#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID return wcscasecmp(lhs, rhs) == 0; #else - // Mac OS X and Cygwin don't define wcscasecmp. Other unknown OSes - // may not define it either. + // Android, Mac OS X and Cygwin don't define wcscasecmp. + // Other unknown OSes may not define it either. wint_t left, right; do { left = towlower(*lhs++); @@ -1698,10 +1707,12 @@ String String::Format(const char * format, ...) { // MSVC 8 deprecates vsnprintf(), so we want to suppress warning // 4996 (deprecated function) there. #ifdef _MSC_VER // We are using MSVC. -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4996) // Temporarily disables warning 4996. +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4996) // Temporarily disables warning 4996. + const int size = vsnprintf(buffer, kBufferSize, format, args); -#pragma warning(pop) // Restores the warning state. + +# pragma warning(pop) // Restores the warning state. #else // We are not using MSVC. const int size = vsnprintf(buffer, kBufferSize, format, args); #endif // _MSC_VER @@ -2716,9 +2727,10 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( } if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) { + const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1); ColoredPrintf(COLOR_YELLOW, - "Note: This is test shard %s of %s.\n", - internal::posix::GetEnv(kTestShardIndex), + "Note: This is test shard %d of %s.\n", + static_cast<int>(shard_index) + 1, internal::posix::GetEnv(kTestTotalShards)); } @@ -3020,7 +3032,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { static String EscapeXml(const char* str, bool is_attribute); // Returns the given string with all characters invalid in XML removed. - static String RemoveInvalidXmlCharacters(const char* str); + static string RemoveInvalidXmlCharacters(const string& str); // Convenience wrapper around EscapeXml when str is an attribute value. static String EscapeXmlAttribute(const char* str) { @@ -3154,17 +3166,14 @@ String XmlUnitTestResultPrinter::EscapeXml(const char* str, bool is_attribute) { // Returns the given string with all characters invalid in XML removed. // Currently invalid characters are dropped from the string. An // alternative is to replace them with certain characters such as . or ?. -String XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const char* str) { - char* const output = new char[strlen(str) + 1]; - char* appender = output; - for (char ch = *str; ch != '\0'; ch = *++str) - if (IsValidXmlCharacter(ch)) - *appender++ = ch; - *appender = '\0'; +string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const string& str) { + string output; + output.reserve(str.size()); + for (string::const_iterator it = str.begin(); it != str.end(); ++it) + if (IsValidXmlCharacter(*it)) + output.push_back(*it); - String ret_value(output); - delete[] output; - return ret_value; + return output; } // The following routines generate an XML representation of a UnitTest @@ -3244,11 +3253,11 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, *stream << " <failure message=\"" << EscapeXmlAttribute(part.summary()).c_str() << "\" type=\"\">"; - const String message = RemoveInvalidXmlCharacters(String::Format( - "%s:%d\n%s", - part.file_name(), part.line_number(), - part.message()).c_str()); - OutputXmlCDataSection(stream, message.c_str()); + const string location = internal::FormatCompilerIndependentFileLocation( + part.file_name(), part.line_number()); + const string message = location + "\n" + part.message(); + OutputXmlCDataSection(stream, + RemoveInvalidXmlCharacters(message).c_str()); *stream << "</failure>\n"; } } @@ -3824,20 +3833,21 @@ int UnitTest::Run() { // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { -#if !GTEST_OS_WINDOWS_MOBILE + +# if !GTEST_OS_WINDOWS_MOBILE // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); -#endif // !GTEST_OS_WINDOWS_MOBILE +# endif // !GTEST_OS_WINDOWS_MOBILE -#if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE +# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE // Death test children can be terminated with _abort(). On Windows, // _abort() can show a dialog with a warning message. This forces the // abort message to go to stderr instead. _set_error_mode(_OUT_TO_STDERR); -#endif +# endif -#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE +# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE // In the debug version, Visual Studio pops up a separate dialog // offering a choice to debug the aborted program. We need to suppress // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement @@ -3853,7 +3863,8 @@ int UnitTest::Run() { _set_abort_behavior( 0x0, // Clear the following flags: _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. -#endif +# endif + } #endif // GTEST_HAS_SEH @@ -3928,12 +3939,12 @@ namespace internal { UnitTestImpl::UnitTestImpl(UnitTest* parent) : parent_(parent), #ifdef _MSC_VER -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4355) // Temporarily disables warning 4355 +# pragma warning(push) // Saves the current warning state. +# pragma warning(disable:4355) // Temporarily disables warning 4355 // (using this in initializer). default_global_test_part_result_reporter_(this), default_per_thread_test_part_result_reporter_(this), -#pragma warning(pop) // Restores the warning state again. +# pragma warning(pop) // Restores the warning state again. #else default_global_test_part_result_reporter_(this), default_per_thread_test_part_result_reporter_(this), @@ -4334,7 +4345,7 @@ bool ShouldShard(const char* total_shards_env, // Parses the environment variable var as an Int32. If it is unset, // returns default_val. If it is not an Int32, prints an error // and aborts. -Int32 Int32FromEnvOrDie(const char* const var, Int32 default_val) { +Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) { const char* str_val = posix::GetEnv(var); if (str_val == NULL) { return default_val; @@ -4851,10 +4862,12 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { internal::g_executable_path = internal::StreamableToString(argv[0]); #if GTEST_HAS_DEATH_TEST + g_argvs.clear(); for (int i = 0; i != *argc; i++) { g_argvs.push_back(StreamableToString(argv[i])); } + #endif // GTEST_HAS_DEATH_TEST ParseGoogleTestFlagsOnly(argc, argv); diff --git a/testing/gtest/test/gtest-death-test_ex_test.cc b/testing/gtest/test/gtest-death-test_ex_test.cc index 71cc7a3..b50a13d 100644 --- a/testing/gtest/test/gtest-death-test_ex_test.cc +++ b/testing/gtest/test/gtest-death-test_ex_test.cc @@ -36,15 +36,15 @@ #if GTEST_HAS_DEATH_TEST -#if GTEST_HAS_SEH -#include <windows.h> // For RaiseException(). -#endif +# if GTEST_HAS_SEH +# include <windows.h> // For RaiseException(). +# endif -#include "gtest/gtest-spi.h" +# include "gtest/gtest-spi.h" -#if GTEST_HAS_EXCEPTIONS +# if GTEST_HAS_EXCEPTIONS -#include <exception> // For std::exception. +# include <exception> // For std::exception. // Tests that death tests report thrown exceptions as failures and that the // exceptions do not escape death test macros. @@ -71,9 +71,9 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), "gtest-death-test_ex_test.cc"); } -#endif // GTEST_HAS_EXCEPTIONS +# endif // GTEST_HAS_EXCEPTIONS -#if GTEST_HAS_SEH +# if GTEST_HAS_SEH // Tests that enabling interception of SEH exceptions with the // catch_exceptions flag does not interfere with SEH exceptions being // treated as death by death tests. @@ -82,7 +82,7 @@ TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { << "with catch_exceptions " << (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); } -#endif +# endif #endif // GTEST_HAS_DEATH_TEST diff --git a/testing/gtest/test/gtest-death-test_test.cc b/testing/gtest/test/gtest-death-test_test.cc index 6cc017b..bcf8e2a 100644 --- a/testing/gtest/test/gtest-death-test_test.cc +++ b/testing/gtest/test/gtest-death-test_test.cc @@ -40,28 +40,28 @@ using testing::internal::AlwaysTrue; #if GTEST_HAS_DEATH_TEST -#if GTEST_OS_WINDOWS -#include <direct.h> // For chdir(). -#else -#include <unistd.h> -#include <sys/wait.h> // For waitpid. -#include <limits> // For std::numeric_limits. -#endif // GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS +# include <direct.h> // For chdir(). +# else +# include <unistd.h> +# include <sys/wait.h> // For waitpid. +# include <limits> // For std::numeric_limits. +# endif // GTEST_OS_WINDOWS -#include <limits.h> -#include <signal.h> -#include <stdio.h> +# include <limits.h> +# include <signal.h> +# include <stdio.h> -#include "gtest/gtest-spi.h" +# include "gtest/gtest-spi.h" // Indicates that this translation unit is part of Google Test's // implementation. It must come before gtest-internal-inl.h is // included, or there will be a compiler error. This trick is to // prevent a user from accidentally including gtest-internal-inl.h in // his code. -#define GTEST_IMPLEMENTATION_ 1 -#include "src/gtest-internal-inl.h" -#undef GTEST_IMPLEMENTATION_ +# define GTEST_IMPLEMENTATION_ 1 +# include "src/gtest-internal-inl.h" +# undef GTEST_IMPLEMENTATION_ namespace posix = ::testing::internal::posix; @@ -195,13 +195,17 @@ void DeathTestSubroutine() { // Death in dbg, not opt. int DieInDebugElse12(int* sideeffect) { if (sideeffect) *sideeffect = 12; -#ifndef NDEBUG + +# ifndef NDEBUG + DieInside("DieInDebugElse12"); -#endif // NDEBUG + +# endif // NDEBUG + return 12; } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // Tests the ExitedWithCode predicate. TEST(ExitStatusPredicateTest, ExitedWithCode) { @@ -214,7 +218,7 @@ TEST(ExitStatusPredicateTest, ExitedWithCode) { EXPECT_FALSE(testing::ExitedWithCode(1)(0)); } -#else +# else // Returns the exit status of a process that calls _exit(2) with a // given exit code. This is a helper function for the @@ -273,7 +277,7 @@ TEST(ExitStatusPredicateTest, KilledBySignal) { EXPECT_FALSE(pred_kill(status_segv)); } -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS // Tests that the death test macros expand to code which may or may not // be followed by operator<<, and that in either case the complete text @@ -305,7 +309,7 @@ void DieWithEmbeddedNul() { _exit(1); } -#if GTEST_USES_PCRE +# if GTEST_USES_PCRE // Tests that EXPECT_DEATH and ASSERT_DEATH work when the error // message has a NUL character in it. TEST_F(TestForDeathTest, EmbeddedNulInMessage) { @@ -314,17 +318,17 @@ TEST_F(TestForDeathTest, EmbeddedNulInMessage) { EXPECT_DEATH(DieWithEmbeddedNul(), "my null world"); ASSERT_DEATH(DieWithEmbeddedNul(), "my null world"); } -#endif // GTEST_USES_PCRE +# endif // GTEST_USES_PCRE // Tests that death test macros expand to code which interacts well with switch // statements. TEST_F(TestForDeathTest, SwitchStatement) { // Microsoft compiler usually complains about switch statements without // case labels. We suppress that warning for this test. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4065) -#endif // _MSC_VER +# ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4065) +# endif // _MSC_VER switch (0) default: @@ -334,9 +338,9 @@ TEST_F(TestForDeathTest, SwitchStatement) { case 0: EXPECT_DEATH(_exit(1), "") << "exit in switch case"; -#ifdef _MSC_VER -#pragma warning(pop) -#endif // _MSC_VER +# ifdef _MSC_VER +# pragma warning(pop) +# endif // _MSC_VER } // Tests that a static member function can be used in a "fast" style @@ -415,7 +419,7 @@ void SetPthreadFlag() { } // namespace -#if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD +# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) { if (!testing::GTEST_FLAG(death_test_use_fork)) { @@ -427,7 +431,7 @@ TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) { } } -#endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD +# endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD // Tests that a method of another class can be used in a death test. TEST_F(TestForDeathTest, MethodOfAnotherClass) { @@ -449,10 +453,12 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) { const testing::internal::RE regex(regex_c_str); EXPECT_DEATH(GlobalFunction(), regex); -#if GTEST_HAS_GLOBAL_STRING +# if GTEST_HAS_GLOBAL_STRING + const string regex_str(regex_c_str); EXPECT_DEATH(GlobalFunction(), regex_str); -#endif // GTEST_HAS_GLOBAL_STRING + +# endif // GTEST_HAS_GLOBAL_STRING const ::std::string regex_std_str(regex_c_str); EXPECT_DEATH(GlobalFunction(), regex_std_str); @@ -568,13 +574,17 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) { EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), "death.*DieInDebugElse12"); -#ifdef NDEBUG +# ifdef NDEBUG + // Checks that the assignment occurs in opt mode (sideeffect). EXPECT_EQ(12, sideeffect); -#else + +# else + // Checks that the assignment does not occur in dbg mode (no sideeffect). EXPECT_EQ(0, sideeffect); -#endif + +# endif } // Tests that ASSERT_DEBUG_DEATH works as expected @@ -594,16 +604,20 @@ TEST_F(TestForDeathTest, TestAssertDebugDeath) { EXPECT_EQ(12, sideeffect); }, "death.*DieInDebugElse12"); -#ifdef NDEBUG +# ifdef NDEBUG + // Checks that the assignment occurs in opt mode (sideeffect). EXPECT_EQ(12, sideeffect); -#else + +# else + // Checks that the assignment does not occur in dbg mode (no sideeffect). EXPECT_EQ(0, sideeffect); -#endif + +# endif } -#ifndef NDEBUG +# ifndef NDEBUG void ExpectDebugDeathHelper(bool* aborted) { *aborted = true; @@ -611,7 +625,7 @@ void ExpectDebugDeathHelper(bool* aborted) { *aborted = false; } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { printf("This test should be considered failing if it shows " "any pop-up dialogs.\n"); @@ -622,7 +636,7 @@ TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { abort(); }, ""); } -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS // Tests that EXPECT_DEBUG_DEATH in debug mode does not abort // the function. @@ -647,19 +661,22 @@ TEST_F(TestForDeathTest, AssertDebugDeathAborts) { EXPECT_TRUE(aborted); } -#endif // _NDEBUG +# endif // _NDEBUG // Tests the *_EXIT family of macros, using a variety of predicates. static void TestExitMacros() { EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), ""); -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS + // Of all signals effects on the process exit code, only those of SIGABRT // are documented on Windows. // See http://msdn.microsoft.com/en-us/library/dwwzkt4c(VS.71).aspx. EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), ""); -#else + +# else + EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL), "") << "foo"; ASSERT_EXIT(raise(SIGUSR2), testing::KilledBySignal(SIGUSR2), "") << "bar"; @@ -667,7 +684,8 @@ static void TestExitMacros() { ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV), "") << "This failure is expected, too."; }, "This failure is expected, too."); -#endif // GTEST_OS_WINDOWS + +# endif // GTEST_OS_WINDOWS EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_EXIT(raise(SIGSEGV), testing::ExitedWithCode(0), "") @@ -1022,7 +1040,7 @@ TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) { EXPECT_STREQ("", GetLastErrnoDescription().c_str()); } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS TEST(AutoHandleTest, AutoHandleWorks) { HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL); ASSERT_NE(INVALID_HANDLE_VALUE, handle); @@ -1047,21 +1065,21 @@ TEST(AutoHandleTest, AutoHandleWorks) { testing::internal::AutoHandle auto_handle2; EXPECT_EQ(INVALID_HANDLE_VALUE, auto_handle2.Get()); } -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS typedef unsigned __int64 BiggestParsable; typedef signed __int64 BiggestSignedParsable; const BiggestParsable kBiggestParsableMax = ULLONG_MAX; const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX; -#else +# else typedef unsigned long long BiggestParsable; typedef signed long long BiggestSignedParsable; const BiggestParsable kBiggestParsableMax = ::std::numeric_limits<BiggestParsable>::max(); const BiggestSignedParsable kBiggestSignedParsableMax = ::std::numeric_limits<BiggestSignedParsable>::max(); -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS TEST(ParseNaturalNumberTest, RejectsInvalidFormat) { BiggestParsable result = 0; @@ -1147,14 +1165,14 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { EXPECT_EQ(123, char_result); } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS TEST(EnvironmentTest, HandleFitsIntoSizeT) { // TODO(vladl@google.com): Remove this test after this condition is verified // in a static assertion in gtest-death-test.cc in the function // GetStatusFileDescriptor. ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t)); } -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS // Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED trigger // failures when death tests are available on the system. @@ -1253,8 +1271,8 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) { // Microsoft compiler usually complains about switch statements without // case labels. We suppress that warning for this test. #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4065) +# pragma warning(push) +# pragma warning(disable: 4065) #endif // _MSC_VER switch (0) @@ -1267,7 +1285,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) { EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in switch case"; #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif // _MSC_VER } diff --git a/testing/gtest/test/gtest-filepath_test.cc b/testing/gtest/test/gtest-filepath_test.cc index 549dcef..66d4118 100644 --- a/testing/gtest/test/gtest-filepath_test.cc +++ b/testing/gtest/test/gtest-filepath_test.cc @@ -51,9 +51,9 @@ #undef GTEST_IMPLEMENTATION_ #if GTEST_OS_WINDOWS_MOBILE -#include <windows.h> // NOLINT +# include <windows.h> // NOLINT #elif GTEST_OS_WINDOWS -#include <direct.h> // NOLINT +# include <direct.h> // NOLINT #endif // GTEST_OS_WINDOWS_MOBILE namespace testing { @@ -91,14 +91,18 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) { const FilePath cwd = FilePath::GetCurrentDir(); posix::ChDir(original_dir.c_str()); -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS + // Skips the ":". const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); ASSERT_TRUE(cwd_without_drive != NULL); EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1); -#else + +# else + EXPECT_STREQ(GTEST_PATH_SEP_, cwd.c_str()); -#endif + +# endif } #endif // GTEST_OS_WINDOWS_MOBILE @@ -415,10 +419,12 @@ TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { TEST(DirectoryTest, CurrentDirectoryExists) { #if GTEST_OS_WINDOWS // We are on Windows. -#ifndef _WIN32_CE // Windows CE doesn't have a current directory. +# ifndef _WIN32_CE // Windows CE doesn't have a current directory. + EXPECT_TRUE(FilePath(".").DirectoryExists()); EXPECT_TRUE(FilePath(".\\").DirectoryExists()); -#endif // _WIN32_CE + +# endif // _WIN32_CE #else EXPECT_TRUE(FilePath(".").DirectoryExists()); EXPECT_TRUE(FilePath("./").DirectoryExists()); diff --git a/testing/gtest/test/gtest-options_test.cc b/testing/gtest/test/gtest-options_test.cc index 30b82f3..9e98f3f 100644 --- a/testing/gtest/test/gtest-options_test.cc +++ b/testing/gtest/test/gtest-options_test.cc @@ -41,9 +41,9 @@ #include "gtest/gtest.h" #if GTEST_OS_WINDOWS_MOBILE -#include <windows.h> +# include <windows.h> #elif GTEST_OS_WINDOWS -#include <direct.h> +# include <direct.h> #endif // GTEST_OS_WINDOWS_MOBILE // Indicates that this translation unit is part of Google Test's diff --git a/testing/gtest/test/gtest-param-test_test.cc b/testing/gtest/test/gtest-param-test_test.cc index 5a681d8..94a53d9 100644 --- a/testing/gtest/test/gtest-param-test_test.cc +++ b/testing/gtest/test/gtest-param-test_test.cc @@ -37,19 +37,19 @@ #if GTEST_HAS_PARAM_TEST -#include <algorithm> -#include <iostream> -#include <list> -#include <sstream> -#include <string> -#include <vector> +# include <algorithm> +# include <iostream> +# include <list> +# include <sstream> +# include <string> +# include <vector> // To include gtest-internal-inl.h. -#define GTEST_IMPLEMENTATION_ 1 -#include "src/gtest-internal-inl.h" // for UnitTestOptions -#undef GTEST_IMPLEMENTATION_ +# define GTEST_IMPLEMENTATION_ 1 +# include "src/gtest-internal-inl.h" // for UnitTestOptions +# undef GTEST_IMPLEMENTATION_ -#include "test/gtest-param-test_test.h" +# include "test/gtest-param-test_test.h" using ::std::vector; using ::std::sort; @@ -62,12 +62,12 @@ using ::testing::TestWithParam; using ::testing::Values; using ::testing::ValuesIn; -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE using ::testing::Combine; using ::std::tr1::get; using ::std::tr1::make_tuple; using ::std::tr1::tuple; -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE using ::testing::internal::ParamGenerator; using ::testing::internal::UnitTestOptions; @@ -85,7 +85,7 @@ template <typename T> return stream.str(); } -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // These overloads allow printing tuples in our tests. We cannot // define an operator<< for tuples, as that definition needs to be in @@ -121,7 +121,7 @@ template <typename T1, typename T2, typename T3, typename T4, typename T5, return stream.str(); } -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE // Verifies that a sequence generated by the generator and accessed // via the iterator object matches the expected one using Google Test @@ -457,7 +457,7 @@ TEST(BoolTest, BoolWorks) { VerifyGenerator(gen, expected_values); } -#if GTEST_HAS_COMBINE +# if GTEST_HAS_COMBINE // Tests that Combine() with two parameters generates the expected sequence. TEST(CombineTest, CombineWithTwoParameters) { @@ -542,7 +542,7 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { VerifyGenerator(gen, expected_values); } -#endif // GTEST_HAS_COMBINE +# endif // GTEST_HAS_COMBINE // Tests that an generator produces correct sequence after being // assigned from another generator. diff --git a/testing/gtest/test/gtest-port_test.cc b/testing/gtest/test/gtest-port_test.cc index 5afba2d..ff0165f 100644 --- a/testing/gtest/test/gtest-port_test.cc +++ b/testing/gtest/test/gtest-port_test.cc @@ -36,7 +36,7 @@ #include <stdio.h> #if GTEST_OS_MAC -#include <time.h> +# include <time.h> #endif // GTEST_OS_MAC #include <utility> // For std::pair and std::make_pair. @@ -209,6 +209,44 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) { GTEST_CHECK_(true) << "Check failed in switch case"; } +// Verifies behavior of FormatFileLocation. +TEST(FormatFileLocationTest, FormatsFileLocation) { + EXPECT_PRED_FORMAT2(IsSubstring, "foo.cc", FormatFileLocation("foo.cc", 42)); + EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation("foo.cc", 42)); +} + +TEST(FormatFileLocationTest, FormatsUnknownFile) { + EXPECT_PRED_FORMAT2( + IsSubstring, "unknown file", FormatFileLocation(NULL, 42)); + EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation(NULL, 42)); +} + +TEST(FormatFileLocationTest, FormatsUknownLine) { + EXPECT_EQ("foo.cc:", FormatFileLocation("foo.cc", -1)); +} + +TEST(FormatFileLocationTest, FormatsUknownFileAndLine) { + EXPECT_EQ("unknown file:", FormatFileLocation(NULL, -1)); +} + +// Verifies behavior of FormatCompilerIndependentFileLocation. +TEST(FormatCompilerIndependentFileLocationTest, FormatsFileLocation) { + EXPECT_EQ("foo.cc:42", FormatCompilerIndependentFileLocation("foo.cc", 42)); +} + +TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFile) { + EXPECT_EQ("unknown file:42", + FormatCompilerIndependentFileLocation(NULL, 42)); +} + +TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) { + EXPECT_EQ("foo.cc", FormatCompilerIndependentFileLocation("foo.cc", -1)); +} + +TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) { + EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(NULL, -1)); +} + #if GTEST_OS_MAC void* ThreadFunc(void* data) { pthread_mutex_t* mutex = static_cast<pthread_mutex_t*>(data); @@ -290,15 +328,19 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) { // For simplicity, we only cover the most important platforms here. TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) { #if GTEST_HAS_POSIX_RE + EXPECT_TRUE(GTEST_USES_POSIX_RE); + #else + EXPECT_TRUE(GTEST_USES_SIMPLE_RE); + #endif } #if GTEST_USES_POSIX_RE -#if GTEST_HAS_TYPED_TEST +# if GTEST_HAS_TYPED_TEST template <typename Str> class RETest : public ::testing::Test {}; @@ -307,9 +349,9 @@ class RETest : public ::testing::Test {}; // supports. typedef testing::Types< ::std::string, -#if GTEST_HAS_GLOBAL_STRING +# if GTEST_HAS_GLOBAL_STRING ::string, -#endif // GTEST_HAS_GLOBAL_STRING +# endif // GTEST_HAS_GLOBAL_STRING const char*> StringTypes; TYPED_TEST_CASE(RETest, StringTypes); @@ -360,7 +402,7 @@ TYPED_TEST(RETest, PartialMatchWorks) { EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re)); } -#endif // GTEST_HAS_TYPED_TEST +# endif // GTEST_HAS_TYPED_TEST #elif GTEST_USES_SIMPLE_RE diff --git a/testing/gtest/test/gtest-printers_test.cc b/testing/gtest/test/gtest-printers_test.cc index da1fbc2..1395c69 100644 --- a/testing/gtest/test/gtest-printers_test.cc +++ b/testing/gtest/test/gtest-printers_test.cc @@ -52,10 +52,10 @@ // hash_map and hash_set are available under Visual C++. #if _MSC_VER -#define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available. -#include <hash_map> // NOLINT -#define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available. -#include <hash_set> // NOLINT +# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available. +# include <hash_map> // NOLINT +# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available. +# include <hash_set> // NOLINT #endif // GTEST_OS_WINDOWS // Some user-defined types for testing the universal value printer. @@ -74,7 +74,7 @@ enum EnumWithoutPrinter { // An enum with a << operator. enum EnumWithStreaming { - kEWS1 = 10, + kEWS1 = 10 }; std::ostream& operator<<(std::ostream& os, EnumWithStreaming e) { @@ -83,7 +83,7 @@ std::ostream& operator<<(std::ostream& os, EnumWithStreaming e) { // An enum with a PrintTo() function. enum EnumWithPrintTo { - kEWPT1 = 1, + kEWPT1 = 1 }; void PrintTo(EnumWithPrintTo e, std::ostream* os) { @@ -276,7 +276,7 @@ TEST(PrintCharTest, PlainChar) { EXPECT_EQ("'\\0'", Print('\0')); EXPECT_EQ("'\\'' (39, 0x27)", Print('\'')); EXPECT_EQ("'\"' (34, 0x22)", Print('"')); - EXPECT_EQ("'\\?' (63, 0x3F)", Print('\?')); + EXPECT_EQ("'?' (63, 0x3F)", Print('?')); EXPECT_EQ("'\\\\' (92, 0x5C)", Print('\\')); EXPECT_EQ("'\\a' (7)", Print('\a')); EXPECT_EQ("'\\b' (8)", Print('\b')); @@ -318,7 +318,7 @@ TEST(PrintBuiltInTypeTest, Wchar_t) { EXPECT_EQ("L'\\0'", Print(L'\0')); EXPECT_EQ("L'\\'' (39, 0x27)", Print(L'\'')); EXPECT_EQ("L'\"' (34, 0x22)", Print(L'"')); - EXPECT_EQ("L'\\?' (63, 0x3F)", Print(L'\?')); + EXPECT_EQ("L'?' (63, 0x3F)", Print(L'?')); EXPECT_EQ("L'\\\\' (92, 0x5C)", Print(L'\\')); EXPECT_EQ("L'\\a' (7)", Print(L'\a')); EXPECT_EQ("L'\\b' (8)", Print(L'\b')); @@ -401,8 +401,8 @@ TEST(PrintCStringTest, Null) { // Tests that C strings are escaped properly. TEST(PrintCStringTest, EscapesProperly) { - const char* p = "'\"\?\\\a\b\f\n\r\t\v\x7F\xFF a"; - EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"\\?\\\\\\a\\b\\f" + const char* p = "'\"?\\\a\b\f\n\r\t\v\x7F\xFF a"; + EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"?\\\\\\a\\b\\f" "\\n\\r\\t\\v\\x7F\\xFF a\"", Print(p)); } @@ -438,9 +438,9 @@ TEST(PrintWideCStringTest, Null) { // Tests that wide C strings are escaped properly. TEST(PrintWideCStringTest, EscapesProperly) { - const wchar_t s[] = {'\'', '"', '\?', '\\', '\a', '\b', '\f', '\n', '\r', + const wchar_t s[] = {'\'', '"', '?', '\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v', 0xD3, 0x576, 0x8D3, 0xC74D, ' ', 'a', '\0'}; - EXPECT_EQ(PrintPointer(s) + " pointing to L\"'\\\"\\?\\\\\\a\\b\\f" + EXPECT_EQ(PrintPointer(s) + " pointing to L\"'\\\"?\\\\\\a\\b\\f" "\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"", Print(static_cast<const wchar_t*>(s))); } @@ -643,18 +643,18 @@ TEST(PrintArrayTest, BigArray) { #if GTEST_HAS_GLOBAL_STRING // ::string. TEST(PrintStringTest, StringInGlobalNamespace) { - const char s[] = "'\"\?\\\a\b\f\n\0\r\t\v\x7F\xFF a"; + const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a"; const ::string str(s, sizeof(s)); - EXPECT_EQ("\"'\\\"\\?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"", + EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"", Print(str)); } #endif // GTEST_HAS_GLOBAL_STRING // ::std::string. TEST(PrintStringTest, StringInStdNamespace) { - const char s[] = "'\"\?\\\a\b\f\n\0\r\t\v\x7F\xFF a"; + const char s[] = "'\"?\\\a\b\f\n\0\r\t\v\x7F\xFF a"; const ::std::string str(s, sizeof(s)); - EXPECT_EQ("\"'\\\"\\?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"", + EXPECT_EQ("\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v\\x7F\\xFF a\\0\"", Print(str)); } @@ -677,9 +677,9 @@ TEST(PrintStringTest, StringAmbiguousHex) { #if GTEST_HAS_GLOBAL_WSTRING // ::wstring. TEST(PrintWideStringTest, StringInGlobalNamespace) { - const wchar_t s[] = L"'\"\?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a"; + const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a"; const ::wstring str(s, sizeof(s)/sizeof(wchar_t)); - EXPECT_EQ("L\"'\\\"\\?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" + EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" "\\xD3\\x576\\x8D3\\xC74D a\\0\"", Print(str)); } @@ -688,9 +688,9 @@ TEST(PrintWideStringTest, StringInGlobalNamespace) { #if GTEST_HAS_STD_WSTRING // ::std::wstring. TEST(PrintWideStringTest, StringInStdNamespace) { - const wchar_t s[] = L"'\"\?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a"; + const wchar_t s[] = L"'\"?\\\a\b\f\n\0\r\t\v\xD3\x576\x8D3\xC74D a"; const ::std::wstring str(s, sizeof(s)/sizeof(wchar_t)); - EXPECT_EQ("L\"'\\\"\\?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" + EXPECT_EQ("L\"'\\\"?\\\\\\a\\b\\f\\n\\0\\r\\t\\v" "\\xD3\\x576\\x8D3\\xC74D a\\0\"", Print(str)); } @@ -936,6 +936,28 @@ TEST(PrintStlContainerTest, TwoDimensionalNativeArray) { EXPECT_EQ("{ { 1, 2, 3 }, { 4, 5, 6 } }", Print(b)); } +// Tests that a class named iterator isn't treated as a container. + +struct iterator { + char x; +}; + +TEST(PrintStlContainerTest, Iterator) { + iterator it = {}; + EXPECT_EQ("1-byte object <00>", Print(it)); +} + +// Tests that a class named const_iterator isn't treated as a container. + +struct const_iterator { + char x; +}; + +TEST(PrintStlContainerTest, ConstIterator) { + const_iterator it = {}; + EXPECT_EQ("1-byte object <00>", Print(it)); +} + #if GTEST_HAS_TR1_TUPLE // Tests printing tuples. @@ -995,7 +1017,7 @@ TEST(PrintTupleTest, NestedTuple) { // Unprintable types in the global namespace. TEST(PrintUnprintableTypeTest, InGlobalNamespace) { EXPECT_EQ("1-byte object <00>", - Print(UnprintableTemplateInGlobal<bool>())); + Print(UnprintableTemplateInGlobal<char>())); } // Unprintable types in a user namespace. diff --git a/testing/gtest/test/gtest_break_on_failure_unittest_.cc b/testing/gtest/test/gtest_break_on_failure_unittest_.cc index 3075509..dd07478 100644 --- a/testing/gtest/test/gtest_break_on_failure_unittest_.cc +++ b/testing/gtest/test/gtest_break_on_failure_unittest_.cc @@ -42,8 +42,8 @@ #include "gtest/gtest.h" #if GTEST_OS_WINDOWS -#include <windows.h> -#include <stdlib.h> +# include <windows.h> +# include <stdlib.h> #endif namespace { @@ -69,7 +69,8 @@ int main(int argc, char **argv) { // a general protection fault (segment violation). SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); -#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE +# if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE + // The default unhandled exception filter does not always exit // with the exception code as exit code - for example it exits with // 0 for EXCEPTION_ACCESS_VIOLATION and 1 for EXCEPTION_BREAKPOINT @@ -77,7 +78,8 @@ int main(int argc, char **argv) { // filter which always exits with the exception code for unhandled // exceptions. SetUnhandledExceptionFilter(ExitWithExceptionCode); -#endif + +# endif #endif testing::InitGoogleTest(&argc, argv); diff --git a/testing/gtest/test/gtest_catch_exceptions_test_.cc b/testing/gtest/test/gtest_catch_exceptions_test_.cc index 3cf7532..a35103f 100644 --- a/testing/gtest/test/gtest_catch_exceptions_test_.cc +++ b/testing/gtest/test/gtest_catch_exceptions_test_.cc @@ -38,12 +38,12 @@ #include <stdlib.h> // For exit(). #if GTEST_HAS_SEH -#include <windows.h> +# include <windows.h> #endif #if GTEST_HAS_EXCEPTIONS -#include <exception> // For set_terminate(). -#include <stdexcept> +# include <exception> // For set_terminate(). +# include <stdexcept> #endif using testing::Test; diff --git a/testing/gtest/test/gtest_environment_test.cc b/testing/gtest/test/gtest_environment_test.cc index 744b405..ec9aa2c 100644 --- a/testing/gtest/test/gtest_environment_test.cc +++ b/testing/gtest/test/gtest_environment_test.cc @@ -115,7 +115,7 @@ TEST(FooTest, Bar) { void Check(bool condition, const char* msg) { if (!condition) { printf("FAILED: %s\n", msg); - abort(); + testing::internal::posix::Abort(); } } diff --git a/testing/gtest/test/gtest_output_test_.cc b/testing/gtest/test/gtest_output_test_.cc index 47343e5..13dbec4 100644 --- a/testing/gtest/test/gtest_output_test_.cc +++ b/testing/gtest/test/gtest_output_test_.cc @@ -788,7 +788,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes); TEST(ADeathTest, ShouldRunFirst) { } -#if GTEST_HAS_TYPED_TEST +# if GTEST_HAS_TYPED_TEST // We rely on the golden file to verify that typed tests whose test // case name ends with DeathTest are run first. @@ -803,9 +803,9 @@ TYPED_TEST_CASE(ATypedDeathTest, NumericTypes); TYPED_TEST(ATypedDeathTest, ShouldRunFirst) { } -#endif // GTEST_HAS_TYPED_TEST +# endif // GTEST_HAS_TYPED_TEST -#if GTEST_HAS_TYPED_TEST_P +# if GTEST_HAS_TYPED_TEST_P // We rely on the golden file to verify that type-parameterized tests @@ -824,7 +824,7 @@ REGISTER_TYPED_TEST_CASE_P(ATypeParamDeathTest, ShouldRunFirst); INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes); -#endif // GTEST_HAS_TYPED_TEST_P +# endif // GTEST_HAS_TYPED_TEST_P #endif // GTEST_HAS_DEATH_TEST @@ -998,11 +998,11 @@ int main(int argc, char **argv) { if (testing::internal::GTEST_FLAG(internal_run_death_test) != "") { // Skip the usual output capturing if we're running as the child // process of an threadsafe-style death test. -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS posix::FReopen("nul:", "w", stdout); -#else +# else posix::FReopen("/dev/null", "w", stdout); -#endif // GTEST_OS_WINDOWS +# endif // GTEST_OS_WINDOWS return RUN_ALL_TESTS(); } #endif // GTEST_HAS_DEATH_TEST diff --git a/testing/gtest/test/gtest_output_test_golden_lin.txt b/testing/gtest/test/gtest_output_test_golden_lin.txt index 0ba9968..a1d342d 100644 --- a/testing/gtest/test/gtest_output_test_golden_lin.txt +++ b/testing/gtest/test/gtest_output_test_golden_lin.txt @@ -697,7 +697,7 @@ Note: Google Test filter = *DISABLED_* [==========] 1 test from 1 test case ran. [ PASSED ] 1 test. Note: Google Test filter = PassingTest.* -Note: This is test shard 1 of 2. +Note: This is test shard 2 of 2. [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from PassingTest diff --git a/testing/gtest/test/gtest_repeat_test.cc b/testing/gtest/test/gtest_repeat_test.cc index ff9063a..5223dc0 100644 --- a/testing/gtest/test/gtest_repeat_test.cc +++ b/testing/gtest/test/gtest_repeat_test.cc @@ -69,7 +69,7 @@ namespace { << " Actual: " << actual_val << "\n"\ << "Expected: " #expected "\n"\ << "Which is: " << expected_val << "\n";\ - abort();\ + ::testing::internal::posix::Abort();\ }\ } while(::testing::internal::AlwaysFalse()) @@ -113,10 +113,10 @@ TEST(BarDeathTest, ThreadSafeAndFast) { g_death_test_count++; GTEST_FLAG(death_test_style) = "threadsafe"; - EXPECT_DEATH_IF_SUPPORTED(abort(), ""); + EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); GTEST_FLAG(death_test_style) = "fast"; - EXPECT_DEATH_IF_SUPPORTED(abort(), ""); + EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); } #if GTEST_HAS_PARAM_TEST diff --git a/testing/gtest/test/gtest_test_utils.py b/testing/gtest/test/gtest_test_utils.py index e7ee9d9..4e897bd 100755 --- a/testing/gtest/test/gtest_test_utils.py +++ b/testing/gtest/test/gtest_test_utils.py @@ -162,11 +162,7 @@ def GetTestExecutablePath(executable_name, build_dir=None): message = ( 'Unable to find the test binary. Please make sure to provide path\n' 'to the binary via the --build_dir flag or the BUILD_DIR\n' - 'environment variable. For convenient use, invoke this script via\n' - 'mk_test.py.\n' - # TODO(vladl@google.com): change mk_test.py to test.py after renaming - # the file. - 'Please run mk_test.py -h for help.') + 'environment variable.') print >> sys.stderr, message sys.exit(1) diff --git a/testing/gtest/test/gtest_unittest.cc b/testing/gtest/test/gtest_unittest.cc index 1069ecf..46db38d 100644 --- a/testing/gtest/test/gtest_unittest.cc +++ b/testing/gtest/test/gtest_unittest.cc @@ -310,10 +310,10 @@ TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) { #if GTEST_CAN_COMPARE_NULL -#ifdef __BORLANDC__ +# ifdef __BORLANDC__ // Silences warnings: "Condition is always true", "Unreachable code" -#pragma option push -w-ccc -w-rch -#endif +# pragma option push -w-ccc -w-rch +# endif // Tests that GTEST_IS_NULL_LITERAL_(x) is true when x is a null // pointer literal. @@ -322,12 +322,15 @@ TEST(NullLiteralTest, IsTrueForNullLiterals) { EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0)); EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0U)); EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0L)); -#ifndef __BORLANDC__ + +# ifndef __BORLANDC__ + // Some compilers may fail to detect some null pointer literals; // as long as users of the framework don't use such literals, this // is harmless. EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(1 - 1)); -#endif + +# endif } // Tests that GTEST_IS_NULL_LITERAL_(x) is false when x is not a null @@ -339,10 +342,10 @@ TEST(NullLiteralTest, IsFalseForNonNullLiterals) { EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast<void*>(NULL))); } -#ifdef __BORLANDC__ +# ifdef __BORLANDC__ // Restores warnings after previous "#pragma option push" suppressed them. -#pragma option pop -#endif +# pragma option pop +# endif #endif // GTEST_CAN_COMPARE_NULL // @@ -1211,7 +1214,7 @@ TEST(StringTest, ShowWideCStringQuoted) { String::ShowWideCStringQuoted(L"foo").c_str()); } -#if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE TEST(StringTest, AnsiAndUtf16Null) { EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); @@ -1234,7 +1237,7 @@ TEST(StringTest, AnsiAndUtf16ConvertPathChars) { EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3)); delete [] utf16; } -#endif // GTEST_OS_WINDOWS_MOBILE +# endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS @@ -1368,7 +1371,7 @@ TEST_F(ExpectFatalFailureTest, CatchesFatalFailureOnAllThreads) { #ifdef __BORLANDC__ // Silences warnings: "Condition is always true" -#pragma option push -w-ccc +# pragma option push -w-ccc #endif // Tests that EXPECT_FATAL_FAILURE() can be used in a non-void @@ -1396,7 +1399,7 @@ void DoesNotAbortHelper(bool* aborted) { #ifdef __BORLANDC__ // Restores warnings after previous "#pragma option push" suppressed them. -#pragma option pop +# pragma option pop #endif TEST_F(ExpectFatalFailureTest, DoesNotAbort) { @@ -1413,8 +1416,8 @@ static int global_var = 0; #define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++ TEST_F(ExpectFatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { -#if !defined(__BORLANDC__) || __BORLANDC__ >= 0x600 - // ICE's in C++Builder 2007. +#ifndef __BORLANDC__ + // ICE's in C++Builder. EXPECT_FATAL_FAILURE({ GTEST_USE_UNPROTECTED_COMMA_; AddFatalFailure(); @@ -3534,7 +3537,7 @@ TEST(AssertionTest, AppendUserMessage) { #ifdef __BORLANDC__ // Silences warnings: "Condition is always true", "Unreachable code" -#pragma option push -w-ccc -w-rch +# pragma option push -w-ccc -w-rch #endif // Tests ASSERT_TRUE. @@ -3547,8 +3550,8 @@ TEST(AssertionTest, ASSERT_TRUE) { // Tests ASSERT_TRUE(predicate) for predicates returning AssertionResult. TEST(AssertionTest, AssertTrueWithAssertionResult) { ASSERT_TRUE(ResultIsEven(2)); -#if !defined(__BORLANDC__) || __BORLANDC__ >= 0x600 - // ICE's in C++Builder 2007. +#ifndef __BORLANDC__ + // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_TRUE(ResultIsEven(3)), "Value of: ResultIsEven(3)\n" " Actual: false (3 is odd)\n" @@ -3573,8 +3576,8 @@ TEST(AssertionTest, ASSERT_FALSE) { // Tests ASSERT_FALSE(predicate) for predicates returning AssertionResult. TEST(AssertionTest, AssertFalseWithAssertionResult) { ASSERT_FALSE(ResultIsEven(3)); -#if !defined(__BORLANDC__) || __BORLANDC__ >= 0x600 - // ICE's in C++Builder 2007. +#ifndef __BORLANDC__ + // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_FALSE(ResultIsEven(2)), "Value of: ResultIsEven(2)\n" " Actual: true (2 is even)\n" @@ -3589,7 +3592,7 @@ TEST(AssertionTest, AssertFalseWithAssertionResult) { #ifdef __BORLANDC__ // Restores warnings after previous "#pragma option push" supressed them -#pragma option pop +# pragma option pop #endif // Tests using ASSERT_EQ on double values. The purpose is to make @@ -3692,13 +3695,14 @@ void ThrowNothing() {} TEST(AssertionTest, ASSERT_THROW) { ASSERT_THROW(ThrowAnInteger(), int); -#ifndef __BORLANDC__ +# ifndef __BORLANDC__ + // ICE's in C++Builder 2007 and 2009. EXPECT_FATAL_FAILURE( ASSERT_THROW(ThrowAnInteger(), bool), "Expected: ThrowAnInteger() throws an exception of type bool.\n" " Actual: it throws a different type."); -#endif +# endif EXPECT_FATAL_FAILURE( ASSERT_THROW(ThrowNothing(), bool), @@ -3807,7 +3811,7 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) { enum NamedEnum { kE1 = 0, - kE2 = 1, + kE2 = 1 }; TEST(AssertionTest, NamedEnum) { @@ -3826,7 +3830,9 @@ TEST(AssertionTest, NamedEnum) { // Tests using assertions with anonymous enums. enum { kCaseA = -1, -#if GTEST_OS_LINUX + +# if GTEST_OS_LINUX + // We want to test the case where the size of the anonymous enum is // larger than sizeof(int), to make sure our implementation of the // assertions doesn't truncate the enums. However, MSVC @@ -3837,16 +3843,22 @@ enum { // int size. We want to test whether this will confuse the // assertions. kCaseB = testing::internal::kMaxBiggestInt, -#else + +# else + kCaseB = INT_MAX, -#endif // GTEST_OS_LINUX + +# endif // GTEST_OS_LINUX + kCaseC = 42, }; TEST(AssertionTest, AnonymousEnum) { -#if GTEST_OS_LINUX +# if GTEST_OS_LINUX + EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB)); -#endif // GTEST_OS_LINUX + +# endif // GTEST_OS_LINUX EXPECT_EQ(kCaseA, kCaseA); EXPECT_NE(kCaseA, kCaseB); @@ -3865,10 +3877,16 @@ TEST(AssertionTest, AnonymousEnum) { ASSERT_LE(kCaseA, kCaseB); ASSERT_GT(kCaseB, kCaseA); ASSERT_GE(kCaseA, kCaseA); + +# ifndef __BORLANDC__ + + // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), "Value of: kCaseB"); EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), "Actual: 42"); +# endif + EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), "Which is: -1"); } @@ -3925,12 +3943,14 @@ TEST(HRESULTAssertionTest, EXPECT_HRESULT_FAILED) { TEST(HRESULTAssertionTest, ASSERT_HRESULT_FAILED) { ASSERT_HRESULT_FAILED(E_UNEXPECTED); -#ifndef __BORLANDC__ +# ifndef __BORLANDC__ + // ICE's in C++Builder 2007 and 2009. EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(OkHRESULTSuccess()), "Expected: (OkHRESULTSuccess()) fails.\n" " Actual: 0x00000000"); -#endif +# endif + EXPECT_FATAL_FAILURE(ASSERT_HRESULT_FAILED(FalseHRESULTSuccess()), "Expected: (FalseHRESULTSuccess()) fails.\n" " Actual: 0x00000001"); @@ -3947,12 +3967,13 @@ TEST(HRESULTAssertionTest, Streaming) { EXPECT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure", "expected failure"); -#ifndef __BORLANDC__ +# ifndef __BORLANDC__ + // ICE's in C++Builder 2007 and 2009. EXPECT_FATAL_FAILURE( ASSERT_HRESULT_SUCCEEDED(E_UNEXPECTED) << "expected failure", "expected failure"); -#endif +# endif EXPECT_NONFATAL_FAILURE( EXPECT_HRESULT_FAILED(S_OK) << "expected failure", @@ -3967,7 +3988,7 @@ TEST(HRESULTAssertionTest, Streaming) { #ifdef __BORLANDC__ // Silences warnings: "Condition is always true", "Unreachable code" -#pragma option push -w-ccc -w-rch +# pragma option push -w-ccc -w-rch #endif // Tests that the assertion macros behave like single statements. @@ -4188,7 +4209,7 @@ TEST(ExpectTest, ExpectFalseWithAssertionResult) { #ifdef __BORLANDC__ // Restores warnings after previous "#pragma option push" supressed them -#pragma option pop +# pragma option pop #endif // Tests EXPECT_EQ. @@ -4776,10 +4797,13 @@ TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) { // Code tested by EXPECT_FATAL_FAILURE cannot reference local // variables, so we have to write UnprintableChar('x') instead of x. +#ifndef __BORLANDC__ + // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_NE(UnprintableChar('x'), UnprintableChar('x')), "1-byte object <78>"); EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')), "1-byte object <78>"); +#endif EXPECT_FATAL_FAILURE(ASSERT_LE(UnprintableChar('y'), UnprintableChar('x')), "1-byte object <79>"); EXPECT_FATAL_FAILURE(ASSERT_GE(UnprintableChar('x'), UnprintableChar('y')), @@ -5426,6 +5450,7 @@ class InitGoogleTestTest : public Test { // This macro wraps TestParsingFlags s.t. the user doesn't need // to specify the array sizes. + #define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ @@ -6239,7 +6264,7 @@ TEST(StreamingAssertionsTest, Unconditional) { #ifdef __BORLANDC__ // Silences warnings: "Condition is always true", "Unreachable code" -#pragma option push -w-ccc -w-rch +# pragma option push -w-ccc -w-rch #endif TEST(StreamingAssertionsTest, Truth) { @@ -6262,7 +6287,7 @@ TEST(StreamingAssertionsTest, Truth2) { #ifdef __BORLANDC__ // Restores warnings after previous "#pragma option push" supressed them -#pragma option pop +# pragma option pop #endif TEST(StreamingAssertionsTest, IntegerEquals) { @@ -7197,8 +7222,10 @@ TEST(CopyArrayTest, WorksForDegeneratedArrays) { TEST(CopyArrayTest, WorksForOneDimensionalArrays) { const char a[3] = "hi"; int b[3]; +#ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. CopyArray(a, &b); EXPECT_TRUE(ArrayEq(a, b)); +#endif int c[3]; CopyArray(a, 3, c); @@ -7208,8 +7235,10 @@ TEST(CopyArrayTest, WorksForOneDimensionalArrays) { TEST(CopyArrayTest, WorksForTwoDimensionalArrays) { const int a[2][3] = { { 0, 1, 2 }, { 3, 4, 5 } }; int b[2][3]; +#ifndef __BORLANDC__ // C++Builder cannot compile some array size deductions. CopyArray(a, &b); EXPECT_TRUE(ArrayEq(a, b)); +#endif int c[2][3]; CopyArray(a, 2, c); |