#include "CbmTrdGeoHandler.h" #include "TFile.h" #include "TGeoManager.h" #include "TString.h" #include "TSystem.h" #include "TList.h" #include "TKey.h" #include "gtest/gtest.h" #include "gtest/gtest-spi.h" #include #include #include #include #include //#include using std::cout; using std::endl; // Structure to pass filenames together with expected response into the // parametrized test struct InOutStructure { TString name; int result; } ; // Base class to use the same basic setup for parameterized and // non-parameterized tests // Here one defines everything which is common for all the different // test cases template class _TestTrdGeoHandlerBase : public T { protected: TFile* fInputFile; TString geomToTest; TString fFileName; CbmTrdGeoHandler* fGeoHandler; int result; virtual void SetUp() { geomToTest="squared_segmented"; CreateFileName(geomToTest); fInputFile = new TFile(fFileName,"READ"); GetGeoManager(); fGeoHandler = new CbmTrdGeoHandler(); } virtual void TearDown() { gGeoManager=NULL; delete fGeoHandler; fInputFile->Close(); delete fInputFile; } virtual void CreateFileName(TString name) { fFileName = gSystem->Getenv("VMCWORKDIR"); fFileName = fFileName + "/input/qa/trd_" + name + "_geometry.root"; } virtual void GetGeoManager() { TList* l= fInputFile->GetListOfKeys(); TKey* key; TIter next( l); while ((key = (TKey*)next())) { /**loop inside the delivered root file and try to fine a TGeoManager object * the first TGeoManager found will be read */ if (strcmp(key->GetClassName(),"TGeoManager") != 0) { continue; } gGeoManager = (TGeoManager*)key->ReadObj(); } } }; // This is the derived class for the non-parameterized test cases. class TrdGeoHandlerTest : public _TestTrdGeoHandlerBase {}; // This is the derived class for the parameterized test cases. class TrdGeoHandlerParamTest : public _TestTrdGeoHandlerBase< testing::TestWithParam > { protected: virtual void SetUp() { InOutStructure const& p = GetParam(); geomToTest = p.name; result = p.result; CreateFileName(geomToTest); fInputFile = new TFile(fFileName,"READ"); GetGeoManager(); fGeoHandler = new CbmTrdGeoHandler(); } }; TEST_F(TrdGeoHandlerTest, CheckDefaultSettings) { cout << "Filename: " << fFileName << endl; fInputFile->Print(); Int_t retVal = fGeoHandler->CheckGeometryVersion(); cout << "Geo Version: " << retVal <Print(); cout<< "Expected result: "<< result << endl; Int_t retVal = fGeoHandler->CheckGeometryVersion(); cout << "Geo Version: " << retVal <