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