stmm-games-doc  0.32.0
Public Member Functions | Protected Member Functions | List of all members
stmi::testing::FakeDeviceManager Class Reference

Class for testing code that interacts with device managers. More...

Inheritance diagram for stmi::testing::FakeDeviceManager:
Inheritance graph
[legend]

Public Member Functions

 FakeDeviceManager (bool bEnableEventClasses, const std::vector< Event::Class > &aEnDisableEventClasses) noexcept
 Constructor. More...
 
 FakeDeviceManager () noexcept
 Default constructor. More...
 
bool simulateRemoveDevice (int32_t nDeviceId) noexcept
 Removes a device. More...
 
bool simulateChangedDevice (int32_t nDeviceId) noexcept
 Sends a changed event to the listeners. More...
 
template<class DEV >
int32_t simulateNewDevice () noexcept
 Adds a device with single capability class. More...
 
int32_t simulateEvent (const shared_ptr< Event > &refEvent) noexcept
 Sends an event to the listeners. More...
 
int32_t simulateKeyEvent (int32_t nDeviceId, KeyEvent::KEY_INPUT_TYPE eType, HARDWARE_KEY eKey) noexcept
 Generates a key event and sends it to listeners. More...
 
int32_t simulatePointerEvent (int32_t nDeviceId, double fX, double fY, PointerEvent::POINTER_INPUT_TYPE eType, int32_t nButton, bool bAnyButtonPressed, bool bWasAnyButtonPressed) noexcept
 Generates a pointer event and sends it to listeners. More...
 
int32_t simulatePointerScrollEvent (int32_t nDeviceId, PointerScrollEvent::POINTER_SCROLL_DIR eScrollDir, double fX, double fY, bool bAnyButtonPressed) noexcept
 Generates a pointer scroll event and sends it to listeners. More...
 
int32_t simulateTouchEvent (int32_t nDeviceId, TouchEvent::TOUCH_INPUT_TYPE eType, double fX, double fY, int64_t nFingerId) noexcept
 Generates a touch event and sends it to listeners. More...
 
int32_t simulateJoystickButtonEvent (int32_t nDeviceId, JoystickButtonEvent::BUTTON_INPUT_TYPE eType, JoystickCapability::BUTTON eButton) noexcept
 Generates a joystick button event and sends it to listeners. More...
 
int32_t simulateJoystickHatEvent (int32_t nDeviceId, int32_t nHat, JoystickCapability::HAT_VALUE eValue, JoystickCapability::HAT_VALUE ePreviousValue) noexcept
 Generates a joystick hat event and sends it to listeners. More...
 
int32_t simulateJoystickAxisEvent (int32_t nDeviceId, JoystickCapability::AXIS eAxis, int32_t nValue) noexcept
 Generates a joystick axis event with key simulation and sends it to listeners. More...
 
- Public Member Functions inherited from stmi::StdDeviceManager
std::vector< Capability::ClassgetCapabilityClasses () const noexcept override
 The registered capability classes of the device manager. More...
 
shared_ptr< CapabilitygetCapability (const Capability::Class &oClass) const noexcept override
 Requests the instance of a capability class. More...
 
shared_ptr< CapabilitygetCapability (int32_t nCapabilityId) const noexcept override
 Returns the device manager's capability with the given id, or null if not found. More...
 
- Public Member Functions inherited from stmi::BasicDeviceManager
shared_ptr< DevicegetDevice (int32_t nDeviceId) const noexcept override
 Returns the device with the given id, or null if not found. More...
 
std::vector< int32_t > getDevicesWithCapabilityClass (const Capability::Class &oCapabilityClass) const noexcept override
 Returns the ids of the devices that have the given capability class. More...
 
std::vector< int32_t > getDevices () const noexcept override
 Returns the ids of all the device manager's devices. More...
 
std::vector< Capability::ClassgetCapabilityClasses () const noexcept override
 The registered capability classes of the device manager. More...
 
std::vector< Capability::ClassgetDeviceCapabilityClasses () const noexcept override
 The registered capability classes of the device manager's devices. More...
 
std::vector< Event::ClassgetEventClasses () const noexcept override
 The registered event classes the device manager and all its devices can send. More...
 
bool isEventClassEnabled (const Event::Class &oEventClass) const noexcept override
 Tells whether an event class is enabled. More...
 
void enableEventClass (const Event::Class &oEventClass) noexcept override
 Enables an event class. More...
 
bool addAccessor (const shared_ptr< Accessor > &) noexcept override
 Default empty implementation. More...
 
bool removeAccessor (const shared_ptr< Accessor > &) noexcept override
 Default empty implementation. More...
 
bool hasAccessor (const shared_ptr< Accessor > &) noexcept override
 Default empty implementation. More...
 
bool addEventListener (const shared_ptr< EventListener > &refEventListener, const shared_ptr< CallIf > &refCallIf) noexcept override
 Adds an event listener with its callif condition to the device manager. More...
 
bool addEventListener (const shared_ptr< EventListener > &refEventListener) noexcept override
 Adds an event listener to the device manager. More...
 
bool removeEventListener (const shared_ptr< EventListener > &refEventListener, bool bFinalize) noexcept override
 Removes an event listener from the device manager. More...
 
bool removeEventListener (const shared_ptr< EventListener > &refEventListener) noexcept override
 Removes an event listener from the device manager. More...
 
- Public Member Functions inherited from stmi::ChildDeviceManager
shared_ptr< ParentDeviceManagergetParent () const noexcept
 Gets the parent of this child device manager. More...
 
shared_ptr< ParentDeviceManagergetParent () noexcept
 Gets the parent of this child device manager. More...
 
shared_ptr< ParentDeviceManagergetRoot () const noexcept
 Returns the root device manager. More...
 
shared_ptr< ParentDeviceManagergetRoot () noexcept
 Returns the root device manager. More...
 
bool isParent () const noexcept
 Tells whether this instance is also a ParentDeviceManager. More...
 
shared_ptr< ParentDeviceManagergetAsParent () const noexcept
 If a parent returns this object as a parent. More...
 
shared_ptr< ParentDeviceManagergetAsParent () noexcept
 If a parent returns this object as a parent. More...
 
- Public Member Functions inherited from stmi::DeviceManager
virtual ~DeviceManager () noexcept=default
 
template<typename TCapa >
bool getCapability (shared_ptr< TCapa > &refCapa) const noexcept
 Request a registered device manager capability. More...
 

Protected Member Functions

void finalizeListener (ListenerData &oListenerData) noexcept override
 Does nothing. More...
 
- Protected Member Functions inherited from stmi::StdDeviceManager
 StdDeviceManager (const std::vector< Capability::Class > &aDeviceCapabitityClasses, const std::vector< Event::Class > &aEventClasses, bool bEnableEventClasses, const std::vector< Event::Class > &aEnDisableEventClasses) noexcept
 Constructor. More...
 
void sendDeviceMgmtToListeners (const DeviceMgmtEvent::DEVICE_MGMT_TYPE &eMgmtType, const shared_ptr< Device > &refDevice) noexcept
 Sends a device mgmt event to the listeners. More...
 
void checkWeakPtr () const noexcept
 
shared_ptr< DeviceMgmtCapabilitygetDeviceMgmtCapability () noexcept
 
- Protected Member Functions inherited from stmi::BasicDeviceManager
 BasicDeviceManager (const std::vector< Capability::Class > &aCapabitityClasses, const std::vector< Capability::Class > &aDeviceCapabitityClasses, const std::vector< Event::Class > &aEventClasses, bool bEnableEventClasses, const std::vector< Event::Class > &aEnDisableEventClasses) noexcept
 Constructor. More...
 
bool addDevice (const shared_ptr< Device > &refDevice) noexcept
 Adding a device. More...
 
bool removeDevice (const shared_ptr< Device > &refDevice) noexcept
 Removing a device. More...
 
bool isWithinAListenerCallback () const noexcept
 Tells whether the caller is within a listener callback. More...
 
shared_ptr< const std::list< ListenerData *> > getListeners () noexcept
 Returns the listeners data pointers. More...
 
int32_t getEventClassIndex (const Event::Class &oEventClass) const noexcept
 Returns the index of the event class in the array passed to the constructor. More...
 
void resetExtraDataOfAllListeners () noexcept
 Calls overloaded ListenerExtraData::reset() for each listener. More...
 
- Protected Member Functions inherited from stmi::ChildDeviceManager
 ChildDeviceManager () noexcept
 Constructor. More...
 
- Protected Member Functions inherited from stmi::DeviceManager
 DeviceManager () noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from stmi::DeviceManager
static int64_t getNowTimeMicroseconds () noexcept
 Current time from epoch in microseconds. More...
 
- Static Protected Member Functions inherited from stmi::BasicDeviceManager
static uint64_t getUniqueTimeStamp () noexcept
 Returns a unique time stamp. More...
 

Detailed Description

Class for testing code that interacts with device managers.

It allows to add and remove listeners, create and remove devices (which trigger a DeviceMgmtEvent to be sent to listeners), send events to the listeners but without providing a consistent state of the fake devices. This means that when a device or a listener is removed pressed keys aren't canceled and that the user has to make sure for example that the press of a key isn't followed by another press of the same key but rather by a release or a cancel. This also means that the JoystickCapability's methods shouldn't be called by the to be tested code because they return bogus values.

This class is supposed to be instantiated with std::make_shared().

Constructor & Destructor Documentation

◆ FakeDeviceManager() [1/2]

stmi::testing::FakeDeviceManager::FakeDeviceManager ( bool  bEnableEventClasses,
const std::vector< Event::Class > &  aEnDisableEventClasses 
)
noexcept

Constructor.

Only the given event classes are enabled.

Parameters
bEnableEventClassesWhether to enable or disable all but aEnDisableEventClasses.
aEnDisableEventClassesThe event classes to be enabled or disabled according to bEnableEventClasses.

◆ FakeDeviceManager() [2/2]

stmi::testing::FakeDeviceManager::FakeDeviceManager ( )
noexcept

Default constructor.

All event classes are enabled.

Member Function Documentation

◆ finalizeListener()

void stmi::testing::FakeDeviceManager::finalizeListener ( ListenerData oListenerData)
overrideprotectedvirtualnoexcept

Does nothing.

Implements stmi::BasicDeviceManager.

◆ simulateChangedDevice()

bool stmi::testing::FakeDeviceManager::simulateChangedDevice ( int32_t  nDeviceId)
noexcept

Sends a changed event to the listeners.

Returns
Whether could send the event.

◆ simulateEvent()

int32_t stmi::testing::FakeDeviceManager::simulateEvent ( const shared_ptr< Event > &  refEvent)
noexcept

Sends an event to the listeners.

Parameters
refEventThe event. Cannot be null.
Returns
The number of listeners to which the event was actually sent or -1 if not enabled.

◆ simulateJoystickAxisEvent()

int32_t stmi::testing::FakeDeviceManager::simulateJoystickAxisEvent ( int32_t  nDeviceId,
JoystickCapability::AXIS  eAxis,
int32_t  nValue 
)
noexcept

Generates a joystick axis event with key simulation and sends it to listeners.

Parameters
nDeviceIdThe id of the device with the joystick capability.
eAxisThe axis.
nValueValue normalized to [-32767, 32767].
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulateJoystickButtonEvent()

int32_t stmi::testing::FakeDeviceManager::simulateJoystickButtonEvent ( int32_t  nDeviceId,
JoystickButtonEvent::BUTTON_INPUT_TYPE  eType,
JoystickCapability::BUTTON  eButton 
)
noexcept

Generates a joystick button event and sends it to listeners.

Parameters
nDeviceIdThe id of the device with the joystick capability.
eTypeWhat happened to the button.
eButtonThe button.
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulateJoystickHatEvent()

int32_t stmi::testing::FakeDeviceManager::simulateJoystickHatEvent ( int32_t  nDeviceId,
int32_t  nHat,
JoystickCapability::HAT_VALUE  eValue,
JoystickCapability::HAT_VALUE  ePreviousValue 
)
noexcept

Generates a joystick hat event and sends it to listeners.

Note: the caller has to set the consistent value for the ePreviousValue parameter to reflect the current state of the hat. If ePreviousValue is set to JoystickCapability::HAT_VALUE_NOT_SET key simulation is disabled (Event::getAsKey() returns false).

Parameters
nDeviceIdThe id of the device with the joystick capability.
nHatThe hat that changed its state. Must be >= 0.
eValueThe new value for the hat. Can't be JoystickCapability::HAT_VALUE_NOT_SET.
ePreviousValueThe previous value for the hat. Can be JoystickCapability::HAT_VALUE_NOT_SET. Can't be HAT_CENTER_CANCEL.
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulateKeyEvent()

int32_t stmi::testing::FakeDeviceManager::simulateKeyEvent ( int32_t  nDeviceId,
KeyEvent::KEY_INPUT_TYPE  eType,
HARDWARE_KEY  eKey 
)
noexcept

Generates a key event and sends it to listeners.

If the device doesn't exists or it has not a key capability -1 is returned.

Parameters
nDeviceIdThe id of the device with the key capability.
eTypeThe key input type.
eKeyThe key.
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulateNewDevice()

template<class DEV >
int32_t stmi::testing::FakeDeviceManager::simulateNewDevice ( )
inlinenoexcept

Adds a device with single capability class.

Example: const int32_t nKeyDevId = refFakeDM->simulateNewDevice<FakeKeyDevice>();

Returns
The id of the added device.

◆ simulatePointerEvent()

int32_t stmi::testing::FakeDeviceManager::simulatePointerEvent ( int32_t  nDeviceId,
double  fX,
double  fY,
PointerEvent::POINTER_INPUT_TYPE  eType,
int32_t  nButton,
bool  bAnyButtonPressed,
bool  bWasAnyButtonPressed 
)
noexcept

Generates a pointer event and sends it to listeners.

If the device doesn't exists or it has not a pointer capability -1 is returned. Note: the caller has to set the consistent values for the bAnyButtonPressed and bWasAnyButtonPressed parameters to reflect the current (and preceding) state of the pointer buttons.

Parameters
nDeviceIdThe id of the device with the pointer capability.
fXThe X position of the pointer.
fYThe Y position of the pointer.
eTypeThe key input type.
nButtonThe button involved or -1 if hover.
bAnyButtonPressedWhether any button is pressed (after this event).
bWasAnyButtonPressedWhether any button was pressed before this event.
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulatePointerScrollEvent()

int32_t stmi::testing::FakeDeviceManager::simulatePointerScrollEvent ( int32_t  nDeviceId,
PointerScrollEvent::POINTER_SCROLL_DIR  eScrollDir,
double  fX,
double  fY,
bool  bAnyButtonPressed 
)
noexcept

Generates a pointer scroll event and sends it to listeners.

If the device doesn't exists or it has not a pointer capability -1 is returned. Note: the caller has to set the consistent value for the bAnyButtonPressed parameter to reflect the current state of the pointer buttons.

Parameters
nDeviceIdThe id of the device with the pointer capability.
eScrollDirThe direction of the scroll.
fXThe X position of the pointer.
fYThe Y position of the pointer.
bAnyButtonPressedWhether any button is pressed.
Returns
The number of listeners to which the event was actually sent or -1 if some error.

◆ simulateRemoveDevice()

bool stmi::testing::FakeDeviceManager::simulateRemoveDevice ( int32_t  nDeviceId)
noexcept

Removes a device.

Parameters
nDeviceIdThe device id as returned by simulateNewXXXDevice().
Returns
Whether the device was removed.

◆ simulateTouchEvent()

int32_t stmi::testing::FakeDeviceManager::simulateTouchEvent ( int32_t  nDeviceId,
TouchEvent::TOUCH_INPUT_TYPE  eType,
double  fX,
double  fY,
int64_t  nFingerId 
)
noexcept

Generates a touch event and sends it to listeners.

Parameters
nDeviceIdThe id of the device with the touch capability.
eTypeThe touch event type.
fXThe X position of the touch.
fYThe Y position of the touch.
nFingerIdThe id of the finger performing the touch.
Returns
The number of listeners to which the event was actually sent or -1 if some error.