@@ -83,20 +83,65 @@ TEST(RFile, OpenForWriting)
83
83
EXPECT_EQ (ROOT::GetROOT ()->GetListOfFiles ()->GetSize (), 0 );
84
84
}
85
85
86
- TEST (RFile, CheckNoAutoRegistration )
86
+ TEST (RFile, CheckNoAutoRegistrationWrite )
87
87
{
88
- FileRaii fileGuard (" test_rfile_noautoreg .root" );
88
+ FileRaii fileGuard (" test_rfile_noautoreg_write .root" );
89
89
90
90
auto file = RFile::Recreate (fileGuard.GetPath ());
91
+ EXPECT_EQ (gDirectory , gROOT );
91
92
auto hist = std::make_unique<TH1D>(" hist" , " " , 100 , -10 , 10 );
92
93
file->Put (" hist" , *hist);
93
- EXPECT_EQ (hist->GetDirectory (), nullptr );
94
+ EXPECT_EQ (hist->GetDirectory (), gROOT );
94
95
file->Close ();
95
- EXPECT_EQ (hist->GetDirectory (), nullptr );
96
+ EXPECT_EQ (hist->GetDirectory (), gROOT );
96
97
hist.reset ();
97
98
// no double free should happen when ROOT exits
98
99
}
99
100
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
+
100
145
TEST (RFile, WriteInvalidPaths)
101
146
{
102
147
FileRaii fileGuard (" test_rfile_write_invalid.root" );
0 commit comments