From 471087fbfcbc3c66071189a67c313eb1d525ee51 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 20 Mar 2023 02:43:07 -0700 Subject: Introduce std::make_unique and bool literals where possible PiperOrigin-RevId: 517910526 Change-Id: I398704f4b2ca0a55c86a06ca8b47d34c8670ddd7 --- googlemock/test/gmock-actions_test.cc | 14 +++++--------- googlemock/test/gmock-matchers-comparisons_test.cc | 3 ++- googlemock/test/gmock-matchers-containers_test.cc | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 7734830..ee9b889 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -444,7 +444,7 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { EXPECT_TRUE(DefaultValue>::Exists()); EXPECT_TRUE(DefaultValue>::Get() == nullptr); DefaultValue>::SetFactory( - [] { return std::unique_ptr(new int(42)); }); + [] { return std::make_unique(42); }); EXPECT_TRUE(DefaultValue>::Exists()); std::unique_ptr i = DefaultValue>::Get(); EXPECT_EQ(42, *i); @@ -1751,9 +1751,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { delete c; } -std::unique_ptr UniquePtrSource() { - return std::unique_ptr(new int(19)); -} +std::unique_ptr UniquePtrSource() { return std::make_unique(19); } std::vector> VectorUniquePtrSource() { std::vector> out; @@ -1802,7 +1800,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { // Check default value DefaultValue>::SetFactory( - [] { return std::unique_ptr(new int(42)); }); + [] { return std::make_unique(42); }); EXPECT_EQ(42, *mock.MakeUnique()); EXPECT_CALL(mock, MakeUnique()).WillRepeatedly(Invoke(UniquePtrSource)); @@ -1822,7 +1820,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { TEST(MockMethodTest, CanTakeMoveOnlyValue) { MockClass mock; - auto make = [](int i) { return std::unique_ptr(new int(i)); }; + auto make = [](int i) { return std::make_unique(i); }; EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { return *i; @@ -2053,9 +2051,7 @@ struct Double { } }; -std::unique_ptr UniqueInt(int i) { - return std::unique_ptr(new int(i)); -} +std::unique_ptr UniqueInt(int i) { return std::make_unique(i); } TEST(FunctorActionTest, ActionFromFunction) { Action a = &Add; diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 0738aaf..b849990 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -31,6 +31,7 @@ // // This file tests some commonly used argument matchers. +#include #include #include "test/gmock-matchers_test.h" @@ -1542,7 +1543,7 @@ TEST(PairTest, MatchesCorrectly) { TEST(PairTest, WorksWithMoveOnly) { pair, std::unique_ptr> p; - p.second.reset(new int(7)); + p.second = std::make_unique(7); EXPECT_THAT(p, Pair(Eq(nullptr), Ne(nullptr))); } diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc index b40a26a..c8d8ea3 100644 --- a/googlemock/test/gmock-matchers-containers_test.cc +++ b/googlemock/test/gmock-matchers-containers_test.cc @@ -1824,8 +1824,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { } TEST(UnorderedElementsAreArrayTest, VectorBool) { - const bool a[] = {0, 1, 0, 1, 1}; - const bool b[] = {1, 0, 1, 1, 0}; + const bool a[] = {false, true, false, true, true}; + const bool b[] = {true, false, true, true, false}; std::vector expected(std::begin(a), std::end(a)); std::vector actual(std::begin(b), std::end(b)); StringMatchResultListener listener; -- cgit v0.12