Skip to content

Commit a3e98e7

Browse files
committed
fix container_requirements.test.cpp
1 parent 98c2e65 commit a3e98e7

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function(add_gtest NAME)
3333
endfunction()
3434

3535
# Tests for official specs
36-
# add_gtest(container_requirements)
36+
add_gtest(container_requirements)
3737
# add_gtest(triviality)
3838
# add_gtest(compare)
3939
# add_gtest(constructors)

tests/beman/inplace_vector/container_requirements.test.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ TYPED_TEST(ContainerRequirements, CopyAssignment) {
177177
// Complexity: Linear.
178178
X const v(TestFixture::unique(X::max_size() / 2));
179179
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
180-
X t(n);
180+
X t = TestFixture::vec_of(n);
181181
t = v;
182182
EXPECT_TRUE((std::is_same_v<decltype(t = v), X &>));
183183
EXPECT_EQ(t, v);
@@ -202,7 +202,7 @@ TYPED_TEST(ContainerRequirements, MoveAssignment) {
202202
if constexpr (counts_objects_v<T>) {
203203
T::num_objects = 0;
204204
}
205-
X t(n);
205+
X t = TestFixture::vec_of(n);
206206
if constexpr (counts_objects_v<T>) {
207207
ASSERT_EQ(T::num_objects, t.size());
208208
}
@@ -228,7 +228,8 @@ TYPED_TEST(ContainerRequirements, Destructor) {
228228
T::num_objects = 0;
229229
}
230230
alignas(X) std::byte storage[sizeof(X)];
231-
X *pa = new (static_cast<void *>(storage)) X(X::max_size());
231+
X *pa = new (static_cast<void *>(storage)) X;
232+
*pa = TestFixture::unique();
232233
X &a = *pa;
233234
if constexpr (counts_objects_v<T>) {
234235
ASSERT_EQ(T::num_objects, X::max_size());
@@ -254,8 +255,8 @@ TYPED_TEST(ContainerRequirements, Begin) {
254255
// Complexity: Constant.
255256

256257
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
257-
X b(n);
258-
X const cb(n);
258+
X b = TestFixture::vec_of(n);
259+
X const cb = TestFixture::vec_of(n);
259260
EXPECT_TRUE((std::is_same_v<decltype(b.begin()), typename X::iterator>));
260261
EXPECT_TRUE(
261262
(std::is_same_v<decltype(cb.begin()), typename X::const_iterator>));
@@ -284,8 +285,8 @@ TYPED_TEST(ContainerRequirements, End) {
284285
// Complexity: Constant.
285286

286287
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
287-
X b(n);
288-
X const cb(n);
288+
X b = TestFixture::vec_of(n);
289+
X const cb = TestFixture::vec_of(n);
289290
EXPECT_TRUE((std::is_same_v<decltype(b.end()), typename X::iterator>));
290291
EXPECT_TRUE(
291292
(std::is_same_v<decltype(cb.end()), typename X::const_iterator>));
@@ -350,9 +351,10 @@ TYPED_TEST(ContainerRequirements, Equality) {
350351
: X{}; // { 0, 1, ... }
351352
values[1] = values[0];
352353
if (values[1].size() < X::max_size()) {
353-
values[1].push_back(TestFixture::unique(1)[0]);
354+
values[1].unchecked_push_back(TestFixture::unique(1)[0]);
354355
} // { 0, 1, 2, ... }
355-
values[2] = X::max_size() > 0 ? X(X::max_size() - 1) : X{}; // { 0, 0, ... }
356+
values[2] = X::max_size() > 0 ? TestFixture::vec_of(X::max_size() - 1)
357+
: X{}; // { 0, 0, ... }
356358
for (X const &c : values) {
357359
EXPECT_TRUE(c == c);
358360
for (X const &b : values) {
@@ -379,7 +381,7 @@ TYPED_TEST(ContainerRequirements, Swap) {
379381
// Effects: Equivalent to t.swap(s).
380382

381383
X const t_proto(TestFixture::unique());
382-
X const s_proto(X::max_size());
384+
X const s_proto = TestFixture::vec_of(X::max_size());
383385
X t(t_proto);
384386
X s(s_proto);
385387

@@ -407,7 +409,7 @@ TYPED_TEST(ContainerRequirements, Size) {
407409
// defined by the rules of constructors, inserts, and erases.
408410

409411
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
410-
X c(n);
412+
X c = TestFixture::vec_of(n);
411413
EXPECT_TRUE((std::is_same_v<decltype(c.size()), typename X::size_type>));
412414
EXPECT_EQ(c.size(), std::distance(c.begin(), c.end()));
413415
}
@@ -422,7 +424,7 @@ TYPED_TEST(ContainerRequirements, MaxSize) {
422424
// Result: size_type.
423425
// Returns: distance(begin(), end()) for the largest possible container.
424426
// Complexity: Constant.
425-
X c(N);
427+
X c = TestFixture::vec_of(N);
426428
EXPECT_TRUE((std::is_same_v<decltype(c.max_size()), typename X::size_type>));
427429
EXPECT_EQ(c.max_size(), std::distance(c.begin(), c.end()));
428430
// How to test complexity?
@@ -438,7 +440,7 @@ TYPED_TEST(ContainerRequirements, Empty) {
438440
// Remarks: If the container is empty, then c.empty() is true.}
439441

440442
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
441-
X c(n);
443+
X c = TestFixture::vec_of(n);
442444
EXPECT_TRUE((std::is_same_v<decltype(c.empty()), bool>));
443445
EXPECT_EQ(c.empty(), c.begin() == c.end());
444446
}
@@ -471,7 +473,7 @@ TYPED_TEST(ContainerRequirements, NothrowPopBack) {
471473

472474
// pop_back() has a narrow contract, therefore we cannot check noexcept().
473475
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
474-
X c(n);
476+
X c = TestFixture::vec_of(n);
475477
if (n > 0) {
476478
EXPECT_NO_THROW(c.pop_back());
477479
}
@@ -540,8 +542,8 @@ TYPED_TEST(ReversibleContainerRequirements, RBegin) {
540542
// Complexity: Constant.
541543

542544
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
543-
X a(n);
544-
X const ca(n);
545+
X a = TestFixture::vec_of(n);
546+
X const ca = TestFixture::vec_of(n);
545547
EXPECT_TRUE(
546548
(std::is_same_v<decltype(a.rbegin()), typename X::reverse_iterator>));
547549
EXPECT_TRUE((std::is_same_v<decltype(ca.rbegin()),
@@ -569,8 +571,8 @@ TYPED_TEST(ReversibleContainerRequirements, REnd) {
569571
// Complexity: Constant.
570572

571573
for (typename X::size_type n = 0; n <= X::max_size(); ++n) {
572-
X a(n);
573-
X const ca(n);
574+
X a = TestFixture::vec_of(n);
575+
X const ca = TestFixture::vec_of(n);
574576
EXPECT_TRUE(
575577
(std::is_same_v<decltype(a.rend()), typename X::reverse_iterator>));
576578
EXPECT_TRUE((std::is_same_v<decltype(ca.rend()),
@@ -621,6 +623,7 @@ TYPED_TEST_SUITE(SequenceContainerRequirements, IVAllTypes);
621623
// X(il)
622624
// Effects: Equivalent to X(il.begin(), il.end()).
623625

626+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
624627
TYPED_TEST(SequenceContainerRequirements, ConstructorInitializerList) {
625628
using IV = TestFixture::IV;
626629
using T = TestFixture::T;
@@ -665,6 +668,7 @@ TYPED_TEST(SequenceContainerRequirements, AssignInitializerList) {
665668
device = {T{20}};
666669
EXPECT_EQ(device, IV{T{20}});
667670
}
671+
#endif
668672

669673
// a.emplace(p, args)
670674
// Result: iterator.

tests/beman/inplace_vector/gtest_setup.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,25 @@ template <typename Param> class IVBasicTest : public ::testing::Test {
351351
using X = beman::inplace_vector<T, N>;
352352
using IV = X;
353353

354+
// Implements inplace_vector's freestanding constructors for convenience
355+
// testing in a freestanding context
356+
static X vec_of(std::size_t size) {
357+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
358+
return IV(size);
359+
#else
360+
X vec;
361+
for (auto i = 0; i < size; ++i)
362+
vec.unchecked_emplace_back();
363+
return vec;
364+
#endif
365+
}
366+
354367
// Returns IV of size n with unique values
355368
static IV unique(typename IV::size_type n = IV::max_size()) {
356369
static T val = T{};
357370
IV res;
358371
while (n > 0) {
359-
res.push_back(val);
372+
res.unchecked_push_back(val);
360373
++val.value;
361374
--n;
362375
}

0 commit comments

Comments
 (0)