[dali_1.0.9] Merge branch 'tizen'
[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 CalculateLineLayoutTest
58 {
59   std::string description;
60   std::string inputParagraph;
61   float parentWidth;
62   std::size_t wordIndex;
63   std::size_t characterIndex;
64   std::size_t characterParagraphIndex;
65   TextViewRelayout::HorizontalWrapType splitPolicy;
66   float shrinkFactor;
67
68   float resultLineLength;
69   float resultMaxCharHeight;
70   float resultMaxAscender;
71 };
72
73 bool TestCalculateLineLayout( const CalculateLineLayoutTest& 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.inputParagraph, 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( 0u, test.wordIndex, test.characterIndex );
91
92   // Get the input paragraph.
93   TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout;
94
95   if( !relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.empty() )
96   {
97     inputParagraphLayout = *relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.begin();
98   }
99
100   // Result struct.
101   TextViewRelayout::LineLayoutInfo resultLayoutInfo;
102
103   CalculateLineLayout( test.parentWidth,
104                        indices,
105                        inputParagraphLayout,
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.mParagraphSize, 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.mParagraphIndex, 0u, TEST_LOCATION );
242   DALI_TEST_EQUALS( relayoutParameters.mIndices.mWordIndex, 0u, TEST_LOCATION );
243   DALI_TEST_EQUALS( relayoutParameters.mIndices.mCharacterIndex, 0u, TEST_LOCATION );
244   DALI_TEST_EQUALS( relayoutParameters.mCharacterGlobalIndex, 0u, TEST_LOCATION );
245   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacter );
246   DALI_TEST_CHECK( !relayoutParameters.mIsFirstCharacterOfWord );
247   DALI_TEST_CHECK( !relayoutParameters.mIsNewLine );
248   DALI_TEST_CHECK( !relayoutParameters.mIsNewParagraphCharacter );
249   DALI_TEST_CHECK( !relayoutParameters.mIsWhiteSpace );
250   DALI_TEST_CHECK( !relayoutParameters.mIsVisible );
251
252   // Test FadeParameter defaults
253   TextViewRelayout::FadeParameters fadeParameters;
254
255   DALI_TEST_EQUALS( fadeParameters.mRightFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
256   DALI_TEST_EQUALS( fadeParameters.mRightFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
257   DALI_TEST_EQUALS( fadeParameters.mRightFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
258   DALI_TEST_EQUALS( fadeParameters.mRightFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
259   DALI_TEST_EQUALS( fadeParameters.mRightAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
260   DALI_TEST_EQUALS( fadeParameters.mLeftFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
261   DALI_TEST_EQUALS( fadeParameters.mLeftFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
262   DALI_TEST_EQUALS( fadeParameters.mLeftFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
263   DALI_TEST_EQUALS( fadeParameters.mLeftFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
264   DALI_TEST_EQUALS( fadeParameters.mLeftAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
265   DALI_TEST_EQUALS( fadeParameters.mTopFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
266   DALI_TEST_EQUALS( fadeParameters.mTopFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
267   DALI_TEST_EQUALS( fadeParameters.mTopFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
268   DALI_TEST_EQUALS( fadeParameters.mTopFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
269   DALI_TEST_EQUALS( fadeParameters.mTopAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
270   DALI_TEST_EQUALS( fadeParameters.mBottomFadeBoundary, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
271   DALI_TEST_EQUALS( fadeParameters.mBottomFadeThreshold, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
272   DALI_TEST_EQUALS( fadeParameters.mBottomFadeBoundaryOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
273   DALI_TEST_EQUALS( fadeParameters.mBottomFadeThresholdOffset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
274   DALI_TEST_EQUALS( fadeParameters.mBottomAlphaCoeficients, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
275   DALI_TEST_CHECK( !fadeParameters.mIsPartiallyVisible );
276
277   // Test EllipsizeParameters defaults
278   TextViewRelayout::EllipsizeParameters ellipsizeParameters;
279
280   DALI_TEST_EQUALS( ellipsizeParameters.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
281   DALI_TEST_EQUALS( ellipsizeParameters.mLineDescender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
282   DALI_TEST_EQUALS( ellipsizeParameters.mLineWidth, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
283   DALI_TEST_EQUALS( ellipsizeParameters.mEllipsizeBoundary, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
284   DALI_TEST_EQUALS( ellipsizeParameters.mFirstIndex, 0u, TEST_LOCATION );
285   DALI_TEST_EQUALS( ellipsizeParameters.mLastIndex, 0u, TEST_LOCATION );
286   DALI_TEST_CHECK( !ellipsizeParameters.mEllipsizeLine );
287   DALI_TEST_CHECK( !ellipsizeParameters.mIsLineWidthFullyVisible );
288   DALI_TEST_CHECK( !ellipsizeParameters.mIsLineHeightFullyVisible );
289   DALI_TEST_CHECK( !ellipsizeParameters.mIsNextLineFullyVisibleHeight );
290   DALI_TEST_CHECK( !ellipsizeParameters.mCreateEllipsizedTextActors );
291   DALI_TEST_CHECK( !ellipsizeParameters.mLineFits );
292   DALI_TEST_CHECK( !ellipsizeParameters.mWordFits );
293
294   // Test UnderlineInfo defaults
295   TextViewRelayout::UnderlineInfo underlineInfo;
296
297   DALI_TEST_EQUALS( underlineInfo.mMaxHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
298   DALI_TEST_EQUALS( underlineInfo.mMaxThickness, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
299   DALI_TEST_EQUALS( underlineInfo.mPosition, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
300
301   // Test TextUnderlineStatus defaults
302   TextViewRelayout::TextUnderlineStatus textUnderlineStatus;
303
304   DALI_TEST_CHECK( textUnderlineStatus.mUnderlineInfo.empty() );
305   DALI_TEST_EQUALS( textUnderlineStatus.mCharacterGlobalIndex, 0u, TEST_LOCATION );
306   DALI_TEST_EQUALS( textUnderlineStatus.mLineGlobalIndex, 0u, TEST_LOCATION );
307   DALI_TEST_CHECK( !textUnderlineStatus.mCurrentUnderlineStatus );
308
309   // Test LineLayoutInfo defaults
310   TextViewRelayout::LineLayoutInfo lineLayoutInfo;
311
312   DALI_TEST_EQUALS( lineLayoutInfo.mLineLength, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
313   DALI_TEST_EQUALS( lineLayoutInfo.mMaxCharHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
314   DALI_TEST_EQUALS( lineLayoutInfo.mMaxAscender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
315   END_TEST;
316 }
317
318 int UtcDaliTextViewCalculateLineLayout(void)
319 {
320   ToolkitTestApplication application;
321
322   tet_infoline("UtcDaliTextViewCalculateLineLayout : ");
323
324   struct CalculateLineLayoutTest calculateLineLayoutTest[] =
325   {
326     //WrapByCharacter
327     {
328       "The paragraph is wraped by character. All characters have the same size.",
329       "Hello world", // input paragraph
330       100.f,         // parent width
331       0,             // indices
332       0,
333       0,
334       TextViewRelayout::WrapByCharacter, // split policy
335       1.f,
336       // results
337       91.041672f, // line length. (only fits 8 characters 8x11.38)
338       11.380209f, // max character height
339       10.242188f  // max ascender
340     },
341     {
342       "The paragraph is wraped by character. There are characters with different sizes.",
343       "Hello <font size='14'>world</font>", // input paragraph
344       100.f,         // parent width
345       0,              // indices
346       0,
347       0,
348       TextViewRelayout::WrapByCharacter, // split policy
349       1.f,
350       // results
351       94.835075f, // line length. (only fits 8 characters 6x11.38 + 2x13.27)
352       13.276911f, // max character height
353       11.949220f  // max ascender
354     },
355     {
356       "The paragraph is wraped by character. There are characters with different sizes. It calculates the layout for the second line.",
357       "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input paragraph
358       100.f,         // parent width
359       2,              // indices. The third character of the third word starts in a new line.
360       2,
361       8,
362       TextViewRelayout::WrapByCharacter, // split policy
363       1.f,
364       // results
365       91.041672f, // line length. (only fits 8 characters 8x11.38)
366       11.380209f, // max character height
367       10.242188f  // max ascender
368     },
369     {
370       "The paragraph is wraped by character. There are characters with different sizes. It calculates the layout for the third line.",
371       "Hello <font size='14'>wo</font>rld hell<font size='14'>o world</font>", // input paragraph
372       100.f,         // parent width
373       4,              // indices. The fifth character of the fifth word starts in a new line.
374       4,
375       16,
376       TextViewRelayout::WrapByCharacter, // split policy
377       1.f,
378       // results
379       92.938377f, // line length. (only fits 8 characters 8x11.38)
380       13.276911f, // max character height
381       11.949220f  // max ascender
382     },
383
384     //WrapByWord
385     {
386       "The paragraph is wraped by word. All characters have the same size.",
387       "Hello world", // input paragraph
388       100.f,         // parent width
389       0,              // indices. It shouldn't use the index character so 9999999 shouldn't make it crash.
390       9999999,
391       9999999,
392       TextViewRelayout::WrapByWord, // split policy
393       1.f,
394       // results
395       56.901047f, // line length. (only fits 5 characters 5x11.38, white space is not counted)
396       11.380209f, // max character height
397       10.242188f  // max ascender
398     },
399     {
400       "The paragraph is wraped by word. There are characters with different sizes.",
401       "Hell<font size='14'>o</font> world", // input paragraph
402       100.f,         // parent width
403       0,              // indices.
404       0,
405       0,
406       TextViewRelayout::WrapByWord, // split policy
407       1.f,
408       // results
409       58.797747f, // line length. (only fits 5 characters 4x11.38 + 13.276911, white space is not counted)
410       13.276911f, // max character height
411       11.949220f  // max ascender
412     },
413     {
414       "The paragraph is wraped by word. There are characters with different sizes. It calculates the layout for the second line.",
415       "Hello <font size='14'>wo</font>rld <font size='16'>hello world</font>", // input paragraph
416       100.f,         // parent width
417       2,              // indices. The third word starts in a new line.
418       0,
419       6,
420       TextViewRelayout::WrapByWord, // split policy
421       1.f,
422       // results
423       60.694449f, // line length. (only fits 5 characters 2x13.276911 + 3x11.38)
424       13.276911f, // max character height
425       11.949220f  // max ascender
426     },
427     {
428       "The paragraph is wraped by word. The word doen't fit.",
429       "Hello world", // input paragraph
430       40.f,          // parent width
431       0,              // indices. The third word starts in a new line.
432       0,
433       0,
434       TextViewRelayout::WrapByWord, // split policy
435       1.f,
436       // results
437       0.f,        // line length. (The word doesn't fit)
438       11.380209f, // max character height
439       10.242188f  // max ascender
440     },
441
442     //WrapByWordAndSplit
443     {
444       "The paragraph is wraped by word and by character. All characters have the same size. There is not a long word.",
445       "Hello world hello world", // input paragraph
446       100.f,         // parent width
447       0,              // indices.
448       0,
449       0,
450       TextViewRelayout::WrapByWordAndSplit, // split policy
451       1.f,
452       // results
453       56.901047f, // line length. (only fits 5 characters 5x11.38, white space is not counted)
454       11.380209f, // max character height
455       10.242188f  // max ascender
456     },
457     {
458       "The paragraph is wraped by word and by character. All characters have the same size. There is a long word.",
459       "Helloooooooo world", // input paragraph
460       100.f,         // parent width
461       0,              // indices.
462       0,
463       0,
464       TextViewRelayout::WrapByWordAndSplit, // split policy
465       1.f,
466       // results
467       91.041672f, // line length. (only fits 8 characters 8x11.38)
468       11.380209f, // max character height
469       10.242188f  // max ascender
470     },
471     {
472       "The paragraph 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.",
473       "Helloooooooo <font size='14'>world</font>", // input paragraph
474       100.f,         // parent width
475       0,              // indices.
476       8,
477       8,
478       TextViewRelayout::WrapByWordAndSplit, // split policy
479       1.f,
480       // results
481       45.520836f, // line length. (only fits 8 characters 8x11.38)
482       11.380209f, // max character height
483       10.242188f  // max ascender
484     },
485     {
486       "The paragraph is wraped by word and by character. There are characters with different sizes. There is a shrink factor.",
487       "Helloooooooo<font size='14'> world</font>", // input paragraph
488       100.f,         // parent width
489       0,              // indices.
490       8,
491       8,
492       TextViewRelayout::WrapByWordAndSplit, // split policy
493       0.7f,
494       // results
495       95.593755f, // line length. (only fits 12 characters 8x11.38)
496       7.9661463f, // max character height
497       7.169531f  // max ascender
498     },
499
500     //WrapByParagraphCharacterAndSplit
501     {
502       "The paragraph is wraped by end of paragraph and by character. All characters have the same size.",
503       "Hello world", // input paragraph
504       100.f,         // parent width
505       0,              // indices
506       0,
507       0,
508       TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
509       1.f,
510       // results
511       91.041672f, // line length. (only fits 8 characters 8x11.38)
512       11.380209f, // max character height
513       10.242188f  // max ascender
514     },
515     {
516       "The paragraph fits in the width.",
517       "Hello", // input paragraph
518       100.f,         // parent width
519       0,             // indices
520       0,
521       0,
522       TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
523       1.f,
524       // results
525       56.901047f, // line length. (only fits 5 characters 5x11.38)
526       11.380209f, // max character height
527       10.242188f  // max ascender
528     },
529     {
530       "The paragraph is wraped by end of paragraph and by character. All characters have the same size. It calculates the layout for the second line.",
531       "Hello world, hello world", // input paragraph
532       100.f,         // parent width
533       2,             // indices
534       2,
535       8,
536       TextViewRelayout::WrapByParagraphCharacterAndSplit, // split policy
537       1.f,
538       // results
539       91.041672f, // line length. (only fits 8 characters 8x11.38)
540       11.380209f, // max character height
541       10.242188f  // max ascender
542     },
543   };
544   const std::size_t numberOfTests( 15 );
545
546   for( std::size_t index = 0; index < numberOfTests; ++index )
547   {
548     const CalculateLineLayoutTest& test = calculateLineLayoutTest[index];
549
550     if( !TestCalculateLineLayout( test, TEST_LOCATION ) )
551     {
552       tet_result( TET_FAIL );
553     }
554   }
555
556   tet_result( TET_PASS );
557   END_TEST;
558 }
559
560 int UtcDaliTextViewCalculateAlignmentOffsets(void)
561 {
562   ToolkitTestApplication application;
563
564   tet_infoline("UtcDaliTextViewCalculateAlignmentOffsets : ");
565
566   struct AlignmentOffsetTest alignmentOffsetTest[] =
567   {
568     {
569       Toolkit::Alignment::HorizontalLeft,
570       100.f,
571       75.f,
572       0.f
573     },
574     {
575       Toolkit::Alignment::HorizontalCenter,
576       100.f,
577       75.f,
578       12.5f
579     },
580     {
581       Toolkit::Alignment::HorizontalRight,
582       100.f,
583       75.f,
584       25.f
585     },
586     {
587       Toolkit::Alignment::VerticalTop,
588       100.f,
589       75.f,
590       0.f
591     },
592     {
593       Toolkit::Alignment::VerticalCenter,
594       100.f,
595       75.f,
596       12.5f
597     },
598     {
599       Toolkit::Alignment::VerticalBottom,
600       100.f,
601       75.f,
602       25.f
603     }
604   };
605   const std::size_t numberOfTests( 6 );
606
607   for( std::size_t index = 0; index < numberOfTests; ++index )
608   {
609     const AlignmentOffsetTest& test = alignmentOffsetTest[index];
610
611     if( !TestAlignmentOffset( test, TEST_LOCATION ) )
612     {
613       tet_result( TET_FAIL );
614     }
615   }
616
617   tet_result( TET_PASS );
618   END_TEST;
619 }
620
621 int UtcDaliTextViewCalculateJustificationOffsets(void)
622 {
623   ToolkitTestApplication application;
624
625   tet_infoline("UtcDaliTextViewCalculateJustificationOffsets : ");
626
627   struct JustificationOffsetTest justificationOffsetTest[] =
628   {
629     {
630       Toolkit::TextView::Left,
631       100.f,
632       75.f,
633       0.f
634     },
635     {
636       Toolkit::TextView::Justified,
637       100.f,
638       75.f,
639       0.f
640     },
641     {
642       Toolkit::TextView::Center,
643       100.f,
644       150.f,
645       -25.f
646     },
647     {
648       Toolkit::TextView::Right,
649       100.f,
650       75.f,
651       25.f
652     },
653   };
654   const std::size_t numberOfTests( 4 );
655
656   for( std::size_t index = 0; index < numberOfTests; ++index )
657   {
658     const JustificationOffsetTest& test = justificationOffsetTest[index];
659
660     if( !TestJustificationOffset( test, TEST_LOCATION ) )
661     {
662       tet_result( TET_FAIL );
663     }
664   }
665
666   tet_result( TET_PASS );
667   END_TEST;
668 }
669
670
671 int UtcDaliTextViewCalculateVisibility(void)
672 {
673   ToolkitTestApplication application;
674
675   tet_infoline("UtcDaliTextViewCalculateVisibility : ");
676
677   struct CalculateVisibilityTest calculateVisibilityTest[] =
678   {
679     {
680       Vector3( 0.f, 10.f, 0.f ),
681       Size( 10.f, 10.f ),
682       Size( 100.f, 100.f ),
683       TextViewRelayout::FULLY_VISIBLE,
684       true
685     },
686     {
687       Vector3( 10.f, 10.f, 0.f ),
688       Size( 10.f, 10.f ),
689       Size( 100.f, 100.f ),
690       TextViewRelayout::FULLY_VISIBLE,
691       true
692     },
693     {
694       Vector3( 0.f, 10.f, 0.f ),
695       Size( 150.f, 10.f ),
696       Size( 100.f, 100.f ),
697       TextViewRelayout::FULLY_VISIBLE,
698       false
699     },
700     {
701       Vector3( 0.f, 10.f, 0.f ),
702       Size( 10.f, 10.f ),
703       Size( 100.f, 100.f ),
704       TextViewRelayout::FULLY_VISIBLE_WIDTH,
705       true
706     },
707     {
708       Vector3( 95.f, 10.f, 0.f ),
709       Size( 10.f, 10.f ),
710       Size( 100.f, 100.f ),
711       TextViewRelayout::FULLY_VISIBLE_WIDTH,
712       false
713     },
714     {
715       Vector3( 0.f, 10.f, 0.f ),
716       Size( 10.f, 10.f ),
717       Size( 100.f, 100.f ),
718       TextViewRelayout::FULLY_VISIBLE_HEIGHT,
719       true
720     },
721     {
722       Vector3( 0.f, 0.f, 0.f ),
723       Size( 10.f, 10.f ),
724       Size( 100.f, 100.f ),
725       TextViewRelayout::FULLY_VISIBLE_HEIGHT,
726       false
727     },
728     {
729       Vector3( -10.f, 10.f, 0.f ),
730       Size( 150.f, 150.f ),
731       Size( 100.f, 100.f ),
732       TextViewRelayout::PARTIALLY_VISIBLE,
733       true
734     },
735     {
736       Vector3( -100.f, -100.f, 0.f ),
737       Size( 10.f, 10.f ),
738       Size( 100.f, 100.f ),
739       TextViewRelayout::PARTIALLY_VISIBLE,
740       false
741     },
742     {
743       Vector3( -10.f, 10.f, 0.f ),
744       Size( 50.f, 10.f ),
745       Size( 100.f, 100.f ),
746       TextViewRelayout::PARTIALLY_VISIBLE_WIDTH,
747       true
748     },
749     {
750       Vector3( 110.f, 10.f, 0.f ),
751       Size( 10.f, 10.f ),
752       Size( 100.f, 100.f ),
753       TextViewRelayout::PARTIALLY_VISIBLE_WIDTH,
754       false
755     },
756     {
757       Vector3( 0.f, 20.f, 0.f ),
758       Size( 10.f, 50.f ),
759       Size( 100.f, 100.f ),
760       TextViewRelayout::PARTIALLY_VISIBLE_HEIGHT,
761       true
762     },
763     {
764       Vector3( 0.f, -10.f, 0.f ),
765       Size( 10.f, 10.f ),
766       Size( 100.f, 100.f ),
767       TextViewRelayout::PARTIALLY_VISIBLE_HEIGHT,
768       false
769     },
770   };
771   const std::size_t numberOfTests( 13 );
772
773   for( std::size_t index = 0; index < numberOfTests; ++index )
774   {
775     const CalculateVisibilityTest& test = calculateVisibilityTest[index];
776
777     if( !TestCalculateVisibility( test, TEST_LOCATION ) )
778     {
779       tet_result( TET_FAIL );
780     }
781   }
782
783   tet_result( TET_PASS );
784   END_TEST;
785 }
786
787 int UtcDaliTextViewMiscelaneousAsserts(void)
788 {
789   ToolkitTestApplication application;
790
791   tet_infoline("UtcDaliTextViewMiscelaneousAsserts : ");
792
793   float offset = 0.f;
794
795   bool assert1 = false;
796   bool assert2 = false;
797   try
798   {
799     offset = Toolkit::Internal::TextViewRelayout::CalculateXoffset( Toolkit::Alignment::VerticalTop, 100.f, 50.f );
800   }
801   catch( Dali::DaliException& e )
802   {
803     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
804     DALI_TEST_EQUALS( e.mCondition, "!\"TextViewRelayout::CalculateXoffset: Wrong horizontal text alignment. Did you set a vertical one?\"", TEST_LOCATION );
805     assert1 = true;
806   }
807   catch( ... )
808   {
809     tet_result( TET_FAIL );
810   }
811   DALI_TEST_EQUALS( offset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
812
813   try
814   {
815     offset = Toolkit::Internal::TextViewRelayout::CalculateYoffset( Toolkit::Alignment::HorizontalRight, 100.f, 50.f );
816   }
817   catch( Dali::DaliException& e )
818   {
819     tet_printf( "Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str() );
820     DALI_TEST_EQUALS( e.mCondition, "!\"TextViewRelayout::CalculateXoffset: Wrong vertical text alignment. Did you set an horizontal one?\"", TEST_LOCATION );
821     assert2 = true;
822   }
823   catch( ... )
824   {
825     tet_result( TET_FAIL );
826   }
827   DALI_TEST_EQUALS( offset, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
828
829   DALI_TEST_CHECK( assert1 && assert2 );
830
831   END_TEST;
832 }