ATLAS Offline Software
Functions
CppUnit_SGtestdriver.cxx File Reference
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TextTestRunner.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/TextOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <iostream>
#include <cassert>
#include <stdexcept>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <list>
#include "TestTools/initGaudi.h"
#include "StoreGate/StoreGateSvc.h"
#include "GaudiKernel/ISvcLocator.h"

Go to the source code of this file.

Functions

bool setupStoreGate ()
 Simple function to instantiate and initialize the StoreGateSvc. More...
 
int main (int, char **)
 Main class for all the CppUnit test classes
More...
 

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Main class for all the CppUnit test classes

Load the StoreGateSvc

Get the top level suite from the registry

Adds the test to the list of test to run

Run the tests.

Definition at line 141 of file CppUnit_SGtestdriver.cxx.

142  {
144  if ( false == setupStoreGate() ) {
145  std::string error = "Could not setup StoreGateSvc !!";
146  throw std::runtime_error(error);
147  }
148 
150  CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
151 
153  CppUnit::TextTestRunner runner;
154  runner.addTest( suite );
155 
156  // Change the default outputter to a compiler error format outputter
157  // uncomment the following line if you need a compiler outputter.
158  //runner.setOutputter(new CppUnit::CompilerOutputter( &runner.result(),
159  // std::cerr ) );
160 
161  // Change the default outputter to a xml error format outputter
162  // uncomment the following line if you need a xml outputter.
163  //runner.setOutputter( new CppUnit::XmlOutputter( &runner.result(),
164  // std::cerr ) );
165 
167  // bool wasSuccessful = runner.run_spi();
168  // If you want to avoid the CppUnit typical output change the line above
169  // by the following one:
170  bool wasSuccessful = runner.run("",false,true,false);
171 
172  // Return error code 1 if the one of test failed.
173  if (!wasSuccessful) return 1;
174 
175  // Uncomment the next line if you want to integrate CppUnit with Oval
176  // std::cout <<"[OVAL] Cppunit-result ="<<!wasSuccessful<<"\n" ;
177 
178  return 0;
179  }

◆ setupStoreGate()

bool setupStoreGate ( )

Simple function to instantiate and initialize the StoreGateSvc.

Get StoreGateSvc

Definition at line 41 of file CppUnit_SGtestdriver.cxx.

42 {
43  ISvcLocator * m_svcLoc;
44  StoreGateSvc * m_storeGate;
45 
46  /* Search for file jobOptions.txt in ../share ../test/ ../cmt */
47  const int SZ = 3;
48  std::string FileName="";
49  std::string fn;
50  std::string filename_in[SZ] = {"../cmt/CppUnit_jobOptions.txt", "../test/CppUnit_jobOptions.txt", "../share/CppUnit_jobOptions.txt"};
51  std::ifstream inFile[SZ];
52 
53  for (int i=0; i<SZ; i++)
54  {
55  fn = filename_in[i];
56  try
57  {
58  inFile[i].open(fn.c_str());
59  if (!inFile[i])
60  throw(fn);
61  FileName=fn;
62  }
63  catch(std::string fn)
64  {
65  // std::cout << "File " << filename_in[i] << "not found" << " FileName " << std::endl;
66  }
67 
68  inFile[i].close();
69 
70  } // for (int i<0
71 
72  // std::cout << "FileFFFF " <<FileName<< std::endl;
73 
74  // Build job options file if CppUnit_jobOptions.txt is unavailable
75 
76  if ( FileName == "" )
77  {
78  FileName = "../run/CppUnit_jobOptions_generated.txt";
79  std::system("touch ../run/CppUnit_jobOptions_generated.txt; rm ../run/CppUnit_jobOptions_generated.txt");
80  std::ofstream jobopt("../run/CppUnit_jobOptions_generated.txt");
81 
82  { // Build a default list of options.
83  std::list<std::string> opts;
84  opts.push_back("#pragma print off");
85  opts.push_back("ApplicationMgr.Dlls += { \"StoreGate\" };");
86  //opts.push_back("ApplicationMgr.Dlls += { \"CLIDSvc\" };");
87  opts.push_back("ApplicationMgr.ExtSvc += { \"ClassIDSvc\" };");
88  opts.push_back("ApplicationMgr.ExtSvc += { \"StoreGateSvc\", \"StoreGateSvc/DetectorStore\", \"StoreGateSvc/HistoryStore\" };");
89  opts.push_back("ApplicationMgr.ExtSvc += { \"ActiveStoreSvc\" };");
90  opts.push_back("AuditorSvc.Auditors += { \"AlgContextAuditor\"};");
91  opts.push_back("StoreGateSvc.OutputLevel = 2;");
92  opts.push_back("StoreGateSvc.ActivateHistory = false;");
93  //opts.push_back("CLIDSvc.OutputLevel = 2;");
94  opts.push_back("MessageSvc.useColors = false;");
95  opts.push_back("MessageSvc.OutputLevel = 3;");
96  // Build job options file from list.
97  for ( std::list<std::string>::const_iterator iopt=opts.begin();
98  iopt!=opts.end(); ++iopt )
99  {
100  jobopt << *iopt << std::endl;
101  }
102  }
103  jobopt.close();
104  } //if ( FileName == "" )
105  try {
106  std::string fileName=FileName;
107 
109  m_svcLoc = 0;
110  if (!Athena_test::initGaudi(fileName, m_svcLoc)) {
111  std::cerr << "This test can not be run" << std::endl;
112  return false;
113  }
114  CPPUNIT_ASSERT( 0 != m_svcLoc);
115 
116  m_storeGate = 0;
117  static const bool CREATE(true);
118  bool sc = ( m_svcLoc->service( "StoreGateSvc",
119  m_storeGate, CREATE) ).isSuccess();
120  CPPUNIT_ASSERT( sc );
121  CPPUNIT_ASSERT( 0 != m_storeGate );
122 
123  if ( false == sc || 0 == m_storeGate ) {
124  std::string error = "No valid pointer to StoreGateSvc !!";
125  std::cerr << error << std::endl;
126  //throw std::runtime_error(error);
127  return false;
128  } else {
129  return true;
130  }
131  } catch ( std::exception& e ) {
132  std::cerr << "Catched : " << e.what() << std::endl;
133  return false;
134  }
135 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
setupStoreGate
bool setupStoreGate()
Simple function to instantiate and initialize the StoreGateSvc.
Definition: CppUnit_SGtestdriver.cxx:41
makeTOC.inFile
string inFile
Definition: makeTOC.py:5
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
lumiFormat.i
int i
Definition: lumiFormat.py:85
RunTileCalibRec.FileName
FileName
Definition: RunTileCalibRec.py:456
calibdata.exception
exception
Definition: calibdata.py:496
Athena_test::initGaudi
bool initGaudi(ISvcLocator *&pSvcLoc)
Minimal Gaudi initialization for unit testing without job options.
Definition: initGaudi.cxx:28
beamspotman.runner
runner
Definition: beamspotman.py:1192
python.TestCases.suite
def suite()
Definition: DataQualityConfigurations/python/TestCases.py:73
athena.opts
opts
Definition: athena.py:88
CREATE
#define CREATE(__TYPE)
error
Definition: IImpactPoint3dEstimator.h:70