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 paragraphIndex;
59 std::size_t wordIndex;
60 std::size_t characterIndex;
64 * Gets the paragraph, 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 resultParagraphIndex Index to the paragraph where the character is located.
72 * @param resultWordIndex Index to the word within the paragraph where the character is located.
73 * @param resultCharacterIndex Index to the character within the word where the character is located.
74 * @param location Where this function has been called.
76 * @return \e true if the experiment is successful. Otherwise returns \e false.
78 bool TestGetIndicesFromGlobalCharacterIndex( const std::string& description,
79 const std::string& input,
80 const std::size_t position,
81 const std::size_t resultParagraphIndex,
82 const std::size_t resultWordIndex,
83 const std::size_t resultCharacterIndex,
84 const char* location )
86 tet_printf( "%s", description.c_str() );
88 // Create natural size, layout and text-actor info for the input word.
89 Toolkit::Internal::TextView::RelayoutData relayoutData;
90 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
92 MarkupProcessor::StyledTextArray inputStyledText;
93 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
95 TextViewProcessor::CreateTextInfo( inputStyledText,
96 DEFAULT_LAYOUT_PARAMETERS,
99 TextViewProcessor::TextInfoIndices indices;
100 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
104 if( indices.mParagraphIndex != resultParagraphIndex )
106 tet_printf( "Fail. different paragraph index. %s", location );
109 if( indices.mWordIndex != resultWordIndex )
111 tet_printf( "Fail. different word index. %s", location );
114 if( indices.mCharacterIndex != resultCharacterIndex )
116 tet_printf( "Fail. different character index. %s", location );
123 //////////////////////////////////////////////////////////////////
127 int UtcDaliTextViewGetIndicesFromGlobalCharacterIndex(void)
129 ToolkitTestApplication application;
131 tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
132 struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
135 std::string( "Test position 0" ),
136 std::string( "text te<font size='30'>xt text te</font>xt text\n"
137 "text t<font size='30'>ext טקסט טקסט te</font>xt\n"
138 "text text text text text\n"
146 std::string( "Test position 76. (just after the last \\n)" ),
147 std::string( "t<font size='30'>ext text te</font>xt text text\n"
148 "text text טקסט טקסט text\n"
149 "text text te<font size='30'>xt text</font> text\n"
157 std::string( "Test position 73. (the last \\n)" ),
158 std::string( "text te<font size='30'>xt text text </font>text\n"
159 "text text טק<font size='30'>סט טקס</font>ט text\n"
160 "text text text text text\n"
168 std::string( "Test position 35. (first hebrew character)" ),
169 std::string( "text text text text text\n"
170 "text text טקסט טקסט text\n"
171 "text text text text text\n"
179 std::string( "Test position 3. (end of the first word)" ),
180 std::string( "text te<font size='30'>xt text text text\n</font>"
181 "text text טק<font size='30'>סט טקסט </font>text\n"
182 "text te<font size='30'>xt text text</font> text\n"
190 std::string( "Test position 33. (end of the second word of the second paragraph)" ),
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 std::string( "Test position 43. (last hebrew character)" ),
202 std::string( "text te<font size='30'>xt text text text\n</font>"
203 "text text טק<font size='30'>סט טקסט </font>text\n"
204 "text te<font size='30'>xt text text</font> text\n"
212 const std::size_t numberOfTests( 7 );
214 for( std::size_t index = 0; index < numberOfTests; ++index )
216 const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
218 if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.paragraphIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
220 tet_result( TET_FAIL );
224 tet_result( TET_PASS );
228 int UtcDaliTextViewDebugCouts(void)
230 /////////////////////////////////////////////////////
231 // Text debug functions to not to penalize coverage
232 /////////////////////////////////////////////////////
234 ToolkitTestApplication application;
236 tet_infoline("UtcDaliTextViewDebugCouts : ");
238 Toolkit::Internal::TextView::RelayoutData relayoutData;
240 MarkupProcessor::StyledTextArray inputStyledText;
241 MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
243 TextViewProcessor::CreateTextInfo( inputStyledText,
244 DEFAULT_LAYOUT_PARAMETERS,
247 Actor dummy = Actor::New();
248 Toolkit::Internal::SplitByNewLineChar::Relayout( dummy,
249 Toolkit::Internal::TextView::RELAYOUT_ALL,
250 DEFAULT_LAYOUT_PARAMETERS,
251 DEFAULT_VISUAL_PARAMETERS,
254 TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
257 TextViewProcessor::dbgPrint( textStyle );
259 TextViewProcessor::TextInfoIndices indices;
260 TextViewProcessor::dbgPrint( indices );
262 TextViewProcessor::dbgPrint( inputStyledText );
264 tet_result( TET_PASS );