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.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/internal/text/characters-helper-functions.h>
25 #include <toolkit-text-utils.h>
28 using namespace Toolkit;
31 // Tests the following function.
33 // CharacterRun RetrieveClusteredCharactersOfCharacterIndex(const VisualModelPtr& visualModel,
34 // const LogicalModelPtr& logicalModel,
35 // const CharacterIndex& characterIndex)
37 //////////////////////////////////////////////////////////
41 const std::string DEFAULT_FONT_DIR("/resources/fonts");
42 const unsigned int DEFAULT_FONT_SIZE = 1152u;
44 struct RetrieveClusteredCharactersOfCharacterIndexData
46 std::string description; ///< Description of the test.
47 std::string text; ///< Input text.
48 bool markupProcessorEnabled; //< Enable markup processor to use markup text.
49 unsigned int numberOfTests; ///< The number of tests.
50 CharacterIndex* characterIndex; ///< The character index for each test.
51 CharacterRun* clusteredCharacters; ///< The expected clustered characters run for each test.
54 bool GetRetrieveClusteredCharactersOfCharacterIndexTest(const RetrieveClusteredCharactersOfCharacterIndexData& data)
56 std::cout << " testing : " << data.description << std::endl;
58 // 1) Create the model.
61 Size textArea(400.f, 600.f);
64 Vector<FontDescriptionRun> fontDescriptionRuns;
65 LayoutOptions options;
66 CreateTextModel(data.text,
73 data.markupProcessorEnabled,
76 Toolkit::DevelText::EllipsisPosition::END,
78 0.0f // characterSpacing
81 LogicalModelPtr logicalModel = textModel->mLogicalModel;
82 VisualModelPtr visualModel = textModel->mVisualModel;
84 for(unsigned int index = 0; index < data.numberOfTests; ++index)
86 CharacterRun clusteredCharacters = RetrieveClusteredCharactersOfCharacterIndex(visualModel, logicalModel, data.characterIndex[index]);
88 if(clusteredCharacters.characterIndex != data.clusteredCharacters[index].characterIndex)
90 std::cout << " test " << index << " failed. Different clusteredCharacters.characterIndex : " << clusteredCharacters.characterIndex << ", expected : " << data.clusteredCharacters[index].characterIndex << std::endl;
94 if(clusteredCharacters.numberOfCharacters != data.clusteredCharacters[index].numberOfCharacters)
96 std::cout << " test " << index << " failed. Different clusteredCharacters.numberOfCharacters : " << clusteredCharacters.numberOfCharacters << ", expected : " << data.clusteredCharacters[index].numberOfCharacters << std::endl;
106 //////////////////////////////////////////////////////////
108 // UtcDaliRetrieveClusteredCharactersOfCharacterIndex
110 //////////////////////////////////////////////////////////
112 int UtcDaliRetrieveClusteredCharactersOfCharacterIndex(void)
114 tet_infoline(" UtcDaliRetrieveClusteredCharactersOfCharacterIndex");
116 CharacterIndex characterIndex01[] = {0u, 1u, 2u, 10u};
118 CharacterRun clusteredCharacters01[] = {
124 CharacterIndex characterIndex02[] = {0u, 4u, 6u};
126 CharacterRun clusteredCharacters02[] = {
131 CharacterIndex characterIndex03[] = {3u, 9u, 14u};
133 CharacterRun clusteredCharacters03[] = {
138 CharacterIndex characterIndex04[] = {0u, 1u, 2u, 10u};
140 CharacterRun clusteredCharacters04[] = {
146 struct RetrieveClusteredCharactersOfCharacterIndexData data[] =
148 {"Easy latin script",
153 clusteredCharacters01},
155 {"FamilyManWomanGirlBoy Single Complex Emoji script",
156 "👨‍👩‍👧‍👦",
160 clusteredCharacters02},
162 {"Long text many Emojis with letters",
163 "AB👨‍👩‍👧‍👦AB👩🏻‍🔬B👨‍👩‍👧‍👦AA☪︎B☪️AB",
167 clusteredCharacters03},
174 clusteredCharacters04},
176 const unsigned int numberOfTests = 4u;
178 for(unsigned int index = 0; index < numberOfTests; ++index)
180 ToolkitTestApplication application;
181 if(!GetRetrieveClusteredCharactersOfCharacterIndexTest(data[index]))
183 tet_result(TET_FAIL);
187 tet_result(TET_PASS);