2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
24 using namespace Toolkit;
26 void dali_textlabel_startup(void)
28 test_return_value = TET_UNDEF;
31 void dali_textlabel_cleanup(void)
33 test_return_value = TET_PASS;
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";
53 static bool gObjectCreatedCallBackCalled;
55 static void TestCallback(BaseHandle handle)
57 gObjectCreatedCallBackCalled = true;
62 int UtcDaliTextLabelNew(void)
64 ToolkitTestApplication application;
65 TextLabel label = TextLabel::New("Test Text");
66 DALI_TEST_CHECK( label );
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 );
72 gObjectCreatedCallBackCalled = false;
73 registry.ObjectCreatedSignal().Connect(&TestCallback);
75 TextLabel label = TextLabel::New("Test Text");
77 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
81 int UtcDaliTextLabelGetSetProperty(void)
83 ToolkitTestApplication application;
84 TextLabel label = TextLabel::New("Test Text");
85 DALI_TEST_CHECK( label );
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 );
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 ), Vector4::ZERO, TEST_LOCATION );
107 DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::UNDERLINE_ENABLED ), false, TEST_LOCATION );
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 );
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 );
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 );
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 );
132 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
133 DALI_TEST_EQUALS( label.GetProperty<bool>( TextLabel::Property::MULTI_LINE ), true, TEST_LOCATION );
137 int utcDaliTextlabelBasicRender(void)
139 ToolkitTestApplication application;
140 TextLabel label = TextLabel::New("Test Text");
141 DALI_TEST_CHECK( label );
143 label.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "BEGIN" );
144 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
148 // Render some text with the basic backend
149 label.SetProperty( TextLabel::Property::RENDERING_BACKEND, Text::RENDERING_BASIC );
150 application.SendNotification();
151 application.Render();
155 tet_result(TET_FAIL);
160 int utcDaliTextlabelAtlasRender(void)
162 ToolkitTestApplication application;
163 TextLabel label = TextLabel::New("Test Text");
164 DALI_TEST_CHECK( label );
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 );
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();
182 tet_result(TET_FAIL);