Moved ControlImpl to Internal namespace & renamed to Control
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextView-HelperAndDebug.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
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>
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32 using namespace Dali::Toolkit::Internal;
33
34 void dali_text_view_helper_and_debug_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void dali_text_view_helper_and_debug_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44
45 namespace
46 {
47 // Data structures used to create an 'experiment' in TET cases
48
49 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
50 const Toolkit::Internal::TextView::VisualParameters DEFAULT_VISUAL_PARAMETERS;
51
52 struct GetIndicesFromGlobalCharacterIndexTest
53 {
54   std::string description;
55   std::string input;
56   std::size_t position;
57   std::size_t lineIndex;
58   std::size_t groupIndex;
59   std::size_t wordIndex;
60   std::size_t characterIndex;
61 };
62
63 /**
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.
65  *
66  * If the test fails it prints a short description and the line where this function was called.
67  *
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.
76  *
77  * @return \e true if the experiment is successful. Otherwise returns \e false.
78  */
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 )
87 {
88   tet_printf( "%s", description.c_str() );
89
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 );
93
94   MarkupProcessor::StyledTextArray inputStyledText;
95   MarkupProcessor::GetStyledTextArray( input, inputStyledText, true );
96
97   TextViewProcessor::CreateTextInfo( inputStyledText,
98                                      DEFAULT_LAYOUT_PARAMETERS,
99                                      relayoutData );
100
101   TextViewProcessor::TextInfoIndices indices;
102   TextViewProcessor::GetIndicesFromGlobalCharacterIndex( position,
103                                                          inputLayout,
104                                                          indices );
105
106   if( indices.mLineIndex != resultLineIndex )
107   {
108     tet_printf( "Fail. different line index. %s", location );
109     return false;
110   }
111   if( indices.mGroupIndex != resultGroupIndex )
112   {
113     tet_printf( "Fail. different group index. %s", location );
114     return false;
115   }
116   if( indices.mWordIndex != resultWordIndex )
117   {
118     tet_printf( "Fail. different word index. %s", location );
119     return false;
120   }
121   if( indices.mCharacterIndex != resultCharacterIndex )
122   {
123     tet_printf( "Fail. different character index. %s", location );
124     return false;
125   }
126
127   return true;
128 }
129
130 //////////////////////////////////////////////////////////////////
131 } // namespace
132
133
134 int UtcDaliTextViewGetIndicesFromGlobalCharacterIndex(void)
135 {
136   ToolkitTestApplication application;
137
138   tet_infoline("UtcDaliTextViewGetIndicesFromGlobalCharacterIndex : ");
139   struct GetIndicesFromGlobalCharacterIndexTest getIndicesFromGlobalCharacterIndexTests[] =
140   {
141     {
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"
146                    "\n" ),
147       0,
148       0,
149       0,
150       0,
151       0
152     },
153     {
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"
158                    "\n" ),
159       76,
160       4,
161       0,
162       0,
163       0
164     },
165     {
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"
170                    "\n" ),
171       75,
172       3,
173       0,
174       0,
175       0
176     },
177     {
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"
182                    "\n" ),
183       35,
184       1,
185       1,
186       0,
187       0
188     },
189     {
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"
194                    "\n" ),
195       3,
196       0,
197       0,
198       0,
199       3
200     },
201     /* TODO Check for mixed RTL and LTR text.
202     {
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"
207                    "\n" ),
208       33,
209       1,
210       0,
211       2,
212       3
213     },
214     {
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"
219                    "\n" ),
220       43,
221       1,
222       1,
223       3,
224       3
225     },
226     */
227   };
228   const std::size_t numberOfTests( 5 );
229
230   for( std::size_t index = 0; index < numberOfTests; ++index )
231   {
232     const GetIndicesFromGlobalCharacterIndexTest& test = getIndicesFromGlobalCharacterIndexTests[index];
233
234     if( !TestGetIndicesFromGlobalCharacterIndex( test.description, test.input, test.position, test.lineIndex, test.groupIndex, test.wordIndex, test.characterIndex, TEST_LOCATION ) )
235     {
236       tet_result( TET_FAIL );
237     }
238   }
239
240   tet_result( TET_PASS );
241   END_TEST;
242 }
243
244 int UtcDaliTextViewDebugCouts(void)
245 {
246   /////////////////////////////////////////////////////
247   // Text debug functions to not to penalize coverage
248   /////////////////////////////////////////////////////
249
250   ToolkitTestApplication application;
251
252   tet_infoline("UtcDaliTextViewDebugCouts : ");
253
254   Toolkit::Internal::TextView::RelayoutData relayoutData;
255
256   MarkupProcessor::StyledTextArray inputStyledText;
257   MarkupProcessor::GetStyledTextArray( std::string( "Hello world\nhello world" ), inputStyledText, true );
258
259   TextViewProcessor::CreateTextInfo( inputStyledText,
260                                      DEFAULT_LAYOUT_PARAMETERS,
261                                      relayoutData );
262
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,
268                                                    relayoutData );
269
270   TextViewProcessor::dbgPrint( relayoutData.mTextLayoutInfo );
271
272   TextStyle textStyle;
273   TextViewProcessor::dbgPrint( textStyle );
274
275   TextViewProcessor::TextInfoIndices indices;
276   TextViewProcessor::dbgPrint( indices );
277
278   TextViewProcessor::dbgPrint( inputStyledText );
279
280   tet_result( TET_PASS );
281   END_TEST;
282 }