Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/memory/memory.h"
00016
00017 #include "gtest/gtest.h"
00018 #include "absl/base/internal/exception_safety_testing.h"
00019
00020 namespace absl {
00021 namespace {
00022
00023 constexpr int kLength = 50;
00024 using Thrower = testing::ThrowingValue<testing::TypeSpec::kEverythingThrows>;
00025 using ThrowerStorage =
00026 absl::aligned_storage_t<sizeof(Thrower), alignof(Thrower)>;
00027 using ThrowerList = std::array<ThrowerStorage, kLength>;
00028
00029 TEST(MakeUnique, CheckForLeaks) {
00030 constexpr int kValue = 321;
00031 auto tester = testing::MakeExceptionSafetyTester()
00032 .WithInitialValue(Thrower(kValue))
00033
00034
00035 .WithContracts(testing::strong_guarantee);
00036
00037 EXPECT_TRUE(tester.Test([](Thrower* thrower) {
00038 static_cast<void>(absl::make_unique<Thrower>(*thrower));
00039 }));
00040
00041 EXPECT_TRUE(tester.Test([](Thrower* thrower) {
00042 static_cast<void>(absl::make_unique<Thrower>(std::move(*thrower)));
00043 }));
00044
00045
00046 EXPECT_TRUE(tester.Test([&](Thrower*) {
00047 static_cast<void>(absl::make_unique<Thrower[]>(kLength));
00048 }));
00049 }
00050
00051 }
00052 }