Property refactor in dali-core: Toolkit changes for compiling
[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   indices.mCharacterParagraphIndex = test.characterParagraphIndex;
92
93   // Get the input paragraph.
94   TextViewProcessor::ParagraphLayoutInfo inputParagraphLayout;
95
96   if( !relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.empty() )
97   {
98     inputParagraphLayout = *relayoutData.mTextLayoutInfo.mParagraphsLayoutInfo.begin();
99   }
100
101   // Result struct.
102   TextViewRelayout::LineLayoutInfo resultLayoutInfo;
103
104   CalculateLineLayout( test.parentWidth,
105                        indices,
106                        inputParagraphLayout,
107                        test.splitPolicy,
108                        test.shrinkFactor,
109                        resultLayoutInfo  );
110
111   // Check results.
112   if( !TestEqual( test.resultLineLength, resultLayoutInfo.mLineLength ) )
113   {
114     tet_printf( "Fail. different line length %f == %f. %s", test.resultLineLength, resultLayoutInfo.mLineLength, location );
115     return false;
116   }
117
118   if( !TestEqual( test.resultMaxCharHeight, resultLayoutInfo.mMaxCharHeight ) )
119   {
120     tet_printf( "Fail. different max character height %f == %f. %s", test.resultMaxCharHeight, resultLayoutInfo.mMaxCharHeight, location );
121     return false;
122   }
123
124   if( !TestEqual( test.resultMaxAscender, resultLayoutInfo.mMaxAscender ) )
125   {
126     tet_printf( "Fail. different max ascender %f == %f. %s", test.resultMaxAscender, resultLayoutInfo.mMaxAscender, location );
127     return false;
128   }
129
130   return true;
131 }
132
133 //////////////////////////////////////////////////////////////////
134
135 struct AlignmentOffsetTest
136 {
137   Toolkit::Alignment::Type alignment;
138   float parentSize;
139   float wholeTextSize;
140
141   float resultOffset;
142 };
143
144 bool TestAlignmentOffset( const AlignmentOffsetTest& test, const char* location )
145 {
146   float offset = 0.f;
147
148   switch( test.alignment )
149   {
150     case Toolkit::Alignment::HorizontalLeft:
151     case Toolkit::Alignment::HorizontalCenter:
152     case Toolkit::Alignment::HorizontalRight:
153     {
154       offset = TextViewRelayout::CalculateXoffset( test.alignment, test.parentSize, test.wholeTextSize );
155       break;
156     }
157     case Toolkit::Alignment::VerticalTop:
158     case Toolkit::Alignment::VerticalCenter:
159     case Toolkit::Alignment::VerticalBottom:
160     {
161       offset = TextViewRelayout::CalculateYoffset( test.alignment, test.parentSize, test.wholeTextSize );
162       break;
163     }
164   }
165
166   // Check results.
167   if( !TestEqual( test.resultOffset, offset ) )
168   {
169     tet_printf( "Fail. different offset %f == %f. %s", test.resultOffset, offset, location );
170     return false;
171   }
172
173   return true;
174 }
175
176 //////////////////////////////////////////////////////////////////
177
178 struct JustificationOffsetTest
179 {
180   Toolkit::TextView::LineJustification justification;
181   float wholeTextWidth;
182   float lineLength;
183
184   float resultOffset;
185 };
186
187 bool TestJustificationOffset( const JustificationOffsetTest& test, const char* location )
188 {
189   float offset = TextViewRelayout::CalculateJustificationOffset( test.justification, test.wholeTextWidth, test.lineLength );
190
191   // Check results.
192   if( !TestEqual( test.resultOffset, offset ) )
193   {
194     tet_printf( "Fail. different offset %f == %f. %s", test.resultOffset, offset, location );
195     return false;
196   }
197
198   return true;
199 }
200
201 //////////////////////////////////////////////////////////////////
202
203 struct CalculateVisibilityTest
204 {
205   Vector3 position;
206   Size size;
207   Size parentSize;
208   TextViewRelayout::VisibilityTestType type;
209
210   bool resultVisible;
211 };
212
213 bool TestCalculateVisibility( const CalculateVisibilityTest& test, const char* location )
214 {
215   if( test.resultVisible != TextViewRelayout::IsVisible( test.position, test.size, test.parentSize, test.type ) )
216   {
217     tet_printf( "Fail. different visibility. Type %d, %s", test.type, location );
218     return false;
219   }
220
221   return true;
222 }
223
224 //////////////////////////////////////////////////////////////////
225
226 } // namespace
227
228
229 int UtcDaliTextViewDefaultConstructorDestructor_RU(void)
230 {
231   ToolkitTestApplication application;
232
233   tet_infoline("UtcDaliTextViewDefaultConstructorDestructor : ");
234
235   // Test RelayoutParameters defaults.
236   TextViewRelayout::RelayoutParameters relayoutParameters;
237
238   DALI_TEST_EQUALS( relayoutParameters.mPositionOffset, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
239   DALI_TEST_EQUALS( relayoutParameters.mParagraphSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
240   DALI_TEST_EQUALS( relayoutParameters.mWordSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
241   DALI_TEST_EQUALS( relayoutParameters.mCharacterSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
242   DALI_TEST_EQUALS( relayoutParameters.mIndices.mParagraphIndex, 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.mIsNewParagraphCharacter );
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 LineLayoutInfo defaults
311   TextViewRelayout::LineLayoutInfo lineLayoutInfo;
312
313   DALI_TEST_EQUALS( lineLayoutInfo.mLineLength, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
314   DALI_TEST_EQUALS( lineLayoutInfo.mMaxCharHeight, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
315   DALI_TEST_EQUALS( lineLayoutInfo.mMaxAscender, 0.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
316   END_TEST;
317 }
318
319 int UtcDaliTextViewCalculateLineLayout(void)
320 {
321   ToolkitTestApplication application;
322
323   tet_infoline("UtcDaliTextViewCalculateLineLayout : ");
324
325   struct CalculateLineLayoutTest calculateLineLayoutTest[] =
326   {
327     //WrapByCharacter
328     {
329       "The paragraph is wraped by character. All characters have the same size.",
330       "Hello world", // input paragraph
331       100.f,         // parent width
332       0,             // indices
333       0,
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 paragraph is wraped by character. There are characters with different sizes.",
344       "Hello <font size='14'>world</font>", // input paragraph
345       100.f,         // parent width
346       0,              // indices
347       0,
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 paragraph 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 paragraph
359       100.f,         // parent width
360       2,              // indices. The third character of the third word starts in a new line.
361       2,
362       8,
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 paragraph 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 paragraph
373       100.f,         // parent width
374       4,              // indices. The fifth character of the fifth word starts in a new line.
375       4,
376       16,
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 paragraph is wraped by word. All characters have the same size.",
388       "Hello world", // input paragraph
389       100.f,         // parent width
390       0,              // indices. It shouldn't use the index character so 9999999 shouldn't make it crash.
391       9999999,
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 paragraph is wraped by word. There are characters with different sizes.",
402       "Hell<font size='14'>o</font> world", // input paragraph
403       100.f,         // parent width
404       0,              // indices.
405       0,
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 paragraph 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 paragraph
417       100.f,         // parent width
418       2,              // indices. The third word starts in a new line.
419       0,
420       6,
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 paragraph is wraped by word. The word doen't fit.",
430       "Hello world", // input paragraph
431       40.f,          // parent width
432       0,              // indices. The third word starts in a new line.
433       0,
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 paragraph 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 paragraph
447       100.f,         // parent width
448       0,              // indices.
449       0,
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 paragraph is wraped by word and by character. All characters have the same size. There is a long word.",
460       "Helloooooooo world", // input paragraph
461       100.f,         // parent width
462       0,              // indices.
463       0,
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 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.",
474       "Helloooooooo <font size='14'>world</font>", // input paragraph
475       100.f,         // parent width
476       0,              // indices.
477       8,
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 paragraph 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 paragraph
489       100.f,         // parent width
490       0,              // indices.
491       8,
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     //WrapByParagraphCharacterAndSplit
502     {
503       "The paragraph is wraped by end of paragraph and by character. All characters have the same size.",
504       "Hello world", // input paragraph
505       100.f,         // parent width
506       0,              // indices
507       0,
508       0,
509       TextViewRelayout::WrapByParagraphCharacterAndSplit, // 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 paragraph fits in the width.",
518       "Hello", // input paragraph
519       100.f,         // parent width
520       0,             // indices
521       0,
522       0,
523       TextViewRelayout::WrapByParagraphCharacterAndSplit, // 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 paragraph is wraped by end of paragraph and by character. All characters have the same size. It calculates the layout for the second line.",
532       "Hello world, hello world", // input paragraph
533       100.f,         // parent width
534       2,             // indices
535       2,
536       8,
537       TextViewRelayout::WrapByParagraphCharacterAndSplit, // 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 CalculateLineLayoutTest& test = calculateLineLayoutTest[index];
550
551     if( !TestCalculateLineLayout( 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     DALI_TEST_PRINT_ASSERT( e );
805     DALI_TEST_EQUALS( e.condition, "!\"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     DALI_TEST_PRINT_ASSERT( e );
821     DALI_TEST_EQUALS( e.condition, "!\"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 }