5a5aa260ed4c3d8578da765d212ca4a436a78658
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-internal-test-suite / text-view / utc-Dali-TextView-Relayout-Utilities.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 <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 // Internal headers are allowed here
28 #include <dali-toolkit/internal/controls/text-view/relayout-utilities.h>
29 #include <dali-toolkit/internal/controls/text-view/text-view-processor.h>
30
31 using namespace Dali;
32 using namespace Dali::Toolkit;
33 using namespace Dali::Toolkit::Internal;
34
35 namespace
36 {
37
38 const Toolkit::Internal::TextView::LayoutParameters DEFAULT_LAYOUT_PARAMETERS;
39
40 // Data structures used to create an 'experiment' in TET cases
41
42
43 bool TestEqual( float x, float y )
44 {
45   return ( fabsf( x - y ) < Math::MACHINE_EPSILON_1000 );
46 }
47
48 //////////////////////////////////////////////////////////////////
49
50 struct CalculateSubLineLayoutTest
51 {
52   std::string description;
53   std::string inputLine;
54   float parentWidth;
55   std::size_t groupIndex;
56   std::size_t wordIndex;
57   std::size_t characterIndex;
58   TextViewRelayout::HorizontalWrapType splitPolicy;
59   float shrinkFactor;
60
61   float resultLineLength;
62   float resultMaxCharHeight;
63   float resultMaxAscender;
64 };
65
66 bool TestCalculateSubLineLayout( const CalculateSubLineLayoutTest& test,  const char* location )
67 {
68   tet_printf( "%s", test.description.c_str() );
69
70   // Create styled text.
71   MarkupProcessor::StyledTextArray inputStyledText;
72   MarkupProcessor::GetStyledTextArray( test.inputLine, inputStyledText, true );
73
74   // Create styled text layout info.
75   Toolkit::Internal::TextView::RelayoutData relayoutData;
76   TextViewProcessor::CreateTextInfo( inputStyledText,
77                                      DEFAULT_LAYOUT_PARAMETERS,
78                                      relayoutData );
79
80   // Prepare input parameters and the result structure and call the function to be tested.
81
82   // Creaqte indices.
83   TextViewProcessor::TextInfoIndices indices( 0, test.groupIndex, test.wordIndex, test.characterIndex );
84
85   // Get the input line.
86   TextViewProcessor::LineLayoutInfo inputLineLayout;
87
88   if( !relayoutData.mTextLayoutInfo.mLinesLayoutInfo.empty() )
89   {
90     inputLineLayout = *relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin();
91   }
92
93   // Result struct.
94   TextViewRelayout::SubLineLayoutInfo resultLayoutInfo;
95
96   CalculateSubLineLayout( test.parentWidth,
97                           indices,
98                           inputLineLayout,
99                           test.splitPolicy,
100                           test.shrinkFactor,
101                           resultLayoutInfo  );
102
103   // Check results.
104   if( !TestEqual( test.resultLineLength, resultLayoutInfo.mLineLength ) )
105   {
106     tet_printf( "Fail. different line length %f == %f. %s", test.resultLineLength, resultLayoutInfo.mLineLength, location );
107     return false;
108   }
109
110   if( !TestEqual( test.resultMaxCharHeight, resultLayoutInfo.mMaxCharHeight ) )
111   {
112     tet_printf( "Fail. different max character height %f == %f. %s", test.resultMaxCharHeight, resultLayoutInfo.mMaxCharHeight, location );
113     return false;
114   }
115
116   if( !TestEqual( test.resultMaxAscender, resultLayoutInfo.mMaxAscender ) )
117   {
118     tet_printf( "Fail. different max ascender %f == %f. %s", test.resultMaxAscender, resultLayoutInfo.mMaxAscender, location );
119     return false;
120   }
121
122   return true;
123 }
124
125 //////////////////////////////////////////////////////////////////
126
127 struct AlignmentOffsetTest
128 {
129   Toolkit::Alignment::Type alignment;
130   float parentSize;
131   float wholeTextSize;
132
133   float resultOffset;
134 };
135
136 bool TestAlignmentOffset( const AlignmentOffsetTest& test, const char* location )
137 {
138   float offset = 0.f;
139
140   switch( test.alignment )
141   {
142     case Toolkit::Alignment::HorizontalLeft:
143     case Toolkit::Alignment::HorizontalCenter:
144     case Toolkit::Alignment::HorizontalRight:
145     {
146       offset = TextViewRelayout::CalculateXoffset( test.alignment, test.parentSize, test.wholeTextSize );
147       break;
148     }
149     case Toolkit::Alignment::VerticalTop:
150     case Toolkit::Alignment::VerticalCenter:
151     case Toolkit::Alignment::VerticalBottom:
152     {
153       offset = TextViewRelayout::CalculateYoffset( test.alignment, test.parentSize, test.wholeTextSize );
154       break;
155     }
156   }
157
158   // Check results.
159   if( !TestEqual( test.resultOffset, offset ) )
160   {
161     tet_printf( "Fail. different offset %f == %f. %s", test.resultOffset, offset, location );
162     return false;
163   }
164
165   return true;
166 }
167
168 //////////////////////////////////////////////////////////////////
169
170 struct JustificationOffsetTest
171 {
172   Toolkit::TextView::LineJustification justification;
173   float wholeTextWidth;
174   float lineLength;
175
176   float resultOffset;
177 };
178
179 bool TestJustificationOffset( const JustificationOffsetTest& test, const char* location )
180 {
181   float offset = TextViewRelayout::CalculateJustificationOffset( test.justification, test.wholeTextWidth, test.lineLength );
182
183   // Check results.
184   if( !TestEqual( test.resultOffset, offset ) )
185   {
186     tet_printf( "Fail. different offset %f == %f. %s", test.resultOffset, offset, location );
187     return false;
188   }
189
190   return true;
191 }
192
193 //////////////////////////////////////////////////////////////////
194
195 struct CalculateVisibilityTest
196 {
197   Vector3 position;
198   Size size;
199   Size parentSize;
200   TextViewRelayout::VisibilityTestType type;
201
202   bool resultVisible;
203 };
204
205 bool TestCalculateVisibility( const CalculateVisibilityTest& test, const char* location )
206 {
207   if( test.resultVisible != TextViewRelayout::IsVisible( test.position, test.size, test.parentSize, test.type ) )
208   {
209     tet_printf( "Fail. different visibility. Type %d, %s", test.type, location );
210     return false;
211   }
212
213   return true;
214 }
215
216 //////////////////////////////////////////////////////////////////
217
218 } // namespace
219
220 static void Startup();
221 static void Cleanup();
222
223 extern "C" {
224   void (*tet_startup)() = Startup;
225   void (*tet_cleanup)() = Cleanup;
226 }
227
228 enum {
229   POSITIVE_TC_IDX = 0x01,
230   NEGATIVE_TC_IDX,
231 };
232
233 #define MAX_NUMBER_OF_TESTS 10000
234 extern "C" {
235   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
236 }
237
238 // Add test functionality for all APIs in the class (Positive and Negative)
239 TEST_FUNCTION( UtcDaliTextViewDefaultConstructorDestructor, POSITIVE_TC_IDX );  // Calls structs's default constructor and destructors and checks their default values.
240 TEST_FUNCTION( UtcDaliTextViewCalculateSubLineLayout, POSITIVE_TC_IDX );        // Checks the function which calculates the layout info of the portion of the line which fits on the text-view width.
241 TEST_FUNCTION( UtcDaliTextViewCalculateAlignmentOffsets, POSITIVE_TC_IDX );     // Checks the horizontal and vertical alignaments (for the whole text).
242 TEST_FUNCTION( UtcDaliTextViewCalculateJustificationOffsets, POSITIVE_TC_IDX ); // Checks the justification alignment (line per line).
243 TEST_FUNCTION( UtcDaliTextViewCalculateVisibility, POSITIVE_TC_IDX );           // Checks the text-actor visibility within the text-view with a rectangle intersection test.
244
245 TEST_FUNCTION( UtcDaliTextViewMiscelaneousAsserts, NEGATIVE_TC_IDX );           // Tests some strange asserts.
246
247 // Called only once before first test is run.
248 static void Startup()
249 {
250 }
251
252 // Called only once after last test is run
253 static void Cleanup()
254 {
255 }
256
257 static void UtcDaliTextViewDefaultConstructorDestructor()
258 {
259   ToolkitTestApplication application;
260
261   tet_infoline("UtcDaliTextViewDefaultConstructorDestructor : ");
262
263   // Test RelayoutParameters defaults.
264   TextViewRelayout::RelayoutParameters relayoutParameters;
265
266   DALI_TEST_EQUALS( relayoutParameters.mPositionOffset, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
267   DALI_TEST_EQUALS( relayoutParameters.mLineSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
268   DALI_TEST_EQUALS( relayoutParameters.mWordSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
269   DALI_TEST_EQUALS( relayoutParameters.mCharacterSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
270   DALI_TEST_EQUALS( relayoutParameters.mIndices.mLineIndex, 0u, TEST_LOCATION );
271   DALI_TEST_EQUALS( relayoutParameters.mIndices.mGroupIndex, 0u, TEST_LOCATION );
272   DALI_TEST_EQUALS( relayoutParameters.mIndices.mWordIndex, 0u, TEST_LOCATION );
273   DALI_TEST_EQUALS( relayoutParameters.mIndices.mCharacterIndex, 0u, TEST_LOCATION );
274   DALI_TEST_EQUALS( relayoutParameters.mCharacterGlobalIndex, 0u, TEST_LOCATION );
275   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacter );
276   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacterOfWord );
277   DALI_TEST_CHECK( !relayoutParameters.mIsNewLine );
278   DALI_TEST_CHECK( !relayoutParameters.mIsNewLineCharacter );
279   DALI_TEST_CHECK( !relayoutParameters.mIsWhiteSpace );
280   DALI_TEST_CHECK( !relayoutParameters.mIsVisible );
281
282   // Test FadeParameter defaults
283   TextViewRelayout::FadeParameters fadeParameters;
284
285   DALI_TEST_EQUALS( fadeParameters.mRightFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
286   DALI_TEST_EQUALS( fadeParameters.mRightFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
287   DALI_TEST_EQUALS( fadeParameters.mRightFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
288   DALI_TEST_EQUALS( fadeParameters.mRightFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
289   DALI_TEST_EQUALS( fadeParameters.mRightAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
290   DALI_TEST_EQUALS( fadeParameters.mLeftFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
291   DALI_TEST_EQUALS( fadeParameters.mLeftFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
292   DALI_TEST_EQUALS( fadeParameters.mLeftFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
293   DALI_TEST_EQUALS( fadeParameters.mLeftFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
294   DALI_TEST_EQUALS( fadeParameters.mLeftAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
295   DALI_TEST_EQUALS( fadeParameters.mTopFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
296   DALI_TEST_EQUALS( fadeParameters.mTopFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
297   DALI_TEST_EQUALS( fadeParameters.mTopFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
298   DALI_TEST_EQUALS( fadeParameters.mTopFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
299   DALI_TEST_EQUALS( fadeParameters.mTopAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
300   DALI_TEST_EQUALS( fadeParameters.mBottomFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
301   DALI_TEST_EQUALS( fadeParameters.mBottomFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
302   DALI_TEST_EQUALS( fadeParameters.mBottomFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
303   DALI_TEST_EQUALS( fadeParameters.mBottomFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
304   DALI_TEST_EQUALS( fadeParameters.mBottomAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
305   DALI_TEST_CHECK( !fadeParameters.mIsPartiallyVisible );
306
307   // Test EllipsizeParameters defaults
308   TextViewRelayout::EllipsizeParameters ellipsizeParameters;
309
310   DALI_TEST_EQUALS( ellipsizeParameters.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
311   DALI_TEST_EQUALS( ellipsizeParameters.mLineDescender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
312   DALI_TEST_EQUALS( ellipsizeParameters.mLineWidth, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
313   DALI_TEST_EQUALS( ellipsizeParameters.mEllipsizeBoundary, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
314   DALI_TEST_EQUALS( ellipsizeParameters.mFirstIndex, 0u, TEST_LOCATION );
315   DALI_TEST_EQUALS( ellipsizeParameters.mLastIndex, 0u, TEST_LOCATION );
316   DALI_TEST_CHECK( !ellipsizeParameters.mEllipsizeLine );
317   DALI_TEST_CHECK( !ellipsizeParameters.mIsLineWidthFullyVisible );
318   DALI_TEST_CHECK( !ellipsizeParameters.mIsLineHeightFullyVisible );
319   DALI_TEST_CHECK( !ellipsizeParameters.mIsNextLineFullyVisibleHeight );
320   DALI_TEST_CHECK( !ellipsizeParameters.mCreateEllipsizedTextActors );
321   DALI_TEST_CHECK( !ellipsizeParameters.mLineFits );
322   DALI_TEST_CHECK( !ellipsizeParameters.mWordFits );
323
324   // Test UnderlineInfo defaults
325   TextViewRelayout::UnderlineInfo underlineInfo;
326
327   DALI_TEST_EQUALS( underlineInfo.mMaxHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
328   DALI_TEST_EQUALS( underlineInfo.mMaxThickness, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
329   DALI_TEST_EQUALS( underlineInfo.mPosition, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
330
331   // Test TextUnderlineStatus defaults
332   TextViewRelayout::TextUnderlineStatus textUnderlineStatus;
333
334   DALI_TEST_CHECK( textUnderlineStatus.mUnderlineInfo.empty() );
335   DALI_TEST_EQUALS( textUnderlineStatus.mCharacterGlobalIndex, 0u, TEST_LOCATION );
336   DALI_TEST_EQUALS( textUnderlineStatus.mLineGlobalIndex, 0u, TEST_LOCATION );
337   DALI_TEST_CHECK( !textUnderlineStatus.mCurrentUnderlineStatus );
338
339   // Test SubLineLayoutInfo defaults
340   TextViewRelayout::SubLineLayoutInfo subLineLayoutInfo;
341
342   DALI_TEST_EQUALS( subLineLayoutInfo.mLineLength, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
343   DALI_TEST_EQUALS( subLineLayoutInfo.mMaxCharHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
344   DALI_TEST_EQUALS( subLineLayoutInfo.mMaxAscender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
345 }
346
347 static void UtcDaliTextViewCalculateSubLineLayout()
348 {
349   ToolkitTestApplication application;
350
351   tet_infoline("UtcDaliTextViewCalculateSubLineLayout : ");
352
353   struct CalculateSubLineLayoutTest calculateSubLineLayoutTest[] =
354   {
355     //WrapByCharacter
356     {
357       "The line is wraped by character. All characters have the same size.",
358       "Hello world", // input line
359       100.f,         // parent width
360       0,
361       0,              // indices
362       0,
363       TextViewRelayout::WrapByCharacter, // split policy
364       1.f,
365       // results
366       91.041672f, // line length. (only fits 8 characters 8x11.38)
367       11.380209f, // max character height
368       10.242188f  // max ascender
369     },
370     {
371       "The line is wraped by character. There are characters with different sizes.",
372       "Hello <font size='14'>world</font>", // input line
373       100.f,         // parent width
374       0,
375       0,              // indices
376       0,
377       TextViewRelayout::WrapByCharacter, // split policy
378       1.f,
379       // results
380       94.835075f, // line length. (only fits 8 characters 6x11.38 + 2x13.27)
381       13.276911f, // max character height
382       11.949220f  // max ascender
383     },
384     {
385       "The line is wraped by character. There are characters with different sizes. It calculates the layout for the second line.",
386       "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input line
387       100.f,         // parent width
388       0,
389       2,              // indices. The third character of the third word starts in a new line.
390       2,
391       TextViewRelayout::WrapByCharacter, // split policy
392       1.f,
393       // results
394       91.041672f, // line length. (only fits 8 characters 8x11.38)
395       11.380209f, // max character height
396       10.242188f  // max ascender
397     },
398     {
399       "The line is wraped by character. There are characters with different sizes. It calculates the layout for the third line.",
400       "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input line
401       100.f,         // parent width
402       0,
403       4,              // indices. The fifth character of the fifth word starts in a new line.
404       4,
405       TextViewRelayout::WrapByCharacter, // split policy
406       1.f,
407       // results
408       92.938377f, // line length. (only fits 8 characters 8x11.38)
409       13.276911f, // max character height
410       11.949220f  // max ascender
411     },
412
413     //WrapByWord
414     {
415       "The line is wraped by word. All characters have the same size.",
416       "Hello world", // input line
417       100.f,         // parent width
418       0,
419       0,              // indices. It shouldn't use the index character so 9999999 shouldn't make it crash.
420       9999999,
421       TextViewRelayout::WrapByWord, // split policy
422       1.f,
423       // results
424       56.901047f, // line length. (only fits 5 characters 5x11.38, white space is not counted)
425       11.380209f, // max character height
426       10.242188f  // max ascender
427     },
428     {
429       "The line is wraped by word. There are characters with different sizes.",
430       "Hell<font size='14'>o</font> world", // input line
431       100.f,         // parent width
432       0,
433       0,              // indices.
434       0,
435       TextViewRelayout::WrapByWord, // split policy
436       1.f,
437       // results
438       58.797747f, // line length. (only fits 5 characters 4x11.38 + 13.276911, white space is not counted)
439       13.276911f, // max character height
440       11.949220f  // max ascender
441     },
442     {
443       "The line is wraped by word. There are characters with different sizes. It calculates the layout for the second line.",
444       "Hello <font size='14'>wo</font>rld <font size='16'>hello world</font>", // input line
445       100.f,         // parent width
446       0,
447       2,              // indices. The third word starts in a new line.
448       0,
449       TextViewRelayout::WrapByWord, // split policy
450       1.f,
451       // results
452       60.694449f, // line length. (only fits 5 characters 2x13.276911 + 3x11.38)
453       13.276911f, // max character height
454       11.949220f  // max ascender
455     },
456     {
457       "The line is wraped by word. The word doen't fit.",
458       "Hello world", // input line
459       40.f,          // parent width
460       0,
461       0,              // indices. The third word starts in a new line.
462       0,
463       TextViewRelayout::WrapByWord, // split policy
464       1.f,
465       // results
466       0.f,        // line length. (The word doesn't fit)
467       11.380209f, // max character height
468       10.242188f  // max ascender
469     },
470
471     //WrapByWordAndSplit
472     {
473       "The line is wraped by word and by character. All characters have the same size. There is not a long word.",
474       "Hello world hello world", // input line
475       100.f,         // parent width
476       0,
477       0,              // indices.
478       0,
479       TextViewRelayout::WrapByWordAndSplit, // split policy
480       1.f,
481       // results
482       56.901047f, // line length. (only fits 5 characters 5x11.38, white space is not counted)
483       11.380209f, // max character height
484       10.242188f  // max ascender
485     },
486     {
487       "The line is wraped by word and by character. All characters have the same size. There is a long word.",
488       "Helloooooooo world", // input line
489       100.f,         // parent width
490       0,
491       0,              // indices.
492       0,
493       TextViewRelayout::WrapByWordAndSplit, // split policy
494       1.f,
495       // results
496       91.041672f, // line length. (only fits 8 characters 8x11.38)
497       11.380209f, // max character height
498       10.242188f  // max ascender
499     },
500     {
501       "The line is wraped by word and by character. There are characters with different sizes. There is a long word. It calculates the layout for the second line.",
502       "Helloooooooo <font size='14'>world</font>", // input line
503       100.f,         // parent width
504       0,
505       0,              // indices.
506       8,
507       TextViewRelayout::WrapByWordAndSplit, // split policy
508       1.f,
509       // results
510       45.520836f, // line length. (only fits 8 characters 8x11.38)
511       11.380209f, // max character height
512       10.242188f  // max ascender
513     },
514     {
515       "The line is wraped by word and by character. There are characters with different sizes. There is a shrink factor.",
516       "Helloooooooo<font size='14'> world</font>", // input line
517       100.f,         // parent width
518       0,
519       0,              // indices.
520       8,
521       TextViewRelayout::WrapByWordAndSplit, // split policy
522       0.7f,
523       // results
524       95.593755f, // line length. (only fits 12 characters 8x11.38)
525       7.9661463f, // max character height
526       7.169531f  // max ascender
527     },
528
529     //WrapByLineAndSplit
530     {
531       "The line is wraped by end of line and by character. All characters have the same size.",
532       "Hello world", // input line
533       100.f,         // parent width
534       0,
535       0,              // indices
536       0,
537       TextViewRelayout::WrapByLineAndSplit, // split policy
538       1.f,
539       // results
540       91.041672f, // line length. (only fits 8 characters 8x11.38)
541       11.380209f, // max character height
542       10.242188f  // max ascender
543     },
544     {
545       "The line fits in the width.",
546       "Hello", // input line
547       100.f,         // parent width
548       0,
549       0,             // indices
550       0,
551       TextViewRelayout::WrapByLineAndSplit, // split policy
552       1.f,
553       // results
554       56.901047f, // line length. (only fits 5 characters 5x11.38)
555       11.380209f, // max character height
556       10.242188f  // max ascender
557     },
558     {
559       "The line is wraped by end of line and by character. All characters have the same size. It calculates the layout for the second line.",
560       "Hello world, hello world", // input line
561       100.f,         // parent width
562       0,
563       2,             // indices
564       2,
565       TextViewRelayout::WrapByLineAndSplit, // split policy
566       1.f,
567       // results
568       91.041672f, // line length. (only fits 8 characters 8x11.38)
569       11.380209f, // max character height
570       10.242188f  // max ascender
571     },
572   };
573   const std::size_t numberOfTests( 15 );
574
575   for( std::size_t index = 0; index < numberOfTests; ++index )
576   {
577     const CalculateSubLineLayoutTest& test = calculateSubLineLayoutTest[index];
578
579     if( !TestCalculateSubLineLayout( test, TEST_LOCATION ) )
580     {
581       tet_result( TET_FAIL );
582     }
583   }
584
585   tet_result( TET_PASS );
586 }
587
588 static void UtcDaliTextViewCalculateAlignmentOffsets()
589 {
590   ToolkitTestApplication application;
591
592   tet_infoline("UtcDaliTextViewCalculateAlignmentOffsets : ");
593
594   struct AlignmentOffsetTest alignmentOffsetTest[] =
595   {
596     {
597       Toolkit::Alignment::HorizontalLeft,
598       100.f,
599       75.f,
600       0.f
601     },
602     {
603       Toolkit::Alignment::HorizontalCenter,
604       100.f,
605       75.f,
606       12.5f
607     },
608     {
609       Toolkit::Alignment::HorizontalRight,
610       100.f,
611       75.f,
612       25.f
613     },
614     {
615       Toolkit::Alignment::VerticalTop,
616       100.f,
617       75.f,
618       0.f
619     },
620     {
621       Toolkit::Alignment::VerticalCenter,
622       100.f,
623       75.f,
624       12.5f
625     },
626     {
627       Toolkit::Alignment::VerticalBottom,
628       100.f,
629       75.f,
630       25.f
631     }
632   };
633   const std::size_t numberOfTests( 6 );
634
635   for( std::size_t index = 0; index < numberOfTests; ++index )
636   {
637     const AlignmentOffsetTest& test = alignmentOffsetTest[index];
638
639     if( !TestAlignmentOffset( test, TEST_LOCATION ) )
640     {
641       tet_result( TET_FAIL );
642     }
643   }
644
645   tet_result( TET_PASS );
646 }
647
648 static void UtcDaliTextViewCalculateJustificationOffsets()
649 {
650   ToolkitTestApplication application;
651
652   tet_infoline("UtcDaliTextViewCalculateJustificationOffsets : ");
653
654   struct JustificationOffsetTest justificationOffsetTest[] =
655   {
656     {
657       Toolkit::TextView::Left,
658       100.f,
659       75.f,
660       0.f
661     },
662     {
663       Toolkit::TextView::Justified,
664       100.f,
665       75.f,
666       0.f
667     },
668     {
669       Toolkit::TextView::Center,
670       100.f,
671       150.f,
672       -25.f
673     },
674     {
675       Toolkit::TextView::Right,
676       100.f,
677       75.f,
678       25.f
679     },
680   };
681   const std::size_t numberOfTests( 4 );
682
683   for( std::size_t index = 0; index < numberOfTests; ++index )
684   {
685     const JustificationOffsetTest& test = justificationOffsetTest[index];
686
687     if( !TestJustificationOffset( test, TEST_LOCATION ) )
688     {
689       tet_result( TET_FAIL );
690     }
691   }
692
693   tet_result( TET_PASS );
694 }
695
696
697 static void UtcDaliTextViewCalculateVisibility()
698 {
699   ToolkitTestApplication application;
700
701   tet_infoline("UtcDaliTextViewCalculateVisibility : ");
702
703   struct CalculateVisibilityTest calculateVisibilityTest[] =
704   {
705     {
706       Vector3( 0.f, 10.f, 0.f ),
707       Size( 10.f, 10.f ),
708       Size( 100.f, 100.f ),
709       TextViewRelayout::FULLY_VISIBLE,
710       true
711     },
712     {
713       Vector3( 10.f, 10.f, 0.f ),
714       Size( 10.f, 10.f ),
715       Size( 100.f, 100.f ),
716       TextViewRelayout::FULLY_VISIBLE,
717       true
718     },
719     {
720       Vector3( 0.f, 10.f, 0.f ),
721       Size( 150.f, 10.f ),
722       Size( 100.f, 100.f ),
723       TextViewRelayout::FULLY_VISIBLE,
724       false
725     },
726     {
727       Vector3( 0.f, 10.f, 0.f ),
728       Size( 10.f, 10.f ),
729       Size( 100.f, 100.f ),
730       TextViewRelayout::FULLY_VISIBLE_WIDTH,
731       true
732     },
733     {
734       Vector3( 95.f, 10.f, 0.f ),
735       Size( 10.f, 10.f ),
736       Size( 100.f, 100.f ),
737       TextViewRelayout::FULLY_VISIBLE_WIDTH,
738       false
739     },
740     {
741       Vector3( 0.f, 10.f, 0.f ),
742       Size( 10.f, 10.f ),
743       Size( 100.f, 100.f ),
744       TextViewRelayout::FULLY_VISIBLE_HEIGHT,
745       true
746     },
747     {
748       Vector3( 0.f, 0.f, 0.f ),
749       Size( 10.f, 10.f ),
750       Size( 100.f, 100.f ),
751       TextViewRelayout::FULLY_VISIBLE_HEIGHT,
752       false
753     },
754     {
755       Vector3( -10.f, 10.f, 0.f ),
756       Size( 150.f, 150.f ),
757       Size( 100.f, 100.f ),
758       TextViewRelayout::PARTIALLY_VISIBLE,
759       true
760     },
761     {
762       Vector3( -100.f, -100.f, 0.f ),
763       Size( 10.f, 10.f ),
764       Size( 100.f, 100.f ),
765       TextViewRelayout::PARTIALLY_VISIBLE,
766       false
767     },
768     {
769       Vector3( -10.f, 10.f, 0.f ),
770       Size( 50.f, 10.f ),
771       Size( 100.f, 100.f ),
772       TextViewRelayout::PARTIALLY_VISIBLE_WIDTH,
773       true
774     },
775     {
776       Vector3( 110.f, 10.f, 0.f ),
777       Size( 10.f, 10.f ),
778       Size( 100.f, 100.f ),
779       TextViewRelayout::PARTIALLY_VISIBLE_WIDTH,
780       false
781     },
782     {
783       Vector3( 0.f, 20.f, 0.f ),
784       Size( 10.f, 50.f ),
785       Size( 100.f, 100.f ),
786       TextViewRelayout::PARTIALLY_VISIBLE_HEIGHT,
787       true
788     },
789     {
790       Vector3( 0.f, -10.f, 0.f ),
791       Size( 10.f, 10.f ),
792       Size( 100.f, 100.f ),
793       TextViewRelayout::PARTIALLY_VISIBLE_HEIGHT,
794       false
795     },
796   };
797   const std::size_t numberOfTests( 13 );
798
799   for( std::size_t index = 0; index < numberOfTests; ++index )
800   {
801     const CalculateVisibilityTest& test = calculateVisibilityTest[index];
802
803     if( !TestCalculateVisibility( test, TEST_LOCATION ) )
804     {
805       tet_result( TET_FAIL );
806     }
807   }
808
809   tet_result( TET_PASS );
810 }
811
812 static void UtcDaliTextViewMiscelaneousAsserts()
813 {
814   ToolkitTestApplication application;
815
816   tet_infoline("UtcDaliTextViewMiscelaneousAsserts : ");
817
818   float offset = 0.f;
819
820   bool assert1 = false;
821   bool assert2 = false;
822   try
823   {
824     offset = Toolkit::Internal::TextViewRelayout::CalculateXoffset( Toolkit::Alignment::VerticalTop, 100.f, 50.f );
825   }
826   catch( Dali::DaliException& e )
827   {
828     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
829     DALI_TEST_EQUALS( e.mCondition, "!\"TextViewRelayout::CalculateXoffset: Wrong horizontal text alignment. Did you set a vertical one?\"", TEST_LOCATION );
830     assert1 = true;
831   }
832   catch( ... )
833   {
834     tet_result( TET_FAIL );
835   }
836   DALI_TEST_EQUALS( offset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
837
838   try
839   {
840     offset = Toolkit::Internal::TextViewRelayout::CalculateYoffset( Toolkit::Alignment::HorizontalRight, 100.f, 50.f );
841   }
842   catch( Dali::DaliException& e )
843   {
844     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
845     DALI_TEST_EQUALS( e.mCondition, "!\"TextViewRelayout::CalculateXoffset: Wrong vertical text alignment. Did you set an horizontal one?\"", TEST_LOCATION );
846     assert2 = true;
847   }
848   catch( ... )
849   {
850     tet_result( TET_FAIL );
851   }
852   DALI_TEST_EQUALS( offset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
853
854   DALI_TEST_CHECK( assert1 && assert2 );
855
856 }