diff --git a/tree/treeplayer/test/data.h b/tree/treeplayer/test/data.h index f6dafdd8a3f97..ec2d8947b14d5 100644 --- a/tree/treeplayer/test/data.h +++ b/tree/treeplayer/test/data.h @@ -2,14 +2,39 @@ #define TTREEREADER_LEAF_TEST_DATA #include -struct Data { - unsigned int fUSize; - int fSize; - double* fArray; //[fSize] - float* fUArray; //[fUSize] - std::vector fVec; - Double32_t fDouble32; - Float16_t fFloat16; +class Data { + unsigned int fUSize{}; + int fSize{}; + double *fArray{nullptr}; //[fSize] + float *fUArray{nullptr}; //[fUSize] + std::vector fVec{}; + Double32_t fDouble32{}; + Float16_t fFloat16{}; + +public: + Data() = default; + Data(const Data &) = delete; + Data &operator=(const Data &) = delete; + Data(Data &&) = delete; + Data &operator=(Data &&) = delete; + ~Data() + { + delete[] fArray; + fArray = nullptr; + delete[] fUArray; + fUArray = nullptr; + } + void Init() + { + fUSize = 2; + fSize = 4; + fArray = new double[4]{12., 13., 14., 15.}; + fUArray = new float[2]{42., 43.}; + fVec = {17., 18., 19., 20., 21., 22.}; + fDouble32 = 17.; + fFloat16 = 44.; + } + std::vector &GetVecMember() { return fVec; } }; struct V { diff --git a/tree/treeplayer/test/leafs.cxx b/tree/treeplayer/test/leafs.cxx index 69ed3fc3d4447..a219b13999524 100644 --- a/tree/treeplayer/test/leafs.cxx +++ b/tree/treeplayer/test/leafs.cxx @@ -84,32 +84,26 @@ TEST(TTreeReaderLeafs, LeafListCaseA) { EXPECT_EQ(Bool, *trBool); } - - -std::unique_ptr CreateTree() { +std::unique_ptr CreateTree() +{ TInterpreter::EErrorCode error = TInterpreter::kNoError; gInterpreter->ProcessLine("#include \"data.h\"", &error); if (error != TInterpreter::kNoError) return {}; Data data; + data.Init(); + auto &vecDataMember = data.GetVecMember(); auto tree = std::make_unique("T", "test tree"); tree->Branch("Data", &data); - data.fArray = new double[4]{12., 13., 14., 15.}; - data.fSize = 4; - data.fUArray = new float[2]{42., 43.}; - data.fUSize = 2; - data.fVec = { 17., 18., 19., 20., 21., 22.}; - data.fDouble32 = 17.; - data.fFloat16 = 44.; tree->Fill(); - data.fVec.clear(); - data.fVec.resize(3210, 1001.f); // ROOT-8747 + vecDataMember.clear(); + vecDataMember.resize(3210, 1001.f); // ROOT-8747 tree->Fill(); - data.fVec.clear(); - data.fVec.resize(2, 42.f); // ROOT-8747 + vecDataMember.clear(); + vecDataMember.resize(2, 42.f); // ROOT-8747 tree->Fill(); tree->ResetBranchAddresses();