Skip to content

Commit 110c222

Browse files
committed
split size_n_data test into base and freestanding tests
1 parent 4fef555 commit 110c222

File tree

3 files changed

+85
-69
lines changed

3 files changed

+85
-69
lines changed

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if(BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED)
4545
else()
4646
add_gtest(container_requirements_fs)
4747
add_gtest(constructors_fs)
48+
add_gtest(size_n_data_fs)
4849
add_gtest(modifiers_fs)
4950
endif()
5051

tests/beman/inplace_vector/size_n_data.test.cpp

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,75 +22,10 @@ TYPED_TEST(SizeNCapacity, Capacity) {
2222
EXPECT_EQ(device.max_size(), N);
2323
}
2424

25-
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
26-
TYPED_TEST(SizeNCapacity, ResizeDown) {
27-
// constexpr void resize(size_type sz);
28-
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
29-
// Effects: If sz < size(), erases the last size() - sz elements from the
30-
// sequence. Otherwise, appends sz - size() default-inserted elements to the
31-
// sequence. Remarks: If an exception is thrown, there are no effects on
32-
// *this.
33-
34-
using IV = TestFixture::IV;
35-
using T = TestFixture::T;
36-
37-
auto device = this->unique();
38-
39-
auto mid_size = std::midpoint(0ul, device.size());
40-
device.resize(mid_size);
41-
EXPECT_EQ(device, IV(device.begin(), device.begin() + mid_size));
42-
43-
device.resize(0);
44-
EXPECT_EQ(device, IV{});
45-
}
46-
47-
TYPED_TEST(SizeNCapacity, ResizeUp) {
48-
// constexpr void resize(size_type sz);
49-
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
50-
// Effects: If sz < size(), erases the last size() - sz elements from the
51-
// sequence. Otherwise, appends sz - size() default-inserted elements to the
52-
// sequence. Remarks: If an exception is thrown, there are no effects on
53-
// *this.
54-
55-
using IV = TestFixture::IV;
56-
using T = TestFixture::T;
57-
58-
IV device;
59-
60-
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1), std::bad_alloc);
61-
EXPECT_EQ(device, IV{});
62-
63-
if (device.capacity() == 0)
64-
return;
65-
66-
// Trying to pollute device[0]
67-
device.push_back(T{255});
68-
device.pop_back();
69-
EXPECT_TRUE(device.empty());
70-
71-
device.resize(1);
72-
EXPECT_EQ(device.size(), 1);
73-
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
74-
std::is_same_v<T, NonTrivial>)
75-
EXPECT_EQ(device, IV{T{0}});
76-
77-
T front{341};
78-
device[0] = front;
79-
device.resize(device.capacity());
80-
EXPECT_EQ(device[0], front);
81-
82-
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
83-
std::is_same_v<T, NonTrivial>) {
84-
IV expected(device.capacity(), T{0});
85-
expected[0] = front;
86-
EXPECT_EQ(device, expected);
87-
}
88-
89-
IV before_resize(device);
90-
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1), std::bad_alloc);
91-
EXPECT_EQ(device, before_resize);
92-
}
93-
#endif
25+
// These functions are marked as freestand delete.
26+
// See size_n_data_fs.test.cpp.
27+
//
28+
// constexpr void resize(size_type sz);
9429

9530
// 23.3.14.4 Data [inplace.vector.data]
9631

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <gtest/gtest.h>
2+
#include <numeric>
3+
4+
#include "gtest_setup.hpp"
5+
6+
namespace {
7+
// 23.3.14.3 Size and capacity [inplace.vector.capacity]
8+
9+
template <typename Param> class SizeNCapacity : public IVBasicTest<Param> {};
10+
TYPED_TEST_SUITE(SizeNCapacity, IVAllTypes);
11+
12+
TYPED_TEST(SizeNCapacity, ResizeDown) {
13+
// constexpr void resize(size_type sz);
14+
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
15+
// Effects: If sz < size(), erases the last size() - sz elements from the
16+
// sequence. Otherwise, appends sz - size() default-inserted elements to the
17+
// sequence. Remarks: If an exception is thrown, there are no effects on
18+
// *this.
19+
20+
using IV = TestFixture::IV;
21+
using T = TestFixture::T;
22+
23+
auto device = this->unique();
24+
25+
auto mid_size = std::midpoint(0ul, device.size());
26+
device.resize(mid_size);
27+
EXPECT_EQ(device, IV(device.begin(), device.begin() + mid_size));
28+
29+
device.resize(0);
30+
EXPECT_EQ(device, IV{});
31+
}
32+
33+
TYPED_TEST(SizeNCapacity, ResizeUp) {
34+
// constexpr void resize(size_type sz);
35+
// Preconditions: T is Cpp17DefaultInsertable into inplace_vector.
36+
// Effects: If sz < size(), erases the last size() - sz elements from the
37+
// sequence. Otherwise, appends sz - size() default-inserted elements to the
38+
// sequence. Remarks: If an exception is thrown, there are no effects on
39+
// *this.
40+
41+
using IV = TestFixture::IV;
42+
using T = TestFixture::T;
43+
44+
IV device;
45+
46+
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1), std::bad_alloc);
47+
EXPECT_EQ(device, IV{});
48+
49+
if (device.capacity() == 0)
50+
return;
51+
52+
// Trying to pollute device[0]
53+
device.push_back(T{255});
54+
device.pop_back();
55+
EXPECT_TRUE(device.empty());
56+
57+
device.resize(1);
58+
EXPECT_EQ(device.size(), 1);
59+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
60+
std::is_same_v<T, NonTrivial>)
61+
EXPECT_EQ(device, IV{T{0}});
62+
63+
T front{341};
64+
device[0] = front;
65+
device.resize(device.capacity());
66+
EXPECT_EQ(device[0], front);
67+
68+
if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
69+
std::is_same_v<T, NonTrivial>) {
70+
IV expected(device.capacity(), T{0});
71+
expected[0] = front;
72+
EXPECT_EQ(device, expected);
73+
}
74+
75+
IV before_resize(device);
76+
SAFE_EXPECT_THROW(device.resize(device.capacity() + 1), std::bad_alloc);
77+
EXPECT_EQ(device, before_resize);
78+
}
79+
80+
}; // namespace

0 commit comments

Comments
 (0)