From d072682119f8673e090e2985f2cb5eb6a7b09fe0 Mon Sep 17 00:00:00 2001 From: Piotr Nycz Date: Thu, 24 Oct 2019 10:22:09 +0200 Subject: [PATCH] Tests simplified and names corrected (POD->scalar) Issue 2527 --- googlemock/test/gmock-actions_test.cc | 67 +++++++-------------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 86f570fa..52f140d1 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -651,65 +651,34 @@ template ()))> bool CanCallReturnRef(T&&) { return true; } bool CanCallReturnRef(Unused) { return false; } -// Defined here, because gmock has to work with C++11 (std::void_t is from C++17) -template struct precpp17_make_void { typedef void type;}; -template using precpp17_void_t = typename precpp17_make_void::type; - -template -struct HasReturnRefAction : std::false_type {}; -template -struct HasReturnRefAction()))>> - : std::true_type {}; - -// Just an example of non-POD type -class MyNonPodType { - public: - MyNonPodType(int a_value) : value_(a_value) {} - - private: - int value_; -}; -// Just an example of POD type -using MyPodType = int; - // Tests that ReturnRef(v) is working with non-temporaries (T&) -TEST(ReturnRefTest, IsAcceptingNonTemporary) { - EXPECT_TRUE(HasReturnRefAction::value); - EXPECT_TRUE(HasReturnRefAction::value); - EXPECT_TRUE(HasReturnRefAction::value); - EXPECT_TRUE(HasReturnRefAction::value); +TEST(ReturnRefTest, WorksForNonTemporary) { + int scalarValue = 123; + EXPECT_TRUE(CanCallReturnRef(scalarValue)); - MyNonPodType nonPodValue{123}; - EXPECT_TRUE(CanCallReturnRef(nonPodValue)); + std::string nonScalarValue("ABC"); + EXPECT_TRUE(CanCallReturnRef(nonScalarValue)); - MyPodType podValue{321}; - EXPECT_TRUE(CanCallReturnRef(podValue)); + const int constScalarValue{321}; + EXPECT_TRUE(CanCallReturnRef(constScalarValue)); - const MyNonPodType constNonPodValue{123}; - EXPECT_TRUE(CanCallReturnRef(constNonPodValue)); - - const MyPodType constPodValue{321}; - EXPECT_TRUE(CanCallReturnRef(constPodValue)); + const std::string constNonScalarValue("CBA"); + EXPECT_TRUE(CanCallReturnRef(constNonScalarValue)); } // Tests that ReturnRef(v) is not working with temporaries (T&&) -TEST(ReturnRefTest, IsNotAcceptingTemporary) { - EXPECT_FALSE(HasReturnRefAction::value); - EXPECT_FALSE(HasReturnRefAction::value); - EXPECT_FALSE(HasReturnRefAction::value); - EXPECT_FALSE(HasReturnRefAction::value); +TEST(ReturnRefTest, DoesNotWorkForTemporary) { + auto scalarValue = []() -> int { return 123; }; + EXPECT_FALSE(CanCallReturnRef(scalarValue())); - auto nonPodValue = []() -> MyNonPodType { return MyNonPodType{123}; }; - EXPECT_FALSE(CanCallReturnRef(nonPodValue())); + auto nonScalarValue = []() -> std::string { return "ABC"; }; + EXPECT_FALSE(CanCallReturnRef(nonScalarValue())); - auto podValue = []() -> MyPodType { return MyPodType{321}; }; - EXPECT_FALSE(CanCallReturnRef(podValue())); + // cannot use here callable returning "const scalar type" because C++ ignores such const for scalar return type, so the static_cast + EXPECT_FALSE(CanCallReturnRef(static_cast(321))); - auto constNonPodValue = []() -> const MyNonPodType { return MyNonPodType{123}; }; - EXPECT_FALSE(CanCallReturnRef(constNonPodValue())); - - // cannot use here callable returning "const POD" because C++ ignores such const for POD return type, so the static_cast - EXPECT_FALSE(CanCallReturnRef(static_cast(42))); + auto constNonScalarValue = []() -> const std::string { return "CBA"; }; + EXPECT_FALSE(CanCallReturnRef(constNonScalarValue())); } // Tests that ReturnRefOfCopy(v) works for reference types.