Fix to default Shadow Color setting
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextLabel.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 void dali_textlabel_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void dali_textlabel_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 namespace
37 {
38
39 const char* const PROPERTY_NAME_RENDERING_BACKEND = "rendering-backend";
40 const char* const PROPERTY_NAME_TEXT = "text";
41 const char* const PROPERTY_NAME_FONT_FAMILY = "font-family";
42 const char* const PROPERTY_NAME_FONT_STYLE = "font-style";
43 const char* const PROPERTY_NAME_POINT_SIZE = "point-size";
44 const char* const PROPERTY_NAME_MULTI_LINE =  "multi-line";
45 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontal-alignment";
46 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "vertical-alignment";
47 const char* const PROPERTY_NAME_TEXT_COLOR = "text-color";
48 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadow-offset";
49 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadow-color";
50 const char* const PROPERTY_NAME_UNDERLINE_ENABLED = "underline-enabled";
51 const char* const PROPERTY_NAME_UNDERLINE_COLOR = "underline-color";
52
53 static bool gObjectCreatedCallBackCalled;
54
55 static void TestCallback(BaseHandle handle)
56 {
57   gObjectCreatedCallBackCalled = true;
58 }
59
60 } // namespace
61
62 int UtcDaliTextLabelNew(void)
63 {
64   ToolkitTestApplication application;
65   TextLabel label = TextLabel::New("Test Text");
66   DALI_TEST_CHECK( label );
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     TextLabel label = TextLabel::New("Test Text");
76   }
77   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
78   END_TEST;
79 }
80
81 int UtcDaliTextLabelGetSetProperty(void)
82 {
83   ToolkitTestApplication application;
84   TextLabel label = TextLabel::New("Test Text");
85   DALI_TEST_CHECK( label );
86
87   // Check Property Indices are correct
88   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextLabel::Property::RENDERING_BACKEND );
89   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextLabel::Property::TEXT );
90   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextLabel::Property::FONT_FAMILY );
91   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextLabel::Property::FONT_STYLE );
92   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextLabel::Property::POINT_SIZE );
93   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_MULTI_LINE ) == TextLabel::Property::MULTI_LINE );
94   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextLabel::Property::HORIZONTAL_ALIGNMENT );
95   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextLabel::Property::VERTICAL_ALIGNMENT );
96   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextLabel::Property::TEXT_COLOR );
97   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextLabel::Property::SHADOW_OFFSET );
98   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextLabel::Property::SHADOW_COLOR );
99   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_ENABLED ) == TextLabel::Property::UNDERLINE_ENABLED );
100   DALI_TEST_CHECK( label.GetPropertyIndex( PROPERTY_NAME_UNDERLINE_COLOR ) == TextLabel::Property::UNDERLINE_COLOR );
101
102   // Check label defaults are correct
103   DALI_TEST_EQUALS( label.GetProperty<int>( TextLabel::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
104   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
105   DALI_TEST_EQUALS( label.GetProperty<Vector2>( TextLabel::Property::SHADOW_OFFSET ), Vector2::ZERO, TEST_LOCATION );
106   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::SHADOW_COLOR ), Color::BLACK, TEST_LOCATION );
107   DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::UNDERLINE_ENABLED ), false, TEST_LOCATION );
108
109   // Check that text can be correctly reset
110   label.SetProperty( TextLabel::Property::TEXT, "Setting Text" );
111   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), "Setting Text", TEST_LOCATION );
112
113   // Check that the Alignment properties can be correctly set
114   label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "BEGIN" );
115   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::HORIZONTAL_ALIGNMENT ), "BEGIN", TEST_LOCATION );
116   label.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "TOP" );
117   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::VERTICAL_ALIGNMENT ), "TOP", TEST_LOCATION );
118
119   // Check that shadow parameters can be correctly set
120   label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 3.0f, 3.0f ) );
121   DALI_TEST_EQUALS( label.GetProperty<Vector2>( TextLabel::Property::SHADOW_OFFSET ), Vector2( 3.0f, 3.0f ), TEST_LOCATION );
122   label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLUE );
123   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::SHADOW_COLOR ), Color::BLUE, TEST_LOCATION );
124
125   // Check that underline parameters can be correctly set
126   label.SetProperty( TextLabel::Property::UNDERLINE_ENABLED, true );
127   DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::UNDERLINE_ENABLED ), true, TEST_LOCATION );
128   label.SetProperty( TextLabel::Property::UNDERLINE_COLOR, Color::RED );
129   DALI_TEST_EQUALS( label.GetProperty<Vector4>( TextLabel::Property::UNDERLINE_COLOR ), Color::RED, TEST_LOCATION );
130
131   // Toggle multi-line
132   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
133   DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::MULTI_LINE ), true, TEST_LOCATION );
134   END_TEST;
135 }
136
137 int utcDaliTextlabelBasicRender(void)
138 {
139   ToolkitTestApplication application;
140   TextLabel label = TextLabel::New("Test Text");
141   DALI_TEST_CHECK( label );
142
143   label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "BEGIN" );
144   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
145
146   try
147   {
148     // Render some text with the basic backend
149     label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_BASIC );
150     application.SendNotification();
151     application.Render();
152   }
153   catch( ... )
154   {
155     tet_result(TET_FAIL);
156   }
157   END_TEST;
158 }
159
160 int utcDaliTextlabelAtlasRender(void)
161 {
162   ToolkitTestApplication application;
163   TextLabel label = TextLabel::New("Test Text");
164   DALI_TEST_CHECK( label );
165
166   // Turn on all the effects
167   label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
168   label.SetProperty( TextLabel::Property::MULTI_LINE, true );
169   label.SetProperty( TextLabel::Property::UNDERLINE_ENABLED, true );
170   label.SetProperty( TextLabel::Property::UNDERLINE_COLOR, Color::RED );
171   label.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
172   label.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLUE );
173   try
174   {
175     // Render some text with the shared atlas backend
176     label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
177     application.SendNotification();
178     application.Render();
179   }
180   catch( ... )
181   {
182     tet_result(TET_FAIL);
183   }
184   END_TEST;
185 }
186