Skip to content

Commit 7810199

Browse files
committed
Update noexceptions.test.cpp
1 parent 43ed978 commit 7810199

File tree

1 file changed

+84
-41
lines changed

1 file changed

+84
-41
lines changed
Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,111 @@
11
#include <array>
22

3-
bool abort_called = false;
4-
#define BEMAN_IV_THROW_OR_ABORT(x) abort_called = true;
5-
63
#include "gtest_setup.hpp"
74

85
namespace {
6+
97
template <typename Param> class NoExceptions : public IVBasicTest<Param> {};
108
TYPED_TEST_SUITE(NoExceptions, IVAllTypes);
119

1210
TYPED_TEST(NoExceptions, NonThrowing) {
1311

1412
using IV = TestFixture::IV;
15-
using T = TestFixture::T;
1613

1714
const auto reference = this->unique();
1815

1916
IV device;
20-
abort_called = false;
2117

2218
device.assign(reference.begin(), reference.end());
2319
EXPECT_EQ(device, reference);
2420
device.clear();
25-
26-
EXPECT_EQ(abort_called, false);
2721
}
2822

29-
TYPED_TEST(NoExceptions, Throwing) {
23+
TYPED_TEST(NoExceptions, IVAllTypes) {
3024

3125
using IV = TestFixture::IV;
3226
using T = TestFixture::T;
3327

34-
const auto reference = this->unique();
35-
auto range = std::array<T, IV::capacity() + 1>{};
36-
37-
IV device;
38-
device.assign(reference.begin(), reference.end());
39-
40-
abort_called = false;
41-
device.emplace_back(T{});
42-
EXPECT_EQ(abort_called, true);
43-
44-
abort_called = false;
45-
device.resize(IV::capacity() + 1);
46-
EXPECT_EQ(abort_called, true);
47-
48-
abort_called = false;
49-
device.resize(IV::capacity() + 1, T{});
50-
EXPECT_EQ(abort_called, true);
51-
52-
abort_called = false;
53-
device.reserve(IV::capacity() + 1);
54-
EXPECT_EQ(abort_called, true);
55-
56-
abort_called = false;
57-
device.append_range(range);
58-
EXPECT_EQ(abort_called, true);
59-
60-
abort_called = false;
61-
device.insert(device.end(), range.begin(), range.end());
62-
EXPECT_EQ(abort_called, true);
63-
64-
abort_called = false;
65-
device.at(IV::capacity() + 1);
66-
EXPECT_EQ(abort_called, true);
28+
IV sanitycheck = this->unique();
29+
EXPECT_EQ(sanitycheck.size(), IV::capacity());
30+
31+
EXPECT_DEATH(
32+
{
33+
IV device = this->unique();
34+
device.emplace_back(T{});
35+
},
36+
".*");
37+
38+
EXPECT_DEATH(
39+
{
40+
IV device = this->unique();
41+
device.resize(IV::capacity() + 1);
42+
},
43+
".*");
44+
45+
EXPECT_DEATH(
46+
{
47+
IV device = this->unique();
48+
device.resize(IV::capacity() + 1, T{});
49+
},
50+
".*");
51+
52+
EXPECT_DEATH(
53+
{
54+
IV device = this->unique();
55+
device.reserve(IV::capacity() + 1);
56+
},
57+
".*");
58+
59+
EXPECT_DEATH(
60+
{
61+
IV device{};
62+
device.append_range(std::array<T, IV::capacity() + 2>{});
63+
},
64+
".*");
65+
66+
EXPECT_DEATH(
67+
{
68+
IV device = this->unique();
69+
device.append_range(std::array<T, 2>{});
70+
},
71+
".*");
72+
73+
// TODO consider adding test for append_range of unsized range
74+
75+
if constexpr (IV::capacity() > 0) {
76+
EXPECT_DEATH(
77+
{
78+
IV device = this->unique();
79+
// test macro fails to compile if we use std::array<T, N> without
80+
// parenthesis ()
81+
auto range = (std::array<T, IV::capacity()>{});
82+
device.insert(device.end(), range.begin(), range.end());
83+
},
84+
".*");
85+
}
86+
87+
EXPECT_DEATH(
88+
{
89+
IV device{};
90+
// test macro fails to compile if we use std::array<T, N> without
91+
// parenthesis ()
92+
auto range = (std::array<T, IV::capacity() + 1>{});
93+
device.insert(device.end(), range.begin(), range.end());
94+
},
95+
".*");
96+
97+
EXPECT_DEATH(
98+
{
99+
IV device = this->unique();
100+
auto e = device.at(IV::capacity() + 1);
101+
},
102+
".*");
103+
104+
EXPECT_DEATH(
105+
{
106+
IV device;
107+
const auto e = device.at(IV::capacity() + 1);
108+
},
109+
".*");
67110
}
68111
} // namespace

0 commit comments

Comments
 (0)