2 * Copyright (c) 2016 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.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-model.h>
26 #include <dali-toolkit/internal/text/markup-processor.h>
27 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
28 #include <dali-toolkit/internal/text/color-run.h>
29 #include <dali-toolkit/internal/text/font-description-run.h>
30 #include <dali-toolkit/internal/text/text-definitions.h>
31 #include <dali-toolkit/internal/text/text-io.h>
34 using namespace Toolkit;
39 ///////////////////////////////////////////////////////////
41 struct TokenComparisonData
43 std::string description;
44 std::string string1; ///< must be in lower case!!!!
49 bool TokenComparisonTest( const TokenComparisonData& data )
51 std::cout << " testing " << data.description << std::endl;
53 const bool result = TokenComparison( data.string1,
55 data.string2.size() );
57 if( result != data.expectedResult )
59 std::cout << " different conparison result : " << result << ", expected : " << data.expectedResult << std::endl;
60 std::cout << " comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl;
68 ///////////////////////////////////////////////////////////
70 struct ColorStringToVector4Data
72 std::string description;
74 Vector4 expectedColor;
77 bool ColorStringToVector4Test( const ColorStringToVector4Data& data )
79 std::cout << " testing " << data.description << std::endl;
82 ColorStringToVector4( data.colorStr.c_str(), data.colorStr.size(), color );
84 if( color != data.expectedColor )
86 std::cout << " different color : " << color << ", expected : " << data.expectedColor << std::endl;
93 ///////////////////////////////////////////////////////////
95 struct Vector4ToColorStringData
97 std::string description;
99 std::string expectedColorStr;
102 bool Vector4ToColorStringTest( const Vector4ToColorStringData& data )
104 std::cout << " testing " << data.description << std::endl;
106 std::string colorStr;
107 Vector4ToColorString( data.color, colorStr );
109 if( colorStr != data.expectedColorStr )
111 std::cout << " different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl;
118 ///////////////////////////////////////////////////////////
120 struct StringToVector2Data
122 std::string description;
123 std::string vector2Str;
124 Vector2 expectedVector2;
127 bool StringToVector2Test( const StringToVector2Data& data )
129 std::cout << " testing " << data.description << std::endl;
132 StringToVector2( data.vector2Str.c_str(), data.vector2Str.size(), vector2 );
134 if( vector2 != data.expectedVector2 )
136 std::cout << " different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl;
143 ///////////////////////////////////////////////////////////
146 struct Vector2ToStringData
148 std::string description;
150 std::string expectedVector2Str;
153 bool Vector2ToStringTest( const Vector2ToStringData& data )
155 std::cout << " testing " << data.description << std::endl;
157 std::string vector2Str;
158 Vector2ToString( data.vector2, vector2Str );
160 if( vector2Str != data.expectedVector2Str )
162 std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
171 int UtcDaliTextTokenComparison(void)
173 tet_infoline(" UtcDaliTextTokenComparison");
175 const TokenComparisonData data[] =
184 "different size text",
202 "some punctuation characters, numbers, ...",
203 "hello0123456789.![?]",
204 "Hello0123456789.![?]",
209 const unsigned int numberOfTests = 5u;
211 for( unsigned int index = 0u; index < numberOfTests; ++index )
213 ToolkitTestApplication application;
214 if( !TokenComparisonTest( data[index] ) )
216 tet_result(TET_FAIL);
220 tet_result(TET_PASS);
224 int UtcDaliTextColorStringToVector4(void)
226 tet_infoline(" UtcDaliTextColorStringToVector4");
228 const ColorStringToVector4Data data[] =
271 "transparent string",
276 "3 component web color",
281 "6 component web color",
286 "hex color red (ARGB)",
291 "hex color green (ARGB)",
301 const unsigned int numberOfTests = 14u;
303 for( unsigned int index = 0u; index < numberOfTests; ++index )
305 ToolkitTestApplication application;
306 if( !ColorStringToVector4Test( data[index] ) )
308 tet_result(TET_FAIL);
312 tet_result(TET_PASS);
316 int UtcDaliTextVector4ToColorString(void)
318 tet_infoline(" UtcDaliTextVector4ToColorString");
320 const Vector4ToColorStringData data[] =
363 "transparent string",
369 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
373 const unsigned int numberOfTests = 10u;
375 for( unsigned int index = 0u; index < numberOfTests; ++index )
377 ToolkitTestApplication application;
378 if( !Vector4ToColorStringTest( data[index] ) )
380 tet_result(TET_FAIL);
384 tet_result(TET_PASS);
388 int UtcDaliTextStringToVector2(void)
390 tet_infoline(" UtcDaliTextStringToVector2");
391 const StringToVector2Data data[] =
409 const unsigned int numberOfTests = 3u;
411 for( unsigned int index = 0u; index < numberOfTests; ++index )
413 ToolkitTestApplication application;
414 if( !StringToVector2Test( data[index] ) )
416 tet_result(TET_FAIL);
420 tet_result(TET_PASS);
424 int UtcDaliTextVector2ToString(void)
426 tet_infoline(" UtcDaliTextVector2ToString");
427 const Vector2ToStringData data[] =
440 const unsigned int numberOfTests = 2u;
442 for( unsigned int index = 0u; index < numberOfTests; ++index )
444 ToolkitTestApplication application;
445 if( !Vector2ToStringTest( data[index] ) )
447 tet_result(TET_FAIL);
451 tet_result(TET_PASS);