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-bridge.h>
5 #include <dali/devel-api/atspi-interfaces/accessible.h>
6 #include "dbus-wrapper.h"
10 namespace Accessibility
12 using MethodType = TestDBusWrapper::MethodType;
13 using MessagePtr = DBusWrapper::MessagePtr;
15 static bool gMoveOutedCalled = false;
17 void TestEnableSC(bool b)
19 static bool firstTime = true;
23 auto bridge = Accessibility::Bridge::GetCurrentBridge();
24 Dali::Stage stage = Dali::Stage::GetCurrent();
25 auto accessible = Accessibility::Accessible::Get( stage.GetRootLayer(), true );
26 bridge->AddTopLevelWindow( accessible );
27 bridge->SetApplicationName( "TestApp" );
30 static bool ScreenReaderEnabled = false;
31 static bool IsEnabled = false;
33 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
35 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 {
36 auto reply = wr->newReplyMessage(m);
37 wr->Encode(reply, std::tuple<TestDBusWrapper::Variant<bool>>{ ScreenReaderEnabled });
40 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 {
41 auto reply = wr->newReplyMessage(m);
42 wr->Encode(reply, std::tuple<TestDBusWrapper::Variant<bool>>{ IsEnabled });
45 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 {
46 auto reply = wr->newReplyMessage(m);
47 wr->Encode(reply, std::tuple<const char*>{ "bus" });
50 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 {
51 auto reply = wr->newReplyMessage(m);
52 wr->Encode(reply, std::tuple<Address>{ {"bus", "root"} });
55 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "PropertyChange", MethodType::Method}] =
56 [wr](const MessagePtr &m) -> MessagePtr {
57 return wr->newReplyMessage(m);
59 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "StateChanged", MethodType::Method}] =
60 [wr](const MessagePtr &m) -> MessagePtr {
61 return wr->newReplyMessage(m);
63 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "BoundsChanged", MethodType::Method}] =
64 [wr](const MessagePtr &m) -> MessagePtr {
65 return wr->newReplyMessage(m);
67 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "ActiveDescendantChanged", MethodType::Method}] =
68 [wr](const MessagePtr &m) -> MessagePtr {
69 return wr->newReplyMessage(m);
71 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextChanged", MethodType::Method}] =
72 [wr](const MessagePtr &m) -> MessagePtr {
73 return wr->newReplyMessage(m);
75 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "TextCaretMoved", MethodType::Method}] =
76 [wr](const MessagePtr &m) -> MessagePtr {
77 return wr->newReplyMessage(m);
79 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Object", "MoveOuted", MethodType::Method}] =
80 [wr](const MessagePtr &m) -> MessagePtr {
81 gMoveOutedCalled = true;
82 return wr->newReplyMessage(m);
85 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Activate", MethodType::Method}] =
86 [wr](const MessagePtr &m) -> MessagePtr {
87 return wr->newReplyMessage(m);
89 wr->testMethods[std::tuple<std::string, std::string, std::string, MethodType>{"/org/a11y/atspi/accessible", "org.a11y.atspi.Event.Window", "Deactivate", MethodType::Method}] =
90 [wr](const MessagePtr &m) -> MessagePtr {
91 return wr->newReplyMessage(m);
94 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
95 wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "ScreenReaderEnabled", b);
96 wr->fromTestChangeProperty("/org/a11y/bus", "org.a11y.Status", "IsEnabled", b);
99 std::vector<Address> TestGetChildren(const Address &adr)
101 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
102 auto chs = wr->fromTestCall<std::vector<Address>>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildren", std::tuple<>());
103 return std::move(std::get<0>(chs));
106 std::string TestGetName(const Address &adr)
108 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
109 auto name = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Name");
113 std::string TestGetDescription(const Address &adr)
115 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
116 auto description = wr->fromTestGet<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "Description");
120 uint32_t TestGetRole(const Address &adr)
122 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
123 auto chs = wr->fromTestCall<uint32_t>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRole", std::tuple<>());
124 return std::move(std::get<0>(chs));
127 std::string TestGetRoleName(const Address &adr)
129 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
130 auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRoleName", std::tuple<>());
131 return std::move(std::get<0>(chs));
134 Address TestGetParent(const Address &adr)
136 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
137 auto chs = wr->fromTestGet< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "Parent");
141 std::string TestGetLocalizedRoleName(const Address &adr)
143 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
144 auto chs = wr->fromTestCall<std::string>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetLocalizedRoleName", std::tuple<>());
145 return std::move(std::get<0>(chs));
148 std::array< uint32_t, 2 > TestGetStates(const Address &adr)
150 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
151 auto chs = wr->fromTestCall<std::array< uint32_t, 2 >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetState", std::tuple<>());
152 return std::move(std::get<0>(chs));
155 std::unordered_map< std::string, std::string > TestGetAttributes(const Address &adr)
157 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
158 auto chs = wr->fromTestCall<std::unordered_map< std::string, std::string >>(adr.GetPath(), "org.a11y.atspi.Accessible", "GetAttributes", std::tuple<>());
159 return std::move(std::get<0>(chs));
162 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)
164 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
165 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Accessible", "DoGesture",
166 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 ));
167 return std::move(std::get<0>(chs));
170 std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > TestGetRelationSet(const Address &adr)
172 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
173 auto chs = wr->fromTestCall< std::vector< std::tuple< uint32_t, std::vector< Dali::Accessibility::Address > > > >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetRelationSet", std::tuple<>());
174 return std::move(std::get<0>(chs));
177 Address TestGetChildAtIndex(const Address &adr, int index)
179 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
180 auto chs = wr->fromTestCall< Address >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetChildAtIndex", std::tuple< int >( index ));
181 return std::move(std::get<0>(chs));
184 ComponentLayer TestGetLayer(const Address &adr)
186 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
187 auto chs = wr->fromTestCall< Dali::Accessibility::ComponentLayer >(adr.GetPath(), "org.a11y.atspi.Component", "GetLayer", std::tuple<>());
188 return std::move(std::get<0>(chs));
191 int TestGetIndexInParent(const Address &adr)
193 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
194 auto chs = wr->fromTestCall< int >(adr.GetPath(), "org.a11y.atspi.Accessible", "GetIndexInParent", std::tuple<>());
195 return std::move(std::get<0>(chs));
198 bool TestGrabFocus(const Address &adr)
200 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
201 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabFocus", std::tuple<>());
202 return std::move(std::get<0>(chs));
205 bool TestGrabHighlight(const Address &adr)
207 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
208 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "GrabHighlight", std::tuple<>());
209 return std::move(std::get<0>(chs));
212 bool TestClearHighlight(const Address &adr)
214 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
215 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Component", "ClearHighlight", std::tuple<>());
216 return std::move(std::get<0>(chs));
219 std::tuple< int32_t, int32_t, int32_t, int32_t > TestGetExtents(const Address &adr, Dali::Accessibility::CoordinateType coordinateType)
221 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
222 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)));
223 return std::move(std::get<0>(chs));
226 int TestGetMdiZOrder(const Address &adr)
228 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
229 auto chs = wr->fromTestCall< int16_t >(adr.GetPath(), "org.a11y.atspi.Component", "GetMDIZOrder", std::tuple<>());
230 return std::move(std::get<0>(chs));
233 double TestGetAlpha(const Address &adr)
235 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
236 auto chs = wr->fromTestCall< double >(adr.GetPath(), "org.a11y.atspi.Component", "GetAlpha", std::tuple<>());
237 return std::move(std::get<0>(chs));
240 std::string TestGetActionName(const Address &adr, size_t index)
242 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
243 auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetName", std::tuple< int32_t >( index ));
244 return std::move(std::get<0>(chs));
247 std::string TestGetLocalizedActionName(const Address &adr, size_t index)
249 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
250 auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetLocalizedName", std::tuple< int32_t >( index ));
251 return std::move(std::get<0>(chs));
254 size_t TestGetActionCount(const Address &adr)
256 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
257 auto count = wr->fromTestGet< int32_t >(adr.GetPath(), "org.a11y.atspi.Action", "NActions");
261 bool TestDoAction(const Address &adr, size_t index)
263 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
264 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoAction", std::tuple< int32_t >( index ));
265 return std::move(std::get<0>(chs));
268 bool TestDoAction(const Address &adr, const std::string& name)
270 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
271 auto chs = wr->fromTestCall< bool >(adr.GetPath(), "org.a11y.atspi.Action", "DoActionName", std::tuple< std::string >( name ));
272 return std::move(std::get<0>(chs));
275 std::string TestGetActionKeyBinding(const Address &adr, size_t index)
277 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
278 auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetKeyBinding", std::tuple< int32_t >( index ));
279 return std::move(std::get<0>(chs));
282 std::string TestGetActionDescription(const Address &adr, size_t index)
284 auto wr = static_cast<TestDBusWrapper*>(DBusWrapper::Installed());
285 auto chs = wr->fromTestCall< std::string >(adr.GetPath(), "org.a11y.atspi.Action", "GetDescription", std::tuple< int32_t >( index ));
286 return std::move(std::get<0>(chs));
289 void TestResetMoveOutedCalled ()
291 gMoveOutedCalled = false;
294 bool TestGetMoveOutedCalled ()
296 return gMoveOutedCalled;
299 void PrintTree(const Address &root, size_t depth)
301 auto name = TestGetName(root);
302 printf("%10s", root.GetPath().c_str());
303 for(unsigned int i = 0; i < depth; ++i) printf(" ");
304 printf("%s\n", name.c_str());
305 auto chs = TestGetChildren(root);
308 PrintTree(c, depth + 1);
312 bool Find(const std::vector< std::string > &collection, const std::string &key)
314 for(auto& it : collection)
324 } // namespace Accessibility