inlined_vector_exception_safety_test.cc
Go to the documentation of this file.
00001 // Copyright 2019 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 <memory>
00016 
00017 #include "gtest/gtest.h"
00018 #include "absl/base/internal/exception_safety_testing.h"
00019 #include "absl/container/inlined_vector.h"
00020 
00021 namespace {
00022 
00023 constexpr size_t kInlined = 4;
00024 constexpr size_t kSmallSize = kInlined / 2;
00025 constexpr size_t kLargeSize = kInlined * 2;
00026 
00027 using Thrower = testing::ThrowingValue<>;
00028 using ThrowerAlloc = testing::ThrowingAllocator<Thrower>;
00029 
00030 template <typename Allocator = std::allocator<Thrower>>
00031 using InlVec = absl::InlinedVector<Thrower, kInlined, Allocator>;
00032 
00033 TEST(InlinedVector, DefaultConstructor) {
00034   testing::TestThrowingCtor<InlVec<>>();
00035 
00036   testing::TestThrowingCtor<InlVec<ThrowerAlloc>>();
00037 }
00038 
00039 TEST(InlinedVector, AllocConstructor) {
00040   auto alloc = std::allocator<Thrower>();
00041   testing::TestThrowingCtor<InlVec<>>(alloc);
00042 
00043   auto throw_alloc = ThrowerAlloc();
00044   testing::TestThrowingCtor<InlVec<ThrowerAlloc>>(throw_alloc);
00045 }
00046 
00047 TEST(InlinedVector, Clear) {
00048   auto small_vec = InlVec<>(kSmallSize);
00049   EXPECT_TRUE(testing::TestNothrowOp([&]() { small_vec.clear(); }));
00050 
00051   auto large_vec = InlVec<>(kLargeSize);
00052   EXPECT_TRUE(testing::TestNothrowOp([&]() { large_vec.clear(); }));
00053 }
00054 
00055 }  // namespace


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