GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestTypes.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 72 72 100.0%
Functions: 92 96 95.8%
Branches: 72 618 11.7%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/openvdb.h>
5 #include <openvdb/Types.h>
6
7 #include <gtest/gtest.h>
8
9 #include <functional> // for std::ref()
10 #include <string>
11
12
13 using namespace openvdb;
14
15 8 class TestTypes: public ::testing::Test
16 {
17 };
18
19
20 namespace { struct Dummy {}; }
21
22 // Work-around for a macro expansion bug in debug mode that presents as an
23 // undefined reference linking error. This happens in cases where template
24 // instantiation of a type trait is prevented from occurring as the template
25 // instantiation is deemed to be in an unreachable code block.
26 // The work-around is to wrap the EXPECT_TRUE macro in another which holds
27 // the expected value in a temporary.
28 #define EXPECT_TRUE_TEMP(expected) \
29 { bool result = expected; EXPECT_TRUE(result); }
30
31
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testVecTraits)
32 {
33 { // VecTraits - IsVec
34
35 // standard types (Vec3s, etc)
36 EXPECT_TRUE_TEMP(VecTraits<Vec3s>::IsVec);
37 EXPECT_TRUE_TEMP(VecTraits<Vec3d>::IsVec);
38 EXPECT_TRUE_TEMP(VecTraits<Vec3i>::IsVec);
39 EXPECT_TRUE_TEMP(VecTraits<Vec2i>::IsVec);
40 EXPECT_TRUE_TEMP(VecTraits<Vec2s>::IsVec);
41 EXPECT_TRUE_TEMP(VecTraits<Vec2d>::IsVec);
42 EXPECT_TRUE_TEMP(VecTraits<Vec4i>::IsVec);
43 EXPECT_TRUE_TEMP(VecTraits<Vec4s>::IsVec);
44 EXPECT_TRUE_TEMP(VecTraits<Vec4d>::IsVec);
45
46 // some less common types (Vec3U16, etc)
47 EXPECT_TRUE_TEMP(VecTraits<Vec2R>::IsVec);
48 EXPECT_TRUE_TEMP(VecTraits<Vec3U16>::IsVec);
49 EXPECT_TRUE_TEMP(VecTraits<Vec4H>::IsVec);
50
51 // some non-vector types
52 EXPECT_TRUE_TEMP(!VecTraits<int>::IsVec);
53 EXPECT_TRUE_TEMP(!VecTraits<double>::IsVec);
54 EXPECT_TRUE_TEMP(!VecTraits<bool>::IsVec);
55 EXPECT_TRUE_TEMP(!VecTraits<Quats>::IsVec);
56 EXPECT_TRUE_TEMP(!VecTraits<Mat4d>::IsVec);
57 EXPECT_TRUE_TEMP(!VecTraits<ValueMask>::IsVec);
58 EXPECT_TRUE_TEMP(!VecTraits<Dummy>::IsVec);
59 EXPECT_TRUE_TEMP(!VecTraits<Byte>::IsVec);
60 }
61
62 { // VecTraits - Size
63
64 // standard types (Vec3s, etc)
65 EXPECT_TRUE(VecTraits<Vec3s>::Size == 3);
66 EXPECT_TRUE(VecTraits<Vec3d>::Size == 3);
67 EXPECT_TRUE(VecTraits<Vec3i>::Size == 3);
68 EXPECT_TRUE(VecTraits<Vec2i>::Size == 2);
69 EXPECT_TRUE(VecTraits<Vec2s>::Size == 2);
70 EXPECT_TRUE(VecTraits<Vec2d>::Size == 2);
71 EXPECT_TRUE(VecTraits<Vec4i>::Size == 4);
72 EXPECT_TRUE(VecTraits<Vec4s>::Size == 4);
73 EXPECT_TRUE(VecTraits<Vec4d>::Size == 4);
74
75 // some less common types (Vec3U16, etc)
76 EXPECT_TRUE(VecTraits<Vec2R>::Size == 2);
77 EXPECT_TRUE(VecTraits<Vec3U16>::Size == 3);
78 EXPECT_TRUE(VecTraits<Vec4H>::Size == 4);
79
80 // some non-vector types
81 EXPECT_TRUE(VecTraits<int>::Size == 1);
82 EXPECT_TRUE(VecTraits<double>::Size == 1);
83 EXPECT_TRUE(VecTraits<bool>::Size == 1);
84 EXPECT_TRUE(VecTraits<Quats>::Size == 1);
85 EXPECT_TRUE(VecTraits<Mat4d>::Size == 1);
86 EXPECT_TRUE(VecTraits<ValueMask>::Size == 1);
87 EXPECT_TRUE(VecTraits<Dummy>::Size == 1);
88 EXPECT_TRUE(VecTraits<Byte>::Size == 1);
89 }
90
91 { // VecTraits - ElementType
92
93 // standard types (Vec3s, etc)
94 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec3s>::ElementType, float>::value));
95 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec3d>::ElementType, double>::value));
96 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec3i>::ElementType, int>::value));
97 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec2i>::ElementType, int>::value));
98 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec2s>::ElementType, float>::value));
99 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec2d>::ElementType, double>::value));
100 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec4i>::ElementType, int>::value));
101 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec4s>::ElementType, float>::value));
102 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec4d>::ElementType, double>::value));
103
104 // some less common types (Vec3U16, etc)
105 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec2R>::ElementType, double>::value));
106 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec3U16>::ElementType, uint16_t>::value));
107 EXPECT_TRUE(bool(std::is_same<VecTraits<Vec4H>::ElementType, math::half>::value));
108
109 // some non-vector types
110 EXPECT_TRUE(bool(std::is_same<VecTraits<int>::ElementType, int>::value));
111 EXPECT_TRUE(bool(std::is_same<VecTraits<double>::ElementType, double>::value));
112 EXPECT_TRUE(bool(std::is_same<VecTraits<bool>::ElementType, bool>::value));
113 EXPECT_TRUE(bool(std::is_same<VecTraits<Quats>::ElementType, Quats>::value));
114 EXPECT_TRUE(bool(std::is_same<VecTraits<Mat4d>::ElementType, Mat4d>::value));
115 EXPECT_TRUE(bool(std::is_same<VecTraits<ValueMask>::ElementType, ValueMask>::value));
116 EXPECT_TRUE(bool(std::is_same<VecTraits<Dummy>::ElementType, Dummy>::value));
117 EXPECT_TRUE(bool(std::is_same<VecTraits<Byte>::ElementType, Byte>::value));
118 }
119 1 }
120
121
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testQuatTraits)
122 {
123 { // QuatTraits - IsQuat
124
125 // standard types (Quats, etc)
126 EXPECT_TRUE_TEMP(QuatTraits<Quats>::IsQuat);
127 EXPECT_TRUE_TEMP(QuatTraits<Quatd>::IsQuat);
128
129 // some non-quaternion types
130 EXPECT_TRUE_TEMP(!QuatTraits<Vec3s>::IsQuat);
131 EXPECT_TRUE_TEMP(!QuatTraits<Vec4d>::IsQuat);
132 EXPECT_TRUE_TEMP(!QuatTraits<Vec2i>::IsQuat);
133 EXPECT_TRUE_TEMP(!QuatTraits<Vec3U16>::IsQuat);
134 EXPECT_TRUE_TEMP(!QuatTraits<int>::IsQuat);
135 EXPECT_TRUE_TEMP(!QuatTraits<double>::IsQuat);
136 EXPECT_TRUE_TEMP(!QuatTraits<bool>::IsQuat);
137 EXPECT_TRUE_TEMP(!QuatTraits<Mat4s>::IsQuat);
138 EXPECT_TRUE_TEMP(!QuatTraits<ValueMask>::IsQuat);
139 EXPECT_TRUE_TEMP(!QuatTraits<Dummy>::IsQuat);
140 EXPECT_TRUE_TEMP(!QuatTraits<Byte>::IsQuat);
141 }
142
143 { // QuatTraits - Size
144
145 // standard types (Quats, etc)
146 EXPECT_TRUE(QuatTraits<Quats>::Size == 4);
147 EXPECT_TRUE(QuatTraits<Quatd>::Size == 4);
148
149 // some non-quaternion types
150 EXPECT_TRUE(QuatTraits<Vec3s>::Size == 1);
151 EXPECT_TRUE(QuatTraits<Vec4d>::Size == 1);
152 EXPECT_TRUE(QuatTraits<Vec2i>::Size == 1);
153 EXPECT_TRUE(QuatTraits<Vec3U16>::Size == 1);
154 EXPECT_TRUE(QuatTraits<int>::Size == 1);
155 EXPECT_TRUE(QuatTraits<double>::Size == 1);
156 EXPECT_TRUE(QuatTraits<bool>::Size == 1);
157 EXPECT_TRUE(QuatTraits<Mat4s>::Size == 1);
158 EXPECT_TRUE(QuatTraits<ValueMask>::Size == 1);
159 EXPECT_TRUE(QuatTraits<Dummy>::Size == 1);
160 EXPECT_TRUE(QuatTraits<Byte>::Size == 1);
161 }
162
163 { // QuatTraits - ElementType
164
165 // standard types (Quats, etc)
166 EXPECT_TRUE(bool(std::is_same<QuatTraits<Quats>::ElementType, float>::value));
167 EXPECT_TRUE(bool(std::is_same<QuatTraits<Quatd>::ElementType, double>::value));
168
169 // some non-matrix types
170 EXPECT_TRUE(bool(std::is_same<QuatTraits<Vec3s>::ElementType, Vec3s>::value));
171 EXPECT_TRUE(bool(std::is_same<QuatTraits<Vec4d>::ElementType, Vec4d>::value));
172 EXPECT_TRUE(bool(std::is_same<QuatTraits<Vec2i>::ElementType, Vec2i>::value));
173 EXPECT_TRUE(bool(std::is_same<QuatTraits<Vec3U16>::ElementType, Vec3U16>::value));
174 EXPECT_TRUE(bool(std::is_same<QuatTraits<int>::ElementType, int>::value));
175 EXPECT_TRUE(bool(std::is_same<QuatTraits<double>::ElementType, double>::value));
176 EXPECT_TRUE(bool(std::is_same<QuatTraits<bool>::ElementType, bool>::value));
177 EXPECT_TRUE(bool(std::is_same<QuatTraits<Mat4s>::ElementType, Mat4s>::value));
178 EXPECT_TRUE(bool(std::is_same<QuatTraits<ValueMask>::ElementType, ValueMask>::value));
179 EXPECT_TRUE(bool(std::is_same<QuatTraits<Dummy>::ElementType, Dummy>::value));
180 EXPECT_TRUE(bool(std::is_same<QuatTraits<Byte>::ElementType, Byte>::value));
181 }
182 1 }
183
184
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testMatTraits)
185 {
186 { // MatTraits - IsMat
187
188 // standard types (Mat4d, etc)
189 EXPECT_TRUE_TEMP(MatTraits<Mat3s>::IsMat);
190 EXPECT_TRUE_TEMP(MatTraits<Mat3d>::IsMat);
191 EXPECT_TRUE_TEMP(MatTraits<Mat4s>::IsMat);
192 EXPECT_TRUE_TEMP(MatTraits<Mat4d>::IsMat);
193
194 // some non-matrix types
195 EXPECT_TRUE_TEMP(!MatTraits<Vec3s>::IsMat);
196 EXPECT_TRUE_TEMP(!MatTraits<Vec4d>::IsMat);
197 EXPECT_TRUE_TEMP(!MatTraits<Vec2i>::IsMat);
198 EXPECT_TRUE_TEMP(!MatTraits<Vec3U16>::IsMat);
199 EXPECT_TRUE_TEMP(!MatTraits<int>::IsMat);
200 EXPECT_TRUE_TEMP(!MatTraits<double>::IsMat);
201 EXPECT_TRUE_TEMP(!MatTraits<bool>::IsMat);
202 EXPECT_TRUE_TEMP(!MatTraits<Quats>::IsMat);
203 EXPECT_TRUE_TEMP(!MatTraits<ValueMask>::IsMat);
204 EXPECT_TRUE_TEMP(!MatTraits<Dummy>::IsMat);
205 EXPECT_TRUE_TEMP(!MatTraits<Byte>::IsMat);
206 }
207
208 { // MatTraits - Size
209
210 // standard types (Mat4d, etc)
211 EXPECT_TRUE(MatTraits<Mat3s>::Size == 3);
212 EXPECT_TRUE(MatTraits<Mat3d>::Size == 3);
213 EXPECT_TRUE(MatTraits<Mat4s>::Size == 4);
214 EXPECT_TRUE(MatTraits<Mat4d>::Size == 4);
215
216 // some non-matrix types
217 EXPECT_TRUE(MatTraits<Vec3s>::Size == 1);
218 EXPECT_TRUE(MatTraits<Vec4d>::Size == 1);
219 EXPECT_TRUE(MatTraits<Vec2i>::Size == 1);
220 EXPECT_TRUE(MatTraits<Vec3U16>::Size == 1);
221 EXPECT_TRUE(MatTraits<int>::Size == 1);
222 EXPECT_TRUE(MatTraits<double>::Size == 1);
223 EXPECT_TRUE(MatTraits<bool>::Size == 1);
224 EXPECT_TRUE(MatTraits<Quats>::Size == 1);
225 EXPECT_TRUE(MatTraits<ValueMask>::Size == 1);
226 EXPECT_TRUE(MatTraits<Dummy>::Size == 1);
227 EXPECT_TRUE(MatTraits<Byte>::Size == 1);
228 }
229
230 { // MatTraits - ElementType
231
232 // standard types (Mat4d, etc)
233 EXPECT_TRUE(bool(std::is_same<MatTraits<Mat3s>::ElementType, float>::value));
234 EXPECT_TRUE(bool(std::is_same<MatTraits<Mat3d>::ElementType, double>::value));
235 EXPECT_TRUE(bool(std::is_same<MatTraits<Mat4s>::ElementType, float>::value));
236 EXPECT_TRUE(bool(std::is_same<MatTraits<Mat4d>::ElementType, double>::value));
237
238 // some non-matrix types
239 EXPECT_TRUE(bool(std::is_same<MatTraits<Vec3s>::ElementType, Vec3s>::value));
240 EXPECT_TRUE(bool(std::is_same<MatTraits<Vec4d>::ElementType, Vec4d>::value));
241 EXPECT_TRUE(bool(std::is_same<MatTraits<Vec2i>::ElementType, Vec2i>::value));
242 EXPECT_TRUE(bool(std::is_same<MatTraits<Vec3U16>::ElementType, Vec3U16>::value));
243 EXPECT_TRUE(bool(std::is_same<MatTraits<int>::ElementType, int>::value));
244 EXPECT_TRUE(bool(std::is_same<MatTraits<double>::ElementType, double>::value));
245 EXPECT_TRUE(bool(std::is_same<MatTraits<bool>::ElementType, bool>::value));
246 EXPECT_TRUE(bool(std::is_same<MatTraits<Quats>::ElementType, Quats>::value));
247 EXPECT_TRUE(bool(std::is_same<MatTraits<ValueMask>::ElementType, ValueMask>::value));
248 EXPECT_TRUE(bool(std::is_same<MatTraits<Dummy>::ElementType, Dummy>::value));
249 EXPECT_TRUE(bool(std::is_same<MatTraits<Byte>::ElementType, Byte>::value));
250 }
251 1 }
252
253
254
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testValueTraits)
255 {
256 { // ValueTraits - IsVec, IsQuat, IsMat, IsScalar
257
258 // vector types
259 EXPECT_TRUE_TEMP(ValueTraits<Vec3s>::IsVec);
260 EXPECT_TRUE_TEMP(!ValueTraits<Vec3s>::IsQuat);
261 EXPECT_TRUE_TEMP(!ValueTraits<Vec3s>::IsMat);
262 EXPECT_TRUE_TEMP(!ValueTraits<Vec3s>::IsScalar);
263 EXPECT_TRUE_TEMP(ValueTraits<Vec4d>::IsVec);
264 EXPECT_TRUE_TEMP(!ValueTraits<Vec4d>::IsQuat);
265 EXPECT_TRUE_TEMP(!ValueTraits<Vec4d>::IsMat);
266 EXPECT_TRUE_TEMP(!ValueTraits<Vec4d>::IsScalar);
267 EXPECT_TRUE_TEMP(ValueTraits<Vec3U16>::IsVec);
268 EXPECT_TRUE_TEMP(!ValueTraits<Vec3U16>::IsQuat);
269 EXPECT_TRUE_TEMP(!ValueTraits<Vec3U16>::IsMat);
270 EXPECT_TRUE_TEMP(!ValueTraits<Vec3U16>::IsScalar);
271
272 // quaternion types
273 EXPECT_TRUE_TEMP(!ValueTraits<Quats>::IsVec);
274 EXPECT_TRUE_TEMP(ValueTraits<Quats>::IsQuat);
275 EXPECT_TRUE_TEMP(!ValueTraits<Quats>::IsMat);
276 EXPECT_TRUE_TEMP(!ValueTraits<Quats>::IsScalar);
277 EXPECT_TRUE_TEMP(!ValueTraits<Quatd>::IsVec);
278 EXPECT_TRUE_TEMP(ValueTraits<Quatd>::IsQuat);
279 EXPECT_TRUE_TEMP(!ValueTraits<Quatd>::IsMat);
280 EXPECT_TRUE_TEMP(!ValueTraits<Quatd>::IsScalar);
281
282 // matrix types
283 EXPECT_TRUE_TEMP(!ValueTraits<Mat3s>::IsVec);
284 EXPECT_TRUE_TEMP(!ValueTraits<Mat3s>::IsQuat);
285 EXPECT_TRUE_TEMP(ValueTraits<Mat3s>::IsMat);
286 EXPECT_TRUE_TEMP(!ValueTraits<Mat3s>::IsScalar);
287 EXPECT_TRUE_TEMP(!ValueTraits<Mat4d>::IsVec);
288 EXPECT_TRUE_TEMP(!ValueTraits<Mat4d>::IsQuat);
289 EXPECT_TRUE_TEMP(ValueTraits<Mat4d>::IsMat);
290 EXPECT_TRUE_TEMP(!ValueTraits<Mat4d>::IsScalar);
291
292 // scalar types
293 EXPECT_TRUE_TEMP(!ValueTraits<double>::IsVec);
294 EXPECT_TRUE_TEMP(!ValueTraits<double>::IsQuat);
295 EXPECT_TRUE_TEMP(!ValueTraits<double>::IsMat);
296 EXPECT_TRUE_TEMP(ValueTraits<double>::IsScalar);
297 EXPECT_TRUE_TEMP(!ValueTraits<bool>::IsVec);
298 EXPECT_TRUE_TEMP(!ValueTraits<bool>::IsQuat);
299 EXPECT_TRUE_TEMP(!ValueTraits<bool>::IsMat);
300 EXPECT_TRUE_TEMP(ValueTraits<bool>::IsScalar);
301 EXPECT_TRUE_TEMP(!ValueTraits<ValueMask>::IsVec);
302 EXPECT_TRUE_TEMP(!ValueTraits<ValueMask>::IsQuat);
303 EXPECT_TRUE_TEMP(!ValueTraits<ValueMask>::IsMat);
304 EXPECT_TRUE_TEMP(ValueTraits<ValueMask>::IsScalar);
305 EXPECT_TRUE_TEMP(!ValueTraits<Dummy>::IsVec);
306 EXPECT_TRUE_TEMP(!ValueTraits<Dummy>::IsQuat);
307 EXPECT_TRUE_TEMP(!ValueTraits<Dummy>::IsMat);
308 EXPECT_TRUE_TEMP(ValueTraits<Dummy>::IsScalar);
309 }
310
311 { // ValueTraits - Size
312
313 // vector types
314 EXPECT_TRUE(ValueTraits<Vec3s>::Size == 3);
315 EXPECT_TRUE(ValueTraits<Vec4d>::Size == 4);
316 EXPECT_TRUE(ValueTraits<Vec3U16>::Size == 3);
317
318 // quaternion types
319 EXPECT_TRUE(ValueTraits<Quats>::Size == 4);
320 EXPECT_TRUE(ValueTraits<Quatd>::Size == 4);
321
322 // matrix types
323 EXPECT_TRUE(ValueTraits<Mat3s>::Size == 3);
324 EXPECT_TRUE(ValueTraits<Mat4d>::Size == 4);
325
326 // scalar types
327 EXPECT_TRUE(ValueTraits<double>::Size == 1);
328 EXPECT_TRUE(ValueTraits<bool>::Size == 1);
329 EXPECT_TRUE(ValueTraits<ValueMask>::Size == 1);
330 EXPECT_TRUE(ValueTraits<Dummy>::Size == 1);
331 }
332
333 { // ValueTraits - Elements
334
335 // vector types
336 EXPECT_TRUE(ValueTraits<Vec3s>::Elements == 3);
337 EXPECT_TRUE(ValueTraits<Vec4d>::Elements == 4);
338 EXPECT_TRUE(ValueTraits<Vec3U16>::Elements == 3);
339
340 // quaternion types
341 EXPECT_TRUE(ValueTraits<Quats>::Elements == 4);
342 EXPECT_TRUE(ValueTraits<Quatd>::Elements == 4);
343
344 // matrix types
345 EXPECT_TRUE(ValueTraits<Mat3s>::Elements == 3*3);
346 EXPECT_TRUE(ValueTraits<Mat4d>::Elements == 4*4);
347
348 // scalar types
349 EXPECT_TRUE(ValueTraits<double>::Elements == 1);
350 EXPECT_TRUE(ValueTraits<bool>::Elements == 1);
351 EXPECT_TRUE(ValueTraits<ValueMask>::Elements == 1);
352 EXPECT_TRUE(ValueTraits<Dummy>::Elements == 1);
353 }
354
355 { // ValueTraits - ElementType
356
357 // vector types
358 EXPECT_TRUE(bool(std::is_same<ValueTraits<Vec3s>::ElementType, float>::value));
359 EXPECT_TRUE(bool(std::is_same<ValueTraits<Vec4d>::ElementType, double>::value));
360 EXPECT_TRUE(bool(std::is_same<ValueTraits<Vec3U16>::ElementType, uint16_t>::value));
361
362 // quaternion types
363 EXPECT_TRUE(bool(std::is_same<ValueTraits<Quats>::ElementType, float>::value));
364 EXPECT_TRUE(bool(std::is_same<ValueTraits<Quatd>::ElementType, double>::value));
365
366 // matrix types
367 EXPECT_TRUE(bool(std::is_same<ValueTraits<Mat3s>::ElementType, float>::value));
368 EXPECT_TRUE(bool(std::is_same<ValueTraits<Mat4d>::ElementType, double>::value));
369
370 // scalar types
371 EXPECT_TRUE(bool(std::is_same<ValueTraits<double>::ElementType, double>::value));
372 EXPECT_TRUE(bool(std::is_same<ValueTraits<bool>::ElementType, bool>::value));
373 EXPECT_TRUE(bool(std::is_same<ValueTraits<ValueMask>::ElementType, ValueMask>::value));
374 EXPECT_TRUE(bool(std::is_same<ValueTraits<Dummy>::ElementType, Dummy>::value));
375 }
376 1 }
377
378
379 ////////////////////////////////////////
380
381
382 namespace {
383
384 template<typename T> char typeCode() { return '.'; }
385 11 template<> char typeCode<bool>() { return 'b'; }
386 4 template<> char typeCode<char>() { return 'c'; }
387 11 template<> char typeCode<double>() { return 'd'; }
388 13 template<> char typeCode<float>() { return 'f'; }
389 10 template<> char typeCode<int>() { return 'i'; }
390 7 template<> char typeCode<long>() { return 'l'; }
391
392
393 struct TypeCodeOp
394 {
395 std::string codes;
396 44 template<typename T> void operator()(const T&) { codes.push_back(typeCode<T>()); }
397 };
398
399 struct ListModifier
400 {
401 template <typename T>
402 using Promote = typename PromoteType<T>::Next;
403
404 template <typename T>
405 using RemoveInt32 = typename std::conditional<std::is_same<int32_t, T>::value, TypeList<>, T>::type;
406
407 template <typename T>
408 using Duplicate = TypeList<T, T>;
409 };
410
411 template<typename TSet>
412 inline std::string
413
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
30 typeSetAsString()
414 {
415 TypeCodeOp op;
416
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
28 TSet::foreach(std::ref(op));
417
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
60 return op.codes;
418 }
419
420 template <typename T1, typename T2>
421 using ConvertIntegrals = typename std::conditional<std::is_integral<T1>::value, T2, T1>::type;
422
423 template <typename T1>
424 using ConvertIntegralsToFloats = ConvertIntegrals<T1, float>;
425
426 template <typename T>
427 struct Tester
428 {
429 template <typename T1>
430 using ConvertIntegralsToFloats = ConvertIntegrals<T1, T>;
431 };
432
433 } // anonymous namespace
434
435 /// @note static_assert with no message requires C++17
436 #define STATIC_ASSERT(exp) static_assert(exp, "");
437
438
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testTypeList)
439 {
440 /// Compile time tests of TypeList
441
442 using IntTypes = TypeList<Int16, Int32, Int64>;
443 using EmptyList = TypeList<>;
444
445 // Size
446 STATIC_ASSERT((IntTypes::Size == 3));
447 STATIC_ASSERT((EmptyList::Size == 0));
448
449 // Contains
450 STATIC_ASSERT((IntTypes::Contains<Int16>));
451 STATIC_ASSERT((IntTypes::Contains<Int32>));
452 STATIC_ASSERT((IntTypes::Contains<Int64>));
453 STATIC_ASSERT((!IntTypes::Contains<float>));
454
455 // Index
456 STATIC_ASSERT((IntTypes::Index<Int16> == 0));
457 STATIC_ASSERT((IntTypes::Index<Int32> == 1));
458 STATIC_ASSERT((IntTypes::Index<Int64> == 2));
459 STATIC_ASSERT((IntTypes::Index<float> == -1));
460
461 // Get
462 STATIC_ASSERT((std::is_same<IntTypes::Get<0>, Int16>::value));
463 STATIC_ASSERT((std::is_same<IntTypes::Get<1>, Int32>::value));
464 STATIC_ASSERT((std::is_same<IntTypes::Get<2>, Int64>::value));
465 STATIC_ASSERT((std::is_same<IntTypes::Get<3>, typelist_internal::NullType>::value));
466 STATIC_ASSERT((!std::is_same<IntTypes::Get<3>, void>::value));
467
468 // Unique
469 STATIC_ASSERT((std::is_same<IntTypes::Unique<>, IntTypes>::value));
470 STATIC_ASSERT((std::is_same<IntTypes::Unique<IntTypes>, IntTypes>::value));
471 STATIC_ASSERT((std::is_same<EmptyList::Unique<>, EmptyList>::value));
472 STATIC_ASSERT((std::is_same<TypeList<int, int, int>::Unique<>, TypeList<int>>::value));
473 STATIC_ASSERT((std::is_same<TypeList<float, int, float>::Unique<>, TypeList<float, int>>::value));
474 STATIC_ASSERT((std::is_same<TypeList<bool, int, float, int, float>::Unique<>, TypeList<bool, int, float>>::value));
475
476 // Front/Back
477 STATIC_ASSERT((std::is_same<IntTypes::Front, Int16>::value));
478 STATIC_ASSERT((std::is_same<IntTypes::Back, Int64>::value));
479
480 // PopFront/PopBack
481 STATIC_ASSERT((std::is_same<IntTypes::PopFront, TypeList<Int32, Int64>>::value));
482 STATIC_ASSERT((std::is_same<IntTypes::PopBack, TypeList<Int16, Int32>>::value));
483
484 // RemoveByIndex
485 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<0,0>, IntTypes::PopFront>::value));
486 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<2,2>, IntTypes::PopBack>::value));
487 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<0,2>, EmptyList>::value));
488 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<1,2>, TypeList<Int16>>::value));
489 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<1,1>, TypeList<Int16, Int64>>::value));
490 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<0,1>, TypeList<Int64>>::value));
491 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<0,10>, EmptyList>::value));
492
493 // invalid indices do nothing
494 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<2,1>, IntTypes>::value));
495 STATIC_ASSERT((std::is_same<IntTypes::RemoveByIndex<3,3>, IntTypes>::value));
496
497 //
498
499 // Test methods on an empty list
500 STATIC_ASSERT((!EmptyList::Contains<Int16>));
501 STATIC_ASSERT((EmptyList::Index<Int16> == -1));
502 STATIC_ASSERT((std::is_same<EmptyList::Get<0>, typelist_internal::NullType>::value));
503 STATIC_ASSERT((std::is_same<EmptyList::Front, typelist_internal::NullType>::value));
504 STATIC_ASSERT((std::is_same<EmptyList::Back, typelist_internal::NullType>::value));
505 STATIC_ASSERT((std::is_same<EmptyList::PopFront, EmptyList>::value));
506 STATIC_ASSERT((std::is_same<EmptyList::PopBack, EmptyList>::value));
507 STATIC_ASSERT((std::is_same<EmptyList::RemoveByIndex<0,0>, EmptyList>::value));
508
509 //
510
511 // Test some methods on lists with duplicate types
512 using DuplicateIntTypes = TypeList<Int32, Int16, Int64, Int16>;
513 using DuplicateRealTypes = TypeList<float, float, float, float>;
514
515 STATIC_ASSERT((DuplicateIntTypes::Size == 4));
516 STATIC_ASSERT((DuplicateRealTypes::Size == 4));
517 STATIC_ASSERT((DuplicateIntTypes::Index<Int16> == 1));
518 STATIC_ASSERT((std::is_same<DuplicateIntTypes::Unique<>, TypeList<Int32, Int16, Int64>>::value));
519 STATIC_ASSERT((std::is_same<DuplicateRealTypes::Unique<>, TypeList<float>>::value));
520 STATIC_ASSERT((std::is_same<DuplicateRealTypes::Unique<DuplicateIntTypes>,
521 TypeList<float, Int32, Int16, Int64>>::value));
522
523 //
524
525 // Tests on VDB grid node chains - reverse node chains from leaf->root
526 using Tree4Float = openvdb::tree::Tree4<float, 5, 4, 3>::Type; // usually the same as FloatTree
527 using NodeChainT = Tree4Float::RootNodeType::NodeChainType;
528
529 // Expected types
530 using LeafT = openvdb::tree::LeafNode<float, 3>;
531 using IternalT1 = openvdb::tree::InternalNode<LeafT, 4>;
532 using IternalT2 = openvdb::tree::InternalNode<IternalT1, 5>;
533 using RootT = openvdb::tree::RootNode<IternalT2>;
534
535 STATIC_ASSERT((std::is_same<NodeChainT::Get<0>, LeafT>::value));
536 STATIC_ASSERT((std::is_same<NodeChainT::Get<1>, IternalT1>::value));
537 STATIC_ASSERT((std::is_same<NodeChainT::Get<2>, IternalT2>::value));
538 STATIC_ASSERT((std::is_same<NodeChainT::Get<3>, RootT>::value));
539 STATIC_ASSERT((std::is_same<NodeChainT::Get<4>, typelist_internal::NullType>::value));
540
541 // Transform
542 STATIC_ASSERT((std::is_same<EmptyList::Transform<ListModifier::Promote>, EmptyList>::value));
543 STATIC_ASSERT((std::is_same<TypeList<int32_t>::Transform<ListModifier::Promote>, TypeList<int64_t>>::value));
544 STATIC_ASSERT((std::is_same<TypeList<float>::Transform<ListModifier::Promote>, TypeList<double>>::value));
545 STATIC_ASSERT((std::is_same<TypeList<bool, uint32_t>::Transform<ListModifier::Promote>, TypeList<uint16_t, uint64_t>>::value));
546
547 STATIC_ASSERT((std::is_same<TypeList<float, uint32_t>::Transform<ConvertIntegralsToFloats>,
548 TypeList<float, float>>::value));
549 STATIC_ASSERT((std::is_same<TypeList<float, uint32_t>::Transform<Tester<float>::ConvertIntegralsToFloats>,
550 TypeList<float, float>>::value));
551
552 // @note Transforming types to TypeList<>s causes the target type to expand.
553 // This has some weird effects like being able to remove/extend types with
554 // TypeList::Transform.
555 STATIC_ASSERT((std::is_same<TypeList<int32_t, int32_t>::Transform<ListModifier::RemoveInt32>, EmptyList>::value));
556 STATIC_ASSERT((std::is_same<TypeList<int32_t, float>::Transform<ListModifier::Duplicate>,
557 TypeList<int32_t, int32_t, float, float>>::value));
558
559 // Foreach
560 using T0 = TypeList<>;
561
1/14
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
2 EXPECT_EQ(std::string(), typeSetAsString<T0>());
562
563 using T1 = TypeList<int>;
564
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("i"), typeSetAsString<T1>());
565
566 using T2 = TypeList<float>;
567
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("f"), typeSetAsString<T2>());
568
569 using T3 = TypeList<bool, double>;
570
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bd"), typeSetAsString<T3>());
571
572 using T4 = T1::Append<T2>;
573
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("if"), typeSetAsString<T4>());
574
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("fi"), typeSetAsString<T2::Append<T1>>());
575
576 using T5 = T3::Append<T4>;
577
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdif"), typeSetAsString<T5>());
578
579 using T6 = T5::Append<T5>;
580
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdifbdif"), typeSetAsString<T6>());
581
582 using T7 = T5::Append<char, long>;
583
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdifcl"), typeSetAsString<T7>());
584
585 using T8 = T5::Append<char>::Append<long>;
586
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdifcl"), typeSetAsString<T8>());
587
588 using T9 = T8::Remove<TypeList<>>;
589
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdifcl"), typeSetAsString<T9>());
590
591 using T10 = T8::Remove<std::string>;
592
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdifcl"), typeSetAsString<T10>());
593
594 using T11 = T8::Remove<char>::Remove<int>;
595
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdfl"), typeSetAsString<T11>());
596
597 using T12 = T8::Remove<char, int>;
598
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdfl"), typeSetAsString<T12>());
599
600 using T13 = T8::Remove<TypeList<char, int>>;
601
2/16
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
2 EXPECT_EQ(std::string("bdfl"), typeSetAsString<T13>());
602
603 // Apply
604 2 FloatGrid g1;
605 GridBase& base = g1;
606
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 bool applied = false;
607 EXPECT_TRUE((!TypeList<>::apply([&](const auto&) {}, base)));
608
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((!TypeList<Int32Grid>::apply([&](const auto&) {}, base)));
609
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((!TypeList<DoubleGrid>::apply([&](const auto&) {}, base)));
610
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((!TypeList<DoubleGrid>::apply([&](auto&) {}, base)));
611
3/32
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
4 EXPECT_TRUE((TypeList<FloatGrid>::apply([&](const auto& typed) {
612 EXPECT_EQ(reinterpret_cast<const void*>(&g1), reinterpret_cast<const void*>(&typed));
613 applied = true; }, base)));
614
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((applied));
615
616 // check arg is passed non-const
617 1 applied = false;
618
3/32
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
4 EXPECT_TRUE((TypeList<FloatGrid>::apply([&](auto& typed) {
619 EXPECT_EQ(reinterpret_cast<const void*>(&g1), reinterpret_cast<const void*>(&typed));
620 applied = true; }, base)));
621
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(applied);
622
623 1 applied = false;
624
3/24
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
5 EXPECT_TRUE((TypeList<Int32Grid, FloatGrid, DoubleGrid>::apply([&](const auto& typed) {
625 EXPECT_EQ(reinterpret_cast<const void*>(&g1), reinterpret_cast<const void*>(&typed));
626 applied = true;
627 }, base)));
628
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(applied);
629
630 // check const args
631 1 applied = false;
632 const GridBase& cbase = base;
633
3/24
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
5 EXPECT_TRUE((TypeList<Int32Grid, FloatGrid, DoubleGrid>::apply([&](const auto& typed) {
634 EXPECT_EQ(reinterpret_cast<const void*>(&g1), reinterpret_cast<const void*>(&typed));
635 applied = true;
636 }, cbase)));
637
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(applied);
638
639 // check same functor is used and how many types are processed
640 struct Counter {
641 Counter() = default;
642 // delete copy constructor to check functor isn't being copied
643 Counter(const Counter&) = delete;
644 2 inline void operator()(const FloatGrid&) { ++mCounter; }
645 int32_t mCounter = 0;
646
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 } count;
647
648
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((TypeList<FloatGrid>::apply(std::ref(count), cbase)));
649
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_EQ(count.mCounter, 1);
650
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE((TypeList<FloatGrid, FloatGrid>::apply(std::ref(count), cbase)));
651
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_EQ(count.mCounter, 2);
652 1 }
653
654
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testConvertElementType)
655 {
656 // Just replaces the type for non VDB math types
657 STATIC_ASSERT((std::is_same<ConvertElementType<float, double>::Type, double>::value));
658 STATIC_ASSERT((std::is_same<ConvertElementType<float, int32_t>::Type, int32_t>::value));
659
660 // Replaces the element type for VDB Math types
661 STATIC_ASSERT((std::is_same<ConvertElementType<Vec2f, int32_t>::Type, Vec2i>::value));
662 STATIC_ASSERT((std::is_same<ConvertElementType<Vec2i, float>::Type, Vec2f>::value));
663 STATIC_ASSERT((std::is_same<ConvertElementType<Vec2f, float>::Type, Vec2f>::value));
664 STATIC_ASSERT((std::is_same<ConvertElementType<Vec2f, double>::Type, Vec2d>::value));
665
666 STATIC_ASSERT((std::is_same<ConvertElementType<Vec3f, int32_t>::Type, Vec3i>::value));
667 STATIC_ASSERT((std::is_same<ConvertElementType<Vec3f, uint32_t>::Type, math::Vec3ui>::value));
668 STATIC_ASSERT((std::is_same<ConvertElementType<Vec3i, float>::Type, Vec3f>::value));
669 STATIC_ASSERT((std::is_same<ConvertElementType<Vec3f, float>::Type, Vec3f>::value));
670 STATIC_ASSERT((std::is_same<ConvertElementType<Vec3f, double>::Type, Vec3d>::value));
671
672 STATIC_ASSERT((std::is_same<ConvertElementType<Vec4f, int32_t>::Type, Vec4i>::value));
673 STATIC_ASSERT((std::is_same<ConvertElementType<Vec4i, float>::Type, Vec4f>::value));
674 STATIC_ASSERT((std::is_same<ConvertElementType<Vec4f, float>::Type, Vec4f>::value));
675 STATIC_ASSERT((std::is_same<ConvertElementType<Vec4f, double>::Type, Vec4d>::value));
676
677 STATIC_ASSERT((std::is_same<ConvertElementType<Quats, float>::Type, Quats>::value));
678 STATIC_ASSERT((std::is_same<ConvertElementType<Quats, double>::Type, Quatd>::value));
679 STATIC_ASSERT((std::is_same<ConvertElementType<Quatd, float>::Type, Quats>::value));
680
681 STATIC_ASSERT((std::is_same<ConvertElementType<Mat3s, float>::Type, Mat3s>::value));
682 STATIC_ASSERT((std::is_same<ConvertElementType<Mat3s, double>::Type, Mat3d>::value));
683 STATIC_ASSERT((std::is_same<ConvertElementType<Mat3d, float>::Type, Mat3s>::value));
684
685 STATIC_ASSERT((std::is_same<ConvertElementType<Mat4s, float>::Type, Mat4s>::value));
686 STATIC_ASSERT((std::is_same<ConvertElementType<Mat4s, double>::Type, Mat4d>::value));
687 STATIC_ASSERT((std::is_same<ConvertElementType<Mat4d, float>::Type, Mat4s>::value));
688 1 }
689
690
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testPromoteType)
691 {
692 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Lowest, math::half>::value));
693 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Previous, math::half>::value));
694 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Next, float>::value));
695 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Highest, double>::value));
696 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<0>, math::half>::value));
697 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<1>, float>::value));
698 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<2>, double>::value));
699 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<3>, double>::value));
700 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Demote<0>, math::half>::value));
701 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Demote<1>, math::half>::value));
702
703 // floating point types
704 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Lowest, math::half>::value));
705 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Previous, math::half>::value));
706 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Next, float>::value));
707 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Highest, double>::value));
708 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<0>, math::half>::value));
709 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<1>, float>::value));
710 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<2>, double>::value));
711 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Promote<3>, double>::value));
712 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Demote<0>, math::half>::value));
713 STATIC_ASSERT((std::is_same<PromoteType<math::half>::Demote<1>, math::half>::value));
714
715 STATIC_ASSERT((std::is_same<PromoteType<float>::Lowest, math::half>::value));
716 STATIC_ASSERT((std::is_same<PromoteType<float>::Previous, math::half>::value));
717 STATIC_ASSERT((std::is_same<PromoteType<float>::Next, double>::value));
718 STATIC_ASSERT((std::is_same<PromoteType<float>::Highest, double>::value));
719 STATIC_ASSERT((std::is_same<PromoteType<float>::Promote<0>, float>::value));
720 STATIC_ASSERT((std::is_same<PromoteType<float>::Promote<1>, double>::value));
721 STATIC_ASSERT((std::is_same<PromoteType<float>::Promote<2>, double>::value));
722 STATIC_ASSERT((std::is_same<PromoteType<float>::Demote<0>, float>::value));
723 STATIC_ASSERT((std::is_same<PromoteType<float>::Demote<1>, math::half>::value));
724 STATIC_ASSERT((std::is_same<PromoteType<float>::Demote<2>, math::half>::value));
725
726 STATIC_ASSERT((std::is_same<PromoteType<double>::Lowest, math::half>::value));
727 STATIC_ASSERT((std::is_same<PromoteType<double>::Previous, float>::value));
728 STATIC_ASSERT((std::is_same<PromoteType<double>::Next, double>::value));
729 STATIC_ASSERT((std::is_same<PromoteType<double>::Highest, double>::value));
730 STATIC_ASSERT((std::is_same<PromoteType<double>::Promote<0>, double>::value));
731 STATIC_ASSERT((std::is_same<PromoteType<double>::Promote<1>, double>::value));
732 STATIC_ASSERT((std::is_same<PromoteType<double>::Demote<0>, double>::value));
733 STATIC_ASSERT((std::is_same<PromoteType<double>::Demote<1>, float>::value));
734 STATIC_ASSERT((std::is_same<PromoteType<double>::Demote<2>, math::half>::value));
735 STATIC_ASSERT((std::is_same<PromoteType<double>::Demote<3>, math::half>::value));
736
737 // int types
738 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Lowest, int8_t>::value));
739 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Previous, int8_t>::value));
740 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Next, int16_t>::value));
741 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Highest, int64_t>::value));
742 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Promote<0>, int8_t>::value));
743 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Promote<1>, int16_t>::value));
744 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Promote<2>, int32_t>::value));
745 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Promote<3>, int64_t>::value));
746 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Promote<4>, int64_t>::value));
747 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Demote<0>, int8_t>::value));
748 STATIC_ASSERT((std::is_same<PromoteType<int8_t>::Demote<1>, int8_t>::value));
749
750 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Lowest, int8_t>::value));
751 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Previous, int8_t>::value));
752 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Next, int32_t>::value));
753 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Highest, int64_t>::value));
754 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Promote<0>, int16_t>::value));
755 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Promote<1>, int32_t>::value));
756 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Promote<2>, int64_t>::value));
757 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Promote<3>, int64_t>::value));
758 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Demote<0>, int16_t>::value));
759 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Demote<1>, int8_t>::value));
760 STATIC_ASSERT((std::is_same<PromoteType<int16_t>::Demote<2>, int8_t>::value));
761
762 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Lowest, int8_t>::value));
763 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Previous, int16_t>::value));
764 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Next, int64_t>::value));
765 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Highest, int64_t>::value));
766 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Promote<0>, int32_t>::value));
767 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Promote<1>, int64_t>::value));
768 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Promote<2>, int64_t>::value));
769 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Demote<0>, int32_t>::value));
770 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Demote<1>, int16_t>::value));
771 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Demote<2>, int8_t>::value));
772 STATIC_ASSERT((std::is_same<PromoteType<int32_t>::Demote<3>, int8_t>::value));
773
774 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Lowest, int8_t>::value));
775 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Previous, int32_t>::value));
776 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Next, int64_t>::value));
777 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Highest, int64_t>::value));
778 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Promote<0>, int64_t>::value));
779 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Promote<1>, int64_t>::value));
780 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Demote<0>, int64_t>::value));
781 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Demote<1>, int32_t>::value));
782 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Demote<2>, int16_t>::value));
783 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Demote<3>, int8_t>::value));
784 STATIC_ASSERT((std::is_same<PromoteType<int64_t>::Demote<4>, int8_t>::value));
785
786 // unsigned
787 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Lowest, uint8_t>::value));
788 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Previous, uint8_t>::value));
789 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Next, uint16_t>::value));
790 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Highest, uint64_t>::value));
791 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Promote<0>, uint8_t>::value));
792 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Promote<1>, uint16_t>::value));
793 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Promote<2>, uint32_t>::value));
794 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Promote<3>, uint64_t>::value));
795 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Promote<4>, uint64_t>::value));
796 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Demote<0>, uint8_t>::value));
797 STATIC_ASSERT((std::is_same<PromoteType<uint8_t>::Demote<1>, uint8_t>::value));
798
799 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Lowest, uint8_t>::value));
800 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Previous, uint8_t>::value));
801 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Next, uint32_t>::value));
802 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Highest, uint64_t>::value));
803 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Promote<0>, uint16_t>::value));
804 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Promote<1>, uint32_t>::value));
805 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Promote<2>, uint64_t>::value));
806 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Promote<3>, uint64_t>::value));
807 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Demote<0>, uint16_t>::value));
808 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Demote<1>, uint8_t>::value));
809 STATIC_ASSERT((std::is_same<PromoteType<uint16_t>::Demote<2>, uint8_t>::value));
810
811 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Lowest, uint8_t>::value));
812 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Previous, uint16_t>::value));
813 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Next, uint64_t>::value));
814 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Highest, uint64_t>::value));
815 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Promote<0>, uint32_t>::value));
816 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Promote<1>, uint64_t>::value));
817 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Promote<2>, uint64_t>::value));
818 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Demote<0>, uint32_t>::value));
819 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Demote<1>, uint16_t>::value));
820 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Demote<2>, uint8_t>::value));
821 STATIC_ASSERT((std::is_same<PromoteType<uint32_t>::Demote<3>, uint8_t>::value));
822
823 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Lowest, uint8_t>::value));
824 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Previous, uint32_t>::value));
825 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Next, uint64_t>::value));
826 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Highest, uint64_t>::value));
827 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Promote<0>, uint64_t>::value));
828 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Promote<1>, uint64_t>::value));
829 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Demote<0>, uint64_t>::value));
830 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Demote<1>, uint32_t>::value));
831 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Demote<2>, uint16_t>::value));
832 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Demote<3>, uint8_t>::value));
833 STATIC_ASSERT((std::is_same<PromoteType<uint64_t>::Demote<4>, uint8_t>::value));
834
835 // Math types
836 #define CHECK_PROMOTED_FLOAT_MATH_TYPE(MATH_TYPE) \
837 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Lowest, math::MATH_TYPE<math::half>>::value)); \
838 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Previous, math::MATH_TYPE<math::half>>::value)); \
839 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Next, math::MATH_TYPE<double>>::value)); \
840 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Highest, math::MATH_TYPE<double>>::value)); \
841 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Promote<0>, math::MATH_TYPE<float>>::value)); \
842 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Promote<1>, math::MATH_TYPE<double>>::value)); \
843 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Promote<2>, math::MATH_TYPE<double>>::value)); \
844 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Demote<0>, math::MATH_TYPE<float>>::value)); \
845 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Demote<1>, math::MATH_TYPE<math::half>>::value)); \
846 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##s>::Demote<2>, math::MATH_TYPE<math::half>>::value));
847
848 CHECK_PROMOTED_FLOAT_MATH_TYPE(Quat)
849 CHECK_PROMOTED_FLOAT_MATH_TYPE(Vec2)
850 CHECK_PROMOTED_FLOAT_MATH_TYPE(Vec3)
851 CHECK_PROMOTED_FLOAT_MATH_TYPE(Vec4)
852
853 CHECK_PROMOTED_FLOAT_MATH_TYPE(Mat3)
854 CHECK_PROMOTED_FLOAT_MATH_TYPE(Mat4)
855
856 #define CHECK_PROMOTED_DOUBLE_MATH_TYPE(MATH_TYPE) \
857 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Lowest, math::MATH_TYPE<math::half>>::value)); \
858 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Previous, math::MATH_TYPE<float>>::value)); \
859 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Next, math::MATH_TYPE<double>>::value)); \
860 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Highest, math::MATH_TYPE<double>>::value)); \
861 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Promote<0>, math::MATH_TYPE<double>>::value)); \
862 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Promote<1>, math::MATH_TYPE<double>>::value)); \
863 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Demote<0>, math::MATH_TYPE<double>>::value)); \
864 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Demote<1>, math::MATH_TYPE<float>>::value)); \
865 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Demote<2>, math::MATH_TYPE<math::half>>::value)); \
866 STATIC_ASSERT((std::is_same<PromoteType<MATH_TYPE##d>::Demote<3>, math::MATH_TYPE<math::half>>::value));
867
868 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Quat)
869 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Vec2)
870 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Vec3)
871 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Vec4)
872
873 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Mat3)
874 CHECK_PROMOTED_DOUBLE_MATH_TYPE(Mat4)
875 1 }
876
877
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
184 template <typename T> struct IsRegistered { inline void operator()() { EXPECT_TRUE(T::isRegistered()); } };
878
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
72 template <typename T> struct IsRegisteredType { inline void operator()() { EXPECT_TRUE(T::isRegisteredType()); } };
879 template <typename GridT> struct GridListContains { inline void operator()() { STATIC_ASSERT((GridTypes::Contains<GridT>)); } };
880 template <typename GridT> struct AttrListContains { inline void operator()() { STATIC_ASSERT((AttributeTypes::Contains<GridT>)); } };
881
882
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTypes, testOpenVDBTypeLists)
883 {
884 1 openvdb::initialize();
885
886 #define CHECK_TYPE_LIST_IS_VALID(LIST_T) \
887 STATIC_ASSERT((LIST_T::Size > 0)); \
888 STATIC_ASSERT((std::is_same<LIST_T::Unique<>, LIST_T>::value));
889
890 CHECK_TYPE_LIST_IS_VALID(GridTypes)
891 CHECK_TYPE_LIST_IS_VALID(RealGridTypes)
892 CHECK_TYPE_LIST_IS_VALID(IntegerGridTypes)
893 CHECK_TYPE_LIST_IS_VALID(NumericGridTypes)
894 CHECK_TYPE_LIST_IS_VALID(Vec3GridTypes)
895
896 CHECK_TYPE_LIST_IS_VALID(TreeTypes)
897 CHECK_TYPE_LIST_IS_VALID(RealTreeTypes)
898 CHECK_TYPE_LIST_IS_VALID(IntegerTreeTypes)
899 CHECK_TYPE_LIST_IS_VALID(NumericTreeTypes)
900 CHECK_TYPE_LIST_IS_VALID(Vec3TreeTypes)
901
902 STATIC_ASSERT((GridTypes::Size == TreeTypes::Size));
903 STATIC_ASSERT((RealGridTypes::Size == RealTreeTypes::Size));
904 STATIC_ASSERT((IntegerGridTypes::Size == IntegerTreeTypes::Size));
905 STATIC_ASSERT((NumericGridTypes::Size == NumericTreeTypes::Size));
906 STATIC_ASSERT((Vec3GridTypes::Size == Vec3TreeTypes::Size));
907
908 GridTypes::foreach<IsRegistered>();
909
910 RealGridTypes::foreach<GridListContains>();
911 IntegerGridTypes::foreach<GridListContains>();
912 NumericGridTypes::foreach<GridListContains>();
913 Vec3GridTypes::foreach<GridListContains>();
914
915 CHECK_TYPE_LIST_IS_VALID(AttributeTypes)
916 CHECK_TYPE_LIST_IS_VALID(IntegerAttributeTypes)
917 CHECK_TYPE_LIST_IS_VALID(NumericAttributeTypes)
918 CHECK_TYPE_LIST_IS_VALID(Vec3AttributeTypes)
919 CHECK_TYPE_LIST_IS_VALID(Mat3AttributeTypes)
920 CHECK_TYPE_LIST_IS_VALID(Mat4AttributeTypes)
921 CHECK_TYPE_LIST_IS_VALID(QuatAttributeTypes)
922
923 AttributeTypes::foreach<IsRegistered>();
924
925 RealAttributeTypes::foreach<AttrListContains>();
926 IntegerAttributeTypes::foreach<AttrListContains>();
927 NumericAttributeTypes::foreach<AttrListContains>();
928 Vec3AttributeTypes::foreach<AttrListContains>();
929 Mat3AttributeTypes::foreach<AttrListContains>();
930 Mat4AttributeTypes::foreach<AttrListContains>();
931 QuatAttributeTypes::foreach<AttrListContains>();
932
933 CHECK_TYPE_LIST_IS_VALID(MapTypes)
934
935 MapTypes::foreach<IsRegistered>();
936
937 CHECK_TYPE_LIST_IS_VALID(MetaTypes)
938
939 MetaTypes::foreach<IsRegisteredType>();
940
941 // Test apply methods
942 2 const FloatGrid grid;
943 const GridBase& gridBase = grid;
944
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(GridTypes::apply([](const auto&) {}, gridBase));
945
946 2 const FloatTree tree;
947 const TreeBase& treeBase = tree;
948
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(TreeTypes::apply([](const auto&) {}, treeBase));
949
950
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::uninitialize();
951 1 }
952