Merge "Remove .clang-format file from toolkit/automated-tests" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / dali-toolkit-test-utils / accessibility-test-utils.cpp
1 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/accessibility-test-utils.h>
2 #include <dali-toolkit-test-suite-utils.h>
3 #include <dali/devel-api/common/stage.h>
4 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
5 #include <dali/devel-api/atspi-interfaces/accessible.h>
6 #include "dbus-wrapper.h"
7
8 namespace Dali
9 {
10 namespace Accessibility
11 {
12   using MethodType = TestDBusWrapper::MethodType;
13   using MessagePtr = DBusWrapper::MessagePtr;
14
15   static bool gMoveOutedCalled = false;
16
17   void TestEnableSC(bool b)
18   {
19     static bool firstTime = true;
20     if (b && firstTime)
21     {
22       firstTime = false;
23       auto bridge = Accessibility::Bridge::GetCurrentBridge();
24       Dali::Stage stage = Dali::Stage::GetCurrent();
25       auto accessible = Accessibility::Accessible::Get( stage.GetRootLayer(), true );
26       bridge->AddTopLevelWindow( accessible );
27       bridge->SetApplicationName( "TestApp" );
28       bridge->Initialize();
29
30       static bool ScreenReaderEnabled = false;
31       static bool IsEnabled = false;
32
33       auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
34
35       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/bus", "org.a11y.Status", "ScreenReaderEnabled", MethodType::Getter}] = [wr](const MessagePtr &m) -> MessagePtr {
36           auto reply = wr->newReplyMessage(m);
37           wr->Encode(reply, std::tuple<TestDBusWrapper::Variant<bool>>{ ScreenReaderEnabled });
38           return reply;
39       };
40       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/bus", "org.a11y.Status", "IsEnabled", MethodType::Getter}] = [wr](const MessagePtr &m) -> MessagePtr {
41           auto reply = wr->newReplyMessage(m);
42           wr->Encode(reply, std::tuple<TestDBusWrapper::Variant<bool>>{ IsEnabled });
43           return reply;
44       };
45       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/bus", "org.a11y.Bus", "GetAddress", MethodType::Method}] = [wr](const MessagePtr &m) -> MessagePtr {
46           auto reply = wr->newReplyMessage(m);
47           wr->Encode(reply, std::tuple<const char*>{ "bus" });
48           return reply;
49       };
50       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible/root", "org.a11y.atspi.Socket", "Embed", MethodType::Method}] = [wr](const MessagePtr &m) -> MessagePtr {
51           auto reply = wr->newReplyMessage(m);
52           wr->Encode(reply, std::tuple<Address>{ {"bus", "root"} });
53           return reply;
54       };
55       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "PropertyChange", MethodType::Method}] =
56       [wr](const MessagePtr &m) -> MessagePtr {
57           return wr->newReplyMessage(m);
58       };
59       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "StateChanged", MethodType::Method}] =
60       [wr](const MessagePtr &m) -> MessagePtr {
61           return wr->newReplyMessage(m);
62       };
63       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "BoundsChanged", MethodType::Method}] =
64       [wr](const MessagePtr &m) -> MessagePtr {
65           return wr->newReplyMessage(m);
66       };
67       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "ActiveDescendantChanged", MethodType::Method}] =
68       [wr](const MessagePtr &m) -> MessagePtr {
69           return wr->newReplyMessage(m);
70       };
71       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextChanged", MethodType::Method}] =
72       [wr](const MessagePtr &m) -> MessagePtr {
73           return wr->newReplyMessage(m);
74       };
75       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextCaretMoved", MethodType::Method}] =
76       [wr](const MessagePtr &m) -> MessagePtr {
77           return wr->newReplyMessage(m);
78       };
79       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "MoveOuted", MethodType::Method}] =
80       [wr](const MessagePtr &m) -> MessagePtr {
81           gMoveOutedCalled = true;
82           return wr->newReplyMessage(m);
83       };
84
85       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Activate", MethodType::Method}] =
86       [wr](const MessagePtr &m) -> MessagePtr {
87           return wr->newReplyMessage(m);
88       };
89       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Deactivate", MethodType::Method}] =
90       [wr](const MessagePtr &m) -> MessagePtr {
91           return wr->newReplyMessage(m);
92       };
93     }
94     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
95     wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "ScreenReaderEnabled", b);
96     wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "IsEnabled", b);
97   }
98
99   std::vector<Address> TestGetChildren(const Address &adr)
100   {
101     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
102     auto chs = wr->fromTestCall<std::vector<Address>>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildren", std::tuple<>());
103     return std::move(std::get<0>(chs));
104   }
105
106   std::string TestGetName(const Address &adr)
107   {
108     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
109     auto name = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Name");
110     return name;
111   }
112
113   std::string TestGetDescription(const Address &adr)
114   {
115     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
116     auto description = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Description");
117     return description;
118   }
119
120   uint32_t TestGetRole(const Address &adr)
121   {
122     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
123     auto chs = wr->fromTestCall<uint32_t>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRole", std::tuple<>());
124     return std::move(std::get<0>(chs));
125   }
126
127   std::string TestGetRoleName(const Address &adr)
128   {
129     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
130     auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRoleName", std::tuple<>());
131     return std::move(std::get<0>(chs));
132   }
133
134   Address TestGetParent(const Address &adr)
135   {
136     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
137     auto chs = wr->fromTestGet< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "Parent");
138     return chs;
139   }
140
141   std::string TestGetLocalizedRoleName(const Address &adr)
142   {
143     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
144     auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetLocalizedRoleName", std::tuple<>());
145     return std::move(std::get<0>(chs));
146   }
147
148   std::array< uint32_t, 2 > TestGetStates(const Address &adr)
149   {
150     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
151     auto chs = wr->fromTestCall<std::array< uint32_t, 2 >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetState", std::tuple<>());
152     return std::move(std::get<0>(chs));
153   }
154
155   std::unordered_map< std::string, std::string > TestGetAttributes(const Address &adr)
156   {
157     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
158     auto chs = wr->fromTestCall<std::unordered_map< std::string, std::string >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetAttributes", std::tuple<>());
159     return std::move(std::get<0>(chs));
160   }
161
162   bool TestDoGesture(const Address &adr, Dali::Accessibility::Gesture type, int32_t xBeg, int32_t xEnd, int32_t yBeg, int32_t yEnd, Dali::Accessibility::GestureState state, uint32_t eventTime)
163   {
164     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
165     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Accessible", "DoGesture",
166         std::tuple< Dali::Accessibility::Gesture, int32_t, int32_t, int32_t, int32_t, Dali::Accessibility::GestureState, uint32_t >(type, xBeg, xEnd, yBeg, yEnd, state, eventTime ));
167     return std::move(std::get<0>(chs));
168   }
169
170   std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > TestGetRelationSet(const Address &adr)
171   {
172     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
173     auto chs = wr->fromTestCall< std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRelationSet", std::tuple<>());
174     return std::move(std::get<0>(chs));
175   }
176
177   Address TestGetChildAtIndex(const Address &adr, int index)
178   {
179     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
180     auto chs = wr->fromTestCall< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildAtIndex", std::tuple< int >( index ));
181     return std::move(std::get<0>(chs));
182   }
183
184   ComponentLayer TestGetLayer(const Address &adr)
185   {
186     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
187     auto chs = wr->fromTestCall< Dali::Accessibility::ComponentLayer >(adr.GetPath(), "org.a11y.atspi.Component", "GetLayer", std::tuple<>());
188     return std::move(std::get<0>(chs));
189   }
190
191   int TestGetIndexInParent(const Address &adr)
192   {
193     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
194     auto chs = wr->fromTestCall< int >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetIndexInParent", std::tuple<>());
195     return std::move(std::get<0>(chs));
196   }
197
198   bool TestGrabFocus(const Address &adr)
199   {
200     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
201     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabFocus", std::tuple<>());
202     return std::move(std::get<0>(chs));
203   }
204
205   bool TestGrabHighlight(const Address &adr)
206   {
207     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
208     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabHighlight", std::tuple<>());
209     return std::move(std::get<0>(chs));
210   }
211
212   bool TestClearHighlight(const Address &adr)
213   {
214     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
215     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "ClearHighlight", std::tuple<>());
216     return std::move(std::get<0>(chs));
217   }
218
219   std::tuple< int32_t, int32_t, int32_t, int32_t > TestGetExtents(const Address &adr, Dali::Accessibility::CoordinateType coordinateType)
220   {
221     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
222     auto chs = wr->fromTestCall< std::tuple< int32_t, int32_t, int32_t, int32_t > >(adr.GetPath(), "org.a11y.atspi.Component", "GetExtents", std::make_tuple(static_cast<uint32_t>(coordinateType)));
223     return std::move(std::get<0>(chs));
224   }
225
226   int TestGetMdiZOrder(const Address &adr)
227   {
228     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
229     auto chs = wr->fromTestCall< int16_t >(adr.GetPath(), "org.a11y.atspi.Component", "GetMDIZOrder", std::tuple<>());
230     return std::move(std::get<0>(chs));
231   }
232
233   double TestGetAlpha(const Address &adr)
234   {
235     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
236     auto chs = wr->fromTestCall< double >(adr.GetPath(), "org.a11y.atspi.Component", "GetAlpha", std::tuple<>());
237     return std::move(std::get<0>(chs));
238   }
239
240   std::string TestGetActionName(const Address &adr, size_t index)
241   {
242     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
243     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetName", std::tuple< int32_t >( index ));
244     return std::move(std::get<0>(chs));
245   }
246
247   std::string TestGetLocalizedActionName(const Address &adr, size_t index)
248   {
249     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
250     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetLocalizedName", std::tuple< int32_t >( index ));
251     return std::move(std::get<0>(chs));
252   }
253
254   size_t TestGetActionCount(const Address &adr)
255   {
256     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
257     auto count = wr->fromTestGet< int32_t >(adr.GetPath(), "org.a11y.atspi.Action", "NActions");
258     return count;
259   }
260
261   bool TestDoAction(const Address &adr, size_t index)
262   {
263     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
264     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoAction", std::tuple< int32_t >( index ));
265     return std::move(std::get<0>(chs));
266   }
267
268   bool TestDoAction(const Address &adr, const std::string& name)
269   {
270     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
271     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoActionName", std::tuple< std::string >( name ));
272     return std::move(std::get<0>(chs));
273   }
274
275   std::string TestGetActionKeyBinding(const Address &adr, size_t index)
276   {
277     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
278     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetKeyBinding", std::tuple< int32_t >( index ));
279     return std::move(std::get<0>(chs));
280   }
281
282   std::string TestGetActionDescription(const Address &adr, size_t index)
283   {
284     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
285     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetDescription", std::tuple< int32_t >( index ));
286     return std::move(std::get<0>(chs));
287   }
288
289   void TestResetMoveOutedCalled ()
290   {
291     gMoveOutedCalled = false;
292   }
293
294   bool TestGetMoveOutedCalled ()
295   {
296     return gMoveOutedCalled;
297   }
298
299   void PrintTree(const Address &root, size_t depth)
300   {
301     auto name = TestGetName(root);
302     printf("%10s", root.GetPath().c_str());
303     for(unsigned int i = 0; i < depth; ++i) printf("  ");
304     printf("%s\n", name.c_str());
305     auto chs = TestGetChildren(root);
306     for(auto &c : chs)
307     {
308       PrintTree(c, depth + 1);
309     }
310   }
311
312   bool Find(const std::vector< std::string > &collection, const std::string &key)
313   {
314     for(auto& it : collection)
315     {
316       if(it == key)
317       {
318         return true;
319       }
320     }
321     return false;
322   }
323
324 } // namespace Accessibility
325 } // namespace Dali