15 #include <initializer_list> 19 #include "gtest/gtest.h" 26 constexpr
size_t kInlined = 25;
27 constexpr
size_t kSmallSize = kInlined / 2;
28 constexpr
size_t kLargeSize = kInlined * 2;
30 constexpr
int kInitialValue = 5;
31 constexpr
int kUpdatedValue = 10;
41 TEST(FixedArrayExceptionSafety, CopyConstructor) {
42 auto small = FixedArr(kSmallSize);
43 TestThrowingCtor<FixedArr>(small);
45 auto large = FixedArr(kLargeSize);
46 TestThrowingCtor<FixedArr>(large);
49 TEST(FixedArrayExceptionSafety, MoveConstructor) {
50 TestThrowingCtor<FixedArr>(FixedArr(kSmallSize));
51 TestThrowingCtor<FixedArr>(FixedArr(kLargeSize));
54 TestThrowingCtor<MoveFixedArr>(MoveFixedArr(kSmallSize));
55 TestThrowingCtor<MoveFixedArr>(MoveFixedArr(kLargeSize));
58 TEST(FixedArrayExceptionSafety, SizeConstructor) {
59 TestThrowingCtor<FixedArr>(kSmallSize);
60 TestThrowingCtor<FixedArr>(kLargeSize);
63 TEST(FixedArrayExceptionSafety, SizeValueConstructor) {
64 TestThrowingCtor<FixedArr>(kSmallSize,
Thrower());
65 TestThrowingCtor<FixedArr>(kLargeSize,
Thrower());
68 TEST(FixedArrayExceptionSafety, IteratorConstructor) {
69 auto small = FixedArr(kSmallSize);
70 TestThrowingCtor<FixedArr>(small.begin(), small.end());
72 auto large = FixedArr(kLargeSize);
73 TestThrowingCtor<FixedArr>(large.begin(), large.end());
76 TEST(FixedArrayExceptionSafety, InitListConstructor) {
77 constexpr
int small_inlined = 3;
80 TestThrowingCtor<SmallFixedArr>(std::initializer_list<Thrower>{});
82 TestThrowingCtor<SmallFixedArr>(
85 TestThrowingCtor<SmallFixedArr>(std::initializer_list<Thrower>{
89 testing::AssertionResult ReadMemory(FixedArr* fixed_arr) {
92 for (
const auto& thrower : *fixed_arr) {
95 return testing::AssertionSuccess() <<
"Values sum to [" << sum <<
"]";
98 TEST(FixedArrayExceptionSafety, Fill) {
101 .WithOperation([&](FixedArr* fixed_arr_ptr) {
104 fixed_arr_ptr->fill(thrower);
108 test_fill.WithInitialValue(FixedArr(kSmallSize,
Thrower(kInitialValue)))
111 test_fill.WithInitialValue(FixedArr(kLargeSize,
Thrower(kInitialValue)))
ExceptionSafetyTestBuilder< Factory, Operation, Contracts..., absl::decay_t< MoreContracts >... > WithContracts(const MoreContracts &...more_contracts) const
TEST(NotificationTest, SanityTest)
exceptions_internal::ExceptionSafetyTestBuilder MakeExceptionSafetyTester()
testing::ThrowingValue<> Thrower
void TestThrowingCtor(Args &&...args)
exceptions_internal::NoThrowTag nothrow_ctor