ATLAS Offline Software
UnitTestService1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
16 #include <gtest/gtest.h>
17 #include <map>
18 
21 
22 //
23 // method implementations
24 //
25 
26 namespace asg
27 {
29  UnitTestService1 (const std::string& name, ISvcLocator* pSvcLocator)
30  : AsgService (name, pSvcLocator)
31  {
32  declareServiceInterface<IUnitTestService1>();
33 
34  declareProperty ("propertyInt", m_propertyInt, "the integer property");
35  declareProperty ("propertyString", m_propertyString, "the string property");
36  declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
37 
38  ++ instance_counts (name);
39 
40  ANA_MSG_DEBUG ("create UnitTestService1 " << this);
41  }
42 
43 
44 
47  {
48  ANA_MSG_DEBUG ("destroy UnitTestService1 " << this);
49 
50  -- instance_counts (name());
51  }
52 
53 
54 
56  initialize ()
57  {
58  ANA_MSG_INFO ("initialize UnitTestService1 " << this);
59  ANA_MSG_INFO (" propertyString: " << m_propertyString);
60  ANA_MSG_INFO (" propertyInt: " << m_propertyInt);
61 
62  if (m_initializeFail)
63  {
64  ATH_MSG_ERROR ("service configured to fail initialize");
65  return StatusCode::FAILURE;
66  }
67  if (m_isInitialized)
68  {
69  ATH_MSG_ERROR ("initialize called twice");
70  return StatusCode::FAILURE;
71  }
72  m_isInitialized = true;
73  return StatusCode::SUCCESS;
74  }
75 
76 
77 
78  std::string UnitTestService1 ::
79  getPropertyString () const
80  {
81  return m_propertyString;
82  }
83 
84 
85 
87  getPropertyInt () const
88  {
89  return m_propertyInt;
90  }
91 
92 
93 
95  setPropertyInt (int val_property)
96  {
97  m_propertyInt = val_property;
98  }
99 
100 
101 
103  isInitialized () const
104  {
105  return m_isInitialized;
106  }
107 
108 
109 
111  instance_counts (const std::string& name)
112  {
113  static std::map<std::string,int> counts;
114  auto iter = counts.find (name);
115  if (iter == counts.end())
116  iter = counts.insert (std::make_pair (name, 0)).first;
117  assert (iter != counts.end());
118  return iter->second;
119  }
120 }
asg::UnitTestService1::getPropertyString
virtual std::string getPropertyString() const override
get the integer property
Definition: UnitTestService1.cxx:79
asg
Definition: DataHandleTestTool.h:28
asg::UnitTestService1::getPropertyInt
virtual int getPropertyInt() const override
get the integer property
Definition: UnitTestService1.cxx:87
asg::UnitTestService1::UnitTestService1
UnitTestService1(const std::string &name, ISvcLocator *pSvcLocator)
standard constructor
Definition: UnitTestService1.cxx:29
asg::UnitTestService1::instance_counts
static int & instance_counts(const std::string &name)
the number of times the service of the given name has been instantiated
Definition: UnitTestService1.cxx:111
asg::UnitTestService1::m_initializeFail
bool m_initializeFail
whether initialize should fail
Definition: UnitTestService1.h:65
UnitTestService1.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AsgService
Base class for the dual-use service implementation classes.
Definition: AsgService.h:43
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
asg::UnitTestService1::~UnitTestService1
~UnitTestService1()
standard destructor
Definition: UnitTestService1.cxx:46
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
MessageCheck.h
macros for messaging and checking status codes
asg::UnitTestService1::m_isInitialized
bool m_isInitialized
whether initialize has been called
Definition: UnitTestService1.h:53
asg::UnitTestService1::m_propertyInt
int m_propertyInt
the integer property
Definition: UnitTestService1.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: UnitTestService1.cxx:20
asg::UnitTestService1::isInitialized
virtual bool isInitialized() const override
get whether we have been initialized
Definition: UnitTestService1.cxx:103
asg::UnitTestService1::m_propertyString
std::string m_propertyString
the string property
Definition: UnitTestService1.h:57
asg::UnitTestService1::initialize
StatusCode initialize() override
set up/tear down functions
Definition: UnitTestService1.cxx:56
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
asg::UnitTestService1::setPropertyInt
virtual void setPropertyInt(int val_property) override
get the integer property
Definition: UnitTestService1.cxx:95
checker_macros.h
Define macros for attributes used to control the static checker.
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288