libaurum: Add test case for new refresh interface 47/304547/2
authorWoochan Lee <wc0917.lee@samsung.com>
Fri, 19 Jan 2024 07:44:28 +0000 (16:44 +0900)
committerWoochan Lee <wc0917.lee@samsung.com>
Fri, 26 Jan 2024 06:10:32 +0000 (15:10 +0900)
This patch contains the test case used for TDD when writing the patch below
which was missing when relfecting the previous patch.

libaurum: new interface applied to improve performance

In addition, it includes code deduplication and removal of unnecessary clear action to improve performance.

Change-Id: I68525d3d8d9bf03f3c94452de26f22f44063fcff

libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc
libaurum/src/Impl/Accessibility/MockAccessibleNode.cc
tests/Test_UiObject.cc

index 5cc212aeda405072c0b2c6efce81b77aaab0a0a6..2c2180bc395ad33b6788874dc2ff3388ad2088bd 100644 (file)
@@ -120,8 +120,6 @@ void AtspiAccessibleNode::updateRoleName()
 {
     if (!mRole.empty()) return;
 
-    AtspiWrapper::Atspi_accessible_clear_cache(mNode);
-
     gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL);
     if (rolename) {
         mRole = rolename;
@@ -133,8 +131,6 @@ void AtspiAccessibleNode::updateUniqueId()
 {
     if (!mId.empty()) return;
 
-    AtspiWrapper::Atspi_accessible_clear_cache(mNode);
-
     #ifdef TIZEN
     gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL);
     if (uID) {
@@ -176,8 +172,6 @@ void AtspiAccessibleNode::updateApplication()
 {
     if (!mPkg.empty()) return;
 
-    AtspiWrapper::Atspi_accessible_clear_cache(mNode);
-
     AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
     if (app) {
         gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
@@ -220,6 +214,7 @@ void AtspiAccessibleNode::updateStates()
     resetFeatureProperty();
 
     AtspiWrapper::Atspi_accessible_clear_cache(mNode);
+
     AtspiStateSet *st = AtspiWrapper::Atspi_accessible_get_state_set(mNode);
     if (st) {
         GArray *states = AtspiWrapper::Atspi_state_set_get_states(st);
@@ -410,106 +405,15 @@ void AtspiAccessibleNode::refresh(bool updateAll)
             // TODO: Add Atspi_accessible_get_node_info() for efl.
             //       In case of efl, there are not many objects nomally so its not big advantage for performance though
             //       need to add interface for consistency.
-            if (mRole.empty()) {
-                gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL);
-                if (rolename) {
-                    mRole = rolename;
-                    g_free(rolename);
-                }
-            }
-            #ifdef TIZEN
-            if (mId.empty()) {
-                gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL);
-                if (uID) {
-                    mId = uID;
-                    g_free(uID);
-                }
-            }
-            #else
-            mId = std::string{"N/A"};
-            #endif
-            gchar *name = AtspiWrapper::Atspi_accessible_get_name(mNode, NULL);
-            if (name) {
-                mText = name;
-                g_free(name);
-            }
-
-            if (mToolkitName.empty()) {
-                gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(mNode, NULL);
-                if (toolkitName) {
-                    mToolkitName = toolkitName;
-                    g_free(toolkitName);
-                }
-            }
-
-            if (mPkg.empty()) {
-                AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
-                if (app) {
-                    gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
-                    if (pkg) {
-                        mPkg = pkg;
-                        g_free(pkg);
-                    }
-                    g_object_unref(app);
-                }
-            }
-
-            if (mType.empty()) {
-                GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL);
-                if (attributes) {
-                    char *t = (char *)g_hash_table_lookup(attributes, "type");
-                    if (!t) t = (char *)g_hash_table_lookup(attributes, "t");
-                    if (!t) t = (char *)g_hash_table_lookup(attributes, "class");
-                    char *s = (char *)g_hash_table_lookup(attributes, "style");
-                    char *a = (char *)g_hash_table_lookup(attributes, "automationId");
-
-                    if (t) mType = std::string(t);
-                    else mType = mRole;
-                    if (s) mStyle = std::string(s);
-                    if (a) mAutomationId = std::string(a);
-
-                    g_hash_table_unref(attributes);
-                }
-            }
-
-            AtspiStateSet *st = AtspiWrapper::Atspi_accessible_get_state_set(mNode);
-            if (st) {
-                GArray *states = AtspiWrapper::Atspi_state_set_get_states(st);
-                if (states) {
-                    AtspiStateType stat;
-                    for (unsigned int i = 0; states && (i < states->len); ++i) {
-                        stat = g_array_index(states, AtspiStateType, i);
-                        setFeatureProperty(stat);
-                    }
-                    g_array_free(states, 1);
-                }
-                g_object_unref(st);
-            }
-            AtspiComponent *component = AtspiWrapper::Atspi_accessible_get_component_iface(mNode);
-            if (component) {
-                AtspiRect *screenExtent = AtspiWrapper::Atspi_component_get_extents(component, ATSPI_COORD_TYPE_SCREEN, NULL);
-                if (screenExtent) {
-                    mScreenBoundingBox = Rect<int>{screenExtent->x, screenExtent->y, screenExtent->x + screenExtent->width, screenExtent->y + screenExtent->height};
-                    g_free(screenExtent);
-                }
-
-                AtspiRect *windowExtent = AtspiWrapper::Atspi_component_get_extents(component, ATSPI_COORD_TYPE_WINDOW, NULL);
-                if (windowExtent) {
-                    mWindowBoundingBox =
-                        Rect<int>{windowExtent->x, windowExtent->y, windowExtent->x + windowExtent->width, windowExtent->y + windowExtent->height};
-                    g_free(windowExtent);
-                }
-                g_object_unref(component);
-            }
-
-            AtspiValue *value = AtspiWrapper::Atspi_accessible_get_value(mNode);
-            if (value) {
-                mMinValue = AtspiWrapper::Atspi_value_get_minimum_value(value, NULL);
-                mMaxValue = AtspiWrapper::Atspi_value_get_maximum_value(value, NULL);
-                mValue = AtspiWrapper::Atspi_value_get_current_value(value, NULL);
-                mIncrement = AtspiWrapper::Atspi_value_get_minimum_increment(value, NULL);
-                g_object_unref(value);
-            }
+            updateRoleName();
+            updateUniqueId();
+            updateName();
+            updateToolkitName();
+            updateApplication();
+            updateAttributes();
+            updateStates();
+            updateExtents();
+            updateValue();
         }
 
         //FIXME: It should be belongs into Atspi_accessible_get_node_info()
index 8811042b212c31ecde6c4d2163ee5a4e1965ccbb..d56361bec0a8f2072bda01b6a912dab9414718e9 100644 (file)
@@ -208,6 +208,16 @@ void MockAccessibleNode::updateTextMinBoundingRect()
 
 void MockAccessibleNode::refresh(bool updateAll)
 {
+    mText = "refreshText";
+    mPkg = "refreshPkg";
+    mRole = "refreshRole";
+    mId = "refreshId";
+    mAutomationId = "refreshAutomationId";
+    mType = "refreshType";
+    mStyle = "refreshStyle";
+    mScreenBoundingBox = {0,0,500,500};
+    mSupportingIfaces = 1;
+    mFeatureProperty = (int)NodeFeatureProperties::SELECTABLE | (int)NodeFeatureProperties::SELECTED;
 }
 
 std::vector<std::string> MockAccessibleNode::getActions() const
index 91a2e110e3fd67b72bb84ace806a1f20dfb529e8..4b3108f262e1bf979e97438321a424a5e48dddfa 100644 (file)
@@ -516,6 +516,39 @@ TEST_F(AurumTestUiObject, getScreenBoundingBox_N1)
     ASSERT_NE(box.mTopLeft.x, 0 );
     ASSERT_NE(box.mTopLeft.y, 0 );
 }
+TEST_F(AurumTestUiObject, refresh_P1)
+{
+    auto obj = UiDevice::getInstance();
+    auto targetNode = obj->findObject(Sel::text("test2"));
+    targetNode->refresh();
+
+    ASSERT_EQ(targetNode->getText(), "refreshText");
+    ASSERT_EQ(targetNode->getApplicationPackage(), "refreshPkg");
+    ASSERT_EQ(targetNode->getRole(), "refreshRole");
+    ASSERT_EQ(targetNode->getId(), "refreshId");
+    ASSERT_EQ(targetNode->getAutomationId(), "refreshAutomationId");
+    ASSERT_EQ(targetNode->getType(), "refreshType");
+    ASSERT_EQ(targetNode->getScreenBoundingBox().width(), 500);
+    ASSERT_EQ(targetNode->getScreenBoundingBox().height(), 500);
+    ASSERT_EQ(targetNode->isSelectable(), true);
+    ASSERT_EQ(targetNode->isSelected(), true);
+}
+
+TEST_F(AurumTestUiObject, refresh_N1)
+{
+    auto obj = UiDevice::getInstance();
+    auto targetNode = obj->findObject(Sel::text("test2"));
+    targetNode->refresh();
+
+    ASSERT_NE(targetNode->getText(), "test2");
+    ASSERT_NE(targetNode->getApplicationPackage(), "pkg");
+    ASSERT_NE(targetNode->getRole(), "TeSt1234!@#$");
+    ASSERT_NE(targetNode->getId(), "res");
+    ASSERT_NE(targetNode->getAutomationId(), "type");
+    ASSERT_NE(targetNode->getType(), "style");
+    ASSERT_NE(targetNode->getScreenBoundingBox().width(), 200);
+    ASSERT_NE(targetNode->getScreenBoundingBox().height(), 200);
+}
 
 TEST_F(AurumTestUiObject, getMatches_P1)
 {