libaurum: Fix indentation and clean code up
[platform/core/uifw/aurum.git] / libaurum / src / Impl / Accessibility / MockAccessibleNode.cc
1 #include "MockAccessibleNode.h"
2 #include "AccessibleWatcher.h"
3
4 #include <algorithm>
5 #include <iostream>
6
7 MockAccessibleNode::MockAccessibleNode(std::shared_ptr<AccessibleNode> parent, std::string text, std::string pkg, std::string role, std::string res, std::string type, std::string style,std::string automationId,  Rect<int> boundingBox, int supportingIfaces,int featureProperty)
8 : mParentNode(parent), mChildrenList{}, mActionSet{}
9 {
10     printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
11     const auto trickDontRemove = std::shared_ptr<MockAccessibleNode>( this, [](MockAccessibleNode *){} );
12
13     setProperties(text,pkg,role,res,type,style,automationId, boundingBox, supportingIfaces, featureProperty);
14     auto watcher = AccessibleWatcher::getInstance();
15     watcher->attach(shared_from_this());
16 }
17
18 MockAccessibleNode::~MockAccessibleNode()
19 {
20     printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
21     auto watcher = AccessibleWatcher::getInstance();
22     watcher->detach(shared_from_this());
23 }
24
25 int MockAccessibleNode::getChildCount() const
26 {
27     return mChildrenList.size();
28 }
29
30 std::shared_ptr<AccessibleNode> MockAccessibleNode::getChildAt(int index) const
31 {
32     return mChildrenList.at(index);
33 }
34 std::vector<std::shared_ptr<AccessibleNode>> MockAccessibleNode::getChildren() const
35 {
36     return mChildrenList;
37 }
38
39 std::shared_ptr<AccessibleNode> MockAccessibleNode::getParent() const
40 {
41     return mParentNode;
42 }
43
44 void* MockAccessibleNode::getRawHandler(void) const
45 {
46     printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
47     return (void*)1;
48 }
49
50 void MockAccessibleNode::setProperties(std::string text,std::string pkg,std::string role,std::string id,std::string type,std::string style,std::string automationId, Rect<int> boundingBox,int supportingIfaces,int featureProperty)
51 {
52     mText = text;
53     mPkg = pkg;
54     mRole = role;
55     mId = id;
56     mAutomationId = automationId;
57     mType = type;
58     mStyle = style;
59     mBoundingBox = boundingBox;
60     mSupportingIfaces = supportingIfaces;
61     mFeatureProperty = featureProperty;
62 }
63
64 void MockAccessibleNode::refresh()
65 {
66 }
67
68 std::vector<std::string> MockAccessibleNode::getActions() const
69 {
70     std::vector<std::string> ret{};
71     std::transform(mActionSet.begin(), mActionSet.end(), std::back_inserter(ret), [](auto action){
72         return action;
73     });
74     return ret;
75 }
76
77 bool MockAccessibleNode::doAction(std::string action)
78 {
79     if (mActionSet.find(action) != mActionSet.end()) return true;
80     return false;
81 }
82
83 void MockAccessibleNode::setValue(std::string text)
84 {
85     mText = text;
86 }
87
88 void MockAccessibleNode::setFeatureProperty(int type)
89 {
90     switch(type) {
91         case 1:
92             setFeatureProperty(NodeFeatureProperties::CHECKED, true);
93             break;
94         case 2:
95             setFeatureProperty(NodeFeatureProperties::CHECKABLE, true);
96             break;
97         case 3:
98             setFeatureProperty(NodeFeatureProperties::ENABLED, true);
99             break;
100         case 4:
101             setFeatureProperty(NodeFeatureProperties::FOCUSABLE, true);
102             break;
103         case 5:
104             setFeatureProperty(NodeFeatureProperties::FOCUSED, true);
105             break;
106         case 6:
107             setFeatureProperty(NodeFeatureProperties::SELECTABLE, true);
108             break;
109         case 7:
110             setFeatureProperty(NodeFeatureProperties::SELECTED, true);
111             break;
112         case 8:
113             setFeatureProperty(NodeFeatureProperties::SHOWING, true);
114             break;
115         case 9:
116             setFeatureProperty(NodeFeatureProperties::VISIBLE, true);
117             break;
118         case 10:
119             setFeatureProperty(NodeFeatureProperties::ACTIVE, true);
120             break;
121         case 11:
122             setFeatureProperty(NodeFeatureProperties::CLICKABLE, true);
123             break;
124         case 12:
125         case 13:
126             setFeatureProperty(NodeFeatureProperties::INVALID, true);
127             break;
128     }
129 }
130
131 void MockAccessibleNode::addChild(std::shared_ptr<AccessibleNode> child)
132 {
133     mChildrenList.push_back(child);
134 }
135
136 std::shared_ptr<MockAccessibleNode> MockAccessibleNode::addChild(std::string text, std::string pkg, std::string role, std::string res, std::string type, std::string style, std::string automationId, Rect<int> geometry, int ifaces, int properties)
137 {
138     auto node = std::make_shared<MockAccessibleNode>(shared_from_this(), text, pkg, role, res, type, style, automationId, geometry, ifaces, properties);
139     this->addChild(node);
140     return node;
141 }
142
143 void MockAccessibleNode::clearChildren(void)
144 {
145     mChildrenList.clear();
146 }
147
148 void MockAccessibleNode::addAction(std::string action)
149 {
150     mActionSet.insert(action);
151 }
152
153 void MockAccessibleNode::clearActions(void)
154 {
155     mActionSet.clear();
156 }