ATLAS Offline Software
InitGaudiGoogleTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/Bootstrap.h"
8 #include "GaudiKernel/IAppMgrUI.h"
9 
10 #include <iostream>
11 #include <fstream>
12 
13 namespace Athena_test {
14 
16  // create a new ApplicationMgr w/o singleton behaviour
17  theApp( Gaudi::createApplicationMgrEx( "GaudiCoreSvc",
18  "ApplicationMgr" ) ),
19  propMgr( theApp ),
20  svcLoc( theApp ),
21  svcMgr( theApp ),
22  m_msgLevel( level ) {
23  EXPECT_TRUE( theApp != nullptr );
24  EXPECT_TRUE( propMgr.isValid() );
25  EXPECT_TRUE( svcLoc.isValid() );
26  EXPECT_TRUE( svcMgr.isValid() );
27  // set the new ApplicationMgr as instance in Gaudi
28  Gaudi::setInstance( theApp );
29  EXPECT_TRUE( propMgr->setProperty( "JobOptionsType", "NONE" ).isSuccess() );
30  EXPECT_TRUE( propMgr->setProperty( "OutputLevel",
31  std::to_string( m_msgLevel ) ).isSuccess() );
32  bool lconfig= false;
33  // Configure ApplicationMgr
34  if( m_msgLevel == MSG::ALWAYS ) {
35  // Redirect cout to /dev/null around configure() to get rid of Gaudi
36  // messages in unit tests
37  std::streambuf* coutbuf= std::cout.rdbuf(); // save std::cout buf
38  std::ofstream out( "/dev/null" );
39  std::cout.rdbuf( out.rdbuf() ); // redirect std::cout
40  lconfig= theApp->configure().isSuccess();
41  std::cout.rdbuf( coutbuf ); // restore std::cout
42  }
43  else {
44  // just configure()
45  lconfig= theApp->configure().isSuccess();
46  }
47  EXPECT_TRUE( lconfig ) << "InitGaudiGoogleTest: theApp->configure() failure";
48  EXPECT_TRUE( theApp->initialize().isSuccess() );
49  }
50 
51  // Finalize and terminate Gaudi, more to make sure that things
52  // went clean than anything else because we are throwing away the
53  // ApplicationMgr anyway
55  EXPECT_TRUE( theApp->finalize().isSuccess() );
56  EXPECT_TRUE( theApp->terminate().isSuccess() );
57  }
58 
59 }
60 
Athena_test::InitGaudiGoogleTest::~InitGaudiGoogleTest
virtual ~InitGaudiGoogleTest()
dtor
Definition: InitGaudiGoogleTest.cxx:54
Athena_test::InitGaudiGoogleTest::InitGaudiGoogleTest
InitGaudiGoogleTest(MSG::Level level=MSG::ALWAYS)
Ctor parameter:
Definition: InitGaudiGoogleTest.cxx:15
Athena_test::InitGaudiGoogleTest::theApp
IAppMgrUI * theApp
public members are visible in tests
Definition: InitGaudiGoogleTest.h:48
Athena_test::InitGaudiGoogleTest::m_msgLevel
MSG::Level m_msgLevel
Definition: InitGaudiGoogleTest.h:55
StdJOSetup.svcMgr
svcMgr
Definition: StdJOSetup.py:33
Athena_test::InitGaudiGoogleTest::svcMgr
SmartIF< ISvcManager > svcMgr
Definition: InitGaudiGoogleTest.h:51
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
Athena_test::InitGaudiGoogleTest::propMgr
SmartIF< IProperty > propMgr
Definition: InitGaudiGoogleTest.h:49
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
TrigConf::MSGTC::ALWAYS
@ ALWAYS
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:29
Athena_test
functions & macros to test the difference between floats
Definition: InitGaudiGoogleTest.h:30
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InitGaudiGoogleTest.h
Gaudi initialisation fixture base class for googletest based unit tests. Test fixture classes for tes...
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
python.AppMgr.theApp
theApp
Definition: AppMgr.py:764
Athena_test::InitGaudiGoogleTest::svcLoc
SmartIF< ISvcLocator > svcLoc
Definition: InitGaudiGoogleTest.h:50