Skip to content

Commit b631f23

Browse files
committed
[ntuple] add test for model extension with streamer fields
1 parent 4ff42ec commit b631f23

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tree/ntuple/inc/ROOT/RNTupleWriter.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ public:
220220
/// Get a RNTupleModel::RUpdater that provides limited support for incremental updates to the underlying
221221
/// model, e.g. addition of new fields.
222222
///
223+
/// Note that a Model may not be extended with Streamer fields.
224+
///
223225
/// **Example: add a new field after the model has been used to construct a `RNTupleWriter` object**
224226
/// ~~~ {.cpp}
225227
/// #include <ROOT/RNTuple.hxx>

tree/ntuple/test/ntuple_modelext.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,21 @@ TEST(RNTuple, ModelExtensionNullableField)
587587
EXPECT_FLOAT_EQ(1.0, viewA(1).value());
588588
EXPECT_FALSE(viewA(2).has_value());
589589
}
590+
591+
TEST(RNTuple, ModelExtensionStreamerFields)
592+
{
593+
FileRaii fileGuard("test_ntuple_modelext_streamer.root");
594+
595+
auto writer = RNTupleWriter::Recreate(RNTupleModel::Create(), "ntpl", fileGuard.GetPath());
596+
writer->Fill();
597+
598+
auto modelUpdater = writer->CreateModelUpdater();
599+
modelUpdater->BeginUpdate();
600+
modelUpdater->AddField(std::make_unique<ROOT::RStreamerField>("foo", "CustomStruct"));
601+
try {
602+
modelUpdater->CommitUpdate();
603+
FAIL() << "extending a Model with a Streamer field should fail";
604+
} catch (const ROOT::RException &ex) {
605+
EXPECT_THAT(ex.what(), testing::HasSubstr("a Model cannot be extended with Streamer fields"));
606+
}
607+
}

0 commit comments

Comments
 (0)