[dali_2.3.20] Merge branch '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() );
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/root", "org.a11y.atspi.Socket", "Unembed", MethodType::Method}] = [wr](const MessagePtr &m) -> MessagePtr {
56           return wr->newReplyMessage(m);
57       };
58       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible/root", "org.a11y.atspi.Socket", "Embedded", MethodType::Method}] = [wr](const MessagePtr &m) -> MessagePtr {
59           return wr->newReplyMessage(m);
60       };
61       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "PropertyChange", MethodType::Method}] =
62       [wr](const MessagePtr &m) -> MessagePtr {
63           return wr->newReplyMessage(m);
64       };
65       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "StateChanged", MethodType::Method}] =
66       [wr](const MessagePtr &m) -> MessagePtr {
67           return wr->newReplyMessage(m);
68       };
69       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "BoundsChanged", MethodType::Method}] =
70       [wr](const MessagePtr &m) -> MessagePtr {
71           return wr->newReplyMessage(m);
72       };
73       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "ActiveDescendantChanged", MethodType::Method}] =
74       [wr](const MessagePtr &m) -> MessagePtr {
75           return wr->newReplyMessage(m);
76       };
77       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextChanged", MethodType::Method}] =
78       [wr](const MessagePtr &m) -> MessagePtr {
79           return wr->newReplyMessage(m);
80       };
81       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextCaretMoved", MethodType::Method}] =
82       [wr](const MessagePtr &m) -> MessagePtr {
83           return wr->newReplyMessage(m);
84       };
85       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "MoveOuted", MethodType::Method}] =
86       [wr](const MessagePtr &m) -> MessagePtr {
87           gMoveOutedCalled = true;
88           return wr->newReplyMessage(m);
89       };
90
91       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Activate", MethodType::Method}] =
92       [wr](const MessagePtr &m) -> MessagePtr {
93           return wr->newReplyMessage(m);
94       };
95       wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Deactivate", MethodType::Method}] =
96       [wr](const MessagePtr &m) -> MessagePtr {
97           return wr->newReplyMessage(m);
98       };
99     }
100     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
101     wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "ScreenReaderEnabled", b);
102     wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "IsEnabled", b);
103   }
104
105   std::vector<Address> TestGetChildren(const Address &adr)
106   {
107     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
108     auto chs = wr->fromTestCall<std::vector<Address>>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildren", std::tuple<>());
109     return std::move(std::get<0>(chs));
110   }
111
112   std::string TestGetName(const Address &adr)
113   {
114     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
115     auto name = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Name");
116     return name;
117   }
118
119   std::string TestGetDescription(const Address &adr)
120   {
121     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
122     auto description = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Description");
123     return description;
124   }
125
126   uint32_t TestGetRole(const Address &adr)
127   {
128     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
129     auto chs = wr->fromTestCall<uint32_t>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRole", std::tuple<>());
130     return std::move(std::get<0>(chs));
131   }
132
133   std::string TestGetRoleName(const Address &adr)
134   {
135     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
136     auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRoleName", std::tuple<>());
137     return std::move(std::get<0>(chs));
138   }
139
140   Address TestGetParent(const Address &adr)
141   {
142     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
143     auto chs = wr->fromTestGet< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "Parent");
144     return chs;
145   }
146
147   std::string TestGetLocalizedRoleName(const Address &adr)
148   {
149     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
150     auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetLocalizedRoleName", std::tuple<>());
151     return std::move(std::get<0>(chs));
152   }
153
154   std::array< uint32_t, 2 > TestGetStates(const Address &adr)
155   {
156     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
157     auto chs = wr->fromTestCall<std::array< uint32_t, 2 >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetState", std::tuple<>());
158     return std::move(std::get<0>(chs));
159   }
160
161   std::unordered_map< std::string, std::string > TestGetAttributes(const Address &adr)
162   {
163     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
164     auto chs = wr->fromTestCall<std::unordered_map< std::string, std::string >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetAttributes", std::tuple<>());
165     return std::move(std::get<0>(chs));
166   }
167
168   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)
169   {
170     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
171     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Accessible", "DoGesture",
172         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 ));
173     return std::move(std::get<0>(chs));
174   }
175
176   std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > TestGetRelationSet(const Address &adr)
177   {
178     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
179     auto chs = wr->fromTestCall< std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRelationSet", std::tuple<>());
180     return std::move(std::get<0>(chs));
181   }
182
183   Address TestGetChildAtIndex(const Address &adr, int index)
184   {
185     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
186     auto chs = wr->fromTestCall< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildAtIndex", std::tuple< int >( index ));
187     return std::move(std::get<0>(chs));
188   }
189
190   ComponentLayer TestGetLayer(const Address &adr)
191   {
192     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
193     auto chs = wr->fromTestCall< Dali::Accessibility::ComponentLayer >(adr.GetPath(), "org.a11y.atspi.Component", "GetLayer", std::tuple<>());
194     return std::move(std::get<0>(chs));
195   }
196
197   int TestGetIndexInParent(const Address &adr)
198   {
199     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
200     auto chs = wr->fromTestCall< int >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetIndexInParent", std::tuple<>());
201     return std::move(std::get<0>(chs));
202   }
203
204   bool TestGrabFocus(const Address &adr)
205   {
206     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
207     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabFocus", std::tuple<>());
208     return std::move(std::get<0>(chs));
209   }
210
211   bool TestGrabHighlight(const Address &adr)
212   {
213     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
214     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabHighlight", std::tuple<>());
215     return std::move(std::get<0>(chs));
216   }
217
218   bool TestClearHighlight(const Address &adr)
219   {
220     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
221     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "ClearHighlight", std::tuple<>());
222     return std::move(std::get<0>(chs));
223   }
224
225   std::tuple< int32_t, int32_t, int32_t, int32_t > TestGetExtents(const Address &adr, Dali::Accessibility::CoordinateType coordinateType)
226   {
227     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
228     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)));
229     return std::move(std::get<0>(chs));
230   }
231
232   int TestGetMdiZOrder(const Address &adr)
233   {
234     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
235     auto chs = wr->fromTestCall< int16_t >(adr.GetPath(), "org.a11y.atspi.Component", "GetMDIZOrder", std::tuple<>());
236     return std::move(std::get<0>(chs));
237   }
238
239   double TestGetAlpha(const Address &adr)
240   {
241     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
242     auto chs = wr->fromTestCall< double >(adr.GetPath(), "org.a11y.atspi.Component", "GetAlpha", std::tuple<>());
243     return std::move(std::get<0>(chs));
244   }
245
246   std::string TestGetActionName(const Address &adr, size_t index)
247   {
248     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
249     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetName", std::tuple< int32_t >( index ));
250     return std::move(std::get<0>(chs));
251   }
252
253   std::string TestGetLocalizedActionName(const Address &adr, size_t index)
254   {
255     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
256     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetLocalizedName", std::tuple< int32_t >( index ));
257     return std::move(std::get<0>(chs));
258   }
259
260   size_t TestGetActionCount(const Address &adr)
261   {
262     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
263     auto count = wr->fromTestGet< int32_t >(adr.GetPath(), "org.a11y.atspi.Action", "NActions");
264     return count;
265   }
266
267   bool TestDoAction(const Address &adr, size_t index)
268   {
269     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
270     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoAction", std::tuple< int32_t >( index ));
271     return std::move(std::get<0>(chs));
272   }
273
274   bool TestDoAction(const Address &adr, const std::string& name)
275   {
276     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
277     auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoActionName", std::tuple< std::string >( name ));
278     return std::move(std::get<0>(chs));
279   }
280
281   std::string TestGetActionKeyBinding(const Address &adr, size_t index)
282   {
283     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
284     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetKeyBinding", std::tuple< int32_t >( index ));
285     return std::move(std::get<0>(chs));
286   }
287
288   std::string TestGetActionDescription(const Address &adr, size_t index)
289   {
290     auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
291     auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetDescription", std::tuple< int32_t >( index ));
292     return std::move(std::get<0>(chs));
293   }
294
295   void TestResetMoveOutedCalled ()
296   {
297     gMoveOutedCalled = false;
298   }
299
300   bool TestGetMoveOutedCalled ()
301   {
302     return gMoveOutedCalled;
303   }
304
305   void PrintTree(const Address &root, size_t depth)
306   {
307     auto name = TestGetName(root);
308     printf("%10s", root.GetPath().c_str());
309     for(unsigned int i = 0; i < depth; ++i) printf("  ");
310     printf("%s\n", name.c_str());
311     auto chs = TestGetChildren(root);
312     for(auto &c : chs)
313     {
314       PrintTree(c, depth + 1);
315     }
316   }
317
318   bool Find(const std::vector< std::string > &collection, const std::string &key)
319   {
320     for(auto& it : collection)
321     {
322       if(it == key)
323       {
324         return true;
325       }
326     }
327     return false;
328   }
329
330 } // namespace Accessibility
331 } // namespace Dali