Adds generateKey method and Tests for this.
apply factory pattern for Key generates it able to be added or changed
without changing exising code.
It also no problem in the operation of the program even if an object of a child
class is replaced with an object of the parent class.
For advantaging of being easy to maintain and highly extensibel.
Change-Id: I5ee504a82f2f7cc5c3ffea9be8914034975bf015
namespace Mock {
-enum class MockKeyType {
- BACK,
- HOME,
- MENU,
- VOLUP,
- VOLDOWN,
- POWER,
- KEY
-};
-
struct TouchData { int x; int y; long long stamp1; long long stamp2;};
class MockDeviceImpl : public IDevice {
public:
* @brief TBD
* @since_tizen 6.5
*/
- bool pressBack(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
- bool pressHome(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
- bool pressMenu(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
- bool pressVolUp(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
- bool pressVolDown(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
- bool pressPower(KeyRequestType type) override;
-
- /**
- * @brief TBD
- * @since_tizen 6.5
- */
bool pressKeyCode(std::string keycode, KeyRequestType type) override;
/**
*/
std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const override;
+public:
+
+ /**
+ * @brief Gets list of keys simulated on Mock device
+ *
+ * @return std::tuple<KeyType, KeyRequestType, std::string> vector
+ */
+ std::vector<std::tuple<KeyType, KeyRequestType, std::string>> getGeneratedKeys();
+
+ /**
+ * @brief Clear list of keys simulated on Mock device
+ */
+ void clearGeneratedKeys();
+
protected:
/**
* @brief TBD
/**
* @brief TBD
*/
- std::vector<std::tuple<MockKeyType, KeyRequestType, std::string>> mKeyDevice;
+ std::vector<std::tuple<KeyType, KeyRequestType, std::string>> mKeyDevice;
/**
* @brief TBD
bool wheelDown(int amount, const int durationMs) override;
/**
- * @copydoc IDevice::pressBack()
- */
- bool pressBack(KeyRequestType type) override;
-
- /**
- * @copydoc IDevice::pressHome()
- */
- bool pressHome(KeyRequestType type) override;
-
- /**
- * @copydoc IDevice::pressMenu()
- */
- bool pressMenu(KeyRequestType type) override;
-
- /**
- * @copydoc IDevice::pressVolUp()
- */
- bool pressVolUp(KeyRequestType type) override;
-
- /**
- * @copydoc IDevice::pressVolDown()
- */
- bool pressVolDown(KeyRequestType type) override;
-
- /**
- * @copydoc IDevice::pressPower()
- */
- bool pressPower(KeyRequestType type) override;
-
- /**
* @copydoc IDevice::pressKeyCode()
*/
bool pressKeyCode(std::string keycode, KeyRequestType type) override;
};
/**
+ * @brief KeyType enum class.
+ *
+ * @since_tizen 8.0
+*/
+enum class KeyType {
+ BACK,
+ HOME,
+ MENU,
+ VOLUP,
+ VOLDOWN,
+ POWER,
+ KEY
+};
+
+/**
* @brief IDevice interface.
* It defines common device controls such as touch, key events
*
virtual bool wheelDown(int amount, const int durationMs) = 0;
/**
- * @brief Simulates a press on the back key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press back succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressBack(KeyRequestType type) = 0;
-
- /**
- * @brief Simulates a press on the home key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press home succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressHome(KeyRequestType type) = 0;
-
- /**
- * @brief Simulates a press on the menu key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press menu succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressMenu(KeyRequestType type) = 0;
-
- /**
- * @brief Simulates a press on the volume up key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press volume up succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressVolUp(KeyRequestType type) = 0;
-
- /**
- * @brief Simulates a press on the volume down key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press volume down succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressVolDown(KeyRequestType type) = 0;
-
- /**
- * @brief Simulates a press on the power key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press power succeeded else false
- *
- * @since_tizen 6.5
- */
- virtual bool pressPower(KeyRequestType type) = 0;
-
- /**
* @brief Simulates a press on the given keycode key.
*
* @param[in] keycode keycode
bool wheelDown(int amount, const int durationMs) override;
/**
- * @brief Simulates a press on the back key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press back succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressBack(KeyRequestType type) override;
-
- /**
- * @brief Simulates a press on the home key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press home succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressHome(KeyRequestType type) override;
-
- /**
- * @brief Simulates a press on the menu key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press menu succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressMenu(KeyRequestType type) override;
-
- /**
- * @brief Simulates a press on the volume up key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press volume up succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressVolUp(KeyRequestType type) override;
-
- /**
- * @brief Simulates a press on the volume down key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press volume down succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressVolDown(KeyRequestType type) override;
-
- /**
- * @brief Simulates a press on the power key.
- *
- * @param[in] type one of @KeyRequestType
- *
- * @return true if the press power succeeded else false
- *
- * @since_tizen 6.5
- */
- bool pressPower(KeyRequestType type) override;
-
- /**
* @brief Simulates a press on the given keycode key.
*
* @param[in] keycode keycode
*/
int getTargetAngle();
+ /**
+ * @brief Simulates a press on the key.
+ *
+ * @param[in] keyType one of @KeyType
+ * @param[in] keyReqestType one of @KeyRequestType
+ *
+ * @return true if the press key succeeded else false
+ *
+ * @since_tizen 8.0
+ */
+ bool generateKey(KeyType keyType, KeyRequestType keyReqestType);
+
private:
/**
* @brief Waits process idle.
}
-bool MockDeviceImpl::pressBack(KeyRequestType type)
-{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::BACK, type, ""));
- return true;
-}
-
-bool MockDeviceImpl::pressHome(KeyRequestType type)
-{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::HOME, type, ""));
- return true;
-}
-
-bool MockDeviceImpl::pressMenu(KeyRequestType type)
-{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::MENU, type, ""));
- return true;
-}
-
-bool MockDeviceImpl::pressVolUp(KeyRequestType type)
-{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::VOLUP, type, ""));
- return true;
-}
-
-bool MockDeviceImpl::pressVolDown(KeyRequestType type)
+bool MockDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type)
{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::VOLDOWN, type, ""));
+ mKeyDevice.push_back(std::tuple<KeyType, KeyRequestType, std::string>(KeyType::KEY, type, keycode));
return true;
}
-bool MockDeviceImpl::pressPower(KeyRequestType type)
+std::vector<std::tuple<KeyType, KeyRequestType, std::string>> MockDeviceImpl::getGeneratedKeys()
{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::POWER, type, ""));
- return true;
+ return mKeyDevice;
}
-bool MockDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type)
+void MockDeviceImpl::clearGeneratedKeys()
{
- mKeyDevice.push_back(std::tuple<MockKeyType, KeyRequestType, std::string>(MockKeyType::KEY, type, keycode));
- return true;
+ mKeyDevice.clear();
}
bool MockDeviceImpl::repeatKeyCode(std::string keycode, int intervalMs, int durationMs)
return true;
}
-bool TizenDeviceImpl::pressBack(KeyRequestType type)
-{
- return pressKeyCode("XF86Back", type);
-}
-
-bool TizenDeviceImpl::pressHome(KeyRequestType type)
-{
- return pressKeyCode("XF86Home", type);
-}
-
-bool TizenDeviceImpl::pressMenu(KeyRequestType type)
-{
- return pressKeyCode("XF86Menu", type);
-}
-
-bool TizenDeviceImpl::pressVolUp(KeyRequestType type)
-{
- return pressKeyCode("XF86AudioRaiseVolume", type);
-}
-
-bool TizenDeviceImpl::pressVolDown(KeyRequestType type)
-{
- return pressKeyCode("XF86AudioLowerVolume", type);
-}
-
-bool TizenDeviceImpl::pressPower(KeyRequestType type)
-{
- return pressKeyCode("XF86PowerOff", type);
-}
-
bool TizenDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type)
{
LOGI("pressKeyCode(%s)", keycode.c_str());
using namespace Aurum;
using namespace AurumInternal;
+class KeyAction {
+public:
+ KeyAction(IDevice *deviceImpl)
+ : mDeviceImpl(deviceImpl) {}
+ virtual ~KeyAction(){};
+
+ virtual bool perform(KeyRequestType type) = 0;
+protected:
+ IDevice *mDeviceImpl;
+};
+
+class BackKeyAction : public KeyAction {
+public:
+ BackKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~BackKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86Back", type);
+ }
+};
+
+class HomeKeyAction : public KeyAction {
+public:
+ HomeKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~HomeKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86Home", type);
+ }
+};
+
+class MenuKeyAction : public KeyAction {
+public:
+ MenuKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~MenuKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86Menu", type);
+ }
+};
+
+class VolUpKeyAction : public KeyAction {
+public:
+ VolUpKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~VolUpKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86AudioRaiseVolume", type);
+ }
+};
+
+class VolDownKeyAction : public KeyAction {
+public:
+ VolDownKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~VolDownKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86AudioLowerVolume", type);
+ }
+};
+
+class PowerKeyAction : public KeyAction {
+public:
+ PowerKeyAction(IDevice *deviceImpl)
+ : KeyAction(deviceImpl) {}
+
+ virtual ~PowerKeyAction(){};
+
+ bool perform(KeyRequestType type) override {
+ return mDeviceImpl->pressKeyCode("XF86PowerOff", type);
+ }
+};
+
std::once_flag UiDevice::mOnceFlag;
UiDevice::UiDevice() : UiDevice(nullptr) {}
return result;
}
-bool UiDevice::pressBack(KeyRequestType type)
+bool UiDevice::generateKey(KeyType keyType, KeyRequestType keyReqestType)
{
- bool result = mDeviceImpl->pressBack(type);
- waitForIdle();
- return result;
-}
-
-bool UiDevice::pressHome(KeyRequestType type)
-{
- bool result = mDeviceImpl->pressHome(type);
- waitForIdle();
- return result;
-}
-
-bool UiDevice::pressMenu(KeyRequestType type)
-{
- bool result = mDeviceImpl->pressMenu(type);
- waitForIdle();
- return result;
-}
+ std::unique_ptr<KeyAction> keyAction;
-bool UiDevice::pressVolUp(KeyRequestType type)
-{
- bool result = mDeviceImpl->pressVolUp(type);
- waitForIdle();
- return result;
-}
+ if (keyType == KeyType::BACK)
+ keyAction = std::make_unique<BackKeyAction>(mDeviceImpl);
+ else if (keyType == KeyType::HOME)
+ keyAction = std::make_unique<HomeKeyAction>(mDeviceImpl);
+ else if (keyType == KeyType::MENU)
+ keyAction = std::make_unique<MenuKeyAction>(mDeviceImpl);
+ else if (keyType == KeyType::VOLUP)
+ keyAction = std::make_unique<VolUpKeyAction>(mDeviceImpl);
+ else if (keyType == KeyType::VOLDOWN)
+ keyAction = std::make_unique<VolDownKeyAction>(mDeviceImpl);
+ else if (keyType == KeyType::POWER)
+ keyAction = std::make_unique<PowerKeyAction>(mDeviceImpl);
-bool UiDevice::pressVolDown(KeyRequestType type)
-{
- bool result = mDeviceImpl->pressVolDown(type);
- waitForIdle();
- return result;
-}
+ bool result = keyAction->perform(keyReqestType);
-bool UiDevice::pressPower(KeyRequestType type)
-{
- bool result = mDeviceImpl->pressPower(type);
- waitForIdle();
return result;
}
KeyRequestType actionType = static_cast<KeyRequestType>(action_type);
if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_BACK)
- mDevice->pressBack(actionType);
+ mDevice->generateKey(KeyType::BACK, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_HOME)
- mDevice->pressHome(actionType);
+ mDevice->generateKey(KeyType::HOME, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_MENU)
- mDevice->pressMenu(actionType);
+ mDevice->generateKey(KeyType::MENU, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLUP)
- mDevice->pressVolUp(actionType);
+ mDevice->generateKey(KeyType::VOLUP, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_VOLDOWN)
- mDevice->pressVolDown(actionType);
+ mDevice->generateKey(KeyType::VOLDOWN, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_POWER)
- mDevice->pressPower(actionType);
+ mDevice->generateKey(KeyType::POWER, actionType);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_WHEELUP)
mDevice->wheelUp(1, 167);
else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_WHEELDOWN)
{
auto windowroot = UiDevice::getInstance()->getWindowRoot();
ASSERT_NE(windowroot.size(), 0);
-}
\ No newline at end of file
+}
+
+TEST_F(AurumTestUiDevice, pressKeyCode_P1)
+{
+ mDevice->pressKeyCode("BACK", KeyRequestType::PRESS);
+ mDevice->pressKeyCode("HOME", KeyRequestType::PRESS);
+ mDevice->pressKeyCode("MENU", KeyRequestType::PRESS);
+ mDevice->pressKeyCode("VOLUP", KeyRequestType::PRESS);
+ mDevice->pressKeyCode("VOLDOWN", KeyRequestType::PRESS);
+ mDevice->pressKeyCode("POWER", KeyRequestType::PRESS);
+
+ auto listOfKeys = mDevice->getGeneratedKeys();
+ auto key = listOfKeys[0];
+ ASSERT_EQ(std::get<2>(key), "BACK");
+ key = listOfKeys[1];
+ ASSERT_EQ(std::get<2>(key), "HOME");
+ key = listOfKeys[2];
+ ASSERT_EQ(std::get<2>(key), "MENU");
+ key = listOfKeys[3];
+ ASSERT_EQ(std::get<2>(key), "VOLUP");
+ key = listOfKeys[4];
+ ASSERT_EQ(std::get<2>(key), "VOLDOWN");
+ key = listOfKeys[5];
+ ASSERT_EQ(std::get<2>(key), "POWER");
+
+ mDevice->clearGeneratedKeys();
+}