Merge "Make DoCreatePropertyMap use index key" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Accessibility-Accessible.cpp
1 /**
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25
26 #include <dali/devel-api/adaptor-framework/accessibility.h>
27 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
28 #include <dali/devel-api/atspi-interfaces/accessible.h>
29
30 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
31
32 void utc_dali_toolkit_accessibility_accessible_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35   DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
36 }
37
38 void utc_dali_toolkit_accessibility_accessible_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int utcDaliAccessibilityCheckBoxButtonGetStates(void)
44 {
45   ToolkitTestApplication application;
46
47   auto check_box_button = Toolkit::CheckBoxButton::New();
48   auto q = Dali::Accessibility::Accessible::Get( check_box_button );
49   DALI_TEST_CHECK( q );
50   auto states = q->GetStates();
51   DALI_TEST_EQUALS( (int) states[ Dali::Accessibility::State::SELECTABLE ], (int) true, TEST_LOCATION );
52
53   END_TEST;
54 }
55
56 int utcDaliAccessibilityCheckLabelText(void)
57 {
58   ToolkitTestApplication application;
59
60   auto check_box_button = Toolkit::CheckBoxButton::New();
61   //check_box_button.SetLabelText( "button" );
62   check_box_button.SetProperty(Toolkit::Button::Property::LABEL, "button");
63   auto q = Dali::Accessibility::Accessible::Get( check_box_button );
64   DALI_TEST_CHECK( q );
65   DALI_TEST_EQUALS( q->GetName(), "button", TEST_LOCATION );
66
67   END_TEST;
68 }
69
70 int UtcDaliAccessibilityCheckShowingState(void)
71 {
72   ToolkitTestApplication application;
73
74   auto parentButton = Toolkit::PushButton::New();
75   parentButton.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
76   parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
77   parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
78   parentButton.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
79   parentButton.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
80   application.GetScene().Add( parentButton );
81
82   // Toatally inside of parent
83   auto buttonA = Toolkit::PushButton::New();
84   buttonA.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
85   buttonA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
86   buttonA.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
87   buttonA.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
88   parentButton.Add(buttonA);
89
90   // Toatally outside of parent
91   auto buttonB = Toolkit::PushButton::New();
92   buttonB.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
93   buttonB.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
94   buttonB.SetProperty(Actor::Property::POSITION, Dali::Vector2(300.0f, 300.0f));
95   buttonB.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
96   parentButton.Add(buttonB);
97
98   // Partially inside of parent
99   auto buttonC = Toolkit::PushButton::New();
100   buttonC.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
101   buttonC.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
102   buttonC.SetProperty(Actor::Property::POSITION, Dali::Vector2(100.0f,100.0f));
103   buttonC.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
104   parentButton.Add(buttonC);
105
106   application.SendNotification();
107   application.Render(16);
108
109   auto q = Dali::Accessibility::Accessible::Get(buttonA);
110   DALI_TEST_CHECK(q);
111   auto states = q->GetStates();
112   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
113
114   q = Dali::Accessibility::Accessible::Get(buttonB);
115   DALI_TEST_CHECK(q);
116   states = q->GetStates();
117   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
118
119   q = Dali::Accessibility::Accessible::Get(buttonC);
120   DALI_TEST_CHECK(q);
121   states = q->GetStates();
122   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
123
124   // Make SHOWING object invisible
125   buttonC.SetProperty(Actor::Property::VISIBLE, false);
126
127   application.SendNotification();
128   application.Render(16);
129
130   states = q->GetStates();
131   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
132
133   // Make SHOWING parent invisible
134   parentButton.SetProperty(Actor::Property::VISIBLE, false);
135
136   application.SendNotification();
137   application.Render(16);
138
139   q = Dali::Accessibility::Accessible::Get(buttonA);
140   DALI_TEST_CHECK(q);
141   states = q->GetStates();
142   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
143
144   END_TEST;
145 }
146
147 int utcDaliAccessibilityHidden(void)
148 {
149   ToolkitTestApplication application;
150
151   auto  control    = Toolkit::Control::New();
152   auto* accessible = Dali::Accessibility::Accessible::Get(control);
153
154   // Check not hidden
155   DALI_TEST_CHECK(accessible);
156   DALI_TEST_CHECK(!accessible->IsHidden());
157   DALI_TEST_CHECK(!control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
158
159   control.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
160
161   // Check hidden
162   DALI_TEST_CHECK(accessible->IsHidden());
163   DALI_TEST_CHECK(control.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN));
164
165   END_TEST;
166 }