Initial removal of Text features
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-RadioButton.cpp
1 /*
2  * Copyright (c) 2014 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 #include <iostream>
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23
24
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27
28 void dali_radio_button_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void dali_radio_button_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40
41 static bool gObjectCreatedCallBackCalled;
42
43 static void TestCallback(BaseHandle handle)
44 {
45   gObjectCreatedCallBackCalled = true;
46 }
47
48 }
49
50 int UtcDaliRadioButtonNew(void)
51 {
52   ToolkitTestApplication application;
53   tet_infoline(" UtcDaliRadioButtonNew");
54
55   // Create the Slider actor
56   RadioButton radioButton;
57
58   DALI_TEST_CHECK( !radioButton );
59
60   radioButton = RadioButton::New();
61
62   DALI_TEST_CHECK( radioButton );
63
64   RadioButton radioButton2(radioButton);
65
66   DALI_TEST_CHECK( radioButton2 == radioButton );
67
68   //Additional check to ensure object is created by checking if it's registered
69   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
70   DALI_TEST_CHECK( registry );
71
72   gObjectCreatedCallBackCalled = false;
73   registry.ObjectCreatedSignal().Connect( &TestCallback );
74   {
75     RadioButton radioButton = RadioButton::New();
76   }
77   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
78   END_TEST;
79 }
80
81 int UtcDaliRadioButtonDestructor(void)
82 {
83   ToolkitTestApplication application;
84
85   RadioButton* radioButton = new RadioButton();
86   delete radioButton;
87
88   DALI_TEST_CHECK( true );
89   END_TEST;
90 }
91
92 int UtcDaliRadioButtonDownCast(void)
93 {
94   ToolkitTestApplication application;
95
96   Handle handle = RadioButton::New();
97
98   RadioButton radioButton = RadioButton::DownCast( handle );
99
100   DALI_TEST_CHECK( radioButton == handle );
101   END_TEST;
102 }
103
104 int UtcDaliRadioButtonLabelActor(void)
105 {
106   // TODO
107   END_TEST;
108 }
109
110 int UtcDaliRadioButtonActive(void)
111 {
112   ToolkitTestApplication application;
113
114   RadioButton radioButton = RadioButton::New();
115
116   // Default active
117   DALI_TEST_CHECK( radioButton.IsActive() == false );
118
119   // False to true
120   radioButton.ToggleState();
121   DALI_TEST_CHECK( radioButton.IsActive() == true );
122
123   // True to false
124   radioButton.ToggleState();
125   DALI_TEST_CHECK( radioButton.IsActive() == false );
126
127   // False
128   radioButton.SetActive( false );
129   DALI_TEST_CHECK( radioButton.IsActive() == false );
130
131   // True
132   radioButton.SetActive( true );
133   DALI_TEST_CHECK( radioButton.IsActive() == true );
134
135   // False
136   radioButton.SetActive( false );
137   DALI_TEST_CHECK( radioButton.IsActive() == false );
138
139   END_TEST;
140 }
141
142 int UtcDaliRadioButtonActiveProperty(void)
143 {
144   ToolkitTestApplication application;  // Exceptions require ToolkitTestApplication
145   tet_infoline(" UtcDaliRadioButtonActiveProperty");
146
147   // Create the RadioButton actor
148   RadioButton radioButton = RadioButton::New();
149   Stage::GetCurrent().Add( radioButton );
150   radioButton.SetParentOrigin(ParentOrigin::TOP_LEFT);
151   radioButton.SetAnchorPoint(ParentOrigin::TOP_LEFT);
152   radioButton.SetPosition( 0.0f, 0.0f );
153
154   // Default active
155   DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
156
157   // Setting false active
158   radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, false );
159   DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
160
161   // Setting true active
162   radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, true );
163   DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
164
165   // Setting false again
166   radioButton.SetProperty( RadioButton::PROPERTY_ACTIVE, false );
167   DALI_TEST_CHECK( radioButton.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
168
169   // Test selecting radio buttons
170   RadioButton radioButton2 = RadioButton::New( "label" );
171   radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);
172   radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);
173   radioButton2.SetPosition( 0.0f, 0.0f );
174
175   RadioButton radioButton3 = RadioButton::New( "label" );
176   radioButton3.SetParentOrigin(ParentOrigin::TOP_LEFT);
177   radioButton3.SetAnchorPoint(ParentOrigin::TOP_LEFT);
178   radioButton3.SetPosition( 0.0f, 40.0f );
179
180   Actor radioGroup = Actor::New();
181   Stage::GetCurrent().Add( radioGroup );
182   radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);
183   radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);
184   radioGroup.SetPosition( 0.0f, 0.0f );
185   radioGroup.SetSize( 400.0f, 400.0 );
186
187   radioGroup.Add( radioButton2 );
188   radioGroup.Add( radioButton3 );
189
190   application.SendNotification();
191   application.Render();
192
193   // Simulate touch events
194   DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
195   DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
196
197   // Select first radio
198   {
199     Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
200
201     const Dali::TouchPoint pointUp( 0, TouchPoint::Up, 10.0f, 10.0f );
202     event.AddPoint( pointUp );
203
204     application.ProcessEvent( event );
205
206     application.SendNotification();
207     application.Render();
208
209     DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
210     DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
211   }
212
213   // Select an already selected radio
214   {
215     Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
216
217     const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 10.0f );
218     event.AddPoint( pointDown );
219
220     application.ProcessEvent( event );
221
222     application.SendNotification();
223     application.Render();
224
225     DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
226     DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
227   }
228
229   // Select second radio
230   {
231     Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
232
233     const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 50.0f );
234     event.AddPoint( pointDown );
235
236     application.ProcessEvent( event );
237
238     application.SendNotification();
239     application.Render();
240
241     DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
242     DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
243   }
244
245   // Select outside radio group
246   {
247     Dali::Integration::TouchEvent event = Dali::Integration::TouchEvent();
248
249     const Dali::TouchPoint pointDown( 0, TouchPoint::Up, 10.0f, 500.0f );
250     event.AddPoint( pointDown );
251
252     application.ProcessEvent( event );
253
254     application.SendNotification();
255     application.Render();
256
257     DALI_TEST_CHECK( radioButton2.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == false );
258     DALI_TEST_CHECK( radioButton3.GetProperty<bool>( RadioButton::PROPERTY_ACTIVE ) == true );
259   }
260
261   END_TEST;
262 }