2 * Copyright (c) 2022 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 <dali-toolkit/internal/text/color-run.h>
26 #include <dali-toolkit/internal/text/font-description-run.h>
27 #include <dali-toolkit/internal/text/markup-processor/markup-processor-helper-functions.h>
28 #include <dali-toolkit/internal/text/markup-processor/markup-processor.h>
29 #include <dali-toolkit/internal/text/text-definitions.h>
30 #include <dali-toolkit/internal/text/text-io.h>
31 #include <toolkit-text-utils.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,
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 ///////////////////////////////////////////////////////////
145 struct Vector2ToStringData
147 std::string description;
149 std::string expectedVector2Str;
152 bool Vector2ToStringTest(const Vector2ToStringData& data)
154 std::cout << " testing " << data.description << std::endl;
156 std::string vector2Str;
157 Vector2ToString(data.vector2, vector2Str);
159 if(vector2Str != data.expectedVector2Str)
161 std::cout << " different vector2 : [" << vector2Str << "], expected : [" << data.expectedVector2Str << "]" << std::endl;
168 ///////////////////////////////////////////////////////////
170 struct XHTMLEntityToUTF8Data
172 std::string description;
173 std::string xHTMLEntityString;
174 std::string expectedString;
177 bool XHTMLEntityToUTF8Test(const XHTMLEntityToUTF8Data& data)
179 std::cout << " testing " << data.description << std::endl;
181 Vector<ColorRun> colorRuns;
182 Vector<FontDescriptionRun> fontRuns;
183 Vector<EmbeddedItem> items;
184 Vector<Anchor> anchors;
185 Vector<UnderlinedCharacterRun> underlinedCharacterRuns;
186 Vector<ColorRun> backgroundColorRuns;
187 Vector<StrikethroughCharacterRun> strikethroughCharacterRuns;
188 Vector<BoundedParagraphRun> boundedParagraphRuns;
189 Vector<CharacterSpacingCharacterRun> characterSpacingCharacterRuns;
190 MarkupProcessData markupProcessData(colorRuns, fontRuns, items, anchors, underlinedCharacterRuns, backgroundColorRuns, strikethroughCharacterRuns, boundedParagraphRuns, characterSpacingCharacterRuns);
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[] =
224 {"different size text",
236 {"some punctuation characters, numbers, ...",
237 "hello0123456789.![?]",
238 "Hello0123456789.![?]",
242 const unsigned int numberOfTests = 5u;
244 for(unsigned int index = 0u; index < numberOfTests; ++index)
246 ToolkitTestApplication application;
247 if(!TokenComparisonTest(data[index]))
249 tet_result(TET_FAIL);
253 tet_result(TET_PASS);
257 int UtcDaliTextColorStringToVector4(void)
259 tet_infoline(" UtcDaliTextColorStringToVector4");
261 const ColorStringToVector4Data data[] =
287 {"transparent string",
290 {"3 component web color",
293 {"6 component web color",
296 {"hex color red (ARGB)",
299 {"hex color green (ARGB)",
306 const unsigned int numberOfTests = 14u;
308 for(unsigned int index = 0u; index < numberOfTests; ++index)
310 ToolkitTestApplication application;
311 if(!ColorStringToVector4Test(data[index]))
313 tet_result(TET_FAIL);
317 tet_result(TET_PASS);
321 int UtcDaliTextVector4ToColorString(void)
323 tet_infoline(" UtcDaliTextVector4ToColorString");
325 const Vector4ToColorStringData data[] =
353 {"transparent string",
357 Vector4(0.4f, 0.5f, 0.6f, 1.f),
360 const unsigned int numberOfTests = 10u;
362 for(unsigned int index = 0u; index < numberOfTests; ++index)
364 ToolkitTestApplication application;
365 if(!Vector4ToColorStringTest(data[index]))
367 tet_result(TET_FAIL);
371 tet_result(TET_PASS);
375 int UtcDaliTextStringToVector2(void)
377 tet_infoline(" UtcDaliTextStringToVector2");
378 const StringToVector2Data data[] =
389 const unsigned int numberOfTests = 3u;
391 for(unsigned int index = 0u; index < numberOfTests; ++index)
393 ToolkitTestApplication application;
394 if(!StringToVector2Test(data[index]))
396 tet_result(TET_FAIL);
400 tet_result(TET_PASS);
404 int UtcDaliTextVector2ToString(void)
406 tet_infoline(" UtcDaliTextVector2ToString");
407 const Vector2ToStringData data[] =
419 const unsigned int numberOfTests = 2u;
421 for(unsigned int index = 0u; index < numberOfTests; ++index)
423 ToolkitTestApplication application;
424 if(!Vector2ToStringTest(data[index]))
426 tet_result(TET_FAIL);
430 tet_result(TET_PASS);
434 int UtcDaliTextXHTMLEntityToUTF8(void)
436 tet_infoline(" UtcDaliTextXHTMLEntityToUTF8");
437 const XHTMLEntityToUTF8Data data[] =
439 {"Text Without XHTML Entity",
440 "Checking XHTML Entitities",
441 "Checking XHTML Entitities"},
442 {"Text With XHTML Entity in Numeric form",
443 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
444 "Checking Numeric Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "},
445 {"Text With XHTML Named Entities",
446 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • ",
447 "Checking Named Entitities & ' < > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å æ Ç È É Ê Ë Ì Í Î Ï ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ý þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω … € ← ↑ → ↓ ↔ ← → ∀ ∃ ∇ ∏ ∑ ∧ ∨ ∫ ≠ ≡ ⊕ ⊥ † ‡ • "},
448 {"Testing of < special character",
449 "Testing of < special character",
451 {"Testing of & special character",
452 "Testing of & special character",
454 {"Testing of & < > special character",
455 "Testing of \\& \\< \\> special character",
456 "Testing of & < > special character"}};
457 const unsigned int numberOfTests = 6u;
459 for(unsigned int index = 0u; index < numberOfTests; ++index)
461 ToolkitTestApplication application;
462 if(!XHTMLEntityToUTF8Test(data[index]))
464 tet_result(TET_FAIL);
468 tet_result(TET_PASS);