mirror of
https://github.com/google/googletest.git
synced 2024-12-26 17:41:03 +08:00
Introduce std::make_unique and bool literals where possible
PiperOrigin-RevId: 517910526 Change-Id: I398704f4b2ca0a55c86a06ca8b47d34c8670ddd7
This commit is contained in:
parent
9fd3fb00ff
commit
471087fbfc
@ -444,7 +444,7 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() == nullptr);
|
||||
DefaultValue<std::unique_ptr<int>>::SetFactory(
|
||||
[] { return std::unique_ptr<int>(new int(42)); });
|
||||
[] { return std::make_unique<int>(42); });
|
||||
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
|
||||
std::unique_ptr<int> i = DefaultValue<std::unique_ptr<int>>::Get();
|
||||
EXPECT_EQ(42, *i);
|
||||
@ -1751,9 +1751,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
|
||||
delete c;
|
||||
}
|
||||
|
||||
std::unique_ptr<int> UniquePtrSource() {
|
||||
return std::unique_ptr<int>(new int(19));
|
||||
}
|
||||
std::unique_ptr<int> UniquePtrSource() { return std::make_unique<int>(19); }
|
||||
|
||||
std::vector<std::unique_ptr<int>> VectorUniquePtrSource() {
|
||||
std::vector<std::unique_ptr<int>> out;
|
||||
@ -1802,7 +1800,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
|
||||
|
||||
// Check default value
|
||||
DefaultValue<std::unique_ptr<int>>::SetFactory(
|
||||
[] { return std::unique_ptr<int>(new int(42)); });
|
||||
[] { return std::make_unique<int>(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<int>(new int(i)); };
|
||||
auto make = [](int i) { return std::make_unique<int>(i); };
|
||||
|
||||
EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr<int> i) {
|
||||
return *i;
|
||||
@ -2053,9 +2051,7 @@ struct Double {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<int> UniqueInt(int i) {
|
||||
return std::unique_ptr<int>(new int(i));
|
||||
}
|
||||
std::unique_ptr<int> UniqueInt(int i) { return std::make_unique<int>(i); }
|
||||
|
||||
TEST(FunctorActionTest, ActionFromFunction) {
|
||||
Action<int(int, int&, int*)> a = &Add;
|
||||
|
@ -31,6 +31,7 @@
|
||||
//
|
||||
// This file tests some commonly used argument matchers.
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "test/gmock-matchers_test.h"
|
||||
@ -1542,7 +1543,7 @@ TEST(PairTest, MatchesCorrectly) {
|
||||
|
||||
TEST(PairTest, WorksWithMoveOnly) {
|
||||
pair<std::unique_ptr<int>, std::unique_ptr<int>> p;
|
||||
p.second.reset(new int(7));
|
||||
p.second = std::make_unique<int>(7);
|
||||
EXPECT_THAT(p, Pair(Eq(nullptr), Ne(nullptr)));
|
||||
}
|
||||
|
||||
|
@ -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<bool> expected(std::begin(a), std::end(a));
|
||||
std::vector<bool> actual(std::begin(b), std::end(b));
|
||||
StringMatchResultListener listener;
|
||||
|
Loading…
x
Reference in New Issue
Block a user