Skip to content

Commit 97df930

Browse files
committed
[ntuple] add test for type trace report
1 parent c6220e6 commit 97df930

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tree/ntuple/test/ntuple_show.cxx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ TEST(RNTupleShow, Vectors)
167167
std::ostringstream os;
168168
ntuple2->Show(0, os);
169169
// clang-format off
170-
std::string fString{
170+
std::string fString{
171171
R"({
172172
"intVec": [4, 5, 6],
173173
"floatVecVec": [[0.1, 0.2], [1.1, 1.2]],
@@ -312,7 +312,7 @@ TEST(RNTupleShow, Objects)
312312
std::ostringstream os;
313313
ntuple2->Show(0, os);
314314
// clang-format off
315-
std::string fString{
315+
std::string fString{
316316
R"({
317317
"CustomStruct": {
318318
"a": 4.1,
@@ -663,3 +663,36 @@ TEST(RNTupleShow, Friends)
663663
writer->Fill();
664664
}
665665
}
666+
667+
TEST(RNTupleShow, TypeTraceReport)
668+
{
669+
FileRaii fileGuard("test_ntuple_show_type_trace_report.ntuple");
670+
{
671+
auto model = RNTupleModel::Create();
672+
model->MakeField<std::variant<double, std::vector<std::pair<float, bool>>>>("f");
673+
auto writer = RNTupleWriter::Recreate(std::move(model), "ntpl", fileGuard.GetPath());
674+
}
675+
676+
auto reader = RNTupleReader::Open("ntpl", fileGuard.GetPath());
677+
678+
// Get the field for the `bool` member of the inner `pair`
679+
const auto field = reader->GetModel().GetDefaultEntry().begin()->GetField().GetConstSubfields()[1]
680+
->GetConstSubfields()[0]->GetConstSubfields()[1];
681+
682+
const auto report = ROOT::Internal::GetTypeTraceReport(*field, reader->GetDescriptor());
683+
684+
const std::string expected{
685+
R"(In-memory field/type hierarchy:
686+
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
687+
_1 [std::vector<std::pair<float,bool>>] (id: 2)
688+
_0 [std::pair<float,bool>] (id: 3)
689+
_1 [bool] (id: 5)
690+
On-disk field/type hierarchy:
691+
f [std::variant<double,std::vector<std::pair<float,bool>>>] (id: 0)
692+
_1 [std::vector<std::pair<float,bool>>] (id: 2)
693+
_0 [std::pair<float,bool>] (id: 3)
694+
_1 [bool] (id: 5)
695+
)"};
696+
697+
EXPECT_EQ(expected, report);
698+
}

0 commit comments

Comments
 (0)