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