Skip to content

Commit b1a0692

Browse files
committed
Update freestanding tests
1 parent cf4f74d commit b1a0692

File tree

6 files changed

+80
-36
lines changed

6 files changed

+80
-36
lines changed

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Artifact from previous implementation, can be used as hints for optimizer
2626
#define IV_EXPECT(EXPR)
2727

28-
#if __STDC_HOSTED__ == 0 || BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
28+
#if BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
2929
#define BEMAN_IV_FREESTANDING_DELETE(impl) = delete
3030
#else
3131
#define BEMAN_IV_FREESTANDING_DELETE(impl) impl

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ add_gtest(constructors)
4242
add_gtest(size_n_data)
4343
add_gtest(erasure)
4444
add_gtest(modifiers)
45-
add_gtest(freestanding)
45+
46+
if(BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED)
47+
add_gtest(freestanding)
48+
endif()
4649

4750
# constexpr test
4851
add_executable(beman.inplace_vector.tests.constexpr constexpr.test.cpp)

tests/beman/inplace_vector/constexpr.test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ template <typename IV> constexpr void test_constructors() {
5858
{
5959
IV v;
6060
}
61+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
6162
{
6263
IV v(10);
6364
}
@@ -70,6 +71,7 @@ template <typename IV> constexpr void test_constructors() {
7071
{
7172
IV v(beman::from_range_t{}, arr);
7273
}
74+
#endif
7375
{
7476
IV other{0, 1};
7577
IV copy(other);
@@ -108,6 +110,7 @@ template <typename IV> constexpr void test_assignment() {
108110
std::array<T, 5> arr;
109111
arr.fill(T(20));
110112

113+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
111114
{
112115
IV v;
113116
v.assign(arr.begin(), arr.end());
@@ -124,6 +127,7 @@ template <typename IV> constexpr void test_assignment() {
124127
IV v;
125128
v.assign({0, 1, 2});
126129
}
130+
#endif
127131
}
128132
TEST(test_assignment);
129133

@@ -147,6 +151,7 @@ TEST(test_iterator_access);
147151
template <typename IV> constexpr void test_size_capacity() {
148152
using T = IV::value_type;
149153

154+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
150155
{
151156
IV v{0, 1};
152157
(void)v.empty();
@@ -166,22 +171,27 @@ template <typename IV> constexpr void test_size_capacity() {
166171
v.reserve(5);
167172
v.shrink_to_fit();
168173
}
174+
#endif
169175
}
170176
TEST(test_size_capacity);
171177

172178
template <typename IV> constexpr void test_element_access() {
173179
{
174180
IV v{0, 1};
175181
(void)v[0];
182+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
176183
(void)v.at(0);
184+
#endif
177185
(void)v.front();
178186
(void)v.back();
179187
}
180188

181189
{
182190
const IV v{0, 1};
183191
(void)v[0];
192+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
184193
(void)v.at(0);
194+
#endif
185195
(void)v.front();
186196
(void)v.back();
187197
}
@@ -206,6 +216,7 @@ template <typename IV> constexpr void test_modifiers() {
206216
std::array<T, 5> arr;
207217
arr.fill(T(20));
208218

219+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
209220
{
210221
IV v;
211222
v.emplace_back(20);
@@ -214,6 +225,7 @@ template <typename IV> constexpr void test_modifiers() {
214225
v.append_range(arr);
215226
v.pop_back();
216227
}
228+
#endif
217229

218230
{
219231
IV v;
@@ -230,6 +242,7 @@ template <typename IV> constexpr void test_modifiers() {
230242
v.unchecked_push_back(T(20));
231243
}
232244

245+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
233246
{
234247
IV v{0, 1};
235248
v.emplace(v.begin(), 20);
@@ -242,6 +255,7 @@ template <typename IV> constexpr void test_modifiers() {
242255
v.erase(v.begin());
243256
v.erase(v.begin(), v.begin() + 2);
244257
}
258+
#endif
245259

246260
{
247261
IV v, other{0, 1};
@@ -304,18 +318,22 @@ template <typename T> constexpr void speical_test_empty() {
304318
{
305319
IV v;
306320
}
321+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
307322
{
308323
IV v(0, T{50});
309324
}
325+
#endif
310326
{
311327
IV a, b;
312328
a = b;
313329
a = IV();
314330
}
331+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
315332
{
316333
IV v;
317334
v.assign(0, T{50});
318335
}
336+
#endif
319337
{
320338
IV v;
321339
(void)v.begin();
@@ -333,9 +351,11 @@ template <typename T> constexpr void speical_test_empty() {
333351
(void)v.size();
334352
(void)v.max_size();
335353
(void)v.capacity();
354+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
336355
v.resize(0);
337356
v.resize(0, T{40});
338357
v.reserve(0);
358+
#endif
339359
v.shrink_to_fit();
340360
}
341361
{
@@ -360,4 +380,5 @@ TEST_EMPTY(speical_test_empty);
360380

361381
int main() {
362382
// compile means passing
383+
return 0;
363384
}

tests/beman/inplace_vector/container_requirements.test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ TYPED_TEST(SequenceContainerRequirements, Clear) {
762762
EXPECT_TRUE(device.empty());
763763
}
764764

765+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
765766
// a.assign(i, j)
766767
// Result: void
767768
// Preconditions: T is Cpp17EmplaceConstructible into X from *i and assignable
@@ -835,6 +836,7 @@ TYPED_TEST(SequenceContainerRequirements, AssignRange) {
835836
ref.back() = T{5};
836837
EXPECT_THROW(device.assign_range(ref), std::bad_alloc);
837838
}
839+
#endif
838840

839841
// a.assign(il)
840842
// Effects: Equivalent to a.assign(il.begin(), il.end()).
@@ -854,6 +856,7 @@ TYPED_TEST(SequenceContainerRequirements, AssignFuncInitializerList) {
854856
EXPECT_EQ(device, IV{T{50}});
855857
}
856858

859+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
857860
// a.assign(n, t)
858861
// Result: void
859862
// Preconditions: T is Cpp17CopyInsertable into X and Cpp17CopyAssignable. t is
@@ -918,6 +921,7 @@ TYPED_TEST(SequenceContainerRequirements, AssignMulti) {
918921
device.clear();
919922
EXPECT_THROW(device.assign(device.capacity() + 1, T{12}), std::bad_alloc);
920923
}
924+
#endif
921925

922926
// a.front()
923927
// Result: reference; const_reference for constant a.
@@ -1002,6 +1006,7 @@ TYPED_TEST(SequenceContainerRequirements, ElementAccess) {
10021006
EXPECT_EQ(device[i], *(device.begin() + i));
10031007
}
10041008

1009+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
10051010
// a.at(n)
10061011
// Result: reference; const_reference for constant a
10071012
// Returns: *(a.begin() + n)
@@ -1019,5 +1024,6 @@ TYPED_TEST(SequenceContainerRequirements, ElementAccessAt) {
10191024

10201025
EXPECT_THROW(device.at(IV::capacity()), std::out_of_range);
10211026
}
1027+
#endif
10221028

10231029
}; // namespace

tests/beman/inplace_vector/inplace_vector.test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ template <typename T> constexpr void test() {
6565
assert(const_data == std::addressof(const_front));
6666
}
6767

68+
#if BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
69+
void test_exceptions() {};
70+
#else
6871
void test_exceptions() {
6972
using vec = inplace_vector<int, 42>;
7073
{
@@ -86,6 +89,7 @@ void test_exceptions() {
8689
}
8790
}
8891
}
92+
#endif
8993
int main() {
9094
test<int>();
9195
test_exceptions();

0 commit comments

Comments
 (0)