memory_exception_safety_test.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/memory/memory.h"
16 
17 #include "gtest/gtest.h"
19 
20 namespace absl {
21 namespace {
22 
23 constexpr int kLength = 50;
25 using ThrowerStorage =
27 using ThrowerList = std::array<ThrowerStorage, kLength>;
28 
29 TEST(MakeUnique, CheckForLeaks) {
30  constexpr int kValue = 321;
32  .WithInitialValue(Thrower(kValue))
33  // Ensures make_unique does not modify the input. The real
34  // test, though, is ConstructorTracker checking for leaks.
35  .WithContracts(testing::strong_guarantee);
36 
37  EXPECT_TRUE(tester.Test([](Thrower* thrower) {
38  static_cast<void>(absl::make_unique<Thrower>(*thrower));
39  }));
40 
41  EXPECT_TRUE(tester.Test([](Thrower* thrower) {
42  static_cast<void>(absl::make_unique<Thrower>(std::move(*thrower)));
43  }));
44 
45  // Test T[n] overload
46  EXPECT_TRUE(tester.Test([&](Thrower*) {
47  static_cast<void>(absl::make_unique<Thrower[]>(kLength));
48  }));
49 }
50 
51 } // namespace
52 } // namespace absl
exceptions_internal::StrongGuaranteeTagType strong_guarantee
typename std::aligned_storage< Len, Align >::type aligned_storage_t
Definition: type_traits.h:541
TEST(NotificationTest, SanityTest)
exceptions_internal::ExceptionSafetyTestBuilder MakeExceptionSafetyTester()
testing::ThrowingValue<> Thrower
Definition: algorithm.h:29
std::initializer_list< Thrower > ThrowerList
ExceptionSafetyTestBuilder< DefaultFactory< T >, Operation, Contracts... > WithInitialValue(const T &t) const


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:36