[dali_1.0.36] Merge branch 'tizen'
[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
37
38 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
39 {
40   BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
41
42   // Create the image
43   PixelBuffer* pixbuf = imageData.GetBuffer();
44   unsigned int size = width * height;
45
46   for( size_t i = 0; i < size; i++ )
47     {
48       pixbuf[i*4+0] = 0xFF * color.r;
49       pixbuf[i*4+1] = 0xFF * color.g;
50       pixbuf[i*4+2] = 0xFF * color.b;
51       pixbuf[i*4+3] = 0xFF * color.a;
52     }
53
54   imageData.Update();
55
56   return imageData;
57 }
58
59 } // namespace
60
61
62 void checkbox_button_startup(void)
63 {
64   test_return_value = TET_UNDEF;
65 }
66
67 void checkbox_button_cleanup(void)
68 {
69   test_return_value = TET_PASS;
70 }
71
72 int UtcDaliCheckBoxButtonSetGetSelected(void)
73 {
74   ToolkitTestApplication application;
75   tet_infoline(" UtcDaliCheckBoxButtonSetGetSelected");
76
77   CheckBoxButton checkBoxButton = CheckBoxButton::New();
78   checkBoxButton.StateChangedSignal().Connect( &CheckBoxButtonClicked );
79
80   // global var used to check if CheckBoxButtonClicked is called;
81   gCheckBoxButtonState = false;
82
83   checkBoxButton.SetSelected( true );
84
85   DALI_TEST_CHECK( checkBoxButton.IsSelected() );
86   DALI_TEST_CHECK( gCheckBoxButtonState );
87
88   checkBoxButton.SetSelected( false );
89
90   DALI_TEST_CHECK( !checkBoxButton.IsSelected() );
91   DALI_TEST_CHECK( !gCheckBoxButtonState );
92
93   checkBoxButton.SetSelected( true );
94
95   DALI_TEST_CHECK( checkBoxButton.IsSelected() );
96   DALI_TEST_CHECK( gCheckBoxButtonState );
97   END_TEST;
98 }
99
100 int UtcDaliCheckBoxButtonSetImages(void)
101 {
102   ToolkitTestApplication application;
103   tet_infoline(" UtcDaliCheckBoxButtonSetImages");
104
105   Actor imageActor;
106
107   Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
108   ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
109   imageActor01.SetSize( 20, 20 );
110
111   Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
112   ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
113   imageActor02.SetSize( 40, 40 );
114   imageActor02.SetName( "imageActor02" );
115
116   Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
117   ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
118   imageActor03.SetSize( 60, 60 );
119
120   Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
121   ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
122   imageActor04.SetSize( 80, 80 );
123
124   Vector3 size;
125   CheckBoxButton checkBoxButton = CheckBoxButton::New();
126   checkBoxButton.SetName( "UtcDaliCheckBoxButtonSetImages" );
127   Stage::GetCurrent().Add( checkBoxButton );
128
129   application.SendNotification();
130   application.Render();
131
132   // Just check if check box button size changes when a bigger image is set.
133
134   checkBoxButton.SetBackgroundImage( image01 );
135
136   application.SendNotification();
137   application.Render();
138
139   size = checkBoxButton.GetCurrentSize();
140
141   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
142   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
143
144   checkBoxButton.SetBackgroundImage( imageActor01 );
145
146   END_TEST;
147 }