diff options
author | Abseil Team <absl-team@google.com> | 2018-06-20 06:25:23 -0700 |
---|---|---|
committer | Shaindel Schwartz <shaindel@google.com> | 2018-06-20 10:15:31 -0400 |
commit | 6c7de165d1c82684359ccb630bb5f83263fa5ebc (patch) | |
tree | f271bc0005ad42773cc0140100699b8bfbaea124 /absl/memory/memory_exception_safety_test.cc | |
parent | e5be80532b5d998813f9db952d2cc5401b1532df (diff) | |
download | abseil-6c7de165d1c82684359ccb630bb5f83263fa5ebc.tar.gz abseil-6c7de165d1c82684359ccb630bb5f83263fa5ebc.tar.bz2 abseil-6c7de165d1c82684359ccb630bb5f83263fa5ebc.zip |
Project import generated by Copybara.
GitOrigin-RevId: d89dba27e35462d7457121b978fd79214205e686
Change-Id: I0eae80578a93a580820bc90d42e6b42faf7fde0a
Diffstat (limited to 'absl/memory/memory_exception_safety_test.cc')
-rw-r--r-- | absl/memory/memory_exception_safety_test.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/absl/memory/memory_exception_safety_test.cc b/absl/memory/memory_exception_safety_test.cc new file mode 100644 index 00000000..dc00f349 --- /dev/null +++ b/absl/memory/memory_exception_safety_test.cc @@ -0,0 +1,51 @@ +// Copyright 2018 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/memory/memory.h" + +#include "gtest/gtest.h" +#include "absl/base/internal/exception_safety_testing.h" + +namespace absl { +inline namespace lts_2018_06_20 { +namespace { + +using Thrower = ::testing::ThrowingValue<>; + +TEST(MakeUnique, CheckForLeaks) { + constexpr int kValue = 321; + constexpr size_t kLength = 10; + auto tester = testing::MakeExceptionSafetyTester() + .WithInitialValue(Thrower(kValue)) + // Ensures make_unique does not modify the input. The real + // test, though, is ConstructorTracker checking for leaks. + .WithInvariants(testing::strong_guarantee); + + EXPECT_TRUE(tester.Test([](Thrower* thrower) { + static_cast<void>(absl::make_unique<Thrower>(*thrower)); + })); + + EXPECT_TRUE(tester.Test([](Thrower* thrower) { + static_cast<void>(absl::make_unique<Thrower>(std::move(*thrower))); + })); + + // Test T[n] overload + EXPECT_TRUE(tester.Test([&](Thrower*) { + static_cast<void>(absl::make_unique<Thrower[]>(kLength)); + })); +} + +} // namespace +} // inline namespace lts_2018_06_20 +} // namespace absl |