2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
23 // Internal headers are allowed here
24 #include <dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.h>
25 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
26 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
27 #include <dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.h>
28 #include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
31 using namespace Dali::Toolkit;
32 using namespace Dali::Toolkit::Internal;
34 void dali_text_view_helper_and_debug_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_text_view_helper_and_debug_cleanup(void)
41 test_return_value = TET_PASS;
47 // Data structures used to create an 'experiment' in TET cases
49 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
50 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
52 struct GetIndicesFromGlobalCharacterIndexTest
54 std::string description;
57 std::size_t lineIndex;
58 std::size_t groupIndex;
59 std::size_t wordIndex;
60 std::size_t characterIndex;
64 * Gets the line, group, word, and character indices for a given text and a given position and checks the results with the given indices.
66 * If the test fails it prints a short description and the line where this function was called.
68 * @param description Short description of the experiment.
69 * @param input The input text.
70 * @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.
71 * @param resultLineIndex Index to the line where the character is located.
72 * @param resultGroupIndex Index to the group within the line where the character is located.
73 * @param resultWordIndex Index to the word within the group where the character is located.
74 * @param resultCharacterIndex Index to the character within the word where the character is located.
75 * @param location Where this function has been called.
77 * @return \e true if the experiment is successful. Otherwise returns \e false.
79 bool TestGetIndicesFromGlobalCharacterIndex( const std::string& description,
80 const std::string& input,
81 const std::size_t position,
82 const std::size_t resultLineIndex,
83 const std::size_t resultGroupIndex,
84 const std::size_t resultWordIndex,
85 const std::size_t resultCharacterIndex,
86 const char* location )
88 tet_printf( "%s", description.c_str() );
90 // Create natural size, layout and text-actor info for the input word.
91 Toolkit::Internal::TextView::RelayoutData relayoutData;
92 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
94 MarkupProcessor::StyledTextArray inputStyledText;
95 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
97 TextViewProcessor::CreateTextInfo( inputStyledText,
98 DEFAULT_LAYOUT_PARAMETERS,
101 TextViewProcessor::TextInfoIndices indices;
102 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
106 if( indices.mLineIndex != resultLineIndex )
108 tet_printf( "Fail. different line index. %s", location );
111 if( indices.mGroupIndex != resultGroupIndex )
113 tet_printf( "Fail. different group index. %s", location );
116 if( indices.mWordIndex != resultWordIndex )
118 tet_printf( "Fail. different word index. %s", location );
121 if( indices.mCharacterIndex != resultCharacterIndex )
123 tet_printf( "Fail. different character index. %s", location );
130 //////////////////////////////////////////////////////////////////
134 int UtcDaliTextViewGetIndicesFromGlobalCharacterIndex(void)
136 ToolkitTestApplication application;
138 tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
139 struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
142 std::string( "Test position 0" ),
143 std::string( "text te<font size='30'>xt text te</font>xt text\n"
144 "text t<font size='30'>ext טקסט טקסט te</font>xt\n"
145 "text text text text text\n"
154 std::string( "Test position 76. (just after the last \\n)" ),
155 std::string( "t<font size='30'>ext text te</font>xt text text\n"
156 "text text טקסט טקסט text\n"
157 "text text te<font size='30'>xt text</font> text\n"
166 std::string( "Test position 73. (the last \\n)" ),
167 std::string( "text te<font size='30'>xt text text </font>text\n"
168 "text text טק<font size='30'>סט טקס</font>ט text\n"
169 "text text text text text\n"
178 std::string( "Test position 35. (first hebrew character)" ),
179 std::string( "text text text text text\n"
180 "text text טקסט טקסט text\n"
181 "text text text text text\n"
190 std::string( "Test position 3. (end of the first word)" ),
191 std::string( "text te<font size='30'>xt text text text\n</font>"
192 "text text טק<font size='30'>סט טקסט </font>text\n"
193 "text te<font size='30'>xt text text</font> text\n"
201 /* TODO Check for mixed RTL and LTR text.
203 std::string( "Test position 33. (end of the second word of the second line)" ),
204 std::string( "text te<font size='30'>xt text text text\n</font>"
205 "text text טק<font size='30'>סט טקסט </font>text\n"
206 "text te<font size='30'>xt text text</font> text\n"
215 std::string( "Test position 43. (last hebrew character)" ),
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"
228 const std::size_t numberOfTests( 5 );
230 for( std::size_t index = 0; index < numberOfTests; ++index )
232 const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
234 if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.lineIndex, test.groupIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
236 tet_result( TET_FAIL );
240 tet_result( TET_PASS );
244 int UtcDaliTextViewDebugCouts(void)
246 /////////////////////////////////////////////////////
247 // Text debug functions to not to penalize coverage
248 /////////////////////////////////////////////////////
250 ToolkitTestApplication application;
252 tet_infoline("UtcDaliTextViewDebugCouts : ");
254 Toolkit::Internal::TextView::RelayoutData relayoutData;
256 MarkupProcessor::StyledTextArray inputStyledText;
257 MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
259 TextViewProcessor::CreateTextInfo( inputStyledText,
260 DEFAULT_LAYOUT_PARAMETERS,
263 Actor dummy = Actor::New();
264 Toolkit::Internal::SplitByNewLineChar::Relayout( dummy,
265 Toolkit::Internal::TextView::RELAYOUT_ALL,
266 DEFAULT_LAYOUT_PARAMETERS,
267 DEFAULT_VISUAL_PARAMETERS,
270 TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
273 TextViewProcessor::dbgPrint( textStyle );
275 TextViewProcessor::TextInfoIndices indices;
276 TextViewProcessor::dbgPrint( indices );
278 TextViewProcessor::dbgPrint( inputStyledText );
280 tet_result( TET_PASS );