f0fd63d850d22faa33b0a4a6af90b3024c50139e
[platform/core/uifw/dali-toolkit.git] / automated-tests / dali-test-suite / text-view / utc-Dali-TextView.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
24 #include <dali-toolkit-test-suite-utils.h>
25
26 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
27 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 namespace
33 {
34
35 bool TestEqual( float x, float y )
36 {
37   return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 );
38 }
39
40 static bool gObjectCreatedCallBackCalled;
41 static unsigned int gNumberObjectCreated;
42
43 static void TestCallback(BaseHandle handle)
44 {
45   gObjectCreatedCallBackCalled = true;
46   ++gNumberObjectCreated;
47 }
48
49 static bool gTextScrolled;
50 static Vector2 gScrollDelta;
51 static void TestTextScrolled( TextView textView, Vector2 scrollDelta )
52 {
53   gTextScrolled = true;
54   gScrollDelta = scrollDelta;
55 }
56
57 } // namespace
58
59 static void Startup();
60 static void Cleanup();
61
62 extern "C"
63 {
64 void (*tet_startup)() = Startup;
65 void (*tet_cleanup)() = Cleanup;
66 }
67
68 enum
69 {
70   POSITIVE_TC_IDX = 0x01,
71   NEGATIVE_TC_IDX,
72 };
73
74 #define MAX_NUMBER_OF_TESTS 10000
75 extern "C" {
76   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
77 }
78
79 // Add test functionality for all APIs in the class (Positive and Negative)
80 TEST_FUNCTION( UtcDaliTextViewNew, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliTextViewSetAndGetText, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliTextViewSetStyleToCurrentText, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliTextViewSetAndGetLineHeight, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliTextViewSetAndGetFadeBoundary, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliTextViewSetAndGetEllipsizeText, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliTextViewSetAndGetWidthExceedPolicy, POSITIVE_TC_IDX );
87 TEST_FUNCTION( UtcDaliTextViewSetAndGetHeightExceedPolicy, POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions01, POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions02, POSITIVE_TC_IDX );
90 TEST_FUNCTION( UtcDaliTextViewInsertRemoveText, POSITIVE_TC_IDX );
91 TEST_FUNCTION( UtcDaliTextViewSnapshotEnable, POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliTextViewScroll, POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliTextViewSetProperty, POSITIVE_TC_IDX );
94 TEST_FUNCTION( UtcDaliTextViewSetSortModifier, POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextViewUnderlineText, POSITIVE_TC_IDX );
96
97 // Called only once before first test is run.
98
99 static void Startup()
100 {
101 }
102
103 // Called only once after last test is run
104
105 static void Cleanup()
106 {
107 }
108
109 static void UtcDaliTextViewNew()
110 {
111   tet_infoline("UtcDaliTextViewNew: ");
112   ToolkitTestApplication application;
113
114   // Test default constructor.
115   TextView view;
116
117   DALI_TEST_CHECK( !view );
118
119   // Test default initialization.
120   view = TextView::New();
121
122   DALI_TEST_CHECK( view );
123
124   // Test copy constructor and asignment operator.
125   TextView viewCopy1;
126
127   viewCopy1 = view;
128
129   DALI_TEST_CHECK( viewCopy1 );
130
131   TextView viewCopy2( view );
132
133   DALI_TEST_CHECK( viewCopy2 );
134
135   // Test down cast.
136   Actor actorView;
137
138   actorView = view;
139
140   TextView downCastView = TextView::DownCast( actorView );
141
142   DALI_TEST_CHECK( downCastView );
143
144   // Test constructor with a given text.
145
146   const std::string text( "Hello world!" );
147
148   const float DESCENDER = 8.0f;
149
150   TextView view1 = TextView::New( text );
151
152   DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION );
153
154   MarkupProcessor::StyledTextArray styledText;
155   MarkupProcessor::GetStyledTextArray( text, styledText );
156
157   TextView view2 = TextView::New( styledText );
158
159   DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION );
160
161   // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage.
162   TextView::CharacterLayoutInfo characterLayoutInfo;
163
164   DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
165   DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
166   DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION );
167   DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION );
168   DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION );
169
170   TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ),
171                                                       Vector3( 3.f, 4.f, 5.f ),
172                                                       true,
173                                                       true,
174                                                       false,
175                                                       DESCENDER );
176
177   characterLayoutInfo = characterLayoutInfo2;
178
179   DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
180   DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
181   DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION );
182   DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION );
183   DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION );
184   DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION );
185
186
187   TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo );
188
189   DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
190   DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
191   DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION );
192   DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION );
193   DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION );
194
195   // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage.
196
197   TextView::TextLayoutInfo textLayoutInfo;
198   DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION );
199   DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION );
200   DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION );
201   DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
202   DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
203
204   textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo );
205   textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 );
206   textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 );
207   textLayoutInfo.mTextSize = Size( 10.f, 10.f );
208   textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f );
209
210   TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo );
211
212   DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
213   DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
214   DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
215   DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
216   DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
217
218   TextView::TextLayoutInfo textLayoutInfo3;
219
220   textLayoutInfo3 = textLayoutInfo2;
221
222   DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
223   DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
224   DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
225   DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
226   DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
227
228   //Additional check to ensure object is created by checking if it's registered
229   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
230   DALI_TEST_CHECK( registry );
231
232   gObjectCreatedCallBackCalled = false;
233   registry.ObjectCreatedSignal().Connect(&TestCallback);
234   {
235     TextView view = TextView::New();
236   }
237   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
238 }
239
240 static void UtcDaliTextViewSetAndGetText()
241 {
242   tet_infoline("UtcDaliTextViewSetAndGetText: ");
243   ToolkitTestApplication application;
244
245   TextView view = TextView::New();
246   view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
247
248   std::string str( "Text with differing aCeNdEr and dEcEnDeR" );
249
250   view.SetText( str );
251   DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
252
253   MarkupProcessor::StyledTextArray styledText;
254   MarkupProcessor::GetStyledTextArray( str, styledText );
255
256   view.SetText( styledText );
257   DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
258
259   // Test the number of text actor created.
260
261   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
262   DALI_TEST_CHECK( registry );
263
264   gNumberObjectCreated = 0;
265   registry.ObjectCreatedSignal().Connect(&TestCallback);
266
267   // Following string should create three text-actors ([Hel], [lo wo] and [rld]).
268   std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
269                     "\n" );
270
271   Stage::GetCurrent().Add( view );
272   view.SetText( text );
273
274   application.SendNotification();
275   application.Render();
276
277   DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION );
278 }
279
280 static void UtcDaliTextViewSetStyleToCurrentText()
281 {
282   tet_infoline("UtcDaliTextViewSetStyleToCurrentText: ");
283   ToolkitTestApplication application;
284
285   TextStyle style;
286   style.SetItalics( true );
287
288   const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
289                           "동물방역부장을 단장으로 하는\n"
290                           "민관합동조사단은 지난달 30일부터\n"
291                           "12일간의 현지 조사활동을 마치고\n"
292                           "11일 새벽 귀국했습니다." );
293   TextView view = TextView::New( text );
294
295   bool fail = false;
296   try
297   {
298     view.SetStyleToCurrentText( style );
299   }
300   catch( ... )
301   {
302     tet_printf( "Tet case fails\n" );
303     fail = true;
304     tet_result(TET_FAIL);
305   }
306
307   DALI_TEST_CHECK( !fail );
308 }
309
310 static void UtcDaliTextViewSetAndGetLineHeight()
311 {
312   tet_infoline("UtcDaliTextViewSetAndGetLineHeight: ");
313
314   ToolkitTestApplication application;
315
316   const float lineHeightOffset( 9.f );
317
318   TextView textView = TextView::New();
319
320   textView.SetLineHeightOffset( PointSize( lineHeightOffset ) );
321
322   DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
323 }
324
325 static void UtcDaliTextViewSetAndGetFadeBoundary()
326 {
327   tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
328
329   ToolkitTestApplication application;
330
331   TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
332
333   TextView textView = TextView::New( "Hello world!" );
334
335   textView.SetFadeBoundary( fadeBoundary );
336
337   TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary();
338
339   DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
340   DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
341   DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
342   DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
343 }
344
345 static void UtcDaliTextViewSetAndGetEllipsizeText()
346 {
347   tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: ");
348
349   ToolkitTestApplication application;
350
351   TextView textView = TextView::New( "Hello world!" );
352
353   textView.SetEllipsizeText( std::string( "..." ) );
354
355   DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
356
357   Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
358
359   GetStyledTextArray( std::string( "..." ), styledTextArray );
360
361   textView.SetEllipsizeText( styledTextArray );
362
363   DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
364
365 }
366
367 static void UtcDaliTextViewSetAndGetWidthExceedPolicy()
368 {
369   tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: ");
370
371   ToolkitTestApplication application;
372
373   const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
374   const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
375
376   TextView textView = TextView::New( "Hello world!" );
377
378   for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
379   {
380     textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
381
382     DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
383   }
384 }
385
386 static void UtcDaliTextViewSetAndGetHeightExceedPolicy()
387 {
388   tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: ");
389
390   ToolkitTestApplication application;
391
392   const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
393   const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
394
395   TextView textView = TextView::New( "Hello world!" );
396
397   for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
398   {
399     textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
400
401     DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
402   }
403 }
404
405 static void UtcDaliTextViewTestLayoutOptions01()
406 {
407   tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
408
409   ToolkitTestApplication application;
410
411   const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
412                           "동물방역부장을 단장으로 하는\n"
413                           "민관합동조사단은 지난달 30일부터\n"
414                           "12일간의 현지 조사활동을 마치고\n"
415                           "11일 새벽 귀국했습니다." );
416
417   const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
418   const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
419   const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
420   const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
421                                              static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
422                                              static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
423                                              static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
424                                              static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
425                                              static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
426                                              static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
427                                              static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
428                                              static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
429   const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
430
431   const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
432   const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
433   const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
434   const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
435   const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
436
437   TextView textView = TextView::New( text );
438   textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
439
440   Stage::GetCurrent().Add( textView );
441
442   TextView::TextLayoutInfo textLayoutInfo;
443
444   for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
445   {
446     textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
447     for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
448     {
449       textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
450       for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
451       {
452         textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
453         for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
454         {
455           textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
456           for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
457           {
458             textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
459
460             try
461             {
462               textView.GetTextLayoutInfo( textLayoutInfo );
463
464               application.SendNotification();
465               application.Render();
466             }
467             catch( Dali::DaliException& e )
468             {
469               DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
470             }
471             catch( ... )
472             {
473               tet_printf( "Tet case fails\n" );
474               tet_printf( "      MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
475               tet_printf( "   Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
476               tet_printf( "  Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
477               tet_printf( "        TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
478               tet_printf( "    LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
479               tet_result(TET_FAIL);
480             }
481
482             DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
483           }
484           DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
485         }
486         DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
487       }
488       DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
489     }
490     DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
491   }
492 }
493
494 static void UtcDaliTextViewTestLayoutOptions02()
495 {
496   tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
497   ToolkitTestApplication application;
498
499   // Check some configurations.
500
501   TextView textView = TextView::New();
502   textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
503
504   Stage::GetCurrent().Add( textView );
505
506   // SplitByWord and ShrinkToFit.
507   // Centered alignment.
508   // Centered justification.
509   // Don't create a text actor per character.
510
511   textView.SetMultilinePolicy( TextView::SplitByWord );
512   textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
513   textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
514   textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
515   textView.SetLineJustification( TextView::Center );
516   textView.SetSize( 136.56252f, 100.f );
517
518   textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
519
520   application.SendNotification();
521   application.Render();
522
523   std::vector<Size> sizes;
524   sizes.push_back( Size( 34.14063f, 11.380210f ) );              //
525   sizes.push_back( Size( 56.90105f, 11.380210f ) );              //
526   sizes.push_back( Size( 45.52084f, 11.380210f ) );              // By default characters have width and height values of 11.380210.
527                                                                  // The result should be a line with the text 'Hello world' as shown below.
528   std::vector<Vector3> positions;                                //  ____________
529   positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) );  // |Hello world!|
530   positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) );  //  ------------
531   positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) );  //
532
533   DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
534
535   for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
536   {
537     const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
538     const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
539
540     DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
541     DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
542     DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
543     DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
544   }
545
546   textView.SetSize( 50.f, 50.f );
547   textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
548   textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
549   textView.SetLineJustification( Toolkit::TextView::Left );
550
551   application.SendNotification();
552   application.Render();
553
554   sizes.clear();
555   sizes.push_back( Size( 24.999999f, 8.333333f ) );              //
556   sizes.push_back( Size( 24.999999f, 8.333333f ) );              //
557   sizes.push_back( Size( 16.666666f, 8.333333f ) );              // Longest word is 'world!' (6 characters x 11.380210) which doesn't fit in the 50x50 box.
558   sizes.push_back( Size( 33.333332f, 8.333333f ) );              // The scale factor is 0.732265339, so the character size is 8.333333.
559                                                                  // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
560   positions.clear();                                             // As shown below, the text is two lines and centered in the vertical dimension and
561   positions.push_back( Vector3(  0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
562   positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); //   ______
563   positions.push_back( Vector3(  0.000006f, 33.556446f, 0.f ) ); //  |      |
564   positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); //  |Hello |
565                                                                  //  |world!|
566                                                                  //  |______|
567                                                                  //
568
569   DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
570
571   for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
572   {
573     const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
574     const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
575
576     DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
577     DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
578     DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
579     DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
580   }
581
582   // TODO: Add more tests when TextView implementation is finished.
583 }
584
585 static void UtcDaliTextViewInsertRemoveText()
586 {
587   tet_infoline("UtcDaliTextViewInsertRemoveText: ");
588   ToolkitTestApplication application;
589
590   std::string text("Hello ");
591
592   MarkupProcessor::StyledTextArray styledText;
593   MarkupProcessor::GetStyledTextArray( text, styledText );
594
595   TextView view = TextView::New( "world!" );
596
597   view.InsertTextAt( 0, styledText );
598
599   DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
600
601   view.RemoveTextFrom( 4, 5 );
602
603   DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
604
605   view.InsertTextAt( 0, "Hello " );
606
607   DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
608
609
610   view.InsertTextAt( 0, "Hello " );
611   view.InsertTextAt( 0, "Hello " );
612   view.InsertTextAt( 0, "Hello " );
613   view.InsertTextAt( 0, "Hello " );
614   view.RemoveTextFrom( 4, 2 );
615   view.RemoveTextFrom( 4, 2 );
616   view.RemoveTextFrom( 4, 2 );
617   view.RemoveTextFrom( 4, 2 );
618   view.RemoveTextFrom( 4, 2 );
619   view.SetText( "Hello world!" );
620
621   DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
622
623   view.ReplaceTextFromTo( 5, 1, "" );
624
625   DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
626
627   view.ReplaceTextFromTo( 0, 11, styledText );
628
629   DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
630 }
631
632 static void UtcDaliTextViewSnapshotEnable()
633 {
634   tet_infoline("UtcDaliTextViewSnapshotEnable: ");
635   ToolkitTestApplication application;
636
637   // Avoids the frame buffer texture to throw an exception.
638   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
639
640   TextView view = TextView::New( "Hel<font color='green'>lo world!</font> This <font color='green'>is</font> a sna<font color='green'>psho</font>t test." );
641
642   Stage::GetCurrent().Add( view );
643
644   view.SetSnapshotModeEnabled( true );  // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
645                                         // This line should be removed when text-view is set to use the snapshot mode by default.
646
647   // Snapshot is enabled by default.
648   DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
649
650   application.SendNotification();
651   application.Render();
652
653   // TextView should have only two actors:
654   // the root (Actor) and the image (ImageActor).
655
656   DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
657
658   view.SetSnapshotModeEnabled( false );
659   DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
660
661   application.SendNotification();
662   application.Render();
663
664   // TextView should have one text-actor per word.
665
666   DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
667 }
668
669 static void UtcDaliTextViewScroll()
670 {
671   tet_infoline("UtcDaliTextViewScroll: ");
672   ToolkitTestApplication application;
673
674   // Avoids the frame buffer texture to throw an exception.
675   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
676
677   TextView view = TextView::New( "Hello world! This is a scroll test." );
678   view.SetSize( 100.f, 100.f );
679   view.SetSnapshotModeEnabled( false );
680
681   Stage::GetCurrent().Add( view );
682
683   application.SendNotification();
684   application.Render();
685
686   DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
687
688   view.SetScrollEnabled( true );
689   view.ScrolledSignal().Connect( &TestTextScrolled );
690
691   DALI_TEST_CHECK( view.IsScrollEnabled() );
692   DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
693
694   gTextScrolled = false;
695   gScrollDelta = Vector2::ZERO;
696   view.SetScrollPosition( Vector2( 400.f, 400.f ) );
697
698   application.SendNotification();
699   application.Render();
700
701   const Vector2& scrollPosition = view.GetScrollPosition();
702   DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
703
704   DALI_TEST_CHECK( gTextScrolled );
705   DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
706
707   DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
708 }
709
710 static void UtcDaliTextViewSetProperty()
711 {
712   tet_infoline("UtcDaliTextViewSetAndGetText: ");
713   ToolkitTestApplication application;
714
715   TextView view = TextView::New( "Hello world!" );
716   Stage::GetCurrent().Add( view );
717
718   //Test multiline policy property
719   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
720   DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
721
722   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByWord");
723   DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
724
725   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByChar");
726   DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
727
728   //Test width exceed policy property
729   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "Original");
730   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
731   DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
732   DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
733
734   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
735   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
736   DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
737   DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
738
739   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
740   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
741   DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
742   DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
743
744   //Test line justification property
745   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Left");
746   DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
747
748   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Center");
749   DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
750
751   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Right");
752   DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
753
754   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Justified");
755   DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
756
757   //Test fade boundary property
758   unsigned int testValue = 23;
759   PixelSize leftFadeBoundary(testValue);
760   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_LEFT), testValue);
761   DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
762
763   testValue = 26;
764   PixelSize rightFadeBoundary(testValue);
765   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
766   DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
767
768   testValue = 2;
769   PixelSize topFadeBoundary(testValue);
770   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_TOP), testValue);
771   DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
772
773   testValue = 11;
774   PixelSize bottomFadeBoundary(testValue);
775   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
776   DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
777
778   //Test Line height offset property
779   float testOffsetValue = 14.04f;
780   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
781   DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
782
783   //Test alignment property
784   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
785   view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
786   DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
787 }
788
789 static void UtcDaliTextViewSetSortModifier()
790 {
791   tet_infoline("UtcDaliTextViewSetAndGetText: ");
792   ToolkitTestApplication application;
793
794   TextView view = TextView::New( "Hello world!" );
795   Stage::GetCurrent().Add( view );
796
797   view.SetSortModifier( 10.f );
798   view.SetSnapshotModeEnabled( false );
799
800   application.SendNotification();
801   application.Render();
802
803   DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
804 }
805
806 static void UtcDaliTextViewUnderlineText()
807 {
808   std::cout << "##############################" << std::endl;
809
810   tet_infoline("UtcDaliTextViewUnderlineText: ");
811   ToolkitTestApplication application;
812
813   TextView textView = TextView::New( "<u><font size='10'>gg<font size='14'>gg<font size='18'>gg<font size='22'>gg</font>gg</font>gg</font>gg</font></u>" );
814   textView.SetSnapshotModeEnabled( false );
815
816   textView.SetSize( 150.f, 100.f );
817
818   Stage::GetCurrent().Add( textView );
819
820   application.SendNotification();
821   application.Render();
822
823   std::vector<float> positions;
824   positions.push_back( 6.448784f );
825   positions.push_back( 9.862847f );
826   positions.push_back( 13.276909f );
827   positions.push_back( 16.690973f );
828   positions.push_back( 13.276909f );
829   positions.push_back( 9.862847f );
830   positions.push_back( 6.448784f );
831
832   for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
833   {
834     TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
835
836     DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
837     DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
838   }
839 }