2 * Copyright (c) 2014 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/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
28 // Internal headers are allowed here
29 #include <dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.h>
30 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
31 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
32 #include <dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.h>
33 #include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
36 using namespace Dali::Toolkit;
37 using namespace Dali::Toolkit::Internal;
41 // Data structures used to create an 'experiment' in TET cases
43 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
44 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
46 struct GetIndicesFromGlobalCharacterIndexTest
48 std::string description;
51 std::size_t lineIndex;
52 std::size_t groupIndex;
53 std::size_t wordIndex;
54 std::size_t characterIndex;
58 * Gets the line, group, word, and character indices for a given text and a given position and checks the results with the given indices.
60 * If the test fails it prints a short description and the line where this function was called.
62 * @param description Short description of the experiment.
63 * @param input The input text.
64 * @param position Global position of the character. i.e in a text with with 1000 characters, position could be any value from 0 to 1000.
65 * @param resultLineIndex Index to the line where the character is located.
66 * @param resultGroupIndex Index to the group within the line where the character is located.
67 * @param resultWordIndex Index to the word within the group where the character is located.
68 * @param resultCharacterIndex Index to the character within the word where the character is located.
69 * @param location Where this function has been called.
71 * @return \e true if the experiment is successful. Otherwise returns \e false.
73 bool TestGetIndicesFromGlobalCharacterIndex( const std::string& description,
74 const std::string& input,
75 const std::size_t position,
76 const std::size_t resultLineIndex,
77 const std::size_t resultGroupIndex,
78 const std::size_t resultWordIndex,
79 const std::size_t resultCharacterIndex,
80 const char* location )
82 tet_printf( "%s", description.c_str() );
84 // Create natural size, layout and text-actor info for the input word.
85 Toolkit::Internal::TextView::RelayoutData relayoutData;
86 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
88 MarkupProcessor::StyledTextArray inputStyledText;
89 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
91 TextViewProcessor::CreateTextInfo( inputStyledText,
92 DEFAULT_LAYOUT_PARAMETERS,
95 TextViewProcessor::TextInfoIndices indices;
96 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
100 if( indices.mLineIndex != resultLineIndex )
102 tet_printf( "Fail. different line index. %s", location );
105 if( indices.mGroupIndex != resultGroupIndex )
107 tet_printf( "Fail. different group index. %s", location );
110 if( indices.mWordIndex != resultWordIndex )
112 tet_printf( "Fail. different word index. %s", location );
115 if( indices.mCharacterIndex != resultCharacterIndex )
117 tet_printf( "Fail. different character index. %s", location );
124 //////////////////////////////////////////////////////////////////
127 static void Startup();
128 static void Cleanup();
131 void (*tet_startup)() = Startup;
132 void (*tet_cleanup)() = Cleanup;
136 POSITIVE_TC_IDX = 0x01,
140 #define MAX_NUMBER_OF_TESTS 10000
142 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
145 // Add test functionality for all APIs in the class (Positive and Negative)
146 TEST_FUNCTION( UtcDaliTextViewGetIndicesFromGlobalCharacterIndex, POSITIVE_TC_IDX ); // Tests correctness when indices to lines, groups, words and characters are worked out from a given global position.
147 TEST_FUNCTION( UtcDaliTextViewDebugCouts, POSITIVE_TC_IDX ); // Tests debug functions just to not to penalize the coverage.
149 // Called only once before first test is run.
150 static void Startup()
154 // Called only once after last test is run
155 static void Cleanup()
159 static void UtcDaliTextViewGetIndicesFromGlobalCharacterIndex()
161 ToolkitTestApplication application;
163 tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
164 struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
167 std::string( "Test position 0" ),
168 std::string( "text te<font size='30'>xt text te</font>xt text\n"
169 "text t<font size='30'>ext טקסט טקסט te</font>xt\n"
170 "text text text text text\n"
179 std::string( "Test position 76. (just after the last \\n)" ),
180 std::string( "t<font size='30'>ext text te</font>xt text text\n"
181 "text text טקסט טקסט text\n"
182 "text text te<font size='30'>xt text</font> text\n"
191 std::string( "Test position 73. (the last \\n)" ),
192 std::string( "text te<font size='30'>xt text text </font>text\n"
193 "text text טק<font size='30'>סט טקס</font>ט text\n"
194 "text text text text text\n"
203 std::string( "Test position 35. (first hebrew character)" ),
204 std::string( "text text text text text\n"
205 "text text טקסט טקסט text\n"
206 "text text text text text\n"
215 std::string( "Test position 3. (end of the first word)" ),
216 std::string( "text te<font size='30'>xt text text text\n</font>"
217 "text text טק<font size='30'>סט טקסט </font>text\n"
218 "text te<font size='30'>xt text text</font> text\n"
226 /* TODO Check for mixed RTL and LTR text.
228 std::string( "Test position 33. (end of the second word of the second line)" ),
229 std::string( "text te<font size='30'>xt text text text\n</font>"
230 "text text טק<font size='30'>סט טקסט </font>text\n"
231 "text te<font size='30'>xt text text</font> text\n"
240 std::string( "Test position 43. (last hebrew character)" ),
241 std::string( "text te<font size='30'>xt text text text\n</font>"
242 "text text טק<font size='30'>סט טקסט </font>text\n"
243 "text te<font size='30'>xt text text</font> text\n"
253 const std::size_t numberOfTests( 5 );
255 for( std::size_t index = 0; index < numberOfTests; ++index )
257 const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
259 if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.lineIndex, test.groupIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
261 tet_result( TET_FAIL );
265 tet_result( TET_PASS );
268 static void UtcDaliTextViewDebugCouts()
270 /////////////////////////////////////////////////////
271 // Text debug functions to not to penalize coverage
272 /////////////////////////////////////////////////////
274 ToolkitTestApplication application;
276 tet_infoline("UtcDaliTextViewDebugCouts : ");
278 Toolkit::Internal::TextView::RelayoutData relayoutData;
280 MarkupProcessor::StyledTextArray inputStyledText;
281 MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
283 TextViewProcessor::CreateTextInfo( inputStyledText,
284 DEFAULT_LAYOUT_PARAMETERS,
287 Actor dummy = Actor::New();
288 Toolkit::Internal::SplitByNewLineChar::Relayout( dummy,
289 Toolkit::Internal::TextView::RELAYOUT_ALL,
290 DEFAULT_LAYOUT_PARAMETERS,
291 DEFAULT_VISUAL_PARAMETERS,
294 TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
297 TextViewProcessor::dbgPrint( textStyle );
299 TextViewProcessor::TextInfoIndices indices;
300 TextViewProcessor::dbgPrint( indices );
302 TextViewProcessor::dbgPrint( inputStyledText );
304 tet_result( TET_PASS );