Skip to content
Snippets Groups Projects
Commit 57c09c9e authored by Florine de Geus's avatar Florine de Geus Committed by Jakob Blomer
Browse files

[ntuple] Add unit test for TChain

parent a3fc6147
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
#include <TFile.h>
#include <TTree.h>
#include <TChain.h>
#include <cstdio>
#include <string>
......@@ -56,6 +57,45 @@ TEST(RNTupleImporter, CreateFromTree)
EXPECT_THROW(importer->Import(), ROOT::Experimental::RException);
}
TEST(RNTupleImporter, CreateFromChain)
{
FileRaii fileGuard1("test_ntuple_create_from_chain_1.root");
{
std::unique_ptr<TFile> file(TFile::Open(fileGuard1.GetPath().c_str(), "RECREATE"));
auto tree = std::make_unique<TTree>("tree", "");
Int_t a = 42;
// For single-leaf branches, use branch name, not leaf name
tree->Branch("a", &a);
tree->Fill();
tree->Write();
}
FileRaii fileGuard2("test_ntuple_create_from_chain_2.root");
{
std::unique_ptr<TFile> file(TFile::Open(fileGuard2.GetPath().c_str(), "RECREATE"));
auto tree = std::make_unique<TTree>("tree", "");
Int_t a = 43;
// For single-leaf branches, use branch name, not leaf name
tree->Branch("a", &a);
tree->Fill();
tree->Write();
}
TChain *chain = new TChain("tree");
chain->Add(fileGuard1.GetPath().c_str());
chain->Add(fileGuard2.GetPath().c_str());
auto importer = RNTupleImporter::Create(chain, fileGuard1.GetPath()).Unwrap();
importer->SetIsQuiet(true);
EXPECT_THROW(importer->Import(), ROOT::Experimental::RException);
importer->SetNTupleName("ntuple");
importer->Import();
auto reader = RNTupleReader::Open("ntuple", fileGuard1.GetPath());
EXPECT_EQ(2U, reader->GetNEntries());
EXPECT_THROW(importer->Import(), ROOT::Experimental::RException);
}
TEST(RNTupleImporter, Simple)
{
FileRaii fileGuard("test_ntuple_importer_simple.root");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment