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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
27 // Internal headers are allowed here
28 #include <dali-toolkit/internal/controls/text-view/split-by-new-line-char-policies.h>
29 #include <dali-toolkit/internal/controls/text-view/text-view-impl.h>
30 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
31 #include <dali-toolkit/internal/controls/text-view/text-view-processor-helper-functions.h>
32 #include <dali-toolkit/internal/controls/text-view/text-view-processor-dbg.h>
35 using namespace Dali::Toolkit;
36 using namespace Dali::Toolkit::Internal;
40 // Data structures used to create an 'experiment' in TET cases
42 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
43 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
45 struct GetIndicesFromGlobalCharacterIndexTest
47 std::string description;
50 std::size_t lineIndex;
51 std::size_t groupIndex;
52 std::size_t wordIndex;
53 std::size_t characterIndex;
57 * Gets the line, group, word, and character indices for a given text and a given position and checks the results with the given indices.
59 * If the test fails it prints a short description and the line where this function was called.
61 * @param description Short description of the experiment.
62 * @param input The input text.
63 * @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.
64 * @param resultLineIndex Index to the line where the character is located.
65 * @param resultGroupIndex Index to the group within the line where the character is located.
66 * @param resultWordIndex Index to the word within the group where the character is located.
67 * @param resultCharacterIndex Index to the character within the word where the character is located.
68 * @param location Where this function has been called.
70 * @return \e true if the experiment is successful. Otherwise returns \e false.
72 bool TestGetIndicesFromGlobalCharacterIndex( const std::string& description,
73 const std::string& input,
74 const std::size_t position,
75 const std::size_t resultLineIndex,
76 const std::size_t resultGroupIndex,
77 const std::size_t resultWordIndex,
78 const std::size_t resultCharacterIndex,
79 const char* location )
81 tet_printf( "%s", description.c_str() );
83 // Create natural size, layout and text-actor info for the input word.
84 Toolkit::Internal::TextView::RelayoutData relayoutData;
85 TextViewProcessor::TextLayoutInfo& inputLayout( relayoutData.mTextLayoutInfo );
87 MarkupProcessor::StyledTextArray inputStyledText;
88 MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
90 TextViewProcessor::CreateTextInfo( inputStyledText,
91 DEFAULT_LAYOUT_PARAMETERS,
94 TextViewProcessor::TextInfoIndices indices;
95 TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
99 if( indices.mLineIndex != resultLineIndex )
101 tet_printf( "Fail. different line index. %s", location );
104 if( indices.mGroupIndex != resultGroupIndex )
106 tet_printf( "Fail. different group 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 //////////////////////////////////////////////////////////////////
126 static void Startup();
127 static void Cleanup();
130 void (*tet_startup)() = Startup;
131 void (*tet_cleanup)() = Cleanup;
135 POSITIVE_TC_IDX = 0x01,
139 #define MAX_NUMBER_OF_TESTS 10000
141 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
144 // Add test functionality for all APIs in the class (Positive and Negative)
145 TEST_FUNCTION( UtcDaliTextViewGetIndicesFromGlobalCharacterIndex, POSITIVE_TC_IDX ); // Tests correctness when indices to lines, groups, words and characters are worked out from a given global position.
146 TEST_FUNCTION( UtcDaliTextViewDebugCouts, POSITIVE_TC_IDX ); // Tests debug functions just to not to penalize the coverage.
148 // Called only once before first test is run.
149 static void Startup()
153 // Called only once after last test is run
154 static void Cleanup()
158 static void UtcDaliTextViewGetIndicesFromGlobalCharacterIndex()
160 ToolkitTestApplication application;
162 tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
163 struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
166 std::string( "Test position 0" ),
167 std::string( "text te<font size='30'>xt text te</font>xt text\n"
168 "text t<font size='30'>ext טקסט טקסט te</font>xt\n"
169 "text text text text text\n"
178 std::string( "Test position 76. (just after the last \\n)" ),
179 std::string( "t<font size='30'>ext text te</font>xt text text\n"
180 "text text טקסט טקסט text\n"
181 "text text te<font size='30'>xt text</font> text\n"
190 std::string( "Test position 73. (the last \\n)" ),
191 std::string( "text te<font size='30'>xt text text </font>text\n"
192 "text text טק<font size='30'>סט טקס</font>ט text\n"
193 "text text text text text\n"
202 std::string( "Test position 35. (first hebrew character)" ),
203 std::string( "text text text text text\n"
204 "text text טקסט טקסט text\n"
205 "text text text text text\n"
214 std::string( "Test position 3. (end of the first word)" ),
215 std::string( "text te<font size='30'>xt text text text\n</font>"
216 "text text טק<font size='30'>סט טקסט </font>text\n"
217 "text te<font size='30'>xt text text</font> text\n"
225 /* TODO Check for mixed RTL and LTR text.
227 std::string( "Test position 33. (end of the second word of the second line)" ),
228 std::string( "text te<font size='30'>xt text text text\n</font>"
229 "text text טק<font size='30'>סט טקסט </font>text\n"
230 "text te<font size='30'>xt text text</font> text\n"
239 std::string( "Test position 43. (last hebrew character)" ),
240 std::string( "text te<font size='30'>xt text text text\n</font>"
241 "text text טק<font size='30'>סט טקסט </font>text\n"
242 "text te<font size='30'>xt text text</font> text\n"
252 const std::size_t numberOfTests( 5 );
254 for( std::size_t index = 0; index < numberOfTests; ++index )
256 const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
258 if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.lineIndex, test.groupIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
260 tet_result( TET_FAIL );
264 tet_result( TET_PASS );
267 static void UtcDaliTextViewDebugCouts()
269 /////////////////////////////////////////////////////
270 // Text debug functions to not to penalize coverage
271 /////////////////////////////////////////////////////
273 ToolkitTestApplication application;
275 tet_infoline("UtcDaliTextViewDebugCouts : ");
277 Toolkit::Internal::TextView::RelayoutData relayoutData;
279 MarkupProcessor::StyledTextArray inputStyledText;
280 MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
282 TextViewProcessor::CreateTextInfo( inputStyledText,
283 DEFAULT_LAYOUT_PARAMETERS,
286 Actor dummy = Actor::New();
287 Toolkit::Internal::SplitByNewLineChar::Relayout( dummy,
288 Toolkit::Internal::TextView::RELAYOUT_ALL,
289 DEFAULT_LAYOUT_PARAMETERS,
290 DEFAULT_VISUAL_PARAMETERS,
293 TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
296 TextViewProcessor::dbgPrint( textStyle );
298 TextViewProcessor::TextInfoIndices indices;
299 TextViewProcessor::dbgPrint( indices );
301 TextViewProcessor::dbgPrint( inputStyledText );
303 tet_result( TET_PASS );