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