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