Skip to content

Commit cbbca24

Browse files
committed
[rfile] make sure RFile doesn't register as gDirectory, add tests
1 parent 97141cb commit cbbca24

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

io/io/test/rfile.cxx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,65 @@ TEST(RFile, OpenForWriting)
8383
EXPECT_EQ(ROOT::GetROOT()->GetListOfFiles()->GetSize(), 0);
8484
}
8585

86-
TEST(RFile, CheckNoAutoRegistration)
86+
TEST(RFile, CheckNoAutoRegistrationWrite)
8787
{
88-
FileRaii fileGuard("test_rfile_noautoreg.root");
88+
FileRaii fileGuard("test_rfile_noautoreg_write.root");
8989

9090
auto file = RFile::Recreate(fileGuard.GetPath());
91+
EXPECT_EQ(gDirectory, gROOT);
9192
auto hist = std::make_unique<TH1D>("hist", "", 100, -10, 10);
9293
file->Put("hist", *hist);
93-
EXPECT_EQ(hist->GetDirectory(), nullptr);
94+
EXPECT_EQ(hist->GetDirectory(), gROOT);
9495
file->Close();
95-
EXPECT_EQ(hist->GetDirectory(), nullptr);
96+
EXPECT_EQ(hist->GetDirectory(), gROOT);
9697
hist.reset();
9798
// no double free should happen when ROOT exits
9899
}
99100

101+
TEST(RFile, CheckNoAutoRegistrationRead)
102+
{
103+
FileRaii fileGuard("test_rfile_noautoreg_read.root");
104+
105+
{
106+
auto file = RFile::Recreate(fileGuard.GetPath());
107+
auto hist = std::make_unique<TH1D>("hist", "", 100, -10, 10);
108+
hist->Fill(4);
109+
file->Put("hist", *hist);
110+
}
111+
112+
{
113+
auto file = RFile::Open(fileGuard.GetPath());
114+
EXPECT_EQ(gDirectory, gROOT);
115+
auto hist = file->Get<TH1D>("hist");
116+
EXPECT_EQ(hist->GetDirectory(), nullptr);
117+
ASSERT_NE(hist, nullptr);
118+
EXPECT_FLOAT_EQ(hist->GetEntries(), 1);
119+
}
120+
// no double free should happen when ROOT exits
121+
}
122+
123+
TEST(RFile, CheckNoAutoRegistrationUpdate)
124+
{
125+
FileRaii fileGuard("test_rfile_noautoreg_update.root");
126+
127+
{
128+
auto file = RFile::Recreate(fileGuard.GetPath());
129+
auto hist = std::make_unique<TH1D>("hist", "", 100, -10, 10);
130+
hist->Fill(4);
131+
file->Put("hist", *hist);
132+
}
133+
134+
{
135+
auto file = RFile::Update(fileGuard.GetPath());
136+
EXPECT_EQ(gDirectory, gROOT);
137+
auto hist = file->Get<TH1D>("hist");
138+
ASSERT_NE(hist, nullptr);
139+
EXPECT_EQ(hist->GetDirectory(), nullptr);
140+
EXPECT_FLOAT_EQ(hist->GetEntries(), 1);
141+
}
142+
// no double free should happen when ROOT exits
143+
}
144+
100145
TEST(RFile, WriteInvalidPaths)
101146
{
102147
FileRaii fileGuard("test_rfile_write_invalid.root");

0 commit comments

Comments
 (0)