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