Merge "Remove .clang-format file from toolkit/automated-tests" 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
25 #include <dali/devel-api/adaptor-framework/accessibility.h>
26 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
27 #include <dali/devel-api/atspi-interfaces/accessible.h>
28
29 #include <automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/dbus-wrapper.h>
30
31 void utc_dali_toolkit_accessibility_accessible_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34   DBusWrapper::Install(std::unique_ptr<DBusWrapper>(new TestDBusWrapper));
35 }
36
37 void utc_dali_toolkit_accessibility_accessible_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 int utcDaliAccessibilityCheckBoxButtonGetStates(void)
43 {
44   ToolkitTestApplication application;
45
46   auto check_box_button = Toolkit::CheckBoxButton::New();
47   auto q = Dali::Accessibility::Accessible::Get( check_box_button );
48   DALI_TEST_CHECK( q );
49   auto states = q->GetStates();
50   DALI_TEST_EQUALS( (int) states[ Dali::Accessibility::State::SELECTABLE ], (int) true, TEST_LOCATION );
51
52   END_TEST;
53 }
54
55 int utcDaliAccessibilityCheckLabelText(void)
56 {
57   ToolkitTestApplication application;
58
59   auto check_box_button = Toolkit::CheckBoxButton::New();
60   //check_box_button.SetLabelText( "button" );
61   check_box_button.SetProperty(Toolkit::Button::Property::LABEL, "button");
62   auto q = Dali::Accessibility::Accessible::Get( check_box_button );
63   DALI_TEST_CHECK( q );
64   DALI_TEST_EQUALS( q->GetName(), "button", TEST_LOCATION );
65
66   END_TEST;
67 }
68
69 int UtcDaliAccessibilityCheckShowingState(void)
70 {
71   ToolkitTestApplication application;
72
73   auto parentButton = Toolkit::PushButton::New();
74   parentButton.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
75   parentButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
76   parentButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
77   parentButton.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
78   parentButton.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
79   application.GetScene().Add( parentButton );
80
81   // Toatally inside of parent
82   auto buttonA = Toolkit::PushButton::New();
83   buttonA.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
84   buttonA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
85   buttonA.SetProperty(Actor::Property::POSITION, Dali::Vector2(0.0f, 0.0f));
86   buttonA.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
87   parentButton.Add(buttonA);
88
89   // Toatally outside of parent
90   auto buttonB = Toolkit::PushButton::New();
91   buttonB.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
92   buttonB.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
93   buttonB.SetProperty(Actor::Property::POSITION, Dali::Vector2(300.0f, 300.0f));
94   buttonB.SetProperty(Actor::Property::SIZE, Dali::Vector2(100.0f, 100.0f));
95   parentButton.Add(buttonB);
96
97   // Partially inside of parent
98   auto buttonC = Toolkit::PushButton::New();
99   buttonC.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
100   buttonC.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
101   buttonC.SetProperty(Actor::Property::POSITION, Dali::Vector2(100.0f,100.0f));
102   buttonC.SetProperty(Actor::Property::SIZE, Dali::Vector2(200.0f, 200.0f));
103   parentButton.Add(buttonC);
104
105   application.SendNotification();
106   application.Render(16);
107
108   auto q = Dali::Accessibility::Accessible::Get(buttonA);
109   DALI_TEST_CHECK(q);
110   auto states = q->GetStates();
111   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
112
113   q = Dali::Accessibility::Accessible::Get(buttonB);
114   DALI_TEST_CHECK(q);
115   states = q->GetStates();
116   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
117
118   q = Dali::Accessibility::Accessible::Get(buttonC);
119   DALI_TEST_CHECK(q);
120   states = q->GetStates();
121   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) true, TEST_LOCATION);
122
123   // Make SHOWING object invisible
124   buttonC.SetProperty(Actor::Property::VISIBLE, false);
125
126   application.SendNotification();
127   application.Render(16);
128
129   states = q->GetStates();
130   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
131
132   // Make SHOWING parent invisible
133   parentButton.SetProperty(Actor::Property::VISIBLE, false);
134
135   application.SendNotification();
136   application.Render(16);
137
138   q = Dali::Accessibility::Accessible::Get(buttonA);
139   DALI_TEST_CHECK(q);
140   states = q->GetStates();
141   DALI_TEST_EQUALS((int) states[Dali::Accessibility::State::SHOWING], (int) false, TEST_LOCATION);
142
143   END_TEST;
144 }