From fbb48a7708fc791ef25096b383791966bbf369f0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 26 Jan 2018 11:57:58 -0500 Subject: Code merges --- googlemock/include/gmock/gmock-matchers.h | 3 +- googlemock/include/gmock/gmock-more-matchers.h | 16 +++++++++ googlemock/include/gmock/gmock-spec-builders.h | 9 +++-- googlemock/include/gmock/gmock.h | 2 +- .../internal/gmock-generated-internal-utils.h | 25 +++++++++----- .../include/gmock/internal/gmock-internal-utils.h | 39 ++++++++++++++++++++-- googlemock/include/gmock/internal/gmock-port.h | 18 ++++------ googlemock/test/gmock_stress_test.cc | 3 +- googlemock/test/gmock_test.cc | 5 +-- 9 files changed, 86 insertions(+), 34 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 3367a0b..41bf6de 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -47,10 +47,9 @@ #include #include #include - +#include "gtest/gtest.h" #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #if GTEST_HAS_STD_INITIALIZER_LIST_ # include // NOLINT -- must be after gtest.h diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 3db899f..a5a8bfa 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -53,6 +53,22 @@ MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { return false; } +// Define a matcher that matches a value that evaluates in boolean +// context to true. Useful for types that define "explicit operator +// bool" operators and so can't be compared for equality with true +// and false. +MATCHER(IsTrue, negation ? "is false" : "is true") { + return static_cast(arg); +} + +// Define a matcher that matches a value that evaluates in boolean +// context to false. Useful for types that define "explicit operator +// bool" operators and so can't be compared for equality with true +// and false. +MATCHER(IsFalse, negation ? "is true" : "is false") { + return !static_cast(arg); +} + } // namespace testing #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index a8347bd..c1b6301 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -65,11 +65,6 @@ #include #include #include - -#if GTEST_HAS_EXCEPTIONS -# include // NOLINT -#endif - #include "gmock/gmock-actions.h" #include "gmock/gmock-cardinalities.h" #include "gmock/gmock-matchers.h" @@ -77,6 +72,10 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" +#if GTEST_HAS_EXCEPTIONS +# include // NOLINT +#endif + namespace testing { // An abstract handle of an expectation. diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h index 5764bc8..6ccb118 100644 --- a/googlemock/include/gmock/gmock.h +++ b/googlemock/include/gmock/gmock.h @@ -59,8 +59,8 @@ #include "gmock/gmock-cardinalities.h" #include "gmock/gmock-generated-actions.h" #include "gmock/gmock-generated-function-mockers.h" -#include "gmock/gmock-generated-nice-strict.h" #include "gmock/gmock-generated-matchers.h" +#include "gmock/gmock-generated-nice-strict.h" #include "gmock/gmock-matchers.h" #include "gmock/gmock-more-actions.h" #include "gmock/gmock-more-matchers.h" diff --git a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h index 7811e43..cd94d64 100644 --- a/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-generated-internal-utils.h @@ -90,42 +90,48 @@ struct MatcherTuple< ::testing::tuple > { template struct MatcherTuple< ::testing::tuple > { - typedef ::testing::tuple, Matcher, Matcher, - Matcher > type; + typedef ::testing::tuple, Matcher, Matcher, Matcher > + type; }; template struct MatcherTuple< ::testing::tuple > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher > type; + Matcher > + type; }; template struct MatcherTuple< ::testing::tuple > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher > type; + Matcher, Matcher > + type; }; template struct MatcherTuple< ::testing::tuple > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher > type; + Matcher, Matcher, Matcher > + type; }; template struct MatcherTuple< ::testing::tuple > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher > type; + Matcher, Matcher, Matcher, Matcher > + type; }; template struct MatcherTuple< ::testing::tuple > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher, Matcher > type; + Matcher, Matcher, Matcher, Matcher, + Matcher > + type; }; template > { typedef ::testing::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher, Matcher, - Matcher > type; + Matcher, Matcher, Matcher, Matcher, + Matcher, Matcher > + type; }; // Template struct Function, where F must be a function type, contains diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 7e65cea..319b389 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -41,7 +41,6 @@ #include #include // NOLINT #include - #include "gmock/internal/gmock-generated-internal-utils.h" #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" @@ -49,11 +48,15 @@ namespace testing { namespace internal { +// Joins a vector of strings as if they are fields of a tuple; returns +// the joined string. +GTEST_API_ std::string JoinAsTuple(const Strings& fields); + // Converts an identifier name to a space-separated list of lower-case // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // treated as one word. For example, both "FooBar123" and // "foo_bar_123" are converted to "foo bar 123". -GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name); +GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name); // PointeeOf::type is the type of a value pointed to by a // Pointer, which can be either a smart pointer or a raw pointer. The @@ -503,8 +506,38 @@ struct RemoveConstFromKey > { template struct BooleanConstant {}; +// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to +// reduce code size. +void IllegalDoDefault(const char* file, int line); + +#if GTEST_LANG_CXX11 +// Helper types for Apply() below. +template struct int_pack { typedef int_pack type; }; + +template struct append; +template +struct append, I> : int_pack {}; + +template +struct make_int_pack : append::type, C - 1> {}; +template <> struct make_int_pack<0> : int_pack<> {}; + +template +auto ApplyImpl(F&& f, Tuple&& args, int_pack) -> decltype( + std::forward(f)(std::get(std::forward(args))...)) { + return std::forward(f)(std::get(std::forward(args))...); +} + +// Apply the function to a tuple of arguments. +template +auto Apply(F&& f, Tuple&& args) + -> decltype(ApplyImpl(std::forward(f), std::forward(args), + make_int_pack::value>())) { + return ApplyImpl(std::forward(f), std::forward(args), + make_int_pack::value>()); +} +#endif } // namespace internal } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ - diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h index 63f4a68..cb37f26 100644 --- a/googlemock/include/gmock/internal/gmock-port.h +++ b/googlemock/include/gmock/internal/gmock-port.h @@ -50,15 +50,11 @@ // portability utilities to Google Test's gtest-port.h instead of // here, as Google Mock depends on Google Test. Only add a utility // here if it's truly specific to Google Mock. + #include "gtest/internal/gtest-linked_ptr.h" #include "gtest/internal/gtest-port.h" #include "gmock/internal/custom/gmock-port.h" -// To avoid conditional compilation everywhere, we make it -// gmock-port.h's responsibility to #include the header implementing -// tr1/tuple. gmock-port.h does this via gtest-port.h, which is -// guaranteed to pull in the tuple header. - // 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 @@ -72,18 +68,18 @@ #if !defined(GMOCK_DECLARE_bool_) // Macros for declaring flags. -#define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) -#define GMOCK_DECLARE_int32_(name) \ +# define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) +# define GMOCK_DECLARE_int32_(name) \ extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) -#define GMOCK_DECLARE_string_(name) \ +# define GMOCK_DECLARE_string_(name) \ extern GTEST_API_ ::std::string GMOCK_FLAG(name) // Macros for defining flags. -#define GMOCK_DEFINE_bool_(name, default_val, doc) \ +# define GMOCK_DEFINE_bool_(name, default_val, doc) \ GTEST_API_ bool GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_int32_(name, default_val, doc) \ +# define GMOCK_DEFINE_int32_(name, default_val, doc) \ GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_string_(name, default_val, doc) \ +# define GMOCK_DEFINE_string_(name, default_val, doc) \ GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) #endif // !defined(GMOCK_DECLARE_bool_) diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index c16badd..b9fdc45 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -33,12 +33,13 @@ // threads concurrently. #include "gmock/gmock.h" + #include "gtest/gtest.h" namespace testing { namespace { -// From . +// From "gtest/internal/gtest-port.h". using ::testing::internal::ThreadWithParam; // The maximum number of test threads (not including helper threads) diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 2899534..7007567 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -37,6 +37,7 @@ #include #include "gtest/gtest.h" +#include "gtest/internal/custom/gtest.h" #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) @@ -51,9 +52,9 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], const ::std::string& expected_gmock_verbose) { const ::std::string old_verbose = GMOCK_FLAG(verbose); - int argc = M; + int argc = M - 1; InitGoogleMock(&argc, const_cast(argv)); - ASSERT_EQ(N, argc) << "The new argv has wrong number of elements."; + ASSERT_EQ(N - 1, argc) << "The new argv has wrong number of elements."; for (int i = 0; i < N; i++) { EXPECT_STREQ(new_argv[i], argv[i]); -- cgit v0.12