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;
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 MarkupProcessData markupProcessData( colorRuns, fontRuns, items, anchors, underlinedCharacterRuns );
190 ProcessMarkupString( data.xHTMLEntityString, markupProcessData );
192 for( Vector<EmbeddedItem>::Iterator it = items.Begin(),
197 EmbeddedItem& item = *it;
202 if( markupProcessData.markupProcessedText != data.expectedString )
204 std::cout << " different output string : " << markupProcessData.markupProcessedText << ", expected : " << data.expectedString << " " << std::endl;
213 int UtcDaliTextTokenComparison(void)
215 tet_infoline(" UtcDaliTextTokenComparison");
217 const TokenComparisonData data[] =
226 "different size text",
244 "some punctuation characters, numbers, ...",
245 "hello0123456789.![?]",
246 "Hello0123456789.![?]",
251 const unsigned int numberOfTests = 5u;
253 for( unsigned int index = 0u; index < numberOfTests; ++index )
255 ToolkitTestApplication application;
256 if( !TokenComparisonTest( data[index] ) )
258 tet_result(TET_FAIL);
262 tet_result(TET_PASS);
266 int UtcDaliTextColorStringToVector4(void)
268 tet_infoline(" UtcDaliTextColorStringToVector4");
270 const ColorStringToVector4Data data[] =
313 "transparent string",
318 "3 component web color",
323 "6 component web color",
328 "hex color red (ARGB)",
333 "hex color green (ARGB)",
343 const unsigned int numberOfTests = 14u;
345 for( unsigned int index = 0u; index < numberOfTests; ++index )
347 ToolkitTestApplication application;
348 if( !ColorStringToVector4Test( data[index] ) )
350 tet_result(TET_FAIL);
354 tet_result(TET_PASS);
358 int UtcDaliTextVector4ToColorString(void)
360 tet_infoline(" UtcDaliTextVector4ToColorString");
362 const Vector4ToColorStringData data[] =
405 "transparent string",
411 Vector4( 0.4f, 0.5f, 0.6f, 1.f ),
415 const unsigned int numberOfTests = 10u;
417 for( unsigned int index = 0u; index < numberOfTests; ++index )
419 ToolkitTestApplication application;
420 if( !Vector4ToColorStringTest( data[index] ) )
422 tet_result(TET_FAIL);
426 tet_result(TET_PASS);
430 int UtcDaliTextStringToVector2(void)
432 tet_infoline(" UtcDaliTextStringToVector2");
433 const StringToVector2Data data[] =
451 const unsigned int numberOfTests = 3u;
453 for( unsigned int index = 0u; index < numberOfTests; ++index )
455 ToolkitTestApplication application;
456 if( !StringToVector2Test( data[index] ) )
458 tet_result(TET_FAIL);
462 tet_result(TET_PASS);
466 int UtcDaliTextVector2ToString(void)
468 tet_infoline(" UtcDaliTextVector2ToString");
469 const Vector2ToStringData data[] =
482 const unsigned int numberOfTests = 2u;
484 for( unsigned int index = 0u; index < numberOfTests; ++index )
486 ToolkitTestApplication application;
487 if( !Vector2ToStringTest( data[index] ) )
489 tet_result(TET_FAIL);
493 tet_result(TET_PASS);
497 int UtcDaliTextXHTMLEntityToUTF8(void)
499 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
500 const XHTMLEntityToUTF8Data data[] =
503 "Text Without XHTML Entity",
504 "Checking XHTML Entitities",
505 "Checking XHTML Entitities"
508 "Text With XHTML Entity in Numeric form",
509 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
510 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
513 "Text With XHTML Named Entities",
514 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
515 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "
518 "Testing of < special character",
519 "Testing of < special character",
523 "Testing of & special character",
524 "Testing of & special character",
528 "Testing of & < > special character",
529 "Testing of \\& \\< \\> special character",
530 "Testing of & < > special character"
533 const unsigned int numberOfTests = 6u;
535 for( unsigned int index = 0u; index < numberOfTests; ++index )
537 ToolkitTestApplication application;
538 if( !XHTMLEntityToUTF8Test( data[index] ) )
540 tet_result(TET_FAIL);
544 tet_result(TET_PASS);