diff options
-rwxr-xr-x | ci/travis.sh | 15 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 26 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-generated-actions.h | 71 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-generated-actions.h.pump | 18 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 2 | ||||
-rw-r--r-- | googlemock/include/gmock/internal/gmock-internal-utils.h | 10 | ||||
-rw-r--r-- | googlemock/test/gmock-actions_test.cc | 99 | ||||
-rw-r--r-- | googlemock/test/gmock-generated-actions_test.cc | 55 | ||||
-rw-r--r-- | googletest/docs/advanced.md | 4 | ||||
-rw-r--r-- | googletest/include/gtest/gtest-death-test.h | 5 | ||||
-rw-r--r-- | googletest/include/gtest/internal/gtest-port.h | 8 | ||||
-rw-r--r-- | googletest/test/googletest-param-test-test.cc | 6 |
12 files changed, 117 insertions, 202 deletions
diff --git a/ci/travis.sh b/ci/travis.sh index f37660bb..a2488229 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -3,21 +3,6 @@ set -evx . ci/get-nprocessors.sh -# if possible, ask for the precise number of processors, -# otherwise take 2 processors as reasonable default; see -# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization -if [ -x /usr/bin/getconf ]; then - NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN) -else - NPROCESSORS=2 -fi -# as of 2017-09-04 Travis CI reports 32 processors, but GCC build -# crashes if parallelized too much (maybe memory consumption problem), -# so limit to 4 processors for the time being. -if [ $NPROCESSORS -gt 4 ] ; then - echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4." - NPROCESSORS=4 -fi # Tell make to use the processors. No preceding '-' required. MAKEFLAGS="j${NPROCESSORS}" export MAKEFLAGS diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 58089e3c..0f30abde 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -138,6 +138,7 @@ #include <functional> #include <memory> #include <string> +#include <tuple> #include <type_traits> #include <utility> @@ -1287,6 +1288,31 @@ inline ::std::reference_wrapper<T> ByRef(T& l_value) { // NOLINT namespace internal { +template <typename T, typename... Params> +struct ReturnNewAction { + T* operator()() const { + return internal::Apply( + [](const Params&... unpacked_params) { + return new T(unpacked_params...); + }, + params); + } + std::tuple<Params...> params; +}; + +} // namespace internal + +// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new +// instance of type T, constructed on the heap with constructor arguments +// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. +template <typename T, typename... Params> +internal::ReturnNewAction<T, typename std::decay<Params>::type...> ReturnNew( + Params&&... params) { + return {std::forward_as_tuple(std::forward<Params>(params)...)}; +} + +namespace internal { + // A macro from the ACTION* family (defined later in gmock-generated-actions.h) // defines an action that can be used in a mock function. Typically, // these actions only care about a subset of the arguments of the mock diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index 0fe6acbc..7030a98e 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -598,77 +598,6 @@ ACTION_TEMPLATE(InvokeArgument, p8, p9); } -// Various overloads for ReturnNew<T>(). -// -// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new -// instance of type T, constructed on the heap with constructor arguments -// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_0_VALUE_PARAMS()) { - return new T(); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_1_VALUE_PARAMS(p0)) { - return new T(p0); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_2_VALUE_PARAMS(p0, p1)) { - return new T(p0, p1); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_3_VALUE_PARAMS(p0, p1, p2)) { - return new T(p0, p1, p2); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { - return new T(p0, p1, p2, p3); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { - return new T(p0, p1, p2, p3, p4); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { - return new T(p0, p1, p2, p3, p4, p5); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { - return new T(p0, p1, p2, p3, p4, p5, p6); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { - return new T(p0, p1, p2, p3, p4, p5, p6, p7); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { - return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { - return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); -} - #ifdef _MSC_VER # pragma warning(pop) #endif diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 02fd9ff7..3430204f 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -340,24 +340,6 @@ ACTION_TEMPLATE(InvokeArgument, ]] -// Various overloads for ReturnNew<T>(). -// -// The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new -// instance of type T, constructed on the heap with constructor arguments -// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. -$range i 0..n -$for i [[ -$range j 0..i-1 -$var ps = [[$for j, [[p$j]]]] - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_$i[[]]_VALUE_PARAMS($ps)) { - return new T($ps); -} - -]] - #ifdef _MSC_VER # pragma warning(pop) #endif diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index c474e0b9..08fd6d14 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -4689,7 +4689,7 @@ inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } // and is printable using 'PrintToString'. It is compatible with // std::optional/std::experimental::optional. // Note that to compare an optional type variable against nullopt you should -// use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the +// use Eq(nullopt) and not Eq(Optional(nullopt)). The latter implies that the // optional value contains an optional itself. template <typename ValueMatcher> inline internal::OptionalMatcher<ValueMatcher> Optional( diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 66cf857b..5580dcb3 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -422,11 +422,13 @@ auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype( // Apply the function to a tuple of arguments. template <typename F, typename Tuple> -auto Apply(F&& f, Tuple&& args) - -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), - MakeIndexSequence<std::tuple_size<Tuple>::value>())) { +auto Apply(F&& f, Tuple&& args) -> decltype( + ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), + MakeIndexSequence<std::tuple_size< + typename std::remove_reference<Tuple>::type>::value>())) { return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), - MakeIndexSequence<std::tuple_size<Tuple>::value>()); + MakeIndexSequence<std::tuple_size< + typename std::remove_reference<Tuple>::type>::value>()); } // Template struct Function<F>, where F must be a function type, contains diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index a252825a..cac8f94f 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -54,35 +54,34 @@ namespace { -// This list should be kept sorted. -using testing::_; -using testing::Action; -using testing::ActionInterface; -using testing::Assign; -using testing::ByMove; -using testing::ByRef; -using testing::DefaultValue; -using testing::DoAll; -using testing::DoDefault; -using testing::IgnoreResult; -using testing::Invoke; -using testing::InvokeWithoutArgs; -using testing::MakePolymorphicAction; -using testing::Ne; -using testing::PolymorphicAction; -using testing::Return; -using testing::ReturnNull; -using testing::ReturnRef; -using testing::ReturnRefOfCopy; -using testing::ReturnRoundRobin; -using testing::SetArgPointee; -using testing::SetArgumentPointee; -using testing::Unused; -using testing::WithArgs; -using testing::internal::BuiltInDefaultValue; +using ::testing::_; +using ::testing::Action; +using ::testing::ActionInterface; +using ::testing::Assign; +using ::testing::ByMove; +using ::testing::ByRef; +using ::testing::DefaultValue; +using ::testing::DoAll; +using ::testing::DoDefault; +using ::testing::IgnoreResult; +using ::testing::Invoke; +using ::testing::InvokeWithoutArgs; +using ::testing::MakePolymorphicAction; +using ::testing::PolymorphicAction; +using ::testing::Return; +using ::testing::ReturnNew; +using ::testing::ReturnNull; +using ::testing::ReturnRef; +using ::testing::ReturnRefOfCopy; +using ::testing::ReturnRoundRobin; +using ::testing::SetArgPointee; +using ::testing::SetArgumentPointee; +using ::testing::Unused; +using ::testing::WithArgs; +using ::testing::internal::BuiltInDefaultValue; #if !GTEST_OS_WINDOWS_MOBILE -using testing::SetErrnoAndReturn; +using ::testing::SetErrnoAndReturn; #endif // Tests that BuiltInDefaultValue<T*>::Get() returns NULL. @@ -1290,6 +1289,52 @@ TEST(ByRefTest, PrintsCorrectly) { EXPECT_EQ(expected.str(), actual.str()); } +struct UnaryConstructorClass { + explicit UnaryConstructorClass(int v) : value(v) {} + int value; +}; + +// Tests using ReturnNew() with a unary constructor. +TEST(ReturnNewTest, Unary) { + Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000); + UnaryConstructorClass* c = a.Perform(std::make_tuple()); + EXPECT_EQ(4000, c->value); + delete c; +} + +TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { + Action<UnaryConstructorClass*(bool, int)> a = + ReturnNew<UnaryConstructorClass>(4000); + UnaryConstructorClass* c = a.Perform(std::make_tuple(false, 5)); + EXPECT_EQ(4000, c->value); + delete c; +} + +TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) { + Action<const UnaryConstructorClass*()> a = + ReturnNew<UnaryConstructorClass>(4000); + const UnaryConstructorClass* c = a.Perform(std::make_tuple()); + EXPECT_EQ(4000, c->value); + delete c; +} + +class TenArgConstructorClass { + public: + TenArgConstructorClass(int a1, int a2, int a3, int a4, int a5, int a6, int a7, + int a8, int a9, int a10) + : value_(a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10) {} + int value_; +}; + +// Tests using ReturnNew() with a 10-argument constructor. +TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { + Action<TenArgConstructorClass*()> a = ReturnNew<TenArgConstructorClass>( + 1000000000, 200000000, 30000000, 4000000, 500000, 60000, 7000, 800, 90, + 0); + TenArgConstructorClass* c = a.Perform(std::make_tuple()); + EXPECT_EQ(1234567890, c->value_); + delete c; +} std::unique_ptr<int> UniquePtrSource() { return std::unique_ptr<int>(new int(19)); diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 4c649a7e..ef39dff7 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -53,7 +53,6 @@ using testing::ByRef; using testing::DoAll; using testing::Invoke; using testing::Return; -using testing::ReturnNew; using testing::SetArgPointee; using testing::StaticAssertTypeEq; using testing::Unused; @@ -844,49 +843,6 @@ TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) { EXPECT_EQ(55, a.Perform(empty)); } -class NullaryConstructorClass { - public: - NullaryConstructorClass() : value_(123) {} - int value_; -}; - -// Tests using ReturnNew() with a nullary constructor. -TEST(ReturnNewTest, NoArgs) { - Action<NullaryConstructorClass*()> a = ReturnNew<NullaryConstructorClass>(); - NullaryConstructorClass* c = a.Perform(std::make_tuple()); - EXPECT_EQ(123, c->value_); - delete c; -} - -class UnaryConstructorClass { - public: - explicit UnaryConstructorClass(int value) : value_(value) {} - int value_; -}; - -// Tests using ReturnNew() with a unary constructor. -TEST(ReturnNewTest, Unary) { - Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000); - UnaryConstructorClass* c = a.Perform(std::make_tuple()); - EXPECT_EQ(4000, c->value_); - delete c; -} - -TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { - Action<UnaryConstructorClass*(bool, int)> a = - ReturnNew<UnaryConstructorClass>(4000); - UnaryConstructorClass* c = a.Perform(std::make_tuple(false, 5)); - EXPECT_EQ(4000, c->value_); - delete c; -} - -TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) { - Action<const UnaryConstructorClass*()> a = - ReturnNew<UnaryConstructorClass>(4000); - const UnaryConstructorClass* c = a.Perform(std::make_tuple()); - EXPECT_EQ(4000, c->value_); - delete c; -} class TenArgConstructorClass { public: @@ -897,17 +853,6 @@ class TenArgConstructorClass { int value_; }; -// Tests using ReturnNew() with a 10-argument constructor. -TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { - Action<TenArgConstructorClass*()> a = - ReturnNew<TenArgConstructorClass>(1000000000, 200000000, 30000000, - 4000000, 500000, 60000, - 7000, 800, 90, 0); - TenArgConstructorClass* c = a.Perform(std::make_tuple()); - EXPECT_EQ(1234567890, c->value_); - delete c; -} - // Tests that ACTION_TEMPLATE works when there is no value parameter. ACTION_TEMPLATE(CreateNew, HAS_1_TEMPLATE_PARAMS(typename, T), diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index d65f1eff..3c3c6fe9 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -401,7 +401,7 @@ alone with them. For a list of matchers gMock provides, read your [own matchers](../../googlemock/docs/cook_book.md#NewMatchers) too. gMock is bundled with googletest, so you don't need to add any build dependency -in order to take advantage of this. Just include `"testing/base/public/gmock.h"` +in order to take advantage of this. Just include `"gmock/gmock.h"` and you're ready to go. ### More String Assertions @@ -863,7 +863,7 @@ restored afterwards, so you need not do that yourself. For example: ```c++ int main(int argc, char** argv) { - InitGoogle(argv[0], &argc, &argv, true); + ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_death_test_style = "fast"; return RUN_ALL_TESTS(); } diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h index dc878ffb..2bd41cf3 100644 --- a/googletest/include/gtest/gtest-death-test.h +++ b/googletest/include/gtest/gtest-death-test.h @@ -190,11 +190,10 @@ GTEST_API_ bool InDeathTestChild(); class GTEST_API_ ExitedWithCode { public: explicit ExitedWithCode(int exit_code); + ExitedWithCode(const ExitedWithCode&) = default; + void operator=(const ExitedWithCode& other) = delete; bool operator()(int exit_status) const; private: - // No implementation - assignment is unsupported. - void operator=(const ExitedWithCode& other); - const int exit_code_; }; diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 44307a13..893c7f30 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -681,8 +681,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // A macro to disallow copy constructor and operator= // This should be used in the private: declarations for a class. #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ - type(type const &) = delete; \ - type& operator=(type const &) = delete + type(type const&) = delete; \ + type& operator=(type const&) = delete // A macro to disallow move operator= // This should be used in the private: declarations for a class. @@ -692,8 +692,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // A macro to disallow move constructor and operator= // This should be used in the private: declarations for a class. #define GTEST_DISALLOW_MOVE_AND_ASSIGN_(type) \ - type(type &&) noexcept = delete; \ - type& operator=(type &&) noexcept = delete + type(type&&) noexcept = delete; \ + type& operator=(type&&) noexcept = delete // Tell the compiler to warn about unused return values for functions declared // with this macro. The macro should be used on function declarations diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 2b26e95f..c852220e 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -491,8 +491,10 @@ class NonDefaultConstructAssignString { public: NonDefaultConstructAssignString(const std::string& s) : str_(s) {} NonDefaultConstructAssignString() = delete; - NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) = default; - NonDefaultConstructAssignString& operator=(const NonDefaultConstructAssignString&) = delete; + NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) = + default; + NonDefaultConstructAssignString& operator=( + const NonDefaultConstructAssignString&) = delete; ~NonDefaultConstructAssignString() = default; const std::string& str() const { return str_; } |