@@ -213,3 +213,147 @@ TEST_F(TestCodec, testBoolCodecIO)
213213 std::remove (rawPath.c_str ());
214214 std::remove (codecPath.c_str ());
215215}
216+
217+
218+ TEST_F (TestCodec, testReadDiagnosticsStruct)
219+ {
220+ using namespace openvdb ::io;
221+
222+ // Default-constructed: no diagnostics
223+ ReadDiagnostics diags;
224+ EXPECT_TRUE (diags.diagnostics ().empty ());
225+
226+ // addWarning accumulates entries
227+ diags.addWarning (" grid_a" , " something went wrong" );
228+ ASSERT_EQ (diags.diagnostics ().size (), size_t (1 ));
229+ EXPECT_EQ (diags.diagnostics ()[0 ].severity , DiagnosticSeverity::Warning);
230+ EXPECT_EQ (diags.diagnostics ()[0 ].context , std::string (" grid_a" ));
231+ EXPECT_EQ (diags.diagnostics ()[0 ].message , std::string (" something went wrong" ));
232+
233+ diags.addWarning (" grid_b" , " another issue" );
234+ EXPECT_EQ (diags.diagnostics ().size (), size_t (2 ));
235+
236+ // clear() empties the vector
237+ diags.clear ();
238+ EXPECT_TRUE (diags.diagnostics ().empty ());
239+ }
240+
241+
242+ TEST_F (TestCodec, testReadDiagnosticsArchiveAPI)
243+ {
244+ using namespace openvdb ;
245+ using namespace openvdb ::io;
246+
247+ openvdb::initialize ();
248+ CodecRegistry::clear ();
249+ io::internal::initialize ();
250+
251+ BoolGrid::Ptr srcGrid = BoolGrid::create (false );
252+ srcGrid->setName (" bool_grid" );
253+ srcGrid->fill (CoordBBox (Coord (-5 ), Coord (5 )), true , true );
254+
255+ const std::string codecPath = " testReadDiagnosticsArchiveAPI.vdb" ;
256+
257+ {
258+ io::File f (codecPath);
259+ f.write (GridPtrVec{srcGrid});
260+ }
261+
262+ // Without enableReadDiagnostics: readDiagnostics() returns nullptr
263+ {
264+ io::File f (codecPath);
265+ f.open ();
266+ EXPECT_EQ (f.readDiagnostics (), nullptr );
267+ f.readGrid (" bool_grid" );
268+ EXPECT_EQ (f.readDiagnostics (), nullptr );
269+ f.close ();
270+ }
271+
272+ // With enableReadDiagnostics: readDiagnostics() returns a pointer, normal read has no warnings
273+ {
274+ io::File f (codecPath);
275+ f.open ();
276+ f.enableReadDiagnostics ();
277+ EXPECT_NE (f.readDiagnostics (), nullptr );
278+ f.readGrid (" bool_grid" );
279+ EXPECT_NE (f.readDiagnostics (), nullptr );
280+ EXPECT_TRUE (f.readDiagnostics ()->diagnostics ().empty ());
281+ f.close ();
282+ }
283+
284+ // clearReadDiagnostics() empties the list but keeps collection active
285+ {
286+ io::File f (codecPath);
287+ f.open ();
288+ f.enableReadDiagnostics ();
289+ f.readGrid (" bool_grid" );
290+ f.readDiagnostics ()->clear ();
291+ EXPECT_NE (f.readDiagnostics (), nullptr );
292+ EXPECT_TRUE (f.readDiagnostics ()->diagnostics ().empty ());
293+ f.close ();
294+ }
295+
296+ // enableReadDiagnostics() is idempotent
297+ {
298+ io::File f (codecPath);
299+ f.open ();
300+ f.enableReadDiagnostics ();
301+ const io::ReadDiagnostics* ptr = f.readDiagnostics ();
302+ f.enableReadDiagnostics ();
303+ EXPECT_EQ (f.readDiagnostics (), ptr);
304+ f.close ();
305+ }
306+
307+ // Cleanup
308+ CodecRegistry::clear ();
309+ std::remove (codecPath.c_str ());
310+ }
311+
312+
313+ TEST_F (TestCodec, testReadDiagnosticsGetGrids)
314+ {
315+ using namespace openvdb ;
316+ using namespace openvdb ::io;
317+
318+ openvdb::initialize ();
319+ CodecRegistry::clear ();
320+ io::internal::initialize ();
321+
322+ BoolGrid::Ptr srcGrid = BoolGrid::create (false );
323+ srcGrid->setName (" bool_grid" );
324+ srcGrid->fill (CoordBBox (Coord (-5 ), Coord (5 )), true , true );
325+
326+ const std::string codecPath = " testReadDiagnosticsGetGrids.vdb" ;
327+
328+ {
329+ io::File f (codecPath);
330+ f.write (GridPtrVec{srcGrid});
331+ }
332+
333+ // getGrids() with diagnostics enabled — normal read produces no warnings
334+ {
335+ io::File f (codecPath);
336+ f.open ();
337+ f.enableReadDiagnostics ();
338+ GridPtrVecPtr grids = f.getGrids ();
339+ ASSERT_TRUE (grids && !grids->empty ());
340+ EXPECT_NE (f.readDiagnostics (), nullptr );
341+ EXPECT_TRUE (f.readDiagnostics ()->diagnostics ().empty ());
342+ f.close ();
343+ }
344+
345+ // clearReadDiagnostics() between getGrids() calls resets state
346+ {
347+ io::File f (codecPath);
348+ f.open ();
349+ f.enableReadDiagnostics ();
350+ f.getGrids ();
351+ f.readDiagnostics ()->clear ();
352+ EXPECT_TRUE (f.readDiagnostics ()->diagnostics ().empty ());
353+ f.close ();
354+ }
355+
356+ // Cleanup
357+ CodecRegistry::clear ();
358+ std::remove (codecPath.c_str ());
359+ }
0 commit comments