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