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