Skip to content

Commit 7d4b7f0

Browse files
committed
[ntuple] add test for type trace report
1 parent 0e9b4ce commit 7d4b7f0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tree/ntuple/test/ntuple_show.cxx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,41 @@ R"({
642642
// clang-format on
643643
EXPECT_EQ(os1.str(), expected);
644644
}
645+
646+
TEST(RNTupleShow, TypeTraceReport)
647+
{
648+
FileRaii fileGuard("test_ntuple_show_type_trace_report.ntuple");
649+
{
650+
auto model = RNTupleModel::Create();
651+
model->MakeField<std::variant<double, std::vector<std::pair<float, bool>>>>("f");
652+
auto writer = RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
653+
}
654+
655+
auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath());
656+
657+
// Get the field for the `bool` member of the inner `pair`
658+
const auto field = reader->GetModel()
659+
.GetDefaultEntry()
660+
.begin()
661+
->GetField()
662+
.GetConstSubfields()[1]
663+
->GetConstSubfields()[0]
664+
->GetConstSubfields()[1];
665+
666+
const auto report = ROOT::Internal::GetTypeTraceReport(*field, reader->GetDescriptor());
667+
668+
const std::string expected{
669+
R"(In-memory field/type hierarchy:
670+
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
671+
_1 [std::vector<std::pair<float,bool>>] (id: 2)
672+
_0 [std::pair<float,bool>] (id: 3)
673+
_1 [bool] (id: 5)
674+
On-disk field/type hierarchy:
675+
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
676+
_1 [std::vector<std::pair<float,bool>>] (id: 2)
677+
_0 [std::pair<float,bool>] (id: 3)
678+
_1 [bool] (id: 5)
679+
)"};
680+
681+
EXPECT_EQ(expected, report);
682+
}

0 commit comments

Comments
 (0)