Upload package dali_0.9.11.
[platform/core/uifw/dali-core.git] / automated-tests / TET / dali-test-suite / actors / utc-Dali-TextActor.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-test-suite-utils.h>
25
26 using namespace Dali;
27
28 static void Startup();
29 static void Cleanup();
30
31 extern "C" {
32   void (*tet_startup)() = Startup;
33   void (*tet_cleanup)() = Cleanup;
34 }
35
36 static const char* TestTextHello = "Hello";
37 static const char* TestTextHelloWorld = "Hello World";
38 static const char* LongTestText = "This is a very long piece of text, and is sure not to fit into any box presented to it";
39
40 const std::string FAMILY_NAME = "Arial";
41 const std::string STYLE = "Bold";
42 const unsigned int POINT_SIZE = 11.f;
43 static const Vector4 FONT_TEXT_COLOR = Color::RED;
44 static const Degree FONT_ITALICS_ANGLE(10.f);
45 static const Radian FONT_ITALICS_RADIAN_ANGLE(0.4f);
46 static const bool FONT_ITALICS = true;
47 static const bool FONT_UNDERLINE = true;
48 static const bool FONT_SHADOW = true;
49 static const bool FONT_GLOW = true;
50 static const bool FONT_OUTLINE = true;
51 static const float FONT_UNDERLINE_THICKNESS = 5.0f;
52 static const float FONT_UNDERLINE_POSITION = 60.0f;
53 static const Vector4 FONT_SHADOW_COLOR = Color::BLUE;
54 static const Vector2 FONT_SHADOW_OFFSET(2.f, 2.f );
55 static const float FONT_SHADOW_SIZE = 55.f;
56 static const Vector4 FONT_TEXT_GLOW_COLOR = Color::BLACK;
57 static const float FONT_GLOW_INTENSITY = 10.0f;
58 static const float FONT_SMOOTH_EDGE = 5.0f;
59 static const Vector4 FONT_OUTLINE_COLOR = Color::MAGENTA;
60 static const Vector2 FONT_OUTLINE_THICKNESS(15.f, 14.f );
61
62 enum {
63   POSITIVE_TC_IDX = 0x01,
64   NEGATIVE_TC_IDX,
65 };
66
67 #define MAX_NUMBER_OF_TESTS 10000
68 extern "C" {
69   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
70 }
71
72 // Add test functionality for all APIs in the class (Positive and Negative)
73 TEST_FUNCTION( UtcDaliTextActorConstructorVoid,           POSITIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliTextActorConstructorRefObject,      POSITIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliTextActorNew01,                     POSITIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliTextActorNew02,                     POSITIVE_TC_IDX );
77 TEST_FUNCTION( UtcDaliTextActorNew03,                     POSITIVE_TC_IDX );
78 TEST_FUNCTION( UtcDaliTextActorNew04,                     POSITIVE_TC_IDX );
79 TEST_FUNCTION( UtcDaliTextActorNew05,                     POSITIVE_TC_IDX );
80 TEST_FUNCTION( UtcDaliTextActorNew06,                     POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliTextActorNew07,                     POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliTextActorDownCast,                  POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliTextActorDownCast2,                 NEGATIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliTextActorSetText,                   POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliTextActorSetTextIndividualStyles,   POSITIVE_TC_IDX );
86
87 TEST_FUNCTION( UtcDaliTextActorSetFont,                   POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliTextActorSetFontDetection,          POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliTextActorChangingText,              POSITIVE_TC_IDX );
90 TEST_FUNCTION( UtcDaliTextActorGetLoadingState,           POSITIVE_TC_IDX );
91 TEST_FUNCTION( UtcDaliTextActorSetItalics,                POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliTextActorSetUnderline,              POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliTextActorSetWeight,                 POSITIVE_TC_IDX );
94 TEST_FUNCTION( UtcDaliTextActorSetStyle,                  POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextActorDefaultProperties,         POSITIVE_TC_IDX );
96 TEST_FUNCTION( UtcDaliTextActorSetGradientColor,          POSITIVE_TC_IDX );
97 TEST_FUNCTION( UtcDaliTextActorSetGradientStartPoint,     POSITIVE_TC_IDX );
98 TEST_FUNCTION( UtcDaliTextActorSetGradientEndPoint,       POSITIVE_TC_IDX );
99
100 TEST_FUNCTION( UtcDaliTextActorSynchronousGlyphLoading,   POSITIVE_TC_IDX );
101
102 TEST_FUNCTION( UtcDaliTextActorAutomaticSizeSet,          POSITIVE_TC_IDX );
103 TEST_FUNCTION( UtcDaliTextActorAutomaticSizeSetAnimation, POSITIVE_TC_IDX );
104
105 TEST_FUNCTION( UtcDaliTextActorPropertyIndices,           POSITIVE_TC_IDX );
106
107 // Called only once before first test is run.
108 static void Startup()
109 {
110 }
111
112 // Called only once after last test is run
113 static void Cleanup()
114 {
115 }
116
117 static void UtcDaliTextActorConstructorVoid()
118 {
119   TestApplication application;
120
121   tet_infoline("Testing Dali::TextActor::TextActor()");
122
123   TextActor actor;
124
125   DALI_TEST_CHECK(!actor);
126 }
127
128 static void UtcDaliTextActorConstructorRefObject()
129 {
130   TestApplication application;
131
132   tet_infoline("Testing Dali::TextActor::TextActor(Internal::TextActor*)");
133
134   TextActor actor(NULL);
135
136   DALI_TEST_CHECK(!actor);
137 }
138
139 static void UtcDaliTextActorNew01()
140 {
141   TestApplication application;
142
143   tet_infoline("Testing Dali::TextActor::New()");
144
145   TextActor actor = TextActor::New(TestTextHello);
146
147   DALI_TEST_CHECK(actor);
148
149   actor = TextActor::New(Text(std::string(TestTextHello)));
150
151   DALI_TEST_CHECK(actor);
152 }
153
154
155 static void UtcDaliTextActorNew02()
156 {
157   TestApplication application;
158
159   tet_infoline("Testing Dali::TextActor::New()");
160
161   TextActor actor = TextActor::New(TestTextHello, false);
162
163   DALI_TEST_CHECK(actor);
164
165   actor = TextActor::New(Text(std::string(TestTextHello)), false);
166
167   DALI_TEST_CHECK(actor);
168 }
169
170 static void UtcDaliTextActorNew03()
171 {
172   TestApplication application;
173
174   tet_infoline("Testing Dali::TextActor::New()");
175
176   TextActor actor = TextActor::New(TestTextHello, false, false);
177
178   DALI_TEST_CHECK(actor);
179
180   actor = TextActor::New(Text(std::string(TestTextHello)), false, false);
181
182   DALI_TEST_CHECK(actor);
183 }
184
185
186 static void UtcDaliTextActorNew04()
187 {
188   TestApplication application;
189
190   tet_infoline("Testing Dali::TextActor::New()");
191
192   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
193   Font freeSerif = Font::New( parameters );
194
195   TextActor actor = TextActor::New(TestTextHello, freeSerif);
196
197   DALI_TEST_CHECK(actor);
198
199   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif);
200
201   DALI_TEST_CHECK(actor);
202 }
203
204 static void UtcDaliTextActorNew05()
205 {
206   TestApplication application;
207
208   tet_infoline("Testing Dali::TextActor::New()");
209
210   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
211   Font freeSerif = Font::New( parameters );
212
213   TextActor actor = TextActor::New(TestTextHello, freeSerif, false);
214
215   DALI_TEST_CHECK(actor);
216
217   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false);
218
219   DALI_TEST_CHECK(actor);
220 }
221
222 static void UtcDaliTextActorNew06()
223 {
224   TestApplication application;
225
226   tet_infoline("Testing Dali::TextActor::New()");
227
228   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
229   Font freeSerif = Font::New( parameters );
230
231   TextActor actor = TextActor::New(TestTextHello, freeSerif, false, false);
232
233   DALI_TEST_CHECK(actor);
234
235   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false, false);
236
237   DALI_TEST_CHECK(actor);
238 }
239
240 static void UtcDaliTextActorNew07()
241 {
242   TestApplication application;
243
244   tet_infoline("Testing Dali::TextActor::New()");
245
246   TextStyle style;
247
248   TextActor actor = TextActor::New(Text(TestTextHello), style, false, false);
249
250   DALI_TEST_CHECK(actor);
251 }
252
253
254 static void UtcDaliTextActorDownCast()
255 {
256   TestApplication application;
257   tet_infoline("Testing Dali::TextActor::DownCast()");
258
259   TextActor actor1 = TextActor::New("Hello, World!");
260   Actor anActor = Actor::New();
261   anActor.Add(actor1);
262
263   Actor child = anActor.GetChildAt(0);
264   TextActor textActor = TextActor::DownCast(child);
265
266   DALI_TEST_CHECK(textActor);
267   DALI_TEST_CHECK(!textActor.GetText().compare("Hello, World!"));
268 }
269
270 static void UtcDaliTextActorDownCast2()
271 {
272   TestApplication application;
273   tet_infoline("Testing Dali::TextActor::DownCast()");
274
275   Actor actor1 = Actor::New();
276   Actor anActor = Actor::New();
277   anActor.Add(actor1);
278
279   Actor child = anActor.GetChildAt(0);
280   TextActor textActor = TextActor::DownCast(child);
281   DALI_TEST_CHECK(!textActor);
282
283   Actor unInitialzedActor;
284   textActor = DownCast< TextActor >( unInitialzedActor );
285   DALI_TEST_CHECK(!textActor);
286 }
287
288 static void UtcDaliTextActorSetText()
289 {
290   TestApplication application;
291
292   tet_infoline("Testing Dali::TextActor::SetText()");
293
294   TextActor actor01 = TextActor::New(TestTextHello);
295
296   actor01.SetText(TestTextHelloWorld);
297
298   std::string text = actor01.GetText();
299
300   DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
301
302   actor01.SetText(Text(std::string(TestTextHelloWorld)));
303
304   text = actor01.GetText();
305
306   DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
307
308   actor01.SetText("");
309
310   text = actor01.GetText();
311
312   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
313
314   TextActor actor02 = TextActor::New("");
315
316   actor02.SetText( std::string() );
317
318   text = actor02.GetText();
319
320   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
321
322   actor02.SetText(TestTextHelloWorld);
323   actor02.SetText( std::string() );
324
325   text = actor02.GetText();
326
327   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
328
329   TextActor actor03 = TextActor::New("");
330   const Text voidText;
331   actor03.SetText(voidText);
332
333   text = actor03.GetText();
334
335   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
336
337   actor03.SetText(TestTextHelloWorld);
338   actor03.SetText(voidText);
339
340   text = actor03.GetText();
341
342   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
343 }
344
345 static void UtcDaliTextActorSetFont()
346 {
347   TestApplication application;
348
349   TextActor actor = TextActor::New(TestTextHello);
350
351   PointSize pointSize( POINT_SIZE );
352   FontParameters params( FAMILY_NAME, STYLE, pointSize);
353
354   Font font = Font::New( params );
355
356   actor.SetFont( font );
357
358   DALI_TEST_CHECK( actor.GetFont().GetName() == FAMILY_NAME );
359 }
360
361 static void UtcDaliTextActorSetFontDetection()
362 {
363   TestApplication application;
364
365   TextActor actor = TextActor::New(TestTextHello);
366
367   actor.SetFontDetectionAutomatic( true );
368
369   DALI_TEST_CHECK( true == actor.IsFontDetectionAutomatic() );
370
371 }
372
373 static void UtcDaliTextActorSetTextIndividualStyles()
374 {
375   TestApplication application;
376
377   TextActor actor = TextActor::New(TestTextHello);
378
379   actor.SetTextColor( FONT_TEXT_COLOR);
380
381   DALI_TEST_CHECK( actor.GetTextColor() == FONT_TEXT_COLOR );
382
383   actor.SetSmoothEdge( FONT_SMOOTH_EDGE  );
384
385   actor.SetOutline( FONT_OUTLINE, FONT_OUTLINE_COLOR, FONT_OUTLINE_THICKNESS );
386
387   actor.SetShadow( FONT_SHADOW, FONT_SHADOW_COLOR, FONT_SHADOW_OFFSET, FONT_SHADOW_SIZE );
388
389   actor.SetItalics( FONT_ITALICS, FONT_ITALICS_ANGLE );
390
391   actor.SetGlow( FONT_GLOW, FONT_TEXT_GLOW_COLOR, FONT_GLOW_INTENSITY );
392
393   TextStyle style = actor.GetTextStyle();
394
395   DALI_TEST_CHECK( FONT_TEXT_COLOR == style.GetTextColor() );
396
397   DALI_TEST_CHECK( FONT_SMOOTH_EDGE == style.GetSmoothEdge() );
398
399   DALI_TEST_CHECK( FONT_OUTLINE == style.GetOutline() );
400   DALI_TEST_CHECK( FONT_OUTLINE_COLOR == style.GetOutlineColor() );
401   DALI_TEST_CHECK( FONT_OUTLINE_THICKNESS == style.GetOutlineThickness() );
402
403
404   DALI_TEST_CHECK( FONT_SHADOW == style.GetShadow() );
405   DALI_TEST_CHECK( FONT_SHADOW_COLOR == style.GetShadowColor() );
406   DALI_TEST_CHECK( FONT_SHADOW_OFFSET == style.GetShadowOffset() );
407   DALI_TEST_CHECK( FONT_SHADOW_SIZE == style.GetShadowSize() );
408
409   DALI_TEST_CHECK( FONT_ITALICS == style.GetItalics() );
410   DALI_TEST_CHECK( FONT_ITALICS_ANGLE == style.GetItalicsAngle() );
411
412   DALI_TEST_CHECK( FONT_GLOW == style.GetGlow() );
413   DALI_TEST_CHECK( FONT_OUTLINE == style.GetOutline() );
414   DALI_TEST_CHECK( FONT_TEXT_GLOW_COLOR == style.GetGlowColor() );
415   DALI_TEST_CHECK( FONT_GLOW_INTENSITY == style.GetGlowIntensity() );
416
417
418   actor.SetItalics( FONT_ITALICS, FONT_ITALICS_RADIAN_ANGLE );
419   style = actor.GetTextStyle();
420   DALI_TEST_CHECK( FONT_ITALICS_RADIAN_ANGLE == style.GetItalicsAngle() );
421
422
423 }
424
425 static void UtcDaliTextActorChangingText()
426 {
427   TestApplication application;
428
429   TextActor actor = TextActor::New(TestTextHello);
430   actor.SetSize(Vector3(200, 20, 0.0f));
431   actor.SetPosition(20.0f, 400.0f, 40.0f);
432   Stage::GetCurrent().Add(actor);
433
434   tet_infoline("Testing Dali::TextActor::SetText() & Dali::TextActor::GetText()");
435   actor.SetText(LongTestText);
436   std::string text = actor.GetText();
437   DALI_TEST_EQUALS(text, LongTestText, TEST_LOCATION);
438
439   // do a render
440   application.SendNotification();
441   application.Render();
442
443   // check that the size did not change
444   DALI_TEST_EQUALS( Vector3(200, 20, 0.0f), actor.GetCurrentSize(), TEST_LOCATION);
445 }
446
447 static void UtcDaliTextActorGetLoadingState()
448 {
449   TestApplication application;
450
451   TextActor actor = TextActor::New(TestTextHello);
452
453   DALI_TEST_CHECK( ResourceLoading == actor.GetLoadingState());
454
455   application.SendNotification();
456   application.Render();
457
458   DALI_TEST_CHECK( ResourceLoadingSucceeded == actor.GetLoadingState());
459
460 }
461
462 static void UtcDaliTextActorSetItalics()
463 {
464   TestApplication application;
465
466   tet_infoline("Testing Dali::TextActor::New()");
467
468   TextActor actor = TextActor::New(TestTextHello);
469
470   DALI_TEST_CHECK(actor);
471
472   actor.SetItalics( true );
473
474   DALI_TEST_CHECK( actor.GetItalics() );
475
476   DALI_TEST_EQUALS( static_cast<float>( Degree( actor.GetItalicsAngle() ) ), static_cast<float>(TextStyle::DEFAULT_ITALICS_ANGLE), 0.0001f, TEST_LOCATION );
477
478   actor.SetItalics( false );
479
480   DALI_TEST_CHECK( ! actor.GetItalics() );
481
482   // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
483 }
484
485 static void UtcDaliTextActorSetUnderline()
486 {
487   TestApplication application;
488
489   tet_infoline("Testing Dali::TextActor::SetUnderline()");
490
491   TextActor actor = TextActor::New(TestTextHello);
492
493   DALI_TEST_CHECK(actor);
494
495   actor.SetUnderline( true );
496
497   DALI_TEST_CHECK( actor.GetUnderline() );
498
499   actor.SetUnderline( false );
500
501   DALI_TEST_CHECK( ! actor.GetUnderline() );
502
503   // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
504 }
505
506 static void UtcDaliTextActorSetWeight()
507 {
508   TestApplication application;
509
510   tet_infoline("Testing Dali::TextActor::SetWeight()");
511
512   TextActor actor = TextActor::New(TestTextHello);
513
514   DALI_TEST_CHECK(actor);
515
516   actor.SetWeight( TextStyle::EXTRABOLD );
517
518   DALI_TEST_CHECK( TextStyle::EXTRABOLD == actor.GetWeight() );
519
520   actor.SetWeight( TextStyle::BOLD );
521
522   DALI_TEST_CHECK( TextStyle::BOLD == actor.GetWeight() );
523 }
524
525 static void UtcDaliTextActorSetStyle()
526 {
527   TestApplication application;
528
529   tet_infoline("Testing Dali::TextActor::SetTextStyle()");
530
531   TextActor actor = TextActor::New(TestTextHello);
532
533   TextStyle defaultStyle = actor.GetTextStyle();
534   DALI_TEST_CHECK( defaultStyle.GetFontName().empty() );
535   DALI_TEST_CHECK( TextStyle::REGULAR == defaultStyle.GetWeight() );
536   DALI_TEST_CHECK( Color::WHITE == defaultStyle.GetTextColor() );
537   DALI_TEST_CHECK( !defaultStyle.GetItalics() );
538   DALI_TEST_CHECK( !defaultStyle.GetUnderline() );
539
540   TextStyle style;
541   style.SetFontPointSize(PointSize( 16.f ));
542   style.SetWeight(TextStyle::EXTRABLACK);
543   style.SetTextColor(Color::BLUE);
544   style.SetItalics(true);
545   style.SetUnderline(true);
546   style.SetShadow(false);
547   style.SetGlow(false);
548   style.SetOutline(false);
549
550   actor.SetTextStyle( style );
551   // This is necessary since SetColor (via TextStyle) is asynchronous
552   application.SendNotification();
553   application.Render();
554   style = actor.GetTextStyle();
555
556   DALI_TEST_CHECK( style.GetFontName().empty() );
557   DALI_TEST_CHECK( style.GetFontStyle().empty() );
558   DALI_TEST_EQUALS( static_cast<float>( PointSize( 16.f ) ),
559                     static_cast<float>( style.GetFontPointSize() ),
560                     GetRangedEpsilon( PointSize( 16.f ), style.GetFontPointSize() ),
561                     TEST_LOCATION );
562   DALI_TEST_CHECK( TextStyle::EXTRABLACK == style.GetWeight() );
563   DALI_TEST_EQUALS( Vector4( 0.f, 0.f, 1.f, 1.f ), style.GetTextColor(), TEST_LOCATION );
564   DALI_TEST_CHECK( style.GetItalics() );
565   DALI_TEST_CHECK( style.GetUnderline() );
566 }
567
568 static void UtcDaliTextActorDefaultProperties()
569 {
570   TestApplication application;
571   tet_infoline("Testing Dali::TextActor DefaultProperties");
572
573   TextActor actor = TextActor::New("@");
574
575   std::vector<Property::Index> indices ;
576   indices.push_back(TextActor::TEXT                     );
577   indices.push_back(TextActor::FONT                     );
578   indices.push_back(TextActor::FONT_STYLE               );
579   indices.push_back(TextActor::OUTLINE_ENABLE           );
580   indices.push_back(TextActor::OUTLINE_COLOR            );
581   indices.push_back(TextActor::OUTLINE_THICKNESS_WIDTH  );
582   indices.push_back(TextActor::SMOOTH_EDGE              );
583   indices.push_back(TextActor::GLOW_ENABLE              );
584   indices.push_back(TextActor::GLOW_COLOR               );
585   indices.push_back(TextActor::GLOW_INTENSITY           );
586   indices.push_back(TextActor::SHADOW_ENABLE            );
587   indices.push_back(TextActor::SHADOW_COLOR             );
588   indices.push_back(TextActor::SHADOW_OFFSET            );
589   indices.push_back(TextActor::ITALICS_ANGLE            );
590   indices.push_back(TextActor::UNDERLINE                );
591   indices.push_back(TextActor::WEIGHT                   );
592   indices.push_back(TextActor::FONT_DETECTION_AUTOMATIC );
593   indices.push_back(TextActor::GRADIENT_COLOR           );
594   indices.push_back(TextActor::GRADIENT_START_POINT     );
595   indices.push_back(TextActor::GRADIENT_END_POINT       );
596   indices.push_back(TextActor::SHADOW_SIZE              );
597   indices.push_back(TextActor::TEXT_COLOR               );
598
599   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
600
601   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
602   {
603     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
604     DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
605     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
606     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
607   }
608
609   // set/get one of them
610   actor.SetUnderline(false);
611   DALI_TEST_CHECK(actor.GetUnderline() != true);
612
613   actor.SetProperty(TextActor::UNDERLINE, Property::Value(true));
614   Property::Value v = actor.GetProperty(TextActor::UNDERLINE);
615   DALI_TEST_CHECK(v.GetType() == Property::BOOLEAN);
616
617   DALI_TEST_CHECK(v.Get<bool>() == true);
618 }
619
620 static void UtcDaliTextActorSetGradientColor()
621 {
622   TestApplication application;
623
624   tet_infoline("Testing Dali::TextActor::SetGradientColor()");
625
626   TextActor actor = TextActor::New(TestTextHello);
627
628   DALI_TEST_CHECK(actor);
629
630   actor.SetGradientColor( Color::RED );
631   DALI_TEST_EQUALS( actor.GetGradientColor(), Color::RED, TEST_LOCATION );
632
633   actor.SetGradientColor( Color::BLUE );
634   DALI_TEST_EQUALS( actor.GetGradientColor(), Color::BLUE, TEST_LOCATION );
635 }
636
637 static void UtcDaliTextActorSetGradientStartPoint()
638 {
639   TestApplication application;
640
641   tet_infoline("Testing Dali::TextActor::SetGradientStartPoint()");
642
643   TextActor actor = TextActor::New(TestTextHello);
644
645   DALI_TEST_CHECK(actor);
646
647   actor.SetGradientStartPoint( Vector2(0.5f, 0.5f) );
648   DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(0.5f, 0.5f), TEST_LOCATION );
649
650   actor.SetGradientStartPoint( Vector2(1.0f, 0.0f) );
651   DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(1.0f, 0.0f), TEST_LOCATION );
652 }
653
654 static void UtcDaliTextActorSetGradientEndPoint()
655 {
656   TestApplication application;
657
658   tet_infoline("Testing Dali::TextActor::SetGradientEndPoint()");
659
660   TextActor actor = TextActor::New(TestTextHello);
661
662   DALI_TEST_CHECK(actor);
663
664   actor.SetGradientEndPoint( Vector2(0.25f, 0.25f) );
665   DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.25f, 0.25f), TEST_LOCATION );
666
667   actor.SetGradientEndPoint( Vector2(0.0f, 1.0f) );
668   DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.0f, 1.0f), TEST_LOCATION );
669 }
670
671 static void UtcDaliTextActorSynchronousGlyphLoading()
672 {
673   TestApplication application;
674
675   tet_infoline( "Testing synchronous loading of glyphs");
676
677   // All numerals 0 through 9 are 'fake' cached in the test abstraction glyphcache
678
679   // create text actor containg "Hello"
680   TextActor actor = TextActor::New(TestTextHello);
681
682   // no glyphs will be cached
683
684   // so..GetGlyphData should have been called to gather metrics
685   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:false" ) );
686   // ..but not to load glyph bitmap data
687   DALI_TEST_CHECK( ! application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
688   // ..also, cached high quality glyphs will not have been requested yet
689   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
690
691   // reset PlatformAbstraction function call traces
692   application.GetPlatform().ResetTrace();
693
694   // Invoke Core::ProcessEvent and tick the update/render threads
695   application.SendNotification();
696   application.Render();
697
698   // An attempt to load high quality glyphs will have been requested and loaded nothing
699   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
700   // low quality glyphs bitmap data will have now been generated
701   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
702
703   // request numerals
704   actor.SetText( "0123456789" );
705
706   // reset PlatformAbstraction function call traces
707   application.GetPlatform().ResetTrace();
708
709   application.SendNotification();
710   application.Render();
711
712   // An attempt to load high quality glyphs will have been requested and loaded all the numerals
713   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
714   // ..therefore no low quality glyphs bitmap data will have been requested
715   DALI_TEST_CHECK( !application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
716 }
717
718 static void UtcDaliTextActorAutomaticSizeSet()
719 {
720   TestApplication application;
721
722   tet_infoline("Testing Dali::TextActor getting size based on text automatically");
723
724   // create empty text actor
725   TextActor actor = TextActor::New();
726   Stage::GetCurrent().Add(actor);
727
728   // initial size is zero
729   DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
730
731   // set some text
732   actor.SetText( "a" );
733   // render a frame
734   application.SendNotification();
735   application.Render();
736
737   // dont care about the actual size as that is too hard to figure out, just want to validate that the size was changed to bigger
738   Vector3 currentSize = actor.GetCurrentSize();
739   DALI_TEST_GREATER( currentSize.width, 0.0f, TEST_LOCATION );
740   DALI_TEST_GREATER( currentSize.height, 0.0f, TEST_LOCATION );
741
742   // set some more text
743   actor.SetText( "abba" );
744   // render a frame
745   application.SendNotification();
746   application.Render();
747
748   Vector3 biggerSize = actor.GetCurrentSize();
749   DALI_TEST_GREATER( biggerSize.width, currentSize.width, TEST_LOCATION );
750
751   // set some shorter text
752   actor.SetText( "i" );
753   // render a frame
754   application.SendNotification();
755   application.Render();
756
757   // actor has shrunk
758   DALI_TEST_GREATER( biggerSize.width, actor.GetCurrentSize().width, TEST_LOCATION );
759
760   // set a size from application side, from this point onwards text actor no longer uses the "natural" size of the text
761   actor.SetSize( Vector2( 10.0f, 11.0f ) );
762   // render a frame
763   application.SendNotification();
764   application.Render();
765   // actor has the user set size
766   DALI_TEST_EQUALS( Vector2( 10.0f, 11.0f ), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
767
768   // set some different text
769   std::string longText( "jabba dabba duu" );
770   actor.SetText( longText );
771   // render a frame
772   application.SendNotification();
773   application.Render();
774   // actor still has the user set size
775   DALI_TEST_EQUALS( Vector2( 10.0f, 11.0f ), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
776
777   // set text to its natural size
778   actor.SetToNaturalSize();
779   // render a frame
780   application.SendNotification();
781   application.Render();
782   // actor has the natural size
783   Font defaultFont = Font::New();
784   Vector3 naturalSize = defaultFont.MeasureText( longText );
785   DALI_TEST_EQUALS( naturalSize.GetVectorXY(), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
786 }
787
788 static void UtcDaliTextActorAutomaticSizeSetAnimation()
789 {
790   TestApplication application;
791
792   tet_infoline("Testing Dali::TextActor getting size based on text automatically with animation");
793
794   // create empty text actor
795   TextActor actor = TextActor::New();
796   Stage::GetCurrent().Add(actor);
797
798   // initial size is zero
799   DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
800
801   // set some text
802   actor.SetText( "a" );
803   // render a frame
804   application.SendNotification();
805   application.Render();
806
807   // dont care about the actual size as that is too hard to figure out, just want to validate that the size was changed to bigger
808   Vector3 currentSize = actor.GetCurrentSize();
809   DALI_TEST_GREATER( currentSize.width, 0.0f, TEST_LOCATION );
810   DALI_TEST_GREATER( currentSize.height, 0.0f, TEST_LOCATION );
811
812   // animate size, from this point onwards text actor no longer uses the "natural" size of the text
813   Animation sizeAnim = Animation::New( 0.1f ); // 0.1 seconds
814   Vector3 animationTargetSize( 20.0f, 30.0f, 0.0f );
815   sizeAnim.AnimateTo( Property( actor, Actor::SIZE ), animationTargetSize );
816   sizeAnim.Play();
817
818   // set some more text
819   actor.SetText( "abba" );
820   // render a frame
821   application.SendNotification();
822   application.Render( 1000 ); // 1 second to complete the animation
823
824   DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
825
826   // set some more text
827   std::string moreText( "something else" );
828   actor.SetText( moreText );
829   // render a frame
830   application.SendNotification();
831   application.Render();
832
833   DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
834
835   // set text to its natural size
836   actor.SetToNaturalSize();
837   // render a frame
838   application.SendNotification();
839   application.Render();
840   // actor has the natural size
841   Font defaultFont = Font::New();
842   Vector3 naturalSize = defaultFont.MeasureText( moreText );
843   DALI_TEST_EQUALS( naturalSize.GetVectorXY(), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
844 }
845
846 void UtcDaliTextActorPropertyIndices()
847 {
848   TestApplication application;
849   Actor basicActor = Actor::New();
850   TextActor textActor = TextActor::New("Text");
851
852   Property::IndexContainer indices;
853   textActor.GetPropertyIndices( indices );
854   DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
855   DALI_TEST_EQUALS( indices.size(), textActor.GetPropertyCount(), TEST_LOCATION );
856 }