GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
#include "gtest/gtest.h" |
||
2 |
|||
3 |
#include "zserio/pmr/PolymorphicAllocator.h" |
||
4 |
#include "zserio/pmr/NewDeleteResource.h" |
||
5 |
|||
6 |
namespace zserio |
||
7 |
{ |
||
8 |
|||
9 |
namespace |
||
10 |
{ |
||
11 |
|||
12 |
✗✓ | 12 |
class TestResource : public zserio::pmr::MemoryResource |
13 |
{ |
||
14 |
public: |
||
15 |
7 |
void* doAllocate(size_t bytes, size_t) override |
|
16 |
{ |
||
17 |
7 |
++m_numAllocations; |
|
18 |
7 |
return ::operator new(bytes); |
|
19 |
} |
||
20 |
|||
21 |
7 |
void doDeallocate(void* p, size_t, size_t) override |
|
22 |
{ |
||
23 |
7 |
--m_numAllocations; |
|
24 |
7 |
::operator delete(p); |
|
25 |
7 |
} |
|
26 |
|||
27 |
4 |
bool doIsEqual(const MemoryResource& other) const noexcept override |
|
28 |
{ |
||
29 |
4 |
return this == &other; |
|
30 |
} |
||
31 |
|||
32 |
10 |
size_t getNumAllocations() const |
|
33 |
{ |
||
34 |
10 |
return m_numAllocations; |
|
35 |
} |
||
36 |
|||
37 |
private: |
||
38 |
size_t m_numAllocations = 0; |
||
39 |
}; |
||
40 |
|||
41 |
} // namespace |
||
42 |
|||
43 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, constructorAndResource) |
44 |
{ |
||
45 |
1 |
pmr::PolymorphicAllocator<> allocator; |
|
46 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(pmr::getDefaultResource(), allocator.resource()); |
47 |
|||
48 |
1 |
pmr::PolymorphicAllocator<> allocatorNull(nullptr); |
|
49 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(pmr::getDefaultResource(), allocatorNull.resource()); |
50 |
|||
51 |
2 |
TestResource resource; |
|
52 |
|||
53 |
1 |
pmr::PolymorphicAllocator<> allocator2(&resource); |
|
54 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(&resource, allocator2.resource()); |
55 |
|||
56 |
1 |
pmr::PolymorphicAllocator<> allocator2Copy(allocator2); |
|
57 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(&resource, allocator2Copy.resource()); |
58 |
|||
59 |
1 |
pmr::PolymorphicAllocator<> allocator2Moved(std::move(allocator2)); |
|
60 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocator2Moved.resource()); |
61 |
} |
||
62 |
|||
63 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, constructorAndResource) |
64 |
{ |
||
65 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator; |
|
66 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(pmr::getDefaultResource(), allocator.resource()); |
67 |
|||
68 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocatorNull(nullptr); |
|
69 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(pmr::getDefaultResource(), allocatorNull.resource()); |
70 |
|||
71 |
2 |
TestResource resource; |
|
72 |
|||
73 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator2(&resource); |
|
74 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(&resource, allocator2.resource()); |
75 |
|||
76 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator2Copy(allocator2); |
|
77 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(&resource, allocator2Copy.resource()); |
78 |
|||
79 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator2Moved(std::move(allocator2)); |
|
80 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocator2Moved.resource()); |
81 |
} |
||
82 |
|||
83 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, constructorRebind) |
84 |
{ |
||
85 |
2 |
TestResource resource; |
|
86 |
1 |
pmr::PolymorphicAllocator<> allocator(&resource); |
|
87 |
1 |
pmr::PolymorphicAllocator<int> allocatorRebind(allocator); |
|
88 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocatorRebind.resource()); |
89 |
} |
||
90 |
|||
91 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, constructorRebind) |
92 |
{ |
||
93 |
2 |
TestResource resource; |
|
94 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator(&resource); |
|
95 |
1 |
pmr::PolymorphicAllocator<int> allocatorRebind(allocator); |
|
96 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocatorRebind.resource()); |
97 |
} |
||
98 |
|||
99 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, assignment) |
100 |
{ |
||
101 |
2 |
TestResource resource; |
|
102 |
1 |
pmr::PolymorphicAllocator<> allocator(&resource); |
|
103 |
1 |
pmr::PolymorphicAllocator<int> allocatorRebind; |
|
104 |
1 |
allocatorRebind = allocator; |
|
105 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocatorRebind.resource()); |
106 |
} |
||
107 |
|||
108 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, assignment) |
109 |
{ |
||
110 |
2 |
TestResource resource; |
|
111 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator(&resource); |
|
112 |
1 |
pmr::PropagatingPolymorphicAllocator<int> allocatorRebind; |
|
113 |
1 |
allocatorRebind = allocator; |
|
114 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, allocatorRebind.resource()); |
115 |
} |
||
116 |
|||
117 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, allocations) |
118 |
{ |
||
119 |
2 |
TestResource resource; |
|
120 |
1 |
pmr::PolymorphicAllocator<> allocator(&resource); |
|
121 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(0, resource.getNumAllocations()); |
122 |
|||
123 |
✓✗ | 1 |
const auto ptr = allocator.allocate(1); |
124 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(1, resource.getNumAllocations()); |
125 |
|||
126 |
✓✗ | 1 |
const auto ptr2 = allocator.allocate(10); |
127 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(2, resource.getNumAllocations()); |
128 |
|||
129 |
1 |
allocator.deallocate(ptr, 1); |
|
130 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(1, resource.getNumAllocations()); |
131 |
|||
132 |
1 |
allocator.deallocate(ptr2, 10); |
|
133 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(0, resource.getNumAllocations()); |
134 |
} |
||
135 |
|||
136 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, allocations) |
137 |
{ |
||
138 |
2 |
TestResource resource; |
|
139 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator(&resource); |
|
140 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(0, resource.getNumAllocations()); |
141 |
|||
142 |
✓✗ | 1 |
const auto ptr = allocator.allocate(1); |
143 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(1, resource.getNumAllocations()); |
144 |
|||
145 |
✓✗ | 1 |
const auto ptr2 = allocator.allocate(10); |
146 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(2, resource.getNumAllocations()); |
147 |
|||
148 |
1 |
allocator.deallocate(ptr, 1); |
|
149 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(1, resource.getNumAllocations()); |
150 |
|||
151 |
1 |
allocator.deallocate(ptr2, 10); |
|
152 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(0, resource.getNumAllocations()); |
153 |
} |
||
154 |
|||
155 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, select_on_container_copy_construction) |
156 |
{ |
||
157 |
2 |
TestResource resource; |
|
158 |
1 |
pmr::PolymorphicAllocator<> allocator(&resource); |
|
159 |
|||
160 |
✓✗ | 2 |
std::vector<int, pmr::PolymorphicAllocator<int>> vector(allocator); |
161 |
✓✗ | 1 |
vector.assign({ 0, 13, 42 }); |
162 |
✓✗✓✗ |
2 |
std::vector<int, pmr::PolymorphicAllocator<int>> vectorCopy(vector); |
163 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_NE(&resource, vectorCopy.get_allocator().resource()); |
164 |
} |
||
165 |
|||
166 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, select_on_container_copy_construction) |
167 |
{ |
||
168 |
2 |
TestResource resource; |
|
169 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator(&resource); |
|
170 |
|||
171 |
✓✗ | 2 |
std::vector<int, pmr::PropagatingPolymorphicAllocator<int>> vector(allocator); |
172 |
✓✗ | 1 |
vector.assign({ 0, 13, 42 }); |
173 |
✓✗✓✗ |
2 |
std::vector<int, pmr::PropagatingPolymorphicAllocator<int>> vectorCopy(vector); |
174 |
✓✗✗✓ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_EQ(&resource, vectorCopy.get_allocator().resource()); |
175 |
} |
||
176 |
|||
177 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PolymorphicAllocatorTest, compare) |
178 |
{ |
||
179 |
1 |
pmr::PolymorphicAllocator<> allocator; |
|
180 |
1 |
pmr::PolymorphicAllocator<> allocator2; |
|
181 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_TRUE(allocator == allocator2); |
182 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocator != allocator2); |
183 |
|||
184 |
2 |
TestResource resource; |
|
185 |
|||
186 |
1 |
pmr::PolymorphicAllocator<> allocatorRes(&resource); |
|
187 |
1 |
pmr::PolymorphicAllocator<> allocatorRes2(&resource); |
|
188 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_TRUE(allocatorRes == allocatorRes2); |
189 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocatorRes != allocatorRes2); |
190 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocatorRes == allocator); |
191 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_TRUE(allocatorRes != allocator); |
192 |
} |
||
193 |
|||
194 |
✓✗✓✗ ✓✗✗✓ |
802 |
TEST(PropagatingPolymorphicAllocatorTest, compare) |
195 |
{ |
||
196 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator; |
|
197 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocator2; |
|
198 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_TRUE(allocator == allocator2); |
199 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocator != allocator2); |
200 |
|||
201 |
2 |
TestResource resource; |
|
202 |
|||
203 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocatorRes(&resource); |
|
204 |
1 |
pmr::PropagatingPolymorphicAllocator<> allocatorRes2(&resource); |
|
205 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_TRUE(allocatorRes == allocatorRes2); |
206 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocatorRes != allocatorRes2); |
207 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_FALSE(allocatorRes == allocator); |
208 |
✗✓✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗ |
1 |
ASSERT_TRUE(allocatorRes != allocator); |
209 |
} |
||
210 |
|||
211 |
✓✗✓✗ |
2394 |
} // namespace zserio |
Generated by: GCOVR (Version 4.2) |