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-utils.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;
169 ///////////////////////////////////////////////////////////
172 struct XHTMLEntityToUTF8Data
174 std::string description;
175 std::string xHTMLEntityString;
176 std::string expectedString;
179 bool XHTMLEntityToUTF8Test( const XHTMLEntityToUTF8Data& data )
181 std::cout << " testing " << data.description << std::endl;
183 Vector<ColorRun> colorRuns;
184 Vector<FontDescriptionRun> fontRuns;
185 MarkupProcessData markupProcessData( colorRuns, fontRuns );
186 ProcessMarkupString( data.xHTMLEntityString, markupProcessData );
188 if( markupProcessData.markupProcessedText != data.expectedString )
190 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
199 int UtcDaliTextTokenComparison(void)
201 tet_infoline(" UtcDaliTextTokenComparison");
203 const TokenComparisonData data[] =
212 "different size text",
230 "some punctuation characters, numbers, ...",
231 "hello0123456789.![?]",
232 "Hello0123456789.![?]",
237 const unsigned int numberOfTests = 5u;
239 for( unsigned int index = 0u; index < numberOfTests; ++index )
241 ToolkitTestApplication application;
242 if( !TokenComparisonTest( data[index] ) )
244 tet_result(TET_FAIL);
248 tet_result(TET_PASS);
252 int UtcDaliTextColorStringToVector4(void)
254 tet_infoline(" UtcDaliTextColorStringToVector4");
256 const ColorStringToVector4Data data[] =
299 "transparent string",
304 "3 component web color",
309 "6 component web color",
314 "hex color red (ARGB)",
319 "hex color green (ARGB)",
329 const unsigned int numberOfTests = 14u;
331 for( unsigned int index = 0u; index < numberOfTests; ++index )
333 ToolkitTestApplication application;
334 if( !ColorStringToVector4Test( data[index] ) )
336 tet_result(TET_FAIL);
340 tet_result(TET_PASS);
344 int UtcDaliTextVector4ToColorString(void)
346 tet_infoline(" UtcDaliTextVector4ToColorString");
348 const Vector4ToColorStringData data[] =
391 "transparent string",
397 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
401 const unsigned int numberOfTests = 10u;
403 for( unsigned int index = 0u; index < numberOfTests; ++index )
405 ToolkitTestApplication application;
406 if( !Vector4ToColorStringTest( data[index] ) )
408 tet_result(TET_FAIL);
412 tet_result(TET_PASS);
416 int UtcDaliTextStringToVector2(void)
418 tet_infoline(" UtcDaliTextStringToVector2");
419 const StringToVector2Data data[] =
437 const unsigned int numberOfTests = 3u;
439 for( unsigned int index = 0u; index < numberOfTests; ++index )
441 ToolkitTestApplication application;
442 if( !StringToVector2Test( data[index] ) )
444 tet_result(TET_FAIL);
448 tet_result(TET_PASS);
452 int UtcDaliTextVector2ToString(void)
454 tet_infoline(" UtcDaliTextVector2ToString");
455 const Vector2ToStringData data[] =
468 const unsigned int numberOfTests = 2u;
470 for( unsigned int index = 0u; index < numberOfTests; ++index )
472 ToolkitTestApplication application;
473 if( !Vector2ToStringTest( data[index] ) )
475 tet_result(TET_FAIL);
479 tet_result(TET_PASS);
483 int UtcDaliTextXHTMLEntityToUTF8(void)
485 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
486 const XHTMLEntityToUTF8Data data[] =
489 "Text Without XHTML Entity",
490 "Checking XHTML Entitities",
491 "Checking XHTML Entitities"
494 "Text With XHTML Entity in Numeric form",
495 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
496 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
499 "Text With XHTML Named Entities",
500 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
501 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
504 "Testing of < special character",
505 "Testing of < special character",
509 "Testing of & special character",
510 "Testing of & special character",
514 "Testing of & < > special character",
515 "Testing of \\& \\< \\> special character",
516 "Testing of & < > special character"
519 const unsigned int numberOfTests = 6u;
521 for( unsigned int index = 0u; index < numberOfTests; ++index )
523 ToolkitTestApplication application;
524 if( !XHTMLEntityToUTF8Test( data[index] ) )
526 tet_result(TET_FAIL);
530 tet_result(TET_PASS);