libaurum: Apply clean code to object releated classes 98/305298/2
authorHosang Kim <hosang12.kim@samsung.com>
Wed, 31 Jan 2024 05:07:11 +0000 (14:07 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Wed, 31 Jan 2024 09:07:01 +0000 (18:07 +0900)
The IObject interface seems to have been added in the past to define a common interface between the ScreenAnalyzer object and the Ui Object.
It seems better to delete it because there is no abstracted object other than UiObject.

Clean Code was applied to the fact that UiObject calls getAccessibleNode even though it has Node.

Change-Id: Icf1262cd5ef69a596fa8793721219404117eef34

libaurum/inc/Accessibility/AccessibleNode.h
libaurum/inc/Aurum.h
libaurum/inc/Interface/IObject.h [deleted file]
libaurum/inc/UiObject.h
libaurum/meson.build
libaurum/src/UiObject.cc

index 26521db8122502f136dbd12a867cc961f9d24292..88a04a054a89c14e72ed0b1fb383b399c79b290c 100644 (file)
@@ -25,7 +25,6 @@
 #include <mutex>
 
 #include "IEventConsumer.h"
-#include "IObject.h"
 #include "Rect.h"
 #include "UiSelector.h"
 #include "config.h"
@@ -86,7 +85,7 @@ enum class NodeFeatureProperties {
  *
  * @since_tizen 6.5
  */
-class AccessibleNode : public std::enable_shared_from_this<AccessibleNode>, public IEventConsumer, public IObject {
+class AccessibleNode : public std::enable_shared_from_this<AccessibleNode>, public IEventConsumer {
 public:
     /**
      * @brief AccessibleNode constructor.
@@ -165,57 +164,57 @@ public:
     /**
      * @copydoc UiObject::getId()
      */
-    std::string getId() const override;
+    std::string getId() const;
 
     /**
      * @copydoc UiObject::getType()
      */
-    std::string getType() const override;
+    std::string getType() const;
 
     /**
      * @copydoc UiObject::getScreenBoundingBox()
      */
-    const Rect<int> getScreenBoundingBox() const override;
+    const Rect<int> getScreenBoundingBox() const;
 
     /**
      * @copydoc UiObject::getOcrText()
      */
-    std::string getOcrText() const override;
+    std::string getOcrText() const;
 
     /**
      * @copydoc UiObject::getWindowAngle()
      */
-    int getWindowAngle() const override;
+    int getWindowAngle() const;
 
     /**
      * @copydoc UiObject::getTargetAngle()
      */
-    int getTargetAngle() const override;
+    int getTargetAngle() const;
 
     /**
      * @copydoc UiObject::isFocusable()
      */
-    bool isFocusable() const override;
+    bool isFocusable() const;
 
     /**
      * @copydoc UiObject::isFocused()
      */
-    bool isFocused() const override;
+    bool isFocused() const;
 
     /**
      * @copydoc UiObject::isClickable()
      */
-    bool isClickable() const override;
+    bool isClickable() const;
 
     /**
      * @copydoc UiObject::isActive()
      */
-    bool isActive() const override;
+    bool isActive() const;
 
     /**
      * @copydoc UiObject::isShowing()
      */
-    bool isShowing() const override;
+    bool isShowing() const;
 
 public:
     /**
index 9abe6278bf72dc816e79c725baa7c5c6f1b8a08e..d3089e33e26d3cbe5956acc388313c128380e542 100644 (file)
@@ -52,7 +52,6 @@
 #include "Waiter.h"
 #include "ISearchable.h"
 #include "IDevice.h"
-#include "IObject.h"
 #include "Accessible.h"
 #include "Point2D.h"
 #include "Size2D.h"
diff --git a/libaurum/inc/Interface/IObject.h b/libaurum/inc/Interface/IObject.h
deleted file mode 100644 (file)
index 6fcaf42..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *               http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- */
-
-#ifndef _IOBJECT_H_
-#define _IOBJECT_H_
-
-#include "config.h"
-#include "Rect.h"
-#include <string>
-
-namespace Aurum {
-
-
-class IObject {
-public:
-
-    /**
-     * @brief IObject destructor
-     */
-    virtual ~IObject() {}
-
-    /**
-     * @copydoc UiObject::getId()
-     */
-    virtual std::string getId() const = 0;
-
-    /**
-     * @copydoc UiObject::getType()
-     */
-    virtual std::string getType() const = 0;
-
-    /**
-     * @copydoc UiObject::getScreenBoundingBox()
-     */
-    virtual const Rect<int> getScreenBoundingBox() const = 0;
-
-    /**
-     * @copydoc UiObject::getOcrText()
-     */
-    virtual std::string getOcrText() const = 0;
-
-    /**
-     * @copydoc UiObject::getWindowAngle()
-     */
-    virtual int getWindowAngle() const = 0;
-
-    /**
-     * @copydoc UiObject::getTargetAngle()
-     */
-    virtual int getTargetAngle() const = 0;
-
-    /**
-     * @copydoc UiObject::isFocusable()
-     */
-    virtual bool isFocusable() const = 0;
-
-    /**
-     * @copydoc UiObject::isFocused()
-     */
-    virtual bool isFocused() const = 0;
-
-    /**
-     * @copydoc UiObject::isClickable()
-     */
-    virtual bool isClickable() const = 0;
-
-    /**
-     * @copydoc UiObject::isActive()
-     */
-    virtual bool isActive() const = 0;
-
-    /**
-     * @copydoc UiObject::isShowing()
-     */
-    virtual bool isShowing() const = 0;
-};
-
-}
-
-#endif
index 5ec7aa4b76de0fe25be193b0a98fb406a6b9fbc4..187d48e114fc9ce828965ae01a325cb456c2c8c4 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "Accessible.h"
 #include "ISearchable.h"
-#include "IObject.h"
 
 #include "UiSelector.h"
 #include "Waiter.h"
@@ -56,7 +55,7 @@ public:
  *        such as object's properties, states, geometry information.
  *        also user can send and receive event via this class.
  */
-class UiObject : public ISearchable , public std::enable_shared_from_this<UiObject>,  public IObject {
+class UiObject : public ISearchable , public std::enable_shared_from_this<UiObject> {
 public:
     /**
      * @brief UiObject constructor with device, selector, node pointer.
@@ -177,7 +176,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    std::string getId() const override;
+    std::string getId() const;
 
     /**
      * @brief Gets object's type.
@@ -186,7 +185,7 @@ public:
      *
      * @since_tizen 7.0
      */
-    std::string getType() const override;
+    std::string getType() const;
 
     /**
      * @brief Gets object's geometry of the screen.
@@ -195,7 +194,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    const Rect<int> getScreenBoundingBox() const override;
+    const Rect<int> getScreenBoundingBox() const;
 
     /**
      * @brief Gets object's ocr text.
@@ -204,7 +203,7 @@ public:
      *
      * @since_tizen 7.0
      */
-    std::string getOcrText() const override;
+    std::string getOcrText() const;
 
     /**
      * @brief Gets object's angle of window.
@@ -213,7 +212,7 @@ public:
      *
      * @since_tizen 7.5
      */
-    int getWindowAngle() const override;
+    int getWindowAngle() const;
 
     /**
      * @brief Gets object's angle of target device.
@@ -222,7 +221,7 @@ public:
      *
      * @since_tizen 7.5
      */
-    int getTargetAngle() const override;
+    int getTargetAngle() const;
 
     /**
      * @brief Gets object's focusable property.
@@ -231,7 +230,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    bool isFocusable() const override;
+    bool isFocusable() const;
 
     /**
      * @brief Gets object's focused property.
@@ -240,7 +239,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    bool isFocused() const override;
+    bool isFocused() const;
 
     /**
      * @brief Gets object's clickable property.
@@ -249,7 +248,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    bool isClickable() const override;
+    bool isClickable() const;
 
     /**
      * @brief Gets object's active property.
@@ -258,7 +257,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    bool isActive() const override;
+    bool isActive() const;
 
     /**
      * @brief Gets object's showing property.
@@ -267,7 +266,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    bool isShowing() const override;
+    bool isShowing() const;
 
 public:
     /**
index 97b50fb4c10e89458cea1497df87768098ec017c..05db20e4f88f5b0a2192b4d4a99117fd635668df 100644 (file)
@@ -9,7 +9,6 @@ libaurum_install_inc = [
   './inc/Waiter.h',
   './inc/Interface/ISearchable.h',
   './inc/Interface/IDevice.h',
-  './inc/Interface/IObject.h',
   './inc/A11yEvent.h',
   './inc/PartialMatch.h',
   './inc/UiScrollable.h',
index d8c3cfa587f7d60bf7914335466a885b28df8e91..8ef6b0080c3452ff1909da33c104d7e7314fa43f 100644 (file)
@@ -70,7 +70,7 @@ std::shared_ptr<UiSelector> UiObject::getSelector()
 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
 {
     std::shared_ptr<AccessibleNode> node =
-        Comparer::findObject(mDevice, selector, getAccessibleNode());
+        Comparer::findObject(mDevice, selector, mNode);
     if (node != nullptr) {
         // todo : what is this node.recycle()
         return true;
@@ -81,7 +81,7 @@ bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
 std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
 {
     std::shared_ptr<AccessibleNode> node =
-        Comparer::findObject(mDevice, selector, getAccessibleNode());
+        Comparer::findObject(mDevice, selector, mNode);
     if (node)
         return std::make_shared<UiObject>(mDevice, selector, std::move(node));
     else
@@ -94,7 +94,7 @@ std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
     std::vector<std::shared_ptr<UiObject>> result{};
 
     std::vector<std::shared_ptr<AccessibleNode>> nodes{};
-    Comparer::findObjects(nodes, mDevice, selector, getAccessibleNode());
+    Comparer::findObjects(nodes, mDevice, selector, mNode);
     for ( auto& node : nodes) {
         if (!node) {
             LOGI("Skipped! (node == nullptr)");
@@ -110,7 +110,7 @@ std::vector<std::shared_ptr<UiObject>> UiObject::getMatches(
 {
     std::vector<std::shared_ptr<UiObject>> result{};
 
-    auto nodes = getAccessibleNode()->getMatches(selector, earlyReturn);
+    auto nodes = mNode->getMatches(selector, earlyReturn);
     for (auto &node : nodes) {
         result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
     }
@@ -122,7 +122,7 @@ std::vector<std::shared_ptr<UiObject>> UiObject::getMatchesInMatches(
 {
     std::vector<std::shared_ptr<UiObject>> result{};
 
-    auto nodes = getAccessibleNode()->getMatchesInMatches(firstSelector, secondSelector, earlyReturn);
+    auto nodes = mNode->getMatchesInMatches(firstSelector, secondSelector, earlyReturn);
     for (auto &node : nodes) {
         result.push_back(std::make_shared<UiObject>(mDevice, nullptr, std::move(node)));
     }
@@ -150,18 +150,18 @@ bool UiObject::waitFor(
 
 UiObject *UiObject::getParent() const
 {
-    std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
+    std::shared_ptr<AccessibleNode> node = mNode->getParent();
     if (!node) return nullptr;
     return new UiObject(mDevice, mSelector, std::move(node));
 }
 
 int UiObject::getChildCount() const
 {
-    return getAccessibleNode()->getChildCount();
+    return mNode->getChildCount();
 }
 
 std::shared_ptr<UiObject> UiObject::getChildAt(int index) const {
-    auto childNode = getAccessibleNode()->getChildAt(index);
+    auto childNode = mNode->getChildAt(index);
     if (childNode) {
         return std::make_shared<UiObject>(mDevice, mSelector, childNode);
     }
@@ -172,7 +172,7 @@ std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
 {
     std::vector<std::shared_ptr<UiObject>> ret{};
 
-    auto children = getAccessibleNode()->getChildren();
+    auto children = mNode->getChildren();
     for (auto &child : children) {
         ret.push_back(std::make_shared<UiObject>(mDevice, mSelector, child));
     }
@@ -193,178 +193,178 @@ std::shared_ptr<Node> UiObject::getDescendant()
 
 std::string UiObject::getApplicationPackage() const
 {
-    return getAccessibleNode()->getPkg();
+    return mNode->getPkg();
 }
 
 std::string UiObject::getId() const
 {
-    return getAccessibleNode()->getId();
+    return mNode->getId();
 }
 
 std::string UiObject::getAutomationId() const
 {
-    return getAccessibleNode()->getAutomationId();
+    return mNode->getAutomationId();
 }
 
 std::string UiObject::getType() const
 {
-    return getAccessibleNode()->getType();
+    return mNode->getType();
 }
 
 std::string UiObject::getElementStyle() const
 {
-    return getAccessibleNode()->getStyle();
+    return mNode->getStyle();
 }
 
 std::string UiObject::getText() const
 {
-    return getAccessibleNode()->getText();
+    return mNode->getText();
 }
 
 std::string UiObject::getRole() const
 {
-    return getAccessibleNode()->getRole();
+    return mNode->getRole();
 }
 
 std::string UiObject::getXPath() const
 {
-    return getAccessibleNode()->getXPath();
+    return mNode->getXPath();
 }
 
 const double UiObject::getMinValue() const
 {
-    return getAccessibleNode()->getMinValue();
+    return mNode->getMinValue();
 }
 
 const double UiObject::getMaxValue() const
 {
-    return getAccessibleNode()->getMaxValue();
+    return mNode->getMaxValue();
 }
 
 const double UiObject::getValue() const
 {
-    return getAccessibleNode()->getValue();
+    return mNode->getValue();
 }
 
 const double UiObject::getIncrement() const
 {
-    return getAccessibleNode()->getIncrement();
+    return mNode->getIncrement();
 }
 
 const Rect<int> UiObject::getTextMinBoundingRect() const
 {
-    return getAccessibleNode()->getTextMinBoundingRect();
+    return mNode->getTextMinBoundingRect();
 }
 
 std::string UiObject::getInterface() const
 {
-    return getAccessibleNode()->getInterface();
+    return mNode->getInterface();
 }
 
 bool UiObject::setValue(double value)
 {
-    return getAccessibleNode()->setValue(value);
+    return mNode->setValue(value);
 }
 
 bool UiObject::setText(std::string text)
 {
-    return getAccessibleNode()->setValue(text);
+    return mNode->setValue(text);
 }
 
 std::string UiObject::getOcrText() const
 {
-    return getAccessibleNode()->getOcrText();
+    return mNode->getOcrText();
 }
 
 int UiObject::getWindowAngle() const
 {
-    return getAccessibleNode()->getWindowAngle();
+    return mNode->getWindowAngle();
 }
 
 int UiObject::getTargetAngle() const
 {
-    return getAccessibleNode()->getTargetAngle();
+    return mNode->getTargetAngle();
 }
 
 std::string UiObject::getToolkitName() const
 {
-    getAccessibleNode()->updateToolkitName();
-    return getAccessibleNode()->getToolkitName();
+    mNode->updateToolkitName();
+    return mNode->getToolkitName();
 }
 
 void UiObject::setOcrText(std::string text)
 {
-    getAccessibleNode()->setOcrText(text);
+    mNode->setOcrText(text);
 }
 
 bool UiObject::isCheckable() const
 {
-    return getAccessibleNode()->isCheckable();
+    return mNode->isCheckable();
 }
 
 bool UiObject::isChecked() const
 {
-    return getAccessibleNode()->isChecked();
+    return mNode->isChecked();
 }
 
 bool UiObject::isClickable() const
 {
-    return getAccessibleNode()->isClickable();
+    return mNode->isClickable();
 }
 
 bool UiObject::isEnabled() const
 {
-    return getAccessibleNode()->isEnabled();
+    return mNode->isEnabled();
 }
 
 bool UiObject::isFocusable() const
 {
-    return getAccessibleNode()->isFocusable();
+    return mNode->isFocusable();
 }
 
 bool UiObject::isFocused() const
 {
-    return getAccessibleNode()->isFocused();
+    return mNode->isFocused();
 }
 
 bool UiObject::isLongClickable() const
 {
-    return getAccessibleNode()->isLongClickable();
+    return mNode->isLongClickable();
 }
 
 bool UiObject::isScrollable() const
 {
-    return getAccessibleNode()->isScrollable();
+    return mNode->isScrollable();
 }
 
 bool UiObject::isSelectable() const
 {
-    return getAccessibleNode()->isSelectable();
+    return mNode->isSelectable();
 }
 
 bool UiObject::isSelected() const
 {
-    return getAccessibleNode()->isSelected();
+    return mNode->isSelected();
 }
 
 bool UiObject::isVisible() const
 {
-    return getAccessibleNode()->isVisible();
+    return mNode->isVisible();
 }
 
 bool UiObject::isShowing() const
 {
-    return getAccessibleNode()->isShowing();
+    return mNode->isShowing();
 }
 
 bool UiObject::isActive() const
 {
-    return getAccessibleNode()->isActive();
+    return mNode->isActive();
 }
 
 bool UiObject::isHighlightable() const
 {
-    return getAccessibleNode()->isHighlightable();
+    return mNode->isHighlightable();
 }
 
 void UiObject::refresh() const
@@ -452,19 +452,22 @@ const Rect<int> UiObject::getWindowBoundingBox() const
     return mNode->getWindowBoundingBox();
 }
 
+const Point2D<int> getMidPoint(std::shared_ptr<Aurum::AccessibleNode> node)
+{
+    node->updateExtents();
+    const Rect<int> rect = node->getScreenBoundingBox();
+    return rect.midPoint();
+}
+
 void UiObject::click() const
 {
-    mNode->updateExtents();
-    const Rect<int> rect = mNode->getScreenBoundingBox();
-    const Point2D<int> midPoint = rect.midPoint();
+    const Point2D<int> midPoint = getMidPoint(mNode);
     mDevice->click(midPoint.x, midPoint.y);
 }
 
 void UiObject::longClick(const unsigned int durationMs) const
 {
-    mNode->updateExtents();
-    const Rect<int> rect = mNode->getScreenBoundingBox();
-    const Point2D<int> midPoint = rect.midPoint();
+    const Point2D<int> midPoint = getMidPoint(mNode);
     mDevice->click(midPoint.x, midPoint.y, durationMs);
 }