| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright Contributors to the OpenVDB Project | ||
| 2 | // SPDX-License-Identifier: MPL-2.0 | ||
| 3 | |||
| 4 | #include <openvdb/Metadata.h> | ||
| 5 | #include <openvdb/Types.h> | ||
| 6 | |||
| 7 | #include <gtest/gtest.h> | ||
| 8 | |||
| 9 | #include <iostream> | ||
| 10 | #include <sstream> | ||
| 11 | |||
| 12 | 16 | class TestMetadataIO: public ::testing::Test | |
| 13 | { | ||
| 14 | public: | ||
| 15 | template <typename T> | ||
| 16 | void test(); | ||
| 17 | template <typename T> | ||
| 18 | void testMultiple(); | ||
| 19 | }; | ||
| 20 | |||
| 21 | |||
| 22 | namespace { | ||
| 23 | |||
| 24 | template<typename T> struct Value { static T create(int i) { return T(i); } }; | ||
| 25 | |||
| 26 | template<> struct Value<std::string> { | ||
| 27 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | static std::string create(int i) { return "test" + std::to_string(i); } |
| 28 | }; | ||
| 29 | |||
| 30 | template<typename T> struct Value<openvdb::math::Vec2<T>> { | ||
| 31 | using ValueType = openvdb::math::Vec2<T>; | ||
| 32 | 2 | static ValueType create(int i) { return ValueType(i, i+1); } | |
| 33 | }; | ||
| 34 | template<typename T> struct Value<openvdb::math::Vec3<T>> { | ||
| 35 | using ValueType = openvdb::math::Vec3<T>; | ||
| 36 | static ValueType create(int i) { return ValueType(i, i+1, i+2); } | ||
| 37 | }; | ||
| 38 | template<typename T> struct Value<openvdb::math::Vec4<T>> { | ||
| 39 | using ValueType = openvdb::math::Vec4<T>; | ||
| 40 | static ValueType create(int i) { return ValueType(i, i+1, i+2, i+3); } | ||
| 41 | }; | ||
| 42 | |||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | template <typename T> | ||
| 47 | void | ||
| 48 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
16 | TestMetadataIO::test() |
| 49 | { | ||
| 50 | using namespace openvdb; | ||
| 51 | |||
| 52 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
12 | const T val = Value<T>::create(1); |
| 53 | TypedMetadata<T> m(val); | ||
| 54 | |||
| 55 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
32 | std::ostringstream ostr(std::ios_base::binary); |
| 56 | |||
| 57 | m.write(ostr); | ||
| 58 | |||
| 59 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
48 | std::istringstream istr(ostr.str(), std::ios_base::binary); |
| 60 | |||
| 61 | TypedMetadata<T> tm; | ||
| 62 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
16 | tm.read(istr); |
| 63 | |||
| 64 | OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN | ||
| 65 | |||
| 66 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 8 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
16 | EXPECT_EQ(val, tm.value()); |
| 67 | |||
| 68 | OPENVDB_NO_FP_EQUALITY_WARNING_END | ||
| 69 | 16 | } | |
| 70 | |||
| 71 | template <typename T> | ||
| 72 | void | ||
| 73 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
16 | TestMetadataIO::testMultiple() |
| 74 | { | ||
| 75 | using namespace openvdb; | ||
| 76 | |||
| 77 |
2/3✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
12 | const T val1 = Value<T>::create(1), val2 = Value<T>::create(2); |
| 78 | TypedMetadata<T> m1(val1); | ||
| 79 | TypedMetadata<T> m2(val2); | ||
| 80 | |||
| 81 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
32 | std::ostringstream ostr(std::ios_base::binary); |
| 82 | |||
| 83 | m1.write(ostr); | ||
| 84 | m2.write(ostr); | ||
| 85 | |||
| 86 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
48 | std::istringstream istr(ostr.str(), std::ios_base::binary); |
| 87 | |||
| 88 | TypedMetadata<T> tm1, tm2; | ||
| 89 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
16 | tm1.read(istr); |
| 90 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
16 | tm2.read(istr); |
| 91 | |||
| 92 | OPENVDB_NO_FP_EQUALITY_WARNING_BEGIN | ||
| 93 | |||
| 94 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 8 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
16 | EXPECT_EQ(val1, tm1.value()); |
| 95 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 8 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
16 | EXPECT_EQ(val2, tm2.value()); |
| 96 | |||
| 97 | OPENVDB_NO_FP_EQUALITY_WARNING_END | ||
| 98 | 16 | } | |
| 99 | |||
| 100 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testInt) { test<int>(); } |
| 101 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleInt) { testMultiple<int>(); } |
| 102 | |||
| 103 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testInt64) { test<int64_t>(); } |
| 104 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleInt64) { testMultiple<int64_t>(); } |
| 105 | |||
| 106 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testFloat) { test<float>(); } |
| 107 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleFloat) { testMultiple<float>(); } |
| 108 | |||
| 109 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testDouble) { test<double>(); } |
| 110 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleDouble) { testMultiple<double>(); } |
| 111 | |||
| 112 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testString) { test<std::string>(); } |
| 113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleString) { testMultiple<std::string>(); } |
| 114 | |||
| 115 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testVec3R) { test<openvdb::Vec3R>(); } |
| 116 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleVec3R) { testMultiple<openvdb::Vec3R>(); } |
| 117 | |||
| 118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testVec2i) { test<openvdb::Vec2i>(); } |
| 119 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleVec2i) { testMultiple<openvdb::Vec2i>(); } |
| 120 | |||
| 121 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testVec4d) { test<openvdb::Vec4d>(); } |
| 122 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMetadataIO, testMultipleVec4d) { testMultiple<openvdb::Vec4d>(); } |
| 123 |