GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestStream.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 112 112 100.0%
Functions: 8 8 100.0%
Branches: 132 586 22.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/io/Stream.h>
6 #include <openvdb/Metadata.h>
7 #include <openvdb/math/Maps.h>
8 #include <openvdb/math/Transform.h>
9 #include <openvdb/version.h>
10 #include <openvdb/openvdb.h>
11 #include "gtest/gtest.h"
12 #include <cstdio> // for remove()
13 #include <fstream>
14
15 #define ASSERT_DOUBLES_EXACTLY_EQUAL(a, b) \
16 EXPECT_NEAR((a), (b), /*tolerance=*/0.0);
17
18
19 3 class TestStream: public ::testing::Test
20 {
21 public:
22 void SetUp() override;
23 void TearDown() override;
24
25 void testFileReadFromStream();
26
27 protected:
28 static openvdb::GridPtrVecPtr createTestGrids(openvdb::MetaMap::Ptr&);
29 static void verifyTestGrids(openvdb::GridPtrVecPtr, openvdb::MetaMap::Ptr);
30 };
31
32
33 ////////////////////////////////////////
34
35
36 void
37 3 TestStream::SetUp()
38 {
39 3 openvdb::uninitialize();
40
41 3 openvdb::Int32Grid::registerGrid();
42 3 openvdb::FloatGrid::registerGrid();
43
44 3 openvdb::StringMetadata::registerType();
45 3 openvdb::Int32Metadata::registerType();
46 3 openvdb::Int64Metadata::registerType();
47 3 openvdb::Vec3IMetadata::registerType();
48 3 openvdb::io::DelayedLoadMetadata::registerType();
49
50 // Register maps
51 3 openvdb::math::MapRegistry::clear();
52 3 openvdb::math::AffineMap::registerMap();
53 3 openvdb::math::ScaleMap::registerMap();
54 3 openvdb::math::UniformScaleMap::registerMap();
55 3 openvdb::math::TranslationMap::registerMap();
56 3 openvdb::math::ScaleTranslateMap::registerMap();
57 3 openvdb::math::UniformScaleTranslateMap::registerMap();
58 3 openvdb::math::NonlinearFrustumMap::registerMap();
59 3 }
60
61
62 void
63 3 TestStream::TearDown()
64 {
65 3 openvdb::uninitialize();
66 3 }
67
68
69 ////////////////////////////////////////
70
71
72 openvdb::GridPtrVecPtr
73 3 TestStream::createTestGrids(openvdb::MetaMap::Ptr& metadata)
74 {
75 using namespace openvdb;
76
77 // Create trees
78
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 Int32Tree::Ptr tree1(new Int32Tree(1));
79
2/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
6 FloatTree::Ptr tree2(new FloatTree(2.0));
80
81 // Set some values
82
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
6 tree1->setValue(Coord(0, 0, 0), 5);
83
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
6 tree1->setValue(Coord(100, 0, 0), 6);
84
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
6 tree2->setValue(Coord(0, 0, 0), 10);
85
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
6 tree2->setValue(Coord(0, 100, 0), 11);
86
87 // Create grids
88 GridBase::Ptr
89
2/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6 grid1 = createGrid(tree1),
90
2/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6 grid2 = createGrid(tree1), // instance of grid1
91
3/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6 grid3 = createGrid(tree2);
92
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 grid1->setName("density");
93
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 grid2->setName("density_copy");
94
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 grid3->setName("temperature");
95
96 // Create transforms
97
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 math::Transform::Ptr trans1 = math::Transform::createLinearTransform(0.1);
98
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 math::Transform::Ptr trans2 = math::Transform::createLinearTransform(0.1);
99
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
6 grid1->setTransform(trans1);
100
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
6 grid2->setTransform(trans2);
101
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 grid3->setTransform(trans2);
102
103
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 metadata.reset(new MetaMap);
104
4/8
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
9 metadata->insertMeta("author", StringMetadata("Einstein"));
105
2/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 metadata->insertMeta("year", Int32Metadata(2009));
106
107
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 GridPtrVecPtr grids(new GridPtrVec);
108
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 grids->push_back(grid1);
109
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 grids->push_back(grid2);
110
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 grids->push_back(grid3);
111
112 3 return grids;
113 }
114
115
116 void
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 TestStream::verifyTestGrids(openvdb::GridPtrVecPtr grids, openvdb::MetaMap::Ptr meta)
118 {
119 using namespace openvdb;
120
121
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(grids.get() != nullptr);
122
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(meta.get() != nullptr);
123
124 // Verify the metadata.
125
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
3 EXPECT_EQ(2, int(meta->metaCount()));
126
4/20
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
6 EXPECT_EQ(std::string("Einstein"), meta->metaValue<std::string>("author"));
127
4/20
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
3 EXPECT_EQ(2009, meta->metaValue<int32_t>("year"));
128
129 // Verify the grids.
130
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 3 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.
3 EXPECT_EQ(3, int(grids->size()));
131
132
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
6 GridBase::Ptr grid = findGridByName(*grids, "density");
133
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(grid.get() != nullptr);
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 Int32Tree::Ptr density = gridPtrCast<Int32Grid>(grid)->treePtr();
135
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(density.get() != nullptr);
136
137 grid.reset();
138
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
6 grid = findGridByName(*grids, "density_copy");
139
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(grid.get() != nullptr);
140
3/20
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ 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 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
9 EXPECT_TRUE(gridPtrCast<Int32Grid>(grid)->treePtr().get() != nullptr);
141 // Verify that "density_copy" is an instance of (i.e., shares a tree with) "density".
142
2/20
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 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 16 not taken.
✗ Branch 17 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.
6 EXPECT_EQ(density, gridPtrCast<Int32Grid>(grid)->treePtr());
143
144 grid.reset();
145
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
6 grid = findGridByName(*grids, "temperature");
146
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(grid.get() != nullptr);
147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 FloatTree::Ptr temperature = gridPtrCast<FloatGrid>(grid)->treePtr();
148
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 3 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.
3 EXPECT_TRUE(temperature.get() != nullptr);
149
150
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 ASSERT_DOUBLES_EXACTLY_EQUAL(5, density->getValue(Coord(0, 0, 0)));
151
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 ASSERT_DOUBLES_EXACTLY_EQUAL(6, density->getValue(Coord(100, 0, 0)));
152
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 ASSERT_DOUBLES_EXACTLY_EQUAL(10, temperature->getValue(Coord(0, 0, 0)));
153
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 ASSERT_DOUBLES_EXACTLY_EQUAL(11, temperature->getValue(Coord(0, 100, 0)));
154 3 }
155
156
157 ////////////////////////////////////////
158
159
160
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestStream, testWrite)
161 {
162 using namespace openvdb;
163
164 // Create test grids and stream them to a string.
165 1 MetaMap::Ptr meta;
166
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GridPtrVecPtr grids = createTestGrids(meta);
167
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::ostringstream ostr(std::ios_base::binary);
168
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 io::Stream(ostr).write(*grids, *meta);
169 //std::ofstream file("debug.vdb2", std::ios_base::binary);
170 //file << ostr.str();
171
172 // Stream the grids back in.
173
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::istringstream is(ostr.str(), std::ios_base::binary);
174
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 io::Stream strm(is);
175
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 meta = strm.getMetadata();
176
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 grids = strm.getGrids();
177
178
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 verifyTestGrids(grids, meta);
179 1 }
180
181
182
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestStream, testRead)
183 {
184 using namespace openvdb;
185
186 // Create test grids and write them to a file.
187 1 MetaMap::Ptr meta;
188
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GridPtrVecPtr grids = createTestGrids(meta);
189 const char* filename = "something.vdb2";
190
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
1 io::File(filename).write(*grids, *meta);
191 SharedPtr<const char> scopedFile(filename, ::remove);
192
193 // Stream the grids back in.
194
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 std::ifstream is(filename, std::ios_base::binary);
195
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 io::Stream strm(is);
196
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 meta = strm.getMetadata();
197
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 grids = strm.getGrids();
198
199
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 verifyTestGrids(grids, meta);
200 1 }
201
202
203 /// Stream grids to a file using io::Stream, then read the file back using io::File.
204 void
205 1 TestStream::testFileReadFromStream()
206 {
207 using namespace openvdb;
208
209 1 MetaMap::Ptr meta;
210
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GridPtrVecPtr grids;
211
212 // Create test grids and stream them to a file (and then close the file).
213 const char* filename = "something.vdb2";
214 SharedPtr<const char> scopedFile(filename, ::remove);
215 {
216
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 std::ofstream os(filename, std::ios_base::binary);
217
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 grids = createTestGrids(meta);
218
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 io::Stream(os).write(*grids, *meta);
219 }
220
221 // Read the grids back in.
222
3/6
✓ 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.
2 io::File file(filename);
223
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(file.inputHasGridOffsets());
224
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 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 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
2 EXPECT_THROW(file.getGrids(), IoError);
225
226
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 file.open();
227
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 meta = file.getMetadata();
228
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
2 grids = file.getGrids();
229
230
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(!file.inputHasGridOffsets());
231
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(meta.get() != nullptr);
232
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(grids.get() != nullptr);
233
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(!grids->empty());
234
235
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 verifyTestGrids(grids, meta);
236 1 }
237
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestStream, testFileReadFromStream) { testFileReadFromStream(); }
238