libaurum: Refactoring using TDD to observe the SRP 04/304904/3
authorWoochan Lee <wc0917.lee@samsung.com>
Thu, 25 Jan 2024 07:37:51 +0000 (16:37 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Fri, 26 Jan 2024 06:53:54 +0000 (06:53 +0000)
The existing AccessibleWatcher was handling event processing and app managing.
Since this violates the single responsibility principle, AccessibleWatcher is responsible for event processing only,
and the structure has been changed so that AccessibleAppManager manages apps.

To this end, we created a test with a structure that adds a MockAccessibleAppManager,
and made sure that the test is satisfied through additional implementation.

Change-Id: I8a619384ac5a7d62b89cd16c960875e56a4a1276

26 files changed:
libaurum/inc/Accessibility/Accessible.h
libaurum/inc/Accessibility/AccessibleAppManager.h [new file with mode: 0644]
libaurum/inc/Accessibility/AccessibleWatcher.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleAppManager.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
libaurum/inc/Impl/Accessibility/MockAccessibleAppManager.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h
libaurum/meson.build
libaurum/src/Accessibility/AccessibleAppManager.cc [new file with mode: 0644]
libaurum/src/Accessibility/AccessibleWatcher.cc
libaurum/src/Accessibility/meson.build
libaurum/src/Impl/Accessibility/AtspiAccessibleAppManager.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc
libaurum/src/Impl/Accessibility/MockAccessibleAppManager.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc
libaurum/src/Impl/Accessibility/MockAccessibleNode.cc
libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc
libaurum/src/Impl/Accessibility/meson.build
libaurum/src/Impl/MockDeviceImpl.cc
libaurum/src/Impl/TizenDeviceImpl.cc
tests/Test_Misc.cc
tests/Test_Sel.cc
tests/Test_UiDevice.cc
tests/Test_UiObject.cc
tests/Test_UiSelector.cc
tests/meson.build

index 2d2c456fcefff62df81805de2bb336667798ffa8..ca0e6d4cf964935e84d4300a36104c8c182fcf67 100644 (file)
@@ -19,6 +19,7 @@
 #define _ACCESSIBLE_H_
 
 #include "AccessibleNode.h"
+#include "AccessibleAppManager.h"
 #include "AccessibleWatcher.h"
 #include "AccessibleApplication.h"
 #include "AccessibleWindow.h"
diff --git a/libaurum/inc/Accessibility/AccessibleAppManager.h b/libaurum/inc/Accessibility/AccessibleAppManager.h
new file mode 100644 (file)
index 0000000..ba5fd54
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2023 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 _ACCESSIBLE_APPMANAGER_H_
+#define _ACCESSIBLE_APPMANAGER_H_
+
+#include "AccessibleApplication.h"
+#include <vector>
+
+#include "config.h"
+
+namespace Aurum {
+
+/**
+ * @class AccessibleAppManager
+ *
+ * @ingroup aurum
+ *
+ * @brief Class that manages a list of application classes
+ */
+class AccessibleAppManager {
+public:
+    /**
+     * @brief AccessibleAppManager constructor.
+     *
+     * @since_tizen 6.5
+     */
+    AccessibleAppManager();
+
+    /**
+     * @brief AccessibleAppManager destructor.
+     *
+     * @since_tizen 6.5
+     */
+    virtual ~AccessibleAppManager();
+
+    /**
+     * @brief Gets @AccessibleAppManager instance.
+     *
+     * @since_tizen 6.5
+     */
+    static AccessibleAppManager *getInstance(AccessibleAppManager *appManagerImpl = nullptr);
+
+public:
+    /**
+     * @brief Gets current running application count in device.
+     *
+     * @return application count
+     *
+     * @since_tizen 6.5
+     */
+    virtual int getApplicationCount(void) const = 0;
+
+    /**
+     * @brief Gets application class at specific index.
+     *
+     * @param[in] index application index
+     *
+     * @return @AccessibleApplication ptr
+     *
+     * @since_tizen 6.5
+     */
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const = 0;
+
+    /**
+     * @brief Gets application node vector.
+     *
+     * @return @AccessibleApplication vector
+     *
+     * @since_tizen 6.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const = 0;
+
+    /**
+     * @brief Gets active application vector.
+     *
+     * @return @AccessibleApplication vector
+     *
+     * @since_tizen 6.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getActiveApplications(void) const;
+};
+
+}
+
+#endif
index e2f7c2b378691492c16a25b12bb70f3276ac0f69..4b4585b85e3139930d6e54152c4bf007321610e9 100644 (file)
@@ -18,7 +18,6 @@
 #ifndef _ACCESSIBLE_WATCHER_H_
 #define _ACCESSIBLE_WATCHER_H_
 
-#include "AccessibleApplication.h"
 #include "AccessibleWindow.h"
 #include "AccessibleNode.h"
 #include "IEventSource.h"
@@ -69,34 +68,6 @@ public:
     static AccessibleWatcher *getInstance(AccessibleWatcher *watcherImpl = nullptr);
 
 public:
-    /**
-     * @brief Gets current running application count in device.
-     *
-     * @return application count
-     *
-     * @since_tizen 6.5
-     */
-    virtual int getApplicationCount(void) const = 0;
-
-    /**
-     * @brief Gets application class at specific index.
-     *
-     * @param[in] index application index
-     *
-     * @return @AccessibleApplication ptr
-     *
-     * @since_tizen 6.5
-     */
-    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const = 0;
-
-    /**
-     * @brief Gets application node vector.
-     *
-     * @return @AccessibleApplication vector
-     *
-     * @since_tizen 6.5
-     */
-    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const = 0;
 
     /**
      * @brief Executes runnable command and wait given event.
@@ -161,16 +132,6 @@ public:
      */
     virtual bool getWindowEventEmitted() = 0;
 
-public:
-    /**
-     * @brief Gets active application vector.
-     *
-     * @return @AccessibleApplication vector
-     *
-     * @since_tizen 6.5
-     */
-    virtual std::vector<std::shared_ptr<AccessibleApplication>> getActiveApplications(void) const;
-
 public:
     /**
      * @copydoc @IEventSource::attach()
diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleAppManager.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleAppManager.h
new file mode 100644 (file)
index 0000000..9029375
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2021 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 _ATSPI_ACCESSIBLE_APPMANAGER_H_
+#define _ATSPI_ACCESSIBLE_APPMANAGER_H_
+
+#include "AccessibleAppManager.h"
+
+using namespace Aurum;
+
+namespace AurumInternal {
+
+/**
+ * @internal
+ *
+ * @class AtspiAccessibleAppManager
+ *
+ * @ingroup aurum
+ *
+ * @brief Class that manages a list of application classes
+ */
+class AtspiAccessibleAppManager : public AccessibleAppManager {
+public:
+    AtspiAccessibleAppManager();
+    virtual ~AtspiAccessibleAppManager();
+
+public:
+    /**
+     * @copydoc @AccessibleAppManager::getApplicationCount()
+     */
+    virtual int getApplicationCount(void) const override;
+
+    /**
+     * @copydoc @AccessibleAppManager::getApplicationAt()
+     */
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
+
+    /**
+     * @copydoc @AccessibleAppManager::getApplications()
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
+
+private:
+};
+
+}
+
+#endif
index 283882712a6f021b95f953f6bb6422480afe1003..5ffbc04ed1304a711f1915e59549187d3db6369e 100644 (file)
@@ -102,21 +102,6 @@ public:
     virtual ~AtspiAccessibleWatcher();
 
 public:
-    /**
-     * @copydoc @AccessibleWatcher::getApplicationCount()
-     */
-    virtual int getApplicationCount(void) const override;
-
-    /**
-     * @copydoc @AccessibleWatcher::getApplicationAt()
-     */
-    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
-
-    /**
-     * @copydoc @AccessibleWatcher::getApplications()
-     */
-    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
-
     /**
      * @copydoc @AccessibleWatcher::executeAndWaitForEvents()
      */
diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleAppManager.h b/libaurum/inc/Impl/Accessibility/MockAccessibleAppManager.h
new file mode 100644 (file)
index 0000000..c10f7c1
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2021 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 _MOCK_ACCESSIBLE_APPMANAGER_H_
+#define _MOCK_ACCESSIBLE_APPMANAGER_H_
+
+#include "AccessibleNode.h"
+#include "AccessibleAppManager.h"
+
+#include "MockAccessibleApplication.h"
+
+#include <mutex>
+#include <shared_mutex>
+#include <memory>
+#include <vector>
+
+using namespace Aurum;
+
+namespace AurumInternal {
+
+namespace Mock {
+
+class MockAccessibleAppManager : public AccessibleAppManager {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    MockAccessibleAppManager();
+
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    virtual ~MockAccessibleAppManager();
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    virtual int getApplicationCount(void) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    void addApplication(std::shared_ptr<AccessibleApplication> application);
+
+    /**
+     * @brief TBD
+     * @since_tizen 6.5
+     */
+    std::shared_ptr<MockAccessibleApplication> addApplication(std::string pkgName, Rect<int> geometry, int ifaces, int properties);
+
+private:
+
+    std::vector<std::shared_ptr<AccessibleApplication>> mApplicationList;
+};
+
+}
+
+}
+
+#endif
index 2cff4ae8057c7ba347aea7fc0ce1244bb41b0be3..a00ad64b97dcb7edd2163243b94ed65a9b49a013 100644 (file)
@@ -18,7 +18,6 @@
 #ifndef _MOCK_ACCESSIBLE_WATCHER_H_
 #define _MOCK_ACCESSIBLE_WATCHER_H_
 
-#include "AccessibleNode.h"
 #include "AccessibleWatcher.h"
 
 #include "MockAccessibleApplication.h"
@@ -49,23 +48,6 @@ public:
     virtual ~MockAccessibleWatcher();
 
 public:
-    /**
-     * @brief TBD
-     * @since_tizen 6.5
-     */
-    virtual int getApplicationCount(void) const override;
-
-    /**
-     * @brief TBD
-     * @since_tizen 6.5
-     */
-    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
-
-    /**
-     * @brief TBD
-     * @since_tizen 6.5
-     */
-    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
 
     /**
      * @brief TBD
@@ -82,24 +64,8 @@ public:
     void setXMLsync(bool sync);
 
     bool getWindowEventEmitted();
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 6.5
-     */
-    void addApplication(std::shared_ptr<AccessibleApplication> application);
-
-    /**
-     * @brief TBD
-     * @since_tizen 6.5
-     */
-    std::shared_ptr<MockAccessibleApplication> addApplication(std::string pkgName, Rect<int> geometry, int ifaces, int properties);
 
 private:
-    /**
-     * @brief TBD
-     */
-    std::vector<std::shared_ptr<AccessibleApplication>> mApplicationList;
 
     std::map<AtspiAccessible *, std::shared_ptr<AccessibleApplication>> mActiveAppMap;
     std::map<std::string, std::shared_ptr<AurumXML>> mXMLDocMap;
index 96dfe18bb206a3692bdb2aea45769e0f3b060175..97b50fb4c10e89458cea1497df87768098ec017c 100644 (file)
@@ -18,6 +18,7 @@ libaurum_install_inc = [
   './inc/Comparer.h',
   './inc/AurumXML.h',
   './inc/Accessibility/AccessibleNode.h',
+  './inc/Accessibility/AccessibleAppManager.h',
   './inc/Accessibility/AccessibleWatcher.h',
   './inc/Accessibility/IEventSource.h',
   './inc/Accessibility/AccessibleWindow.h',
diff --git a/libaurum/src/Accessibility/AccessibleAppManager.cc b/libaurum/src/Accessibility/AccessibleAppManager.cc
new file mode 100644 (file)
index 0000000..5479bf1
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ */
+
+#include "Aurum.h"
+
+#ifdef TIZEN
+#include "AtspiAccessibleAppManager.h"
+#endif
+#include "MockAccessibleAppManager.h"
+
+using namespace Aurum;
+using namespace AurumInternal;
+
+AccessibleAppManager::AccessibleAppManager()
+{
+}
+
+AccessibleAppManager::~AccessibleAppManager()
+{
+}
+
+AccessibleAppManager *AccessibleAppManager::getInstance(AccessibleAppManager *appManagerImpl)
+{
+    static AccessibleAppManager *mInstance = nullptr;
+    if (appManagerImpl) {
+        delete mInstance;
+        mInstance = appManagerImpl;
+        return mInstance;
+    } else {
+        if (mInstance) return mInstance;
+        else {
+#ifdef TIZEN
+            mInstance = new AtspiAccessibleAppManager();
+#else
+            mInstance = new MockAccessibleAppManager();
+#endif
+        }
+    }
+    return mInstance;
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> AccessibleAppManager::getActiveApplications(void) const
+{
+    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
+    auto apps = this->getApplications();
+    LOGI("available app process size %d", (int)apps.size());
+
+    apps.erase(std::remove_if(apps.begin(), apps.end(), [](auto app){
+        return !app->isActive();
+    }), apps.end());
+
+    LOGI("active apps size %d", (int)apps.size());
+
+    return apps;
+}
index d26461d88595d4a9e846c6b979a83e82befd877b..86cbce6db9d4728efee2dc39a7cbac6467e73d07 100644 (file)
@@ -59,21 +59,6 @@ AccessibleWatcher *AccessibleWatcher::getInstance(AccessibleWatcher *watcherImpl
     return mInstance;
 }
 
-std::vector<std::shared_ptr<AccessibleApplication>> AccessibleWatcher::getActiveApplications(void) const
-{
-    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
-    auto apps = this->getApplications();
-    LOGI("available app process size %d", (int)apps.size());
-
-    apps.erase(std::remove_if(apps.begin(), apps.end(), [](auto app){
-        return !app->isActive();
-    }), apps.end());
-
-    LOGI("active apps size %d", (int)apps.size());
-
-    return apps;
-}
-
 void AccessibleWatcher::attach(std::shared_ptr<IEventConsumer> source)
 {
     std::unique_lock<std::mutex> lock(mLock);
index 4bb5f1d6a6b50b4e93471a486be9cd5a24c7d80c..652d62ab7087618e9015e6c6486db845fd080830 100644 (file)
@@ -1,6 +1,7 @@
 libaurum_src += [
     files('AccessibleApplication.cc'),
     files('AccessibleNode.cc'),
+    files('AccessibleAppManager.cc'),
     files('AccessibleWatcher.cc'),
     files('AccessibleWindow.cc'),
-]
\ No newline at end of file
+]
diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleAppManager.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleAppManager.cc
new file mode 100644 (file)
index 0000000..3f938a0
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ */
+
+#include "Aurum.h"
+
+#include "AtspiAccessibleAppManager.h"
+#include "AtspiAccessibleApplication.h"
+#include "AtspiWrapper.h"
+#include "AtspiAccessibleNode.h"
+
+using namespace Aurum;
+using namespace AurumInternal;
+
+AtspiAccessibleAppManager::AtspiAccessibleAppManager()
+{
+}
+
+AtspiAccessibleAppManager::~AtspiAccessibleAppManager()
+{
+}
+
+int AtspiAccessibleAppManager::getApplicationCount(void) const
+{
+    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
+    int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL);
+    g_object_unref(root);
+
+    if (nchild <= 0) return 0;
+    return nchild;
+}
+
+std::shared_ptr<AccessibleApplication> AtspiAccessibleAppManager::getApplicationAt(int index) const
+{
+    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
+    AtspiAccessible *child = AtspiWrapper::Atspi_accessible_get_child_at_index(root, index, NULL);
+    g_object_unref(root);
+    return std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child));
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> AtspiAccessibleAppManager::getApplications(void) const
+{
+    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
+    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
+    GArray *children = AtspiWrapper::Atspi_accessible_get_children(root, NULL);
+    if (children) {
+        ret.reserve(children->len);
+        AtspiAccessible *child = nullptr;
+        for (unsigned int i = 0; i < children->len; i++) {
+            child = g_array_index(children, AtspiAccessible *, i);
+            if (child) {
+                ret.push_back(std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child)));
+            }
+        }
+        g_array_free(children, true);
+    }
+    g_object_unref(root);
+
+    return ret;
+}
index 77cfcb734d4b2adc252e3edab7811d801c0fbac0..0d093d11a2db931afeb4830cfc8331d859af6d57 100644 (file)
@@ -18,6 +18,7 @@
 #include "Aurum.h"
 
 #include "AtspiAccessibleWatcher.h"
+#include "AtspiAccessibleAppManager.h"
 #include "AtspiAccessibleApplication.h"
 #include "AtspiAccessibleWindow.h"
 #include "AtspiAccessibleNode.h"
@@ -356,45 +357,6 @@ void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node)
     notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateDefunct, node);
 }
 
-int AtspiAccessibleWatcher::getApplicationCount(void) const
-{
-    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
-    int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL);
-    g_object_unref(root);
-
-    if (nchild <= 0) return 0;
-    return nchild;
-}
-
-std::shared_ptr<AccessibleApplication> AtspiAccessibleWatcher::getApplicationAt(int index) const
-{
-    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
-    AtspiAccessible *child = AtspiWrapper::Atspi_accessible_get_child_at_index(root, index, NULL);
-    g_object_unref(root);
-    return std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child));
-}
-
-std::vector<std::shared_ptr<AccessibleApplication>> AtspiAccessibleWatcher::getApplications(void) const
-{
-    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
-    AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0);
-    GArray *children = AtspiWrapper::Atspi_accessible_get_children(root, NULL);
-    if (children) {
-        ret.reserve(children->len);
-        AtspiAccessible *child = nullptr;
-        for (unsigned int i = 0; i < children->len; i++) {
-            child = g_array_index(children, AtspiAccessible *, i);
-            if (child) {
-                ret.push_back(std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child)));
-            }
-        }
-        g_array_free(children, true);
-    }
-    g_object_unref(root);
-
-    return ret;
-}
-
 bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout, const std::string packageName, std::shared_ptr<AccessibleNode> obj, const int count)
 {
     mMutex.lock();
@@ -579,7 +541,7 @@ void AtspiAccessibleWatcher::setXMLsync(bool sync)
         mAppCount = 0;
         mAppXMLLoadedCount = 0;
     } else {
-        auto apps = getApplications();
+        auto apps = AccessibleAppManager::getInstance()->getApplications();
         for (auto &app : apps)
         {
             app->getAccessibleNode()->updateName();
diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleAppManager.cc b/libaurum/src/Impl/Accessibility/MockAccessibleAppManager.cc
new file mode 100644 (file)
index 0000000..1797224
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ */
+
+#include "MockAccessibleAppManager.h"
+#include "MockAccessibleWindow.h"
+#include "MockAccessibleApplication.h"
+#include "MockAccessibleNode.h"
+
+using namespace Aurum;
+using namespace AurumInternal::Mock;
+
+MockAccessibleAppManager::MockAccessibleAppManager()
+{
+}
+
+MockAccessibleAppManager::~MockAccessibleAppManager()
+{
+}
+
+int MockAccessibleAppManager::getApplicationCount(void) const
+{
+    return mApplicationList.size();
+}
+
+std::shared_ptr<AccessibleApplication> MockAccessibleAppManager::getApplicationAt(int index) const
+{
+    return mApplicationList.at(index);
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> MockAccessibleAppManager::getApplications(void) const
+{
+    return mApplicationList;
+}
+
+void MockAccessibleAppManager::addApplication(std::shared_ptr<AccessibleApplication> application)
+{
+    mApplicationList.push_back(application);
+}
+
+std::shared_ptr<MockAccessibleApplication> MockAccessibleAppManager::addApplication(std::string pkgName, Rect<int> geometry, int ifaces, int properties)
+{
+    std::shared_ptr<MockAccessibleNode> appNode = std::make_shared<MockAccessibleNode>(nullptr, pkgName, pkgName, "application", "", "Elm_Win", "default", "", geometry, ifaces, properties);
+    std::shared_ptr<MockAccessibleApplication> app = std::make_shared<MockAccessibleApplication>(appNode);
+    this->addApplication(app);
+    return app;
+}
\ No newline at end of file
index efe80fac7e5a2c861e404eb7327fffff9b7fbcb7..c9c726b54dc112a456d2034b310a2f29c1eb2d96 100644 (file)
@@ -54,6 +54,7 @@ void MockAccessibleApplication::clearWindows(void)
 
 std::shared_ptr<MockAccessibleWindow> MockAccessibleApplication::addWindow(std::string title, std::string widget, Rect<int> geometry, int properties)
 {
+
     auto node = std::make_shared<MockAccessibleNode>(nullptr, title, title, "window", "res",widget,"style", "", geometry, 0, properties);
     auto win = std::make_shared<MockAccessibleWindow>(shared_from_this(), node);
     this->addWindow(win);
index d56361bec0a8f2072bda01b6a912dab9414718e9..df9bd223619b8368a4df923d0a4fea989341d051 100644 (file)
@@ -30,14 +30,10 @@ MockAccessibleNode::MockAccessibleNode(std::shared_ptr<AccessibleNode> parent, s
     const auto trickDontRemove = std::shared_ptr<MockAccessibleNode>( this, [](MockAccessibleNode *){} );
 
     setProperties(text,pkg,role,res,type,style,automationId, screenBoundingBox, supportingIfaces, featureProperty);
-    auto watcher = AccessibleWatcher::getInstance();
-    watcher->attach(shared_from_this());
 }
 
 MockAccessibleNode::~MockAccessibleNode()
 {
-    auto watcher = AccessibleWatcher::getInstance();
-    watcher->detach(shared_from_this());
 }
 
 int MockAccessibleNode::getChildCount() const
index a3b2f613abd186f0967d5a3fdbbe7def61d1281e..eb661a6fcff97fb7315acdbda16133b44088a26c 100644 (file)
@@ -16,9 +16,6 @@
  */
 
 #include "MockAccessibleWatcher.h"
-#include "MockAccessibleWindow.h"
-#include "MockAccessibleApplication.h"
-#include "MockAccessibleNode.h"
 
 using namespace Aurum;
 using namespace AurumInternal::Mock;
@@ -31,26 +28,6 @@ MockAccessibleWatcher::~MockAccessibleWatcher()
 {
 }
 
-int MockAccessibleWatcher::getApplicationCount(void) const
-{
-    return mApplicationList.size();
-}
-
-std::shared_ptr<AccessibleApplication> MockAccessibleWatcher::getApplicationAt(int index) const
-{
-    return mApplicationList.at(index);
-}
-
-std::vector<std::shared_ptr<AccessibleApplication>> MockAccessibleWatcher::getApplications(void) const
-{
-    return mApplicationList;
-}
-
-void MockAccessibleWatcher::addApplication(std::shared_ptr<AccessibleApplication> application)
-{
-    mApplicationList.push_back(application);
-}
-
 std::map<std::string, std::shared_ptr<AurumXML>> MockAccessibleWatcher::getXMLDocMap(void)
 {
     return mXMLDocMap;
@@ -61,14 +38,6 @@ std::shared_ptr<AurumXML> MockAccessibleWatcher::getXMLDoc(std::string pkgName)
     return std::shared_ptr<AurumXML>();
 }
 
-std::shared_ptr<MockAccessibleApplication> MockAccessibleWatcher::addApplication(std::string pkgName, Rect<int> geometry, int ifaces, int properties)
-{
-    std::shared_ptr<MockAccessibleNode> appNode = std::make_shared<MockAccessibleNode>(nullptr, pkgName, pkgName, "application", "", "Elm_Win", "default", "", geometry, ifaces, properties);
-    std::shared_ptr<MockAccessibleApplication> app = std::make_shared<MockAccessibleApplication>(appNode);
-    this->addApplication(app);
-    return app;
-}
-
 bool MockAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout, const std::string packageName, std::shared_ptr<AccessibleNode> obj, const int count)
 {
     return true;
index f7b23b4e15b289352b1461c68a88d9dd4060258b..b80cd8e20a8f66a3535414064c782deb50b84ce9 100644 (file)
@@ -3,6 +3,7 @@
         files('AtspiAccessibleWindow.cc'),
         files('AtspiAccessibleNode.cc'),
         files('AtspiAccessibleWatcher.cc'),
+        files('AtspiAccessibleAppManager.cc'),
         files('AtspiWrapper.cc'),
         files('AtspiMatchRuleConvertor.cc'),
     ]
@@ -12,4 +13,5 @@
         files('MockAccessibleWindow.cc'),
         files('MockAccessibleNode.cc'),
         files('MockAccessibleWatcher.cc'),
+        files('MockAccessibleAppManager.cc'),
     ]
index 2005deeea5f48a3dc6180bc8f38c57606dab8d67..e9bb481c9bd74b97b0525589f64797a54d2d87c3 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include "Aurum.h"
-#include "AccessibleWatcher.h"
+#include "AccessibleAppManager.h"
 #include "MockDeviceImpl.h"
 
 #include <functional>
@@ -268,7 +268,7 @@ std::vector<std::shared_ptr<AccessibleNode>> MockDeviceImpl::getWindowRoot() con
 {
     std::vector<std::shared_ptr<AccessibleNode>> ret{};
 
-    auto apps = AccessibleWatcher::getInstance()->getApplications();
+    auto apps = AccessibleAppManager::getInstance()->getApplications();
 
     for (auto &app : apps)
     {
index cb06f34cbdf31d58380c6be06f05479d0b3de5f1..22eecd1b18b7fdb0311f8f0cd8794ef115b8fa89 100644 (file)
@@ -454,7 +454,7 @@ std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() co
     std::vector<std::shared_ptr<AccessibleNode>> ret{};
     std::unordered_map<int, std::shared_ptr<AccessibleApplication>> pidToAppNode{};
 
-    auto apps = AccessibleWatcher::getInstance()->getApplications();
+    auto apps = AccessibleAppManager::getInstance()->getApplications();
     for (auto &app : apps)
     {
         app->getAccessibleNode()->updateName();
index 99e6a63e2119f1a9d70879af8f51b9c4d4a48392..15c46b310dd499bcd448dfa6e4a035f117f0acc8 100644 (file)
 #include <iostream>
 #include <algorithm>
 
-#include "MockAccessibleWatcher.h"
 #include "MockAccessibleApplication.h"
 #include "MockAccessibleWindow.h"
 #include "MockAccessibleNode.h"
+#include "MockAccessibleAppManager.h"
 
 class AurumTestMisc : public ::testing::Test {
     public:
index 0853a035cdef0cfe42b862825b454ae751878533..332351cb4acc22284d13f8e13081b2d7f21e0fca 100644 (file)
@@ -11,6 +11,7 @@
 #include <algorithm>
 
 #include "MockAccessibleWatcher.h"
+#include "MockAccessibleAppManager.h"
 #include "MockAccessibleApplication.h"
 #include "MockAccessibleWindow.h"
 #include "MockAccessibleNode.h"
@@ -20,7 +21,7 @@ using namespace AurumInternal::Mock;
 
 class AurumTestSel : public ::testing::Test {
     public:
-        AurumTestSel() : mDevice{nullptr}, mWatcher{nullptr}, mApps{}, mWins{}, mNodes{}{
+        AurumTestSel() : mDevice{nullptr}, mAppManager{nullptr}, mWatcher{nullptr}, mApps{}, mWins{}, mNodes{}{
         }
     protected:
         void SetUp() override {
@@ -30,8 +31,11 @@ class AurumTestSel : public ::testing::Test {
             mWatcher = new MockAccessibleWatcher();
             AccessibleWatcher::getInstance(mWatcher);
 
-            mApps.push_back(mWatcher->addApplication("org.tizen.aurum.test.app1", {0,0,1024,1024}, 0, 0));
-            mApps.push_back(mWatcher->addApplication("org.tizen.aurum.test.app2", {0,0,1024,1024}, 0, 0));
+            mAppManager = new MockAccessibleAppManager();
+            AccessibleAppManager::getInstance(mAppManager);
+
+            mApps.push_back(mAppManager->addApplication("org.tizen.aurum.test.app1", {0,0,1024,1024}, 0, 0));
+            mApps.push_back(mAppManager->addApplication("org.tizen.aurum.test.app2", {0,0,1024,1024}, 0, 0));
 
             mWins.push_back(mApps[0]->addWindow("win1", "Elm_Win", {100,100,200,200}, (int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::ACTIVE));
             mWins.push_back(mApps[0]->addWindow("win2", "Elm_Win", {200,200,200,200}, (int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::ACTIVE));
@@ -48,8 +52,8 @@ class AurumTestSel : public ::testing::Test {
         }
 
         MockDeviceImpl *mDevice;
+        MockAccessibleAppManager *mAppManager;
         MockAccessibleWatcher *mWatcher;
-
         std::vector<std::shared_ptr<MockAccessibleApplication>> mApps;
         std::vector<std::shared_ptr<MockAccessibleWindow>> mWins;
         std::vector<std::shared_ptr<MockAccessibleNode>> mNodes;
@@ -115,4 +119,4 @@ TEST_F(AurumTestSel, depth_N1)
 {
     auto founds = UiDevice::getInstance()->findObjects(Sel::depth(1));
     ASSERT_NE(founds.size(), 10);
-}
\ No newline at end of file
+}
index dbab873be6d912246c78f13c0dea811048dbe33e..c14781cd4b88c9569f746687ee7c645018cca5f6 100644 (file)
@@ -14,6 +14,7 @@
 #include <thread>
 
 #include "MockAccessibleWatcher.h"
+#include "MockAccessibleAppManager.h"
 #include "MockAccessibleApplication.h"
 #include "MockAccessibleWindow.h"
 #include "MockAccessibleNode.h"
@@ -24,7 +25,7 @@ using namespace AurumInternal::Mock;
 class AurumTestUiDevice : public ::testing::Test {
     public:
         AurumTestUiDevice()
-        : mDevice{nullptr}, mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} {
+        : mDevice{nullptr}, mAppManager{nullptr}, mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} {
         }
 
         void SetUp() override {
@@ -34,7 +35,10 @@ class AurumTestUiDevice : public ::testing::Test {
             mWatcher = new MockAccessibleWatcher();
             AccessibleWatcher::getInstance(mWatcher);
 
-            mApp = mWatcher->addApplication("org.tizen.aurum.test.app", {0,0,1024,1024}, 0, 0);
+            mAppManager = new MockAccessibleAppManager();
+            AccessibleAppManager::getInstance(mAppManager);
+
+            mApp = mAppManager->addApplication("org.tizen.aurum.test.app", {0,0,1024,1024}, 0, 0);
             mWin = mApp->addWindow("title", "Elm_Win", {100,100,200,200}, (int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::ACTIVE);
             mWin->addNode("test", "pkg", "TeSt1234!@#$", "res", "type", "style", "", {0,0,100,100}, 0, 0);
             mNode = mWin->addNode("test", "pkg", "TeSt1234!@#$", "res", "type", "style", "", {100,100,200,200}, 0, 0);
@@ -44,6 +48,7 @@ class AurumTestUiDevice : public ::testing::Test {
         }
 
         MockDeviceImpl *mDevice;
+        MockAccessibleAppManager *mAppManager;
         MockAccessibleWatcher *mWatcher;
         std::shared_ptr<MockAccessibleApplication> mApp;
         std::shared_ptr<MockAccessibleWindow> mWin;
index 4b3108f262e1bf979e97438321a424a5e48dddfa..5862284360a8ee699bc44caed5eb9a9c711b3b84 100644 (file)
@@ -15,6 +15,7 @@
 #include <thread>
 
 #include "MockAccessibleWatcher.h"
+#include "MockAccessibleAppManager.h"
 #include "MockAccessibleApplication.h"
 #include "MockAccessibleWindow.h"
 #include "MockAccessibleNode.h"
@@ -24,7 +25,7 @@ using namespace AurumInternal::Mock;
 
 class AurumTestUiObject : public ::testing::Test {
     public:
-        AurumTestUiObject() : mDevice{nullptr},mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} {
+        AurumTestUiObject() : mDevice{nullptr}, mAppManager{nullptr}, mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} {
         }
 
         void SetUp() override {
@@ -34,7 +35,10 @@ class AurumTestUiObject : public ::testing::Test {
             mWatcher = new MockAccessibleWatcher();
             AccessibleWatcher::getInstance(mWatcher);
 
-            mApp = mWatcher->addApplication("org.tizen.aurum.test.app", {0,0,1024,1024}, 0, 0);
+            mAppManager = new MockAccessibleAppManager();
+            AccessibleAppManager::getInstance(mAppManager);
+
+            mApp = mAppManager->addApplication("org.tizen.aurum.test.app", {0,0,1024,1024}, 0, 0);
             mWin = mApp->addWindow("title", "Elm_Win", {100,100,200,200}, (int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::ACTIVE);
             mWin->addNode("test", "pkg", "TeSt1234!@#$", "res", "type", "style", "", {0,0,100,100}, 0, 0);
             mNode = mWin->addNode("test2", "pkg", "TeSt1234!@#$", "res", "type", "style", "", {100,100,200,200}, 0, 0);
@@ -63,6 +67,7 @@ class AurumTestUiObject : public ::testing::Test {
 
     public:
         MockDeviceImpl *mDevice;
+        MockAccessibleAppManager *mAppManager;
         MockAccessibleWatcher *mWatcher;
         std::shared_ptr<MockAccessibleApplication> mApp;
         std::shared_ptr<MockAccessibleWindow> mWin;
index 524c69ddc8a3a0f5fdf709057b706c685c361662..bc783957cf7db3ced3eb47c5049149888dc280e3 100644 (file)
@@ -9,8 +9,11 @@
 
 #include <iostream>
 #include <algorithm>
+#include <chrono>
+#include <thread>
 
 #include "MockAccessibleWatcher.h"
+#include "MockAccessibleAppManager.h"
 #include "MockAccessibleApplication.h"
 #include "MockAccessibleWindow.h"
 #include "MockAccessibleNode.h"
@@ -20,7 +23,7 @@ using namespace AurumInternal::Mock;
 
 class AurumTestUiSelector : public ::testing::Test {
     public:
-        AurumTestUiSelector(): mDevice{nullptr}, mWatcher{nullptr}, mApps{}, mWins{}, mNodes{}{
+        AurumTestUiSelector(): mDevice{nullptr}, mWatcher{nullptr}, mAppManager{nullptr}, mApps{}, mWins{}, mNodes{}{
         }
     protected:
         void SetUp() override {
@@ -30,8 +33,11 @@ class AurumTestUiSelector : public ::testing::Test {
             mWatcher = new MockAccessibleWatcher();
             AccessibleWatcher::getInstance(mWatcher);
 
-            mApps.push_back(mWatcher->addApplication("org.tizen.aurum.test.app1", {0,0,1024,1024}, 0, 0));
-            mApps.push_back(mWatcher->addApplication("org.tizen.aurum.test.app2", {0,0,1024,1024}, 0, 0));
+            mAppManager = new MockAccessibleAppManager();
+            AccessibleAppManager::getInstance(mAppManager);
+
+            mApps.push_back(mAppManager->addApplication("org.tizen.aurum.test.app1", {0,0,1024,1024}, 0, 0));
+            mApps.push_back(mAppManager->addApplication("org.tizen.aurum.test.app2", {0,0,1024,1024}, 0, 0));
 
             mWins.push_back(mApps[0]->addWindow("win1", "Elm_Win", {100,100,200,200}, (int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::ACTIVE));
             mWins.push_back(mApps[0]->addWindow("win2", "Elm_Win", {200,200,200,200}, (int)NodeFeatureProperties::VISIBLE|(int)NodeFeatureProperties::SHOWING|(int)NodeFeatureProperties::ACTIVE));
@@ -50,7 +56,7 @@ class AurumTestUiSelector : public ::testing::Test {
 
         MockDeviceImpl *mDevice;
         MockAccessibleWatcher *mWatcher;
-
+        MockAccessibleAppManager *mAppManager;
         std::vector<std::shared_ptr<MockAccessibleApplication>> mApps;
         std::vector<std::shared_ptr<MockAccessibleWindow>> mWins;
         std::vector<std::shared_ptr<MockAccessibleNode>> mNodes;
index 427edd0598a8a39397f6ac09252b8954c6748816..7d668feaeb9e6ff5acad1ef353a1c1ba79305321 100644 (file)
@@ -24,4 +24,4 @@ foreach atest : test_src
             )
 
     test(atest[0], test_bin)
-endforeach
\ No newline at end of file
+endforeach