Raised test coverage for Model3dView
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-CheckBoxButton.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
23 using namespace Dali;
24 using namespace Toolkit;
25
26 namespace
27 {
28
29 static bool gCheckBoxButtonState = false;
30 bool CheckBoxButtonClicked( Button button )
31 {
32   gCheckBoxButtonState = button.IsSelected();
33   return true;
34 }
35
36 } // namespace
37
38 void checkbox_button_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void checkbox_button_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 int UtcDaliCheckBoxButtonConstructorP(void)
49 {
50   TestApplication application;
51
52   CheckBoxButton checkBox;
53
54   DALI_TEST_CHECK( !checkBox );
55   END_TEST;
56 }
57
58 int UtcDaliCheckBoxButtonCopyConstructorP(void)
59 {
60   TestApplication application;
61
62   // Initialize an object, ref count == 1
63   CheckBoxButton checkBox = CheckBoxButton::New();
64
65   CheckBoxButton copy( checkBox );
66   DALI_TEST_CHECK( copy );
67   END_TEST;
68 }
69
70 int UtcDaliCheckBoxButtonAssignmentOperatorP(void)
71 {
72   TestApplication application;
73
74   CheckBoxButton checkBox = CheckBoxButton::New();
75
76   CheckBoxButton copy( checkBox );
77   DALI_TEST_CHECK( copy );
78
79   DALI_TEST_CHECK( checkBox == copy );
80   END_TEST;
81 }
82
83 int UtcDaliCheckBoxButtonNewP(void)
84 {
85   TestApplication application;
86
87   CheckBoxButton checkBox = CheckBoxButton::New();
88
89   DALI_TEST_CHECK( checkBox );
90   END_TEST;
91 }
92
93 int UtcDaliCheckBoxButtonDownCastP(void)
94 {
95   TestApplication application;
96
97   CheckBoxButton checkBox = CheckBoxButton::New();
98
99   BaseHandle object(checkBox);
100
101   CheckBoxButton checkBox2 = CheckBoxButton::DownCast( object );
102   DALI_TEST_CHECK(checkBox2);
103
104   CheckBoxButton checkBox3 = DownCast< CheckBoxButton >(object);
105   DALI_TEST_CHECK(checkBox3);
106   END_TEST;
107 }
108
109 int UtcDaliCheckBoxButtonDownCastN(void)
110 {
111   TestApplication application;
112
113   BaseHandle unInitializedObject;
114
115   CheckBoxButton checkBox1 = CheckBoxButton::DownCast( unInitializedObject );
116   DALI_TEST_CHECK( !checkBox1 );
117
118   CheckBoxButton checkBox2 = DownCast< CheckBoxButton >( unInitializedObject );
119   DALI_TEST_CHECK( !checkBox2 );
120   END_TEST;
121 }
122
123 int UtcDaliCheckBoxButtonSetGetSelected(void)
124 {
125   ToolkitTestApplication application;
126   tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected");
127
128   CheckBoxButton checkBoxButton = CheckBoxButton::New();
129   checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked );
130
131   // global var used to check if CheckBoxButtonClicked is called;
132   gCheckBoxButtonState = false;
133
134   checkBoxButton.SetSelected( true );
135
136   DALI_TEST_CHECK( checkBoxButton.IsSelected() );
137   DALI_TEST_CHECK( gCheckBoxButtonState );
138
139   checkBoxButton.SetSelected( false );
140
141   DALI_TEST_CHECK( !checkBoxButton.IsSelected() );
142   DALI_TEST_CHECK( !gCheckBoxButtonState );
143
144   checkBoxButton.SetSelected( true );
145
146   DALI_TEST_CHECK( checkBoxButton.IsSelected() );
147   DALI_TEST_CHECK( gCheckBoxButtonState );
148   END_TEST;
149 }
150
151 int UtcDaliCheckBoxSetLabelP(void)
152 {
153   TestApplication application;
154
155   CheckBoxButton checkBox = CheckBoxButton::New();
156
157   Property::Map propertyMap;
158   propertyMap.Insert("text",  "activate");
159   checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap );
160
161   DALI_TEST_EQUALS( checkBox.GetLabelText(), "activate", TEST_LOCATION ); // Change to use GerProperty once that code is implemented
162
163   END_TEST;
164 }
165
166 int UtcDaliCheckBoxSetLabelDisabledP(void)
167 {
168   TestApplication application;
169
170   CheckBoxButton checkBox = CheckBoxButton::New();
171   Stage::GetCurrent().Add( checkBox );
172
173   checkBox.SetSize( Vector2( 20.0f, 20.0f ) );
174   checkBox.SetDisabledBackgroundImage( "Image.jpg" );
175
176   application.SendNotification();
177   application.Render();
178
179   Property::Map propertyMap;
180   propertyMap.Insert("text",  "activate");
181   checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true);
182
183   checkBox.SetProperty( checkBox.GetPropertyIndex("label"), propertyMap );
184
185   DALI_TEST_CHECK(  checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
186   DALI_TEST_EQUALS( checkBox.GetLabelText(), "activate", TEST_LOCATION ); // Change to use GerProperty once that code is implemented
187
188   END_TEST;
189 }
190
191 int UtcDaliCheckBoxSettingDisabled(void)
192 {
193   ToolkitTestApplication application;
194
195   CheckBoxButton checkBox = CheckBoxButton::New();
196
197   checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), true);
198   DALI_TEST_CHECK(  checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
199
200   checkBox.SetProperty(checkBox.GetPropertyIndex("disabled"), false);
201
202   DALI_TEST_CHECK(  !checkBox.GetProperty<bool>(checkBox.GetPropertyIndex("disabled")) );
203
204   END_TEST;
205 }