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