2 * Copyright (c) 2021 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;
40 ///////////////////////////////////////////////////////////
42 struct TokenComparisonData
44 std::string description;
45 std::string string1; ///< must be in lower case!!!!
50 bool TokenComparisonTest( const TokenComparisonData& data )
52 std::cout << " testing " << data.description << std::endl;
54 const bool result = TokenComparison( data.string1,
56 data.string2.size() );
58 if( result != data.expectedResult )
60 std::cout << " different conparison result : " << result << ", expected : " << data.expectedResult << std::endl;
61 std::cout << " comparing : [" << data.string1 << "] and [" << data.string2 << "]" << std::endl;
69 ///////////////////////////////////////////////////////////
71 struct ColorStringToVector4Data
73 std::string description;
75 Vector4 expectedColor;
78 bool ColorStringToVector4Test( const ColorStringToVector4Data& data )
80 std::cout << " testing " << data.description << std::endl;
83 ColorStringToVector4( data.colorStr.c_str(), data.colorStr.size(), color );
85 if( color != data.expectedColor )
87 std::cout << " different color : " << color << ", expected : " << data.expectedColor << std::endl;
94 ///////////////////////////////////////////////////////////
96 struct Vector4ToColorStringData
98 std::string description;
100 std::string expectedColorStr;
103 bool Vector4ToColorStringTest( const Vector4ToColorStringData& data )
105 std::cout << " testing " << data.description << std::endl;
107 std::string colorStr;
108 Vector4ToColorString( data.color, colorStr );
110 if( colorStr != data.expectedColorStr )
112 std::cout << " different color : [" << colorStr << "], expected : [" << data.expectedColorStr << "]" << std::endl;
119 ///////////////////////////////////////////////////////////
121 struct StringToVector2Data
123 std::string description;
124 std::string vector2Str;
125 Vector2 expectedVector2;
128 bool StringToVector2Test( const StringToVector2Data& data )
130 std::cout << " testing " << data.description << std::endl;
133 StringToVector2( data.vector2Str.c_str(), data.vector2Str.size(), vector2 );
135 if( vector2 != data.expectedVector2 )
137 std::cout << " different vector2 : " << vector2 << ", expected : " << data.expectedVector2 << std::endl;
144 ///////////////////////////////////////////////////////////
147 struct Vector2ToStringData
149 std::string description;
151 std::string expectedVector2Str;
154 bool Vector2ToStringTest( const Vector2ToStringData& data )
156 std::cout << " testing " << data.description << std::endl;
158 std::string vector2Str;
159 Vector2ToString( data.vector2, vector2Str );
161 if( vector2Str != data.expectedVector2Str )
163 std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
170 ///////////////////////////////////////////////////////////
173 struct XHTMLEntityToUTF8Data
175 std::string description;
176 std::string xHTMLEntityString;
177 std::string expectedString;
180 bool XHTMLEntityToUTF8Test( const XHTMLEntityToUTF8Data& data )
182 std::cout << " testing " << data.description << std::endl;
184 Vector<ColorRun> colorRuns;
185 Vector<FontDescriptionRun> fontRuns;
186 Vector<EmbeddedItem> items;
187 Vector<Anchor> anchors;
188 Vector<UnderlinedCharacterRun> underlinedCharacterRuns;
189 Vector<ColorRun> backgroundColorRuns;
190 MarkupProcessData markupProcessData( colorRuns, fontRuns, items, anchors, underlinedCharacterRuns, backgroundColorRuns );
191 ProcessMarkupString( data.xHTMLEntityString, markupProcessData );
193 for( Vector<EmbeddedItem>::Iterator it = items.Begin(),
198 EmbeddedItem& item = *it;
203 if( markupProcessData.markupProcessedText != data.expectedString )
205 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
214 int UtcDaliTextTokenComparison(void)
216 tet_infoline(" UtcDaliTextTokenComparison");
218 const TokenComparisonData data[] =
227 "different size text",
245 "some punctuation characters, numbers, ...",
246 "hello0123456789.![?]",
247 "Hello0123456789.![?]",
252 const unsigned int numberOfTests = 5u;
254 for( unsigned int index = 0u; index < numberOfTests; ++index )
256 ToolkitTestApplication application;
257 if( !TokenComparisonTest( data[index] ) )
259 tet_result(TET_FAIL);
263 tet_result(TET_PASS);
267 int UtcDaliTextColorStringToVector4(void)
269 tet_infoline(" UtcDaliTextColorStringToVector4");
271 const ColorStringToVector4Data data[] =
314 "transparent string",
319 "3 component web color",
324 "6 component web color",
329 "hex color red (ARGB)",
334 "hex color green (ARGB)",
344 const unsigned int numberOfTests = 14u;
346 for( unsigned int index = 0u; index < numberOfTests; ++index )
348 ToolkitTestApplication application;
349 if( !ColorStringToVector4Test( data[index] ) )
351 tet_result(TET_FAIL);
355 tet_result(TET_PASS);
359 int UtcDaliTextVector4ToColorString(void)
361 tet_infoline(" UtcDaliTextVector4ToColorString");
363 const Vector4ToColorStringData data[] =
406 "transparent string",
412 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
416 const unsigned int numberOfTests = 10u;
418 for( unsigned int index = 0u; index < numberOfTests; ++index )
420 ToolkitTestApplication application;
421 if( !Vector4ToColorStringTest( data[index] ) )
423 tet_result(TET_FAIL);
427 tet_result(TET_PASS);
431 int UtcDaliTextStringToVector2(void)
433 tet_infoline(" UtcDaliTextStringToVector2");
434 const StringToVector2Data data[] =
452 const unsigned int numberOfTests = 3u;
454 for( unsigned int index = 0u; index < numberOfTests; ++index )
456 ToolkitTestApplication application;
457 if( !StringToVector2Test( data[index] ) )
459 tet_result(TET_FAIL);
463 tet_result(TET_PASS);
467 int UtcDaliTextVector2ToString(void)
469 tet_infoline(" UtcDaliTextVector2ToString");
470 const Vector2ToStringData data[] =
483 const unsigned int numberOfTests = 2u;
485 for( unsigned int index = 0u; index < numberOfTests; ++index )
487 ToolkitTestApplication application;
488 if( !Vector2ToStringTest( data[index] ) )
490 tet_result(TET_FAIL);
494 tet_result(TET_PASS);
498 int UtcDaliTextXHTMLEntityToUTF8(void)
500 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
501 const XHTMLEntityToUTF8Data data[] =
504 "Text Without XHTML Entity",
505 "Checking XHTML Entitities",
506 "Checking XHTML Entitities"
509 "Text With XHTML Entity in Numeric form",
510 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
511 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
514 "Text With XHTML Named Entities",
515 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
516 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
519 "Testing of < special character",
520 "Testing of < special character",
524 "Testing of & special character",
525 "Testing of & special character",
529 "Testing of & < > special character",
530 "Testing of \\& \\< \\> special character",
531 "Testing of & < > special character"
534 const unsigned int numberOfTests = 6u;
536 for( unsigned int index = 0u; index < numberOfTests; ++index )
538 ToolkitTestApplication application;
539 if( !XHTMLEntityToUTF8Test( data[index] ) )
541 tet_result(TET_FAIL);
545 tet_result(TET_PASS);