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.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
24 // Internal headers are allowed here
25 #include <dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.h>
26 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
27 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
28 #include <dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.h>
29 #include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
32 using namespace Dali::Toolkit;
33 using namespace Dali::Toolkit::Internal;
35 void dali_text_view_helper_and_debug_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_text_view_helper_and_debug_cleanup(void)
42 test_return_value = TET_PASS;
48 // Data structures used to create an 'experiment' in TET cases
50 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
51 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
53 struct GetIndicesFromGlobalCharacterIndexTest
55 std::string description;
58 std::size_t lineIndex;
59 std::size_t groupIndex;
60 std::size_t wordIndex;
61 std::size_t characterIndex;
65 * Gets the line, group, word, and character indices for a given text and a given position and checks the results with the given indices.
67 * If the test fails it prints a short description and the line where this function was called.
69 * @param description Short description of the experiment.
70 * @param input The input text.
71 * @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.
72 * @param resultLineIndex Index to the line where the character is located.
73 * @param resultGroupIndex Index to the group within the line where the character is located.
74 * @param resultWordIndex Index to the word within the group where the character is located.
75 * @param resultCharacterIndex Index to the character within the word where the character is located.
76 * @param location Where this function has been called.
78 * @return \e true if the experiment is successful. Otherwise returns \e false.
80 bool TestGetIndicesFromGlobalCharacterIndex( const std::string& description,
81 const std::string& input,
82 const std::size_t position,
83 const std::size_t resultLineIndex,
84 const std::size_t resultGroupIndex,
85 const std::size_t resultWordIndex,
86 const std::size_t resultCharacterIndex,
87 const char* location )
89 tet_printf( "%s", description.c_str() );
91 // Create natural size, layout and text-actor info for the input word.
92 Toolkit::Internal::TextView::RelayoutData relayoutData;
93 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
95 MarkupProcessor::StyledTextArray inputStyledText;
96 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
98 TextViewProcessor::CreateTextInfo( inputStyledText,
99 DEFAULT_LAYOUT_PARAMETERS,
102 TextViewProcessor::TextInfoIndices indices;
103 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
107 if( indices.mLineIndex != resultLineIndex )
109 tet_printf( "Fail. different line index. %s", location );
112 if( indices.mGroupIndex != resultGroupIndex )
114 tet_printf( "Fail. different group index. %s", location );
117 if( indices.mWordIndex != resultWordIndex )
119 tet_printf( "Fail. different word index. %s", location );
122 if( indices.mCharacterIndex != resultCharacterIndex )
124 tet_printf( "Fail. different character index. %s", location );
131 //////////////////////////////////////////////////////////////////
135 int UtcDaliTextViewGetIndicesFromGlobalCharacterIndex(void)
137 ToolkitTestApplication application;
139 tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
140 struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
143 std::string( "Test position 0" ),
144 std::string( "text te<font size='30'>xt text te</font>xt text\n"
145 "text t<font size='30'>ext טקסט טקסט te</font>xt\n"
146 "text text text text text\n"
155 std::string( "Test position 76. (just after the last \\n)" ),
156 std::string( "t<font size='30'>ext text te</font>xt text text\n"
157 "text text טקסט טקסט text\n"
158 "text text te<font size='30'>xt text</font> text\n"
167 std::string( "Test position 73. (the last \\n)" ),
168 std::string( "text te<font size='30'>xt text text </font>text\n"
169 "text text טק<font size='30'>סט טקס</font>ט text\n"
170 "text text text text text\n"
179 std::string( "Test position 35. (first hebrew character)" ),
180 std::string( "text text text text text\n"
181 "text text טקסט טקסט text\n"
182 "text text text text text\n"
191 std::string( "Test position 3. (end of the first word)" ),
192 std::string( "text te<font size='30'>xt text text text\n</font>"
193 "text text טק<font size='30'>סט טקסט </font>text\n"
194 "text te<font size='30'>xt text text</font> text\n"
202 /* TODO Check for mixed RTL and LTR text.
204 std::string( "Test position 33. (end of the second word of the second line)" ),
205 std::string( "text te<font size='30'>xt text text text\n</font>"
206 "text text טק<font size='30'>סט טקסט </font>text\n"
207 "text te<font size='30'>xt text text</font> text\n"
216 std::string( "Test position 43. (last hebrew character)" ),
217 std::string( "text te<font size='30'>xt text text text\n</font>"
218 "text text טק<font size='30'>סט טקסט </font>text\n"
219 "text te<font size='30'>xt text text</font> text\n"
229 const std::size_t numberOfTests( 5 );
231 for( std::size_t index = 0; index < numberOfTests; ++index )
233 const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
235 if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.lineIndex, test.groupIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
237 tet_result( TET_FAIL );
241 tet_result( TET_PASS );
245 int UtcDaliTextViewDebugCouts(void)
247 /////////////////////////////////////////////////////
248 // Text debug functions to not to penalize coverage
249 /////////////////////////////////////////////////////
251 ToolkitTestApplication application;
253 tet_infoline("UtcDaliTextViewDebugCouts : ");
255 Toolkit::Internal::TextView::RelayoutData relayoutData;
257 MarkupProcessor::StyledTextArray inputStyledText;
258 MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
260 TextViewProcessor::CreateTextInfo( inputStyledText,
261 DEFAULT_LAYOUT_PARAMETERS,
264 Actor dummy = Actor::New();
265 Toolkit::Internal::SplitByNewLineChar::Relayout( dummy,
266 Toolkit::Internal::TextView::RELAYOUT_ALL,
267 DEFAULT_LAYOUT_PARAMETERS,
268 DEFAULT_VISUAL_PARAMETERS,
271 TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
274 TextViewProcessor::dbgPrint( textStyle );
276 TextViewProcessor::TextInfoIndices indices;
277 TextViewProcessor::dbgPrint( indices );
279 TextViewProcessor::dbgPrint( inputStyledText );
281 tet_result( TET_PASS );