Skip to content
Snippets Groups Projects
Commit 23e0948e authored by Walter Lampl's avatar Walter Lampl
Browse files

Merge branch 'fwinkl_20250108T182828' into 'main'

TestTools: add generic Gaudi test fixture

See merge request atlas/athena!77038
parents b2e9fcb0 746dd317
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TEST_INITGAUDI_H
......@@ -11,6 +11,7 @@
**/
#include <string>
#include "GaudiKernel/SmartIF.h"
#undef NDEBUG
......@@ -34,5 +35,38 @@ namespace Athena_test {
* @return true on success, false on failure
*/
bool initGaudi(const std::string& jobOptsFile, ISvcLocator*& pSvcLoc);
/**
* Generic test fixture to setup Gaudi.
*
* Example usage with boost test:
*
* @code
* BOOST_FIXTURE_TEST_SUITE( MyTestSuite,
* * boost::unit_test::fixture<Athena_test::InitGaudi>(std::string("jo.txt")) )
* @endcode
*/
class InitGaudi {
public:
/**
* @brief Create Gaudi test fixture.
* @param jobOptsPath Path to job options
*/
InitGaudi(const std::string& jobOptsFile);
/**
* @brief Create Gaudi test fixture without job options.
*/
InitGaudi() : InitGaudi("") {}
/**
* @brief Finalize Gaudi.
*/
~InitGaudi();
SmartIF<ISvcLocator> svcLoc;
};
}
#endif // TEST_INITGAUDI_H
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
......@@ -95,6 +95,20 @@ namespace Athena_test {
{
ModuleLoadedIncident inc2 ("", "");
}
}
InitGaudi::InitGaudi(const std::string& jobOptsFile) {
ISvcLocator* pSvcLoc{};
if (!Athena_test::initGaudi(jobOptsFile, pSvcLoc)) {
throw std::runtime_error("Cannot initialize Gaudi");
}
svcLoc = pSvcLoc;
}
InitGaudi::~InitGaudi() {
auto appMgr = svcLoc.as<IAppMgrUI>();
appMgr->finalize().ignore();
appMgr->terminate().ignore();
}
}
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