libaurum: apply smart pointer wider and extract impl out
[platform/core/uifw/aurum.git] / tests / ua_test.cpp
1 #include <gtest/gtest.h>
2
3 #include <UiDevice.h>
4 #include <UiObject.h>
5 #include <UiSelector.h>
6 #include <Sel.h>
7
8 #include "MockDeviceImpl.h"
9
10 #include <iostream>
11 #include <algorithm>
12
13 #include <loguru.hpp>
14
15
16 #include "MockAccessibleWatcher.h"
17 #include "MockAccessibleApplication.h"
18 #include "MockAccessibleWindow.h"
19 #include "MockAccessibleNode.h"
20
21
22 class UaTest : public ::testing::Test {
23     public:
24         UaTest(){
25             /*const char *logPath = "/tmp/ua.log";
26             loguru::g_preamble = false;
27             loguru::add_file(logPath, loguru::Append, loguru::Verbosity_MAX);*/
28         }
29     protected:
30         void SetUp() override {
31         }
32
33         void TearDown() override {
34         }
35 };
36
37
38 TEST_F(UaTest, EmptyTest)
39 {
40     ASSERT_EQ(true, true);
41 }
42
43
44
45 TEST_F(UaTest, DeviceInit)
46 {
47     std::shared_ptr<UiDevice> mDevice1 = UiDevice::getInstance(nullptr);
48     ASSERT_NE(mDevice1, nullptr);
49 }
50
51
52 TEST_F(UaTest, TextSelector)
53 {
54     std::shared_ptr<UiSelector> sel = Sel::text("test");
55     ASSERT_NE(sel.get(), nullptr);
56     auto result = UiDevice::getInstance()->findObjects(sel);
57     std::for_each(result.begin(), result.end(), [](auto obj){
58         std::cout << obj->getText() << std::endl;
59     });
60     ASSERT_EQ(nullptr, nullptr);
61 }
62
63 TEST_F(UaTest, DeviceClick)
64 {
65     auto result = UiDevice::getInstance()->click(1,2);
66     ASSERT_EQ(result, false);
67 }
68
69 TEST_F(UaTest, FindElement)
70 {
71     auto watcher = AccessibleWatcher::getInstance();
72
73     MockAccessibleWatcher *mockWatcher = dynamic_cast<MockAccessibleWatcher*>(const_cast<AccessibleWatcher*>(watcher));
74
75     std::shared_ptr<MockAccessibleNode> appNode = std::make_shared<MockAccessibleNode>(nullptr, "text", "pkg", "application", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
76     std::shared_ptr<MockAccessibleApplication> app = std::make_shared<MockAccessibleApplication>(appNode);
77     mockWatcher->addApplication(app);
78
79     std::shared_ptr<MockAccessibleNode> winNode = std::make_shared<MockAccessibleNode>(nullptr, "text", "pkg", "window", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
80     std::shared_ptr<MockAccessibleWindow> win = std::make_shared<MockAccessibleWindow>(app, winNode);
81     winNode->setFeatureProperty(8);
82     winNode->setFeatureProperty(9);
83     winNode->setFeatureProperty(10);
84     app->addWindow(win);
85
86     std::shared_ptr<MockAccessibleNode> node = std::make_shared<MockAccessibleNode>(nullptr, "test", "pkg", "ahahah", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
87     winNode->addChild(node);
88
89     std::shared_ptr<UiSelector> sel = Sel::text("test");
90     auto result = UiDevice::getInstance()->findObjects(sel);
91     std::for_each(result.begin(), result.end(), [](auto obj){
92         ASSERT_EQ(obj->getRole(), "ahahah");
93     });
94
95     ASSERT_EQ(nullptr, nullptr);
96 }