ATLAS Offline Software
UnitTestTool1.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 
15 #include <gtest/gtest.h>
16 #include <map>
17 
20 
21 //
22 // method implementations
23 //
24 
25 namespace asg
26 {
28  UnitTestTool1 (const std::string& val_name)
29  : AsgTool (val_name)
30  {
31  declareProperty ("propertyInt", m_propertyInt, "the integer property");
32  declareProperty ("propertyString", m_propertyString, "the string property");
33  declareProperty ("initializeFail", m_initializeFail, "whether initialize should fail");
34 
35  ++ instance_counts (name());
36 
37  ANA_MSG_DEBUG ("create UnitTestTool1 " << this);
38  }
39 
40 
41 
44  {
45  ANA_MSG_DEBUG ("destroy UnitTestTool1 " << this);
46 
47  -- instance_counts (name());
48  }
49 
50 
51 
53  initialize ()
54  {
55  ANA_MSG_INFO ("initialize UnitTestTool1 " << this);
56  ANA_MSG_INFO (" propertyString: " << m_propertyString);
57  ANA_MSG_INFO (" propertyInt: " << m_propertyInt);
58 
59  if (m_initializeFail)
60  {
61  ATH_MSG_ERROR ("tool configured to fail initialize");
62  return StatusCode::FAILURE;
63  }
64  if (m_isInitialized)
65  {
66  ATH_MSG_ERROR ("initialize called twice");
67  return StatusCode::FAILURE;
68  }
69  m_isInitialized = true;
70  return StatusCode::SUCCESS;
71  }
72 
73 
74 
75  std::string UnitTestTool1 ::
76  getPropertyString () const
77  {
78  return m_propertyString;
79  }
80 
81 
82 
84  getPropertyInt () const
85  {
86  return m_propertyInt;
87  }
88 
89 
90 
92  setPropertyInt (int val_property)
93  {
94  m_propertyInt = val_property;
95  }
96 
97 
98 
100  isInitialized () const
101  {
102  return m_isInitialized;
103  }
104 
105 
106 
108  instance_counts (const std::string& name)
109  {
110  static std::map<std::string,int> counts;
111  auto iter = counts.find (name);
112  if (iter == counts.end())
113  iter = counts.insert (std::make_pair (name, 0)).first;
114  assert (iter != counts.end());
115  return iter->second;
116  }
117 }
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
asg::UnitTestTool1::UnitTestTool1
UnitTestTool1(const std::string &val_name)
standard constructor
Definition: UnitTestTool1.cxx:28
asg::UnitTestTool1::getPropertyString
virtual std::string getPropertyString() const override
get the integer property
Definition: UnitTestTool1.cxx:76
asg::UnitTestTool1::m_propertyString
std::string m_propertyString
the string property
Definition: UnitTestTool1.h:59
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg
Definition: DataHandleTestTool.h:28
asg::UnitTestTool1::isInitialized
virtual bool isInitialized() const override
get whether we have been initialized
Definition: UnitTestTool1.cxx:100
asg::UnitTestTool1::setPropertyInt
virtual void setPropertyInt(int val_property) override
get the integer property
Definition: UnitTestTool1.cxx:92
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
UnitTestTool1.h
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: UnitTestTool1.cxx:19
asg::UnitTestTool1::m_isInitialized
bool m_isInitialized
whether initialize has been called
Definition: UnitTestTool1.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
asg::UnitTestTool1::initialize
StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: UnitTestTool1.cxx:53
asg::UnitTestTool1::m_initializeFail
bool m_initializeFail
whether initialize should fail
Definition: UnitTestTool1.h:67
asg::UnitTestTool1::instance_counts
static int & instance_counts(const std::string &name)
the number of times the tool of the given name has been instantiated
Definition: UnitTestTool1.cxx:108
asg::UnitTestTool1::m_propertyInt
int m_propertyInt
the integer property
Definition: UnitTestTool1.h:63
asg::UnitTestTool1::getPropertyInt
virtual int getPropertyInt() const override
get the integer property
Definition: UnitTestTool1.cxx:84
asg::UnitTestTool1::~UnitTestTool1
~UnitTestTool1()
standard destructor
Definition: UnitTestTool1.cxx:43
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