16 #ifndef SURGSIM_FRAMEWORK_UNITTESTS_MOCKOBJECTS_H 17 #define SURGSIM_FRAMEWORK_UNITTESTS_MOCKOBJECTS_H 22 #include "SurgSim/Framework/BasicThread.h" 23 #include "SurgSim/Framework/Behavior.h" 24 #include "SurgSim/Framework/Component.h" 25 #include "SurgSim/Framework/ComponentManager.h" 26 #include "SurgSim/Framework/Representation.h" 27 #include "SurgSim/Framework/Runtime.h" 28 #include "SurgSim/Framework/SamplingMetricBase.h" 29 #include "SurgSim/Framework/Scene.h" 30 #include "SurgSim/Framework/SceneElement.h" 43 m_localRuntime = std::make_shared<SurgSim::Framework::Runtime>();
46 m_localScene = m_localRuntime->getScene();
50 virtual void update(
double dt)
54 virtual void lateUpdate(
double dt)
58 virtual void fixedRateUpdate(
double dt)
60 didFixedUpdate =
true;
74 std::shared_ptr<SurgSim::Framework::Runtime> m_localRuntime;
75 std::shared_ptr<SurgSim::Framework::Scene> m_localScene;
86 runIndefinetly(
false),
107 didInitialize =
true;
111 virtual bool doStartUp()
117 virtual bool doUpdate(
double dt)
125 virtual void doBeforeStop()
127 didBeforeStop =
true;
135 explicit MockComponent(
const std::string& name,
bool succeedInit =
true,
bool succeedWakeUp =
true);
142 bool doWakeUp()
override;
143 void doRetire()
override;
145 bool getSucceedWithInit()
const;
146 void setSucceedWithInit(
bool val);
148 bool getSucceedWithWakeUp()
const;
149 void setSucceedWithWakeUp(
bool val);
153 bool succeedWithInit;
154 bool succeedWithWakeUp;
164 explicit MockBehavior(
const std::string& name,
bool succeedInit =
true,
bool succeedWakeUp =
true) :
166 succeedWithInit(succeedInit),
167 succeedWithWakeUp(succeedWakeUp),
177 return succeedWithInit;
182 return succeedWithWakeUp;
190 bool succeedWithInit;
191 bool succeedWithWakeUp;
199 explicit MockManager(
bool succeedInit =
true,
bool succeedStartup =
true) :
200 succeedInit(succeedInit),
201 succeedStartup(succeedStartup),
202 didInitialize(
false),
204 didBeforeStop(
false),
215 return SurgSim::Framework::MANAGER_TYPE_NONE;
218 const std::vector<std::shared_ptr<MockComponent>>&
getComponents()
223 bool testTryAddComponent(
const std::shared_ptr<SurgSim::Framework::Component>& component)
225 return executeAdditions(component);
228 bool testTryRemoveComponent(
const std::shared_ptr<SurgSim::Framework::Component>& component)
230 return executeRemovals(component);
233 void testProcessComponents()
248 didInitialize =
true;
251 virtual bool doStartUp()
254 return succeedStartup;
256 virtual bool doUpdate(
double dt)
263 virtual void doBeforeStop()
265 didBeforeStop =
true;
266 retireComponents(m_components);
267 ComponentManager::doBeforeStop();
270 bool executeAdditions(
const std::shared_ptr<SurgSim::Framework::Component>& component)
override 272 return tryAddComponent(component, &m_components) !=
nullptr;
275 bool executeRemovals(
const std::shared_ptr<SurgSim::Framework::Component>& component)
override 277 return tryRemoveComponent(component, &m_components);
281 std::vector<std::shared_ptr<MockComponent>> m_components;
330 virtual bool doWakeUp()
344 bool ableToMeasure =
true,
345 double initialMeasurement = 0.0) :
346 SurgSim::Framework::SamplingMetricBase(name),
347 m_canMeasure(ableToMeasure),
348 m_measurement(initialMeasurement)
372 double m_measurement;
376 bool canMeasure(
double dt)
381 double performMeasurement(
double dt)
383 return ++m_measurement;
387 #endif // SURGSIM_FRAMEWORK_UNITTESTS_MOCKOBJECTS_H bool didWakeUp() const
Returns true if the representation has been woken up, otherwise false.
Definition: MockObjects.h:309
Class to catch the calls made to the scene element, does nothing.
Definition: MockObjects.h:33
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
SurgSim::Framework::SamplingMetricBase::MeasurementsType MeasurementsType
Type of the cumulative entries data structure.
Definition: MockObjects.h:365
Definition: MockObjects.h:132
Representation class for testing.
Definition: MockObjects.h:286
void setRuntime(std::weak_ptr< Runtime > runtime)
Sets the Runtime.
Definition: SceneElement.cpp:238
std::vector< std::shared_ptr< Component > > getComponents() const
Gets all the components of this SceneElement.
Definition: SceneElement.cpp:195
std::pair< double, double > MeasurementEntryType
Type of the individual entries in the measurement data structure.
Definition: SamplingMetricBase.h:55
SurgSim::Framework::SamplingMetricBase::MeasurementEntryType MeasurementEntryType
Type of the individual entries in the measurement data structure.
Definition: MockObjects.h:357
virtual bool doInitialize()
Interface to be implemented by derived classes.
Definition: MockObjects.h:175
Base Component Manager class.
Definition: ComponentManager.h:49
Datastructure to contain basic event data.
Definition: Messenger.h:45
Manager class for testing.
Definition: MockObjects.h:196
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:42
SamplingMetricBase provides a base class to support metric development.
Definition: SamplingMetricBase.h:45
Definition: MockObjects.h:338
virtual bool doInitialize()
Method to initialize this SceneElement.
Definition: MockObjects.h:63
virtual bool doWakeUp()
Interface to be implemented by derived classes.
Definition: MockObjects.h:180
The header that provides the assertion API.
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization...
Definition: BasicThread.h:48
Behaviors perform actions.
Definition: Behavior.h:40
std::deque< MeasurementEntryType > MeasurementsType
Type of the cumulative entries data structure.
Definition: SamplingMetricBase.h:63
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
Definition: MockObjects.h:79
bool didInit() const
Returns true if the representation has been initialized, otherwise false.
Definition: MockObjects.h:303
MockSamplingMetric(const std::string &name, bool ableToMeasure=true, double initialMeasurement=0.0)
Constructor.
Definition: MockObjects.h:343
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:51
int getType() const override
Returns the type of Manager.
Definition: MockObjects.h:213
Definition: MockObjects.h:161
MockRepresentation(const std::string &name)
Constructor.
Definition: MockObjects.h:294
virtual void update(double dt)
Update the behavior.
Definition: MockObjects.h:185
SceneElement(const std::string &name)
Constructor.
Definition: SceneElement.cpp:34
void setScene(std::weak_ptr< Scene > scene)
Sets the Scene.
Definition: SceneElement.cpp:224