memory_exception_safety_test.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
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                     // Ensures make_unique does not modify the input. The real
00034                     // test, though, is ConstructorTracker checking for leaks.
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   // Test T[n] overload
00046   EXPECT_TRUE(tester.Test([&](Thrower*) {
00047     static_cast<void>(absl::make_unique<Thrower[]>(kLength));
00048   }));
00049 }
00050 
00051 }  // namespace
00052 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15