|
1 | 1 | #include <array> |
2 | 2 |
|
3 | | -bool abort_called = false; |
4 | | -#define BEMAN_IV_THROW_OR_ABORT(x) abort_called = true; |
5 | | - |
6 | 3 | #include "gtest_setup.hpp" |
7 | 4 |
|
8 | 5 | namespace { |
| 6 | + |
9 | 7 | template <typename Param> class NoExceptions : public IVBasicTest<Param> {}; |
10 | 8 | TYPED_TEST_SUITE(NoExceptions, IVAllTypes); |
11 | 9 |
|
12 | 10 | TYPED_TEST(NoExceptions, NonThrowing) { |
13 | 11 |
|
14 | 12 | using IV = TestFixture::IV; |
15 | | - using T = TestFixture::T; |
16 | 13 |
|
17 | 14 | const auto reference = this->unique(); |
18 | 15 |
|
19 | 16 | IV device; |
20 | | - abort_called = false; |
21 | 17 |
|
22 | 18 | device.assign(reference.begin(), reference.end()); |
23 | 19 | EXPECT_EQ(device, reference); |
24 | 20 | device.clear(); |
25 | | - |
26 | | - EXPECT_EQ(abort_called, false); |
27 | 21 | } |
28 | 22 |
|
29 | | -TYPED_TEST(NoExceptions, Throwing) { |
| 23 | +TYPED_TEST(NoExceptions, IVAllTypes) { |
30 | 24 |
|
31 | 25 | using IV = TestFixture::IV; |
32 | 26 | using T = TestFixture::T; |
33 | 27 |
|
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 | + ".*"); |
67 | 110 | } |
68 | 111 | } // namespace |
0 commit comments