GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestLeafIO.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 49 49 100.0%
Functions: 12 12 100.0%
Branches: 68 257 26.5%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Exceptions.h>
5 #include <openvdb/tree/LeafNode.h>
6 #include <openvdb/Types.h>
7 #include <gtest/gtest.h>
8
9 #include <cctype> // for toupper()
10 #include <iostream>
11 #include <sstream>
12
13 template<typename T>
14 class TestLeafIO
15 {
16 public:
17 static void testBuffer();
18 };
19
20 template<typename T>
21 void
22 10 TestLeafIO<T>::testBuffer()
23 {
24 10 openvdb::tree::LeafNode<T, 3> leaf(openvdb::Coord(0, 0, 0));
25
26
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
10 leaf.setValueOn(openvdb::Coord(0, 1, 0), T(1));
27
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
10 leaf.setValueOn(openvdb::Coord(1, 0, 0), T(1));
28
29
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
20 std::ostringstream ostr(std::ios_base::binary);
30
31
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
10 leaf.writeBuffers(ostr);
32
33
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
10 leaf.setValueOn(openvdb::Coord(0, 1, 0), T(0));
34
3/5
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
10 leaf.setValueOn(openvdb::Coord(0, 1, 1), T(1));
35
36
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
20 std::istringstream istr(ostr.str(), std::ios_base::binary);
37
38 // Since the input stream doesn't include a VDB header with file format version info,
39 // tag the input stream explicitly with the current version number.
40
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
10 openvdb::io::setCurrentVersion(istr);
41
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 leaf.readBuffers(istr);
43
44
5/24
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
10 EXPECT_NEAR(T(1), leaf.getValue(openvdb::Coord(0, 1, 0)), /*tolerance=*/0);
45
5/24
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
10 EXPECT_NEAR(T(1), leaf.getValue(openvdb::Coord(1, 0, 0)), /*tolerance=*/0);
46
47
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 5 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.
10 EXPECT_TRUE(leaf.onVoxelCount() == 2);
48 10 }
49
50
51 7 class TestLeafIOTest: public ::testing::Test
52 {
53 };
54
55
56
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferInt) { TestLeafIO<int>::testBuffer(); }
57
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferFloat) { TestLeafIO<float>::testBuffer(); }
58
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferDouble) { TestLeafIO<double>::testBuffer(); }
59
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferBool) { TestLeafIO<bool>::testBuffer(); }
60
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferByte) { TestLeafIO<openvdb::Byte>::testBuffer(); }
61
62
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 TEST_F(TestLeafIOTest, testBufferString)
63 {
64 openvdb::tree::LeafNode<std::string, 3>
65
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 leaf(openvdb::Coord(0, 0, 0), std::string());
66
67
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 0), std::string("test"));
68
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(1, 0, 0), std::string("test"));
69
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::ostringstream ostr(std::ios_base::binary);
71
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 leaf.writeBuffers(ostr);
73
74
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 0), std::string("douche"));
75
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 1), std::string("douche"));
76
77
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::istringstream istr(ostr.str(), std::ios_base::binary);
78
79 // Since the input stream doesn't include a VDB header with file format version info,
80 // tag the input stream explicitly with the current version number.
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::io::setCurrentVersion(istr);
82
83 leaf.readBuffers(istr);
84
85
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
2 EXPECT_EQ(std::string("test"), leaf.getValue(openvdb::Coord(0, 1, 0)));
86
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
2 EXPECT_EQ(std::string("test"), leaf.getValue(openvdb::Coord(1, 0, 0)));
87
88
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(leaf.onVoxelCount() == 2);
89 1 }
90
91
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestLeafIOTest, testBufferVec3R)
93 {
94
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 openvdb::tree::LeafNode<openvdb::Vec3R, 3> leaf(openvdb::Coord(0, 0, 0));
95
96
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 0), openvdb::Vec3R(1, 1, 1));
97
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 leaf.setValueOn(openvdb::Coord(1, 0, 0), openvdb::Vec3R(1, 1, 1));
98
99
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::ostringstream ostr(std::ios_base::binary);
100
101
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 leaf.writeBuffers(ostr);
102
103
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 0), openvdb::Vec3R(0, 0, 0));
104
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 leaf.setValueOn(openvdb::Coord(0, 1, 1), openvdb::Vec3R(1, 1, 1));
105
106
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::istringstream istr(ostr.str(), std::ios_base::binary);
107
108 // Since the input stream doesn't include a VDB header with file format version info,
109 // tag the input stream explicitly with the current version number.
110
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::io::setCurrentVersion(istr);
111
112 leaf.readBuffers(istr);
113
114
2/18
✓ 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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
2 EXPECT_TRUE(leaf.getValue(openvdb::Coord(0, 1, 0)) == openvdb::Vec3R(1, 1, 1));
115
2/18
✓ 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 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
2 EXPECT_TRUE(leaf.getValue(openvdb::Coord(1, 0, 0)) == openvdb::Vec3R(1, 1, 1));
116
117
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(leaf.onVoxelCount() == 2);
118 1 }
119