Property - Allow the custom property to be INTEGER type
[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/public-api/dali-core.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 static const std::string DEFAULT_NAME_STYLE( "" );
43 static const PointSize DEFAULT_FONT_POINT_SIZE( 0.f );
44
45 static const std::string FONT_FAMILY( "Arial" );
46 static const std::string FONT_STYLE( "Bold" );
47 static const PointSize FONT_POINT_SIZE( 12.f );
48 static const Vector4 TEXT_COLOR( Color::RED );
49
50 static const TextStyle::Weight TEXT_WEIGHT( TextStyle::EXTRALIGHT );
51 static const float SMOOTH_EDGE( 5.0f );
52
53 static const bool ITALICS( true );
54 static const Degree ITALICS_ANGLE( 10.f );
55 static const Radian ITALICS_RADIAN_ANGLE(0.4f);
56
57 static const bool UNDERLINE( true );
58 static const float UNDERLINE_THICKNESS( 5.0f );
59 static const float UNDERLINE_POSITION( 60.0f );
60
61 static const bool SHADOW( true );
62 static const Vector4 SHADOW_COLOR( Color::BLUE );
63 static const Vector2 SHADOW_OFFSET( 2.f, 2.f );
64 static const float SHADOW_SIZE( 55.f );
65
66 static const bool GLOW( true );
67 static const Vector4 GLOW_COLOR( Color::BLACK );
68 static const float GLOW_INTENSITY( 10.0f );
69
70 static const bool OUTLINE( true );
71 static const Vector4 OUTLINE_COLOR( Color::MAGENTA );
72 static const Vector2 OUTLINE_THICKNESS( 15.f, 14.f );
73
74 static const bool GRADIENT( true );
75 static const Vector4 GRADIENT_COLOR( Color::YELLOW );
76 static const Vector2 GRADIENT_START_POINT( 1.f, 1.f );
77 static const Vector2 GRADIENT_END_POINT( 2.f, 2.f );
78 } // anon namespace
79
80 int UtcDaliTextActorConstructorVoid(void)
81 {
82   TestApplication application;
83
84   tet_infoline("Testing Dali::TextActor::TextActor()");
85
86   TextActor actor;
87
88   DALI_TEST_CHECK(!actor);
89   END_TEST;
90 }
91
92 int UtcDaliTextActorNew01(void)
93 {
94   TestApplication application;
95
96   tet_infoline("Testing Dali::TextActor::New()");
97
98   TextActor actor = TextActor::New(TestTextHello);
99
100   DALI_TEST_CHECK(actor);
101
102   actor = TextActor::New(Text(std::string(TestTextHello)));
103
104   DALI_TEST_CHECK(actor);
105   END_TEST;
106 }
107
108
109 int UtcDaliTextActorNew02(void)
110 {
111   TestApplication application;
112
113   tet_infoline("Testing Dali::TextActor::New()");
114
115   TextActor actor = TextActor::New(TestTextHello, false);
116
117   DALI_TEST_CHECK(actor);
118
119   actor = TextActor::New(Text(std::string(TestTextHello)), false);
120
121   DALI_TEST_CHECK(actor);
122   END_TEST;
123 }
124
125 int UtcDaliTextActorNew03(void)
126 {
127   TestApplication application;
128
129   tet_infoline("Testing Dali::TextActor::New()");
130
131   TextActor actor = TextActor::New(TestTextHello, false, false);
132
133   DALI_TEST_CHECK(actor);
134
135   actor = TextActor::New(Text(std::string(TestTextHello)), false, false);
136
137   DALI_TEST_CHECK(actor);
138   END_TEST;
139 }
140
141
142 int UtcDaliTextActorNew04(void)
143 {
144   TestApplication application;
145
146   tet_infoline("Testing Dali::TextActor::New()");
147
148   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
149   Font freeSerif = Font::New( parameters );
150
151   TextActor actor = TextActor::New(TestTextHello, freeSerif);
152
153   DALI_TEST_CHECK(actor);
154
155   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif);
156
157   DALI_TEST_CHECK(actor);
158   END_TEST;
159 }
160
161 int UtcDaliTextActorNew05(void)
162 {
163   TestApplication application;
164
165   tet_infoline("Testing Dali::TextActor::New()");
166
167   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
168   Font freeSerif = Font::New( parameters );
169
170   TextActor actor = TextActor::New(TestTextHello, freeSerif, false);
171
172   DALI_TEST_CHECK(actor);
173
174   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false);
175
176   DALI_TEST_CHECK(actor);
177   END_TEST;
178 }
179
180 int UtcDaliTextActorNew06(void)
181 {
182   TestApplication application;
183
184   tet_infoline("Testing Dali::TextActor::New()");
185
186   FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
187   Font freeSerif = Font::New( parameters );
188
189   TextActor actor = TextActor::New(TestTextHello, freeSerif, false, false);
190
191   DALI_TEST_CHECK(actor);
192
193   actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false, false);
194
195   DALI_TEST_CHECK(actor);
196   END_TEST;
197 }
198
199 int UtcDaliTextActorNew07(void)
200 {
201   TestApplication application;
202
203   tet_infoline("Testing Dali::TextActor::New()");
204
205   TextStyle style;
206
207   TextActor actor = TextActor::New(Text(TestTextHello), style, false, false);
208
209   DALI_TEST_CHECK(actor);
210   END_TEST;
211 }
212
213
214 int UtcDaliTextActorDownCast(void)
215 {
216   TestApplication application;
217   tet_infoline("Testing Dali::TextActor::DownCast()");
218
219   TextActor actor1 = TextActor::New("Hello, World!");
220   Actor anActor = Actor::New();
221   anActor.Add(actor1);
222
223   Actor child = anActor.GetChildAt(0);
224   TextActor textActor = TextActor::DownCast(child);
225
226   DALI_TEST_CHECK(textActor);
227   DALI_TEST_CHECK(!textActor.GetText().compare("Hello, World!"));
228   END_TEST;
229 }
230
231 int UtcDaliTextActorDownCast2(void)
232 {
233   TestApplication application;
234   tet_infoline("Testing Dali::TextActor::DownCast()");
235
236   Actor actor1 = Actor::New();
237   Actor anActor = Actor::New();
238   anActor.Add(actor1);
239
240   Actor child = anActor.GetChildAt(0);
241   TextActor textActor = TextActor::DownCast(child);
242   DALI_TEST_CHECK(!textActor);
243
244   Actor unInitialzedActor;
245   textActor = DownCast< TextActor >( unInitialzedActor );
246   DALI_TEST_CHECK(!textActor);
247   END_TEST;
248 }
249
250 int UtcDaliTextActorSetText(void)
251 {
252   TestApplication application;
253
254   tet_infoline("Testing Dali::TextActor::SetText()");
255
256   TextActor actor01 = TextActor::New(TestTextHello);
257
258   actor01.SetText(TestTextHelloWorld);
259
260   std::string text = actor01.GetText();
261
262   DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
263
264   actor01.SetText(Text(std::string(TestTextHelloWorld)));
265
266   text = actor01.GetText();
267
268   DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
269
270   actor01.SetText("");
271
272   text = actor01.GetText();
273
274   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
275
276   TextActor actor02 = TextActor::New("");
277
278   actor02.SetText( std::string() );
279
280   text = actor02.GetText();
281
282   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
283
284   actor02.SetText(TestTextHelloWorld);
285   actor02.SetText( std::string() );
286
287   text = actor02.GetText();
288
289   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
290
291   TextActor actor03 = TextActor::New("");
292   const Text voidText;
293   actor03.SetText(voidText);
294
295   text = actor03.GetText();
296
297   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
298
299   actor03.SetText(TestTextHelloWorld);
300   actor03.SetText(voidText);
301
302   text = actor03.GetText();
303
304   DALI_TEST_EQUALS(text, "", TEST_LOCATION);
305   END_TEST;
306 }
307
308 int UtcDaliTextActorSetFont(void)
309 {
310   TestApplication application;
311
312   TextActor actor = TextActor::New(TestTextHello);
313
314   Font defaultFont = actor.GetFont();
315   DALI_TEST_EQUALS( defaultFont.GetName(), DEFAULT_NAME_STYLE, TEST_LOCATION );
316   DALI_TEST_EQUALS( defaultFont.GetStyle(), DEFAULT_NAME_STYLE, TEST_LOCATION );
317   DALI_TEST_CHECK( defaultFont.IsDefaultSystemSize() );
318
319   TextStyle defaultStyle = actor.GetTextStyle();
320   DALI_TEST_EQUALS( defaultStyle.GetFontName(), DEFAULT_NAME_STYLE, TEST_LOCATION );
321   DALI_TEST_EQUALS( defaultStyle.GetFontStyle(), DEFAULT_NAME_STYLE, TEST_LOCATION );
322   DALI_TEST_EQUALS( defaultStyle.GetFontPointSize(), DEFAULT_FONT_POINT_SIZE, TEST_LOCATION );
323
324   FontParameters params( FONT_FAMILY, FONT_STYLE, FONT_POINT_SIZE );
325
326   Font font = Font::New( params );
327
328   actor.SetFont( font );
329
330   Font font2 = actor.GetFont();
331
332   DALI_TEST_EQUALS( font2.GetName(), FONT_FAMILY, TEST_LOCATION );
333   DALI_TEST_EQUALS( font2.GetStyle(), FONT_STYLE, TEST_LOCATION );
334   DALI_TEST_CHECK( !font2.IsDefaultSystemSize() );
335   DALI_TEST_EQUALS( PointSize( font2.GetPointSize() ), FONT_POINT_SIZE, TEST_LOCATION );
336
337   TextStyle style = actor.GetTextStyle();
338   DALI_TEST_EQUALS( style.GetFontName(), FONT_FAMILY, TEST_LOCATION );
339   DALI_TEST_EQUALS( style.GetFontStyle(), FONT_STYLE, TEST_LOCATION );
340   DALI_TEST_EQUALS( style.GetFontPointSize(), FONT_POINT_SIZE, TEST_LOCATION );
341
342   END_TEST;
343 }
344
345 int UtcDaliTextActorSetFontDetection(void)
346 {
347   TestApplication application;
348
349   TextActor actor = TextActor::New(TestTextHello);
350
351   actor.SetFontDetectionAutomatic( true );
352
353   DALI_TEST_CHECK( true == actor.IsFontDetectionAutomatic() );
354
355   END_TEST;
356 }
357
358 int UtcDaliTextActorSetTextIndividualStyles(void)
359 {
360   TestApplication application;
361
362   TextActor actor = TextActor::New(TestTextHello);
363   TextStyle defaultStyle = actor.GetTextStyle();
364
365   DALI_TEST_EQUALS( actor.GetTextColor(), TextStyle::DEFAULT_TEXT_COLOR, TEST_LOCATION );
366   DALI_TEST_EQUALS( defaultStyle.GetTextColor(), TextStyle::DEFAULT_TEXT_COLOR, TEST_LOCATION );
367
368   DALI_TEST_EQUALS( actor.GetWeight(), TextStyle::DEFAULT_FONT_WEIGHT, TEST_LOCATION );
369   DALI_TEST_EQUALS( defaultStyle.GetWeight(), TextStyle::DEFAULT_FONT_WEIGHT, TEST_LOCATION );
370
371   DALI_TEST_EQUALS( defaultStyle.GetSmoothEdge(), TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
372
373   DALI_TEST_CHECK( !actor.GetItalics() );
374   DALI_TEST_EQUALS( actor.GetItalicsAngle(), TextStyle::DEFAULT_ITALICS_ANGLE, TEST_LOCATION );
375   DALI_TEST_CHECK( defaultStyle.IsItalicsDefault() );
376   DALI_TEST_CHECK( !defaultStyle.IsItalicsEnabled() );
377   DALI_TEST_EQUALS( defaultStyle.GetItalicsAngle(), TextStyle::DEFAULT_ITALICS_ANGLE, TEST_LOCATION );
378
379   DALI_TEST_CHECK( !actor.GetUnderline() );
380   DALI_TEST_CHECK( defaultStyle.IsUnderlineDefault() );
381   DALI_TEST_CHECK( !defaultStyle.IsUnderlineEnabled() );
382   DALI_TEST_EQUALS( defaultStyle.GetUnderlinePosition(), TextStyle::DEFAULT_UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
383   DALI_TEST_EQUALS( defaultStyle.GetUnderlineThickness(), TextStyle::DEFAULT_UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
384
385   DALI_TEST_CHECK( defaultStyle.IsShadowDefault() );
386   DALI_TEST_CHECK( !defaultStyle.IsShadowEnabled() );
387   DALI_TEST_EQUALS( defaultStyle.GetShadowColor(), TextStyle::DEFAULT_SHADOW_COLOR, TEST_LOCATION );
388   DALI_TEST_EQUALS( defaultStyle.GetShadowOffset(), TextStyle::DEFAULT_SHADOW_OFFSET, TEST_LOCATION );
389
390   DALI_TEST_CHECK( defaultStyle.IsGlowDefault() );
391   DALI_TEST_CHECK( !defaultStyle.IsGlowEnabled() );
392   DALI_TEST_EQUALS( defaultStyle.GetGlowColor(), TextStyle::DEFAULT_GLOW_COLOR, TEST_LOCATION );
393   DALI_TEST_EQUALS( defaultStyle.GetGlowIntensity(), TextStyle::DEFAULT_GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
394
395   DALI_TEST_CHECK( defaultStyle.IsOutlineDefault() );
396   DALI_TEST_CHECK( !defaultStyle.IsOutlineEnabled() );
397   DALI_TEST_EQUALS( defaultStyle.GetOutlineColor(), TextStyle::DEFAULT_OUTLINE_COLOR, TEST_LOCATION );
398   DALI_TEST_EQUALS( defaultStyle.GetOutlineThickness(), TextStyle::DEFAULT_OUTLINE_THICKNESS, TEST_LOCATION );
399
400   DALI_TEST_CHECK( defaultStyle.IsGradientDefault() );
401   DALI_TEST_CHECK( !defaultStyle.IsGradientEnabled() );
402   DALI_TEST_EQUALS( defaultStyle.GetGradientColor(), TextStyle::DEFAULT_GRADIENT_COLOR, TEST_LOCATION );
403   DALI_TEST_EQUALS( defaultStyle.GetGradientStartPoint(), TextStyle::DEFAULT_GRADIENT_START_POINT, TEST_LOCATION );
404   DALI_TEST_EQUALS( defaultStyle.GetGradientEndPoint(), TextStyle::DEFAULT_GRADIENT_END_POINT, TEST_LOCATION );
405
406
407   actor.SetTextColor( TEXT_COLOR );
408
409   actor.SetWeight( TEXT_WEIGHT );
410   actor.SetSmoothEdge( SMOOTH_EDGE  );
411
412   actor.SetItalics( ITALICS, ITALICS_ANGLE );
413   actor.SetUnderline( UNDERLINE );
414
415   actor.SetShadow( SHADOW, SHADOW_COLOR, SHADOW_OFFSET, SHADOW_SIZE );
416   actor.SetGlow( GLOW, GLOW_COLOR, GLOW_INTENSITY );
417   actor.SetOutline( OUTLINE, OUTLINE_COLOR, OUTLINE_THICKNESS );
418   actor.SetGradientColor( GRADIENT_COLOR );
419   actor.SetGradientStartPoint( GRADIENT_START_POINT );
420   actor.SetGradientEndPoint( GRADIENT_END_POINT );
421
422
423   TextStyle style = actor.GetTextStyle();
424
425   DALI_TEST_EQUALS( actor.GetTextColor(), TEXT_COLOR, TEST_LOCATION );
426   DALI_TEST_EQUALS( style.GetTextColor(), TEXT_COLOR, TEST_LOCATION );
427
428   DALI_TEST_EQUALS( actor.GetWeight(), TEXT_WEIGHT, TEST_LOCATION );
429   DALI_TEST_EQUALS( style.GetWeight(), TEXT_WEIGHT, TEST_LOCATION );
430
431   DALI_TEST_EQUALS( style.GetSmoothEdge(), SMOOTH_EDGE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
432
433   DALI_TEST_CHECK( actor.GetItalics() );
434   DALI_TEST_EQUALS( actor.GetItalicsAngle(), ITALICS_ANGLE, TEST_LOCATION );
435   DALI_TEST_CHECK( !style.IsItalicsDefault() );
436   DALI_TEST_CHECK( style.IsItalicsEnabled() );
437   DALI_TEST_EQUALS( style.GetItalicsAngle(), ITALICS_ANGLE, TEST_LOCATION );
438
439   DALI_TEST_CHECK( actor.GetUnderline() );
440   DALI_TEST_CHECK( !style.IsUnderlineDefault() );
441   DALI_TEST_CHECK( style.IsUnderlineEnabled() );
442   DALI_TEST_EQUALS( style.GetUnderlinePosition(), TextStyle::DEFAULT_UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
443   DALI_TEST_EQUALS( style.GetUnderlineThickness(), TextStyle::DEFAULT_UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
444
445   DALI_TEST_CHECK( !style.IsShadowDefault() );
446   DALI_TEST_CHECK( style.IsShadowEnabled() );
447   DALI_TEST_EQUALS( style.GetShadowColor(), SHADOW_COLOR, TEST_LOCATION );
448   DALI_TEST_EQUALS( style.GetShadowOffset(), SHADOW_OFFSET, TEST_LOCATION );
449
450   DALI_TEST_CHECK( !style.IsGlowDefault() );
451   DALI_TEST_CHECK( style.IsGlowEnabled() );
452   DALI_TEST_EQUALS( style.GetGlowColor(), GLOW_COLOR, TEST_LOCATION );
453   DALI_TEST_EQUALS( style.GetGlowIntensity(), GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
454
455   DALI_TEST_CHECK( !style.IsOutlineDefault() );
456   DALI_TEST_CHECK( style.IsOutlineEnabled() );
457   DALI_TEST_EQUALS( style.GetOutlineColor(), OUTLINE_COLOR, TEST_LOCATION );
458   DALI_TEST_EQUALS( style.GetOutlineThickness(), OUTLINE_THICKNESS, TEST_LOCATION );
459
460   DALI_TEST_EQUALS( actor.GetGradientColor(), GRADIENT_COLOR, TEST_LOCATION );
461   DALI_TEST_EQUALS( actor.GetGradientStartPoint(), GRADIENT_START_POINT, TEST_LOCATION );
462   DALI_TEST_EQUALS( actor.GetGradientEndPoint(), GRADIENT_END_POINT, TEST_LOCATION );
463   DALI_TEST_CHECK( !style.IsGradientDefault() );
464   DALI_TEST_CHECK( style.IsGradientEnabled() );
465   DALI_TEST_EQUALS( style.GetGradientColor(), GRADIENT_COLOR, TEST_LOCATION );
466   DALI_TEST_EQUALS( style.GetGradientStartPoint(), GRADIENT_START_POINT, TEST_LOCATION );
467   DALI_TEST_EQUALS( style.GetGradientEndPoint(), GRADIENT_END_POINT, TEST_LOCATION );
468
469   // Added to increase coverage.
470
471   // Set a different color.
472   actor.SetTextColor( TEXT_COLOR );
473   actor.SetTextColor( Color::GREEN );
474   DALI_TEST_EQUALS( actor.GetTextColor(), Color::GREEN, TEST_LOCATION );
475
476   // Set a different weight
477   actor.SetWeight( TEXT_WEIGHT );
478   actor.SetWeight( TextStyle::BOLD );
479   DALI_TEST_EQUALS( actor.GetWeight(), TextStyle::BOLD, TEST_LOCATION );
480
481   // Set a different smooth edge
482   actor.SetSmoothEdge( SMOOTH_EDGE );
483   actor.SetSmoothEdge( 1.f );
484   DALI_TEST_EQUALS( actor.GetTextStyle().GetSmoothEdge(), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
485
486   // Set different italic parameters
487   actor.SetItalics( true, ITALICS_ANGLE );
488   actor.SetItalics( false );
489   DALI_TEST_CHECK( !actor.GetItalics() );
490   actor.SetItalics( true, Degree( 15.f ) );
491   DALI_TEST_EQUALS( actor.GetItalicsAngle(), Degree( 15.f ), TEST_LOCATION );
492
493   END_TEST;
494 }
495
496 int UtcDaliTextActorChangingText(void)
497 {
498   TestApplication application;
499
500   TextActor actor = TextActor::New(TestTextHello);
501   actor.SetSize(Vector3(200, 20, 0.0f));
502   actor.SetPosition(20.0f, 400.0f, 40.0f);
503   Stage::GetCurrent().Add(actor);
504
505   tet_infoline("Testing Dali::TextActor::SetText() & Dali::TextActor::GetText()");
506   actor.SetText(LongTestText);
507   std::string text = actor.GetText();
508   DALI_TEST_EQUALS(text, LongTestText, TEST_LOCATION);
509
510   // do a render
511   application.SendNotification();
512   application.Render();
513
514   // check that the size did not change
515   DALI_TEST_EQUALS( Vector3(200, 20, 0.0f), actor.GetCurrentSize(), TEST_LOCATION);
516   END_TEST;
517 }
518
519 int UtcDaliTextActorGetLoadingState(void)
520 {
521   TestApplication application;
522
523   TextActor actor = TextActor::New(TestTextHello);
524
525   DALI_TEST_CHECK( ResourceLoading == actor.GetLoadingState());
526
527   application.SendNotification();
528   application.Render();
529
530   DALI_TEST_CHECK( ResourceLoadingSucceeded == actor.GetLoadingState());
531
532   END_TEST;
533 }
534
535 int UtcDaliTextActorSetItalics(void)
536 {
537   TestApplication application;
538
539   tet_infoline("Testing Dali::TextActor::New()");
540
541   TextActor actor = TextActor::New(TestTextHello);
542
543   DALI_TEST_CHECK(actor);
544
545   actor.SetItalics( true );
546
547   DALI_TEST_CHECK( actor.GetItalics() );
548
549   DALI_TEST_EQUALS( static_cast<float>( Degree( actor.GetItalicsAngle() ) ), static_cast<float>(TextStyle::DEFAULT_ITALICS_ANGLE), 0.0001f, TEST_LOCATION );
550
551   actor.SetItalics( false );
552
553   DALI_TEST_CHECK( ! actor.GetItalics() );
554
555   // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
556   END_TEST;
557 }
558
559 int UtcDaliTextActorSetUnderline(void)
560 {
561   TestApplication application;
562
563   tet_infoline("Testing Dali::TextActor::SetUnderline()");
564
565   TextActor actor = TextActor::New(TestTextHello);
566
567   DALI_TEST_CHECK(actor);
568
569   actor.SetUnderline( true );
570
571   DALI_TEST_CHECK( actor.GetUnderline() );
572
573   actor.SetUnderline( false );
574
575   DALI_TEST_CHECK( ! actor.GetUnderline() );
576
577   // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
578   END_TEST;
579 }
580
581 int UtcDaliTextActorSetWeight(void)
582 {
583   TestApplication application;
584
585   tet_infoline("Testing Dali::TextActor::SetWeight()");
586
587   TextActor actor = TextActor::New(TestTextHello);
588
589   DALI_TEST_CHECK(actor);
590
591   actor.SetWeight( TextStyle::EXTRABOLD );
592
593   DALI_TEST_CHECK( TextStyle::EXTRABOLD == actor.GetWeight() );
594
595   actor.SetWeight( TextStyle::BOLD );
596
597   DALI_TEST_CHECK( TextStyle::BOLD == actor.GetWeight() );
598   END_TEST;
599 }
600
601 int UtcDaliTextActorSetStyle(void)
602 {
603   TestApplication application;
604
605   tet_infoline("Testing Dali::TextActor::SetTextStyle()");
606
607   TextActor actor = TextActor::New(TestTextHello);
608
609   const TextStyle defaultStyle = actor.GetTextStyle();
610
611   DALI_TEST_EQUALS( defaultStyle.GetFontName(), DEFAULT_NAME_STYLE, TEST_LOCATION );
612   DALI_TEST_EQUALS( defaultStyle.GetFontStyle(), DEFAULT_NAME_STYLE, TEST_LOCATION );
613   DALI_TEST_EQUALS( defaultStyle.GetFontPointSize(), DEFAULT_FONT_POINT_SIZE, TEST_LOCATION );
614   DALI_TEST_EQUALS( defaultStyle.GetTextColor(), TextStyle::DEFAULT_TEXT_COLOR, TEST_LOCATION );
615
616   DALI_TEST_EQUALS( defaultStyle.GetWeight(), TextStyle::DEFAULT_FONT_WEIGHT, TEST_LOCATION );
617   DALI_TEST_EQUALS( defaultStyle.GetSmoothEdge(), TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
618
619   DALI_TEST_CHECK( defaultStyle.IsItalicsDefault() );
620   DALI_TEST_CHECK( !defaultStyle.IsItalicsEnabled() );
621   DALI_TEST_EQUALS( defaultStyle.GetItalicsAngle(), TextStyle::DEFAULT_ITALICS_ANGLE, TEST_LOCATION );
622
623   DALI_TEST_CHECK( defaultStyle.IsUnderlineDefault() );
624   DALI_TEST_CHECK( !defaultStyle.IsUnderlineEnabled() );
625   DALI_TEST_EQUALS( defaultStyle.GetUnderlinePosition(), TextStyle::DEFAULT_UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
626   DALI_TEST_EQUALS( defaultStyle.GetUnderlineThickness(), TextStyle::DEFAULT_UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
627
628   DALI_TEST_CHECK( defaultStyle.IsShadowDefault() );
629   DALI_TEST_CHECK( !defaultStyle.IsShadowEnabled() );
630   DALI_TEST_EQUALS( defaultStyle.GetShadowColor(), TextStyle::DEFAULT_SHADOW_COLOR, TEST_LOCATION );
631   DALI_TEST_EQUALS( defaultStyle.GetShadowOffset(), TextStyle::DEFAULT_SHADOW_OFFSET, TEST_LOCATION );
632
633   DALI_TEST_CHECK( defaultStyle.IsGlowDefault() );
634   DALI_TEST_CHECK( !defaultStyle.IsGlowEnabled() );
635   DALI_TEST_EQUALS( defaultStyle.GetGlowColor(), TextStyle::DEFAULT_GLOW_COLOR, TEST_LOCATION );
636   DALI_TEST_EQUALS( defaultStyle.GetGlowIntensity(), TextStyle::DEFAULT_GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
637
638   DALI_TEST_CHECK( defaultStyle.IsOutlineDefault() );
639   DALI_TEST_CHECK( !defaultStyle.IsOutlineEnabled() );
640   DALI_TEST_EQUALS( defaultStyle.GetOutlineColor(), TextStyle::DEFAULT_OUTLINE_COLOR, TEST_LOCATION );
641   DALI_TEST_EQUALS( defaultStyle.GetOutlineThickness(), TextStyle::DEFAULT_OUTLINE_THICKNESS, TEST_LOCATION );
642
643   DALI_TEST_CHECK( defaultStyle.IsGradientDefault() );
644   DALI_TEST_CHECK( !defaultStyle.IsGradientEnabled() );
645   DALI_TEST_EQUALS( defaultStyle.GetGradientColor(), TextStyle::DEFAULT_GRADIENT_COLOR, TEST_LOCATION );
646   DALI_TEST_EQUALS( defaultStyle.GetGradientStartPoint(), TextStyle::DEFAULT_GRADIENT_START_POINT, TEST_LOCATION );
647   DALI_TEST_EQUALS( defaultStyle.GetGradientEndPoint(), TextStyle::DEFAULT_GRADIENT_END_POINT, TEST_LOCATION );
648
649
650   // Set a non default style.
651
652   TextStyle style;
653   style.SetFontName( FONT_FAMILY );
654   style.SetFontStyle( FONT_STYLE );
655   style.SetFontPointSize( FONT_POINT_SIZE );
656   style.SetTextColor( TEXT_COLOR );
657
658   style.SetWeight( TEXT_WEIGHT );
659   style.SetSmoothEdge( SMOOTH_EDGE );
660
661   style.SetItalics( ITALICS, ITALICS_ANGLE );
662   style.SetUnderline( UNDERLINE, UNDERLINE_THICKNESS, UNDERLINE_POSITION );
663
664   style.SetShadow( SHADOW, SHADOW_COLOR, SHADOW_OFFSET, SHADOW_SIZE );
665   style.SetGlow( GLOW, GLOW_COLOR, GLOW_INTENSITY );
666   style.SetOutline( OUTLINE, OUTLINE_COLOR, OUTLINE_THICKNESS );
667   style.SetGradient( GRADIENT, GRADIENT_COLOR, GRADIENT_START_POINT, GRADIENT_END_POINT );
668
669   actor.SetTextStyle( style );
670
671   // This is necessary since SetColor (via TextStyle) is asynchronous
672   application.SendNotification();
673   application.Render();
674
675   TextStyle style2 = actor.GetTextStyle();
676
677   DALI_TEST_CHECK( !style2.IsFontNameDefault() );
678   DALI_TEST_CHECK( !style2.IsFontStyleDefault() );
679   DALI_TEST_CHECK( !style2.IsFontSizeDefault() );
680   DALI_TEST_CHECK( !style2.IsTextColorDefault() );
681   DALI_TEST_CHECK( !style2.IsFontWeightDefault() );
682   DALI_TEST_CHECK( !style2.IsSmoothEdgeDefault() );
683   DALI_TEST_CHECK( !style2.IsItalicsDefault() );
684   DALI_TEST_CHECK( !style2.IsUnderlineDefault() );
685   DALI_TEST_CHECK( !style2.IsShadowDefault() );
686   DALI_TEST_CHECK( !style2.IsGlowDefault() );
687   DALI_TEST_CHECK( !style2.IsOutlineDefault() );
688   DALI_TEST_CHECK( !style2.IsGradientDefault() );
689
690   DALI_TEST_EQUALS( style2.GetFontName(), FONT_FAMILY, TEST_LOCATION );
691   DALI_TEST_EQUALS( style2.GetFontStyle(), FONT_STYLE, TEST_LOCATION );
692   DALI_TEST_EQUALS( style2.GetFontPointSize(), FONT_POINT_SIZE, TEST_LOCATION );
693   DALI_TEST_EQUALS( style2.GetTextColor(), TEXT_COLOR, TEST_LOCATION );
694
695   DALI_TEST_EQUALS( style2.GetWeight(), TEXT_WEIGHT, TEST_LOCATION );
696   DALI_TEST_EQUALS( style2.GetSmoothEdge(), SMOOTH_EDGE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
697
698   DALI_TEST_CHECK( style2.IsItalicsEnabled() );
699   DALI_TEST_EQUALS( style2.GetItalicsAngle(), ITALICS_ANGLE, TEST_LOCATION );
700
701   DALI_TEST_CHECK( style2.IsUnderlineEnabled() );
702   DALI_TEST_EQUALS( style2.GetUnderlineThickness(), UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
703   DALI_TEST_EQUALS( style2.GetUnderlinePosition(), UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
704
705   DALI_TEST_CHECK( style2.IsShadowEnabled() );
706   DALI_TEST_EQUALS( style2.GetShadowColor(), SHADOW_COLOR, TEST_LOCATION );
707   DALI_TEST_EQUALS( style2.GetShadowOffset(), SHADOW_OFFSET, TEST_LOCATION );
708
709   DALI_TEST_CHECK( style2.IsGlowEnabled() );
710   DALI_TEST_EQUALS( style2.GetGlowColor(), GLOW_COLOR, TEST_LOCATION );
711   DALI_TEST_EQUALS( style2.GetGlowIntensity(), GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
712
713   DALI_TEST_CHECK( style2.IsOutlineEnabled() );
714   DALI_TEST_EQUALS( style2.GetOutlineColor(), OUTLINE_COLOR, TEST_LOCATION );
715   DALI_TEST_EQUALS( style2.GetOutlineThickness(), OUTLINE_THICKNESS, TEST_LOCATION );
716
717   DALI_TEST_CHECK( style2.IsGradientEnabled() );
718   DALI_TEST_EQUALS( style2.GetGradientColor(), GRADIENT_COLOR, TEST_LOCATION );
719   DALI_TEST_EQUALS( style2.GetGradientStartPoint(), GRADIENT_START_POINT, TEST_LOCATION );
720   DALI_TEST_EQUALS( style2.GetGradientEndPoint(), GRADIENT_END_POINT, TEST_LOCATION );
721
722
723   // Set a default style
724   actor.SetTextStyle( defaultStyle );
725
726   TextStyle style3 = actor.GetTextStyle();
727
728   DALI_TEST_EQUALS( style3.GetFontName(), DEFAULT_NAME_STYLE, TEST_LOCATION );
729   DALI_TEST_EQUALS( style3.GetFontStyle(), DEFAULT_NAME_STYLE, TEST_LOCATION );
730   DALI_TEST_EQUALS( style3.GetFontPointSize(), DEFAULT_FONT_POINT_SIZE, TEST_LOCATION );
731   DALI_TEST_EQUALS( style3.GetTextColor(), TextStyle::DEFAULT_TEXT_COLOR, TEST_LOCATION );
732
733   DALI_TEST_EQUALS( style3.GetWeight(), TextStyle::DEFAULT_FONT_WEIGHT, TEST_LOCATION );
734   DALI_TEST_EQUALS( style3.GetSmoothEdge(), TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
735
736   DALI_TEST_CHECK( style3.IsItalicsDefault() );
737   DALI_TEST_CHECK( !style3.IsItalicsEnabled() );
738   DALI_TEST_EQUALS( style3.GetItalicsAngle(), TextStyle::DEFAULT_ITALICS_ANGLE, TEST_LOCATION );
739
740   DALI_TEST_CHECK( style3.IsUnderlineDefault() );
741   DALI_TEST_CHECK( !style3.IsUnderlineEnabled() );
742   DALI_TEST_EQUALS( style3.GetUnderlinePosition(), TextStyle::DEFAULT_UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
743   DALI_TEST_EQUALS( style3.GetUnderlineThickness(), TextStyle::DEFAULT_UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
744
745   DALI_TEST_CHECK( style3.IsShadowDefault() );
746   DALI_TEST_CHECK( !style3.IsShadowEnabled() );
747   DALI_TEST_EQUALS( style3.GetShadowColor(), TextStyle::DEFAULT_SHADOW_COLOR, TEST_LOCATION );
748   DALI_TEST_EQUALS( style3.GetShadowOffset(), TextStyle::DEFAULT_SHADOW_OFFSET, TEST_LOCATION );
749
750   DALI_TEST_CHECK( style3.IsGlowDefault() );
751   DALI_TEST_CHECK( !style3.IsGlowEnabled() );
752   DALI_TEST_EQUALS( style3.GetGlowColor(), TextStyle::DEFAULT_GLOW_COLOR, TEST_LOCATION );
753   DALI_TEST_EQUALS( style3.GetGlowIntensity(), TextStyle::DEFAULT_GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
754
755   DALI_TEST_CHECK( style3.IsOutlineDefault() );
756   DALI_TEST_CHECK( !style3.IsOutlineEnabled() );
757   DALI_TEST_EQUALS( style3.GetOutlineColor(), TextStyle::DEFAULT_OUTLINE_COLOR, TEST_LOCATION );
758   DALI_TEST_EQUALS( style3.GetOutlineThickness(), TextStyle::DEFAULT_OUTLINE_THICKNESS, TEST_LOCATION );
759
760   DALI_TEST_CHECK( style3.IsGradientDefault() );
761   DALI_TEST_CHECK( !style3.IsGradientEnabled() );
762   DALI_TEST_EQUALS( style3.GetGradientColor(), TextStyle::DEFAULT_GRADIENT_COLOR, TEST_LOCATION );
763   DALI_TEST_EQUALS( style3.GetGradientStartPoint(), TextStyle::DEFAULT_GRADIENT_START_POINT, TEST_LOCATION );
764   DALI_TEST_EQUALS( style3.GetGradientEndPoint(), TextStyle::DEFAULT_GRADIENT_END_POINT, TEST_LOCATION );
765
766   // Added to increase coverage.
767   // Reset what is already reset.
768
769   actor.SetTextStyle( style3 );
770
771   TextStyle style4 = actor.GetTextStyle();
772
773   DALI_TEST_EQUALS( style4.GetFontName(), DEFAULT_NAME_STYLE, TEST_LOCATION );
774   DALI_TEST_EQUALS( style4.GetFontStyle(), DEFAULT_NAME_STYLE, TEST_LOCATION );
775   DALI_TEST_EQUALS( style4.GetFontPointSize(), DEFAULT_FONT_POINT_SIZE, TEST_LOCATION );
776   DALI_TEST_EQUALS( style4.GetTextColor(), TextStyle::DEFAULT_TEXT_COLOR, TEST_LOCATION );
777
778   DALI_TEST_EQUALS( style4.GetWeight(), TextStyle::DEFAULT_FONT_WEIGHT, TEST_LOCATION );
779   DALI_TEST_EQUALS( style4.GetSmoothEdge(), TextStyle::DEFAULT_SMOOTH_EDGE_DISTANCE_FIELD, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
780
781   DALI_TEST_CHECK( style4.IsItalicsDefault() );
782   DALI_TEST_CHECK( !style4.IsItalicsEnabled() );
783   DALI_TEST_EQUALS( style4.GetItalicsAngle(), TextStyle::DEFAULT_ITALICS_ANGLE, TEST_LOCATION );
784
785   DALI_TEST_CHECK( style4.IsUnderlineDefault() );
786   DALI_TEST_CHECK( !style4.IsUnderlineEnabled() );
787   DALI_TEST_EQUALS( style4.GetUnderlinePosition(), TextStyle::DEFAULT_UNDERLINE_POSITION, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
788   DALI_TEST_EQUALS( style4.GetUnderlineThickness(), TextStyle::DEFAULT_UNDERLINE_THICKNESS, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
789
790   DALI_TEST_CHECK( style4.IsShadowDefault() );
791   DALI_TEST_CHECK( !style4.IsShadowEnabled() );
792   DALI_TEST_EQUALS( style4.GetShadowColor(), TextStyle::DEFAULT_SHADOW_COLOR, TEST_LOCATION );
793   DALI_TEST_EQUALS( style4.GetShadowOffset(), TextStyle::DEFAULT_SHADOW_OFFSET, TEST_LOCATION );
794
795   DALI_TEST_CHECK( style4.IsGlowDefault() );
796   DALI_TEST_CHECK( !style4.IsGlowEnabled() );
797   DALI_TEST_EQUALS( style4.GetGlowColor(), TextStyle::DEFAULT_GLOW_COLOR, TEST_LOCATION );
798   DALI_TEST_EQUALS( style4.GetGlowIntensity(), TextStyle::DEFAULT_GLOW_INTENSITY, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
799
800   DALI_TEST_CHECK( style4.IsOutlineDefault() );
801   DALI_TEST_CHECK( !style4.IsOutlineEnabled() );
802   DALI_TEST_EQUALS( style4.GetOutlineColor(), TextStyle::DEFAULT_OUTLINE_COLOR, TEST_LOCATION );
803   DALI_TEST_EQUALS( style4.GetOutlineThickness(), TextStyle::DEFAULT_OUTLINE_THICKNESS, TEST_LOCATION );
804
805   DALI_TEST_CHECK( style4.IsGradientDefault() );
806   DALI_TEST_CHECK( !style4.IsGradientEnabled() );
807   DALI_TEST_EQUALS( style4.GetGradientColor(), TextStyle::DEFAULT_GRADIENT_COLOR, TEST_LOCATION );
808   DALI_TEST_EQUALS( style4.GetGradientStartPoint(), TextStyle::DEFAULT_GRADIENT_START_POINT, TEST_LOCATION );
809   DALI_TEST_EQUALS( style4.GetGradientEndPoint(), TextStyle::DEFAULT_GRADIENT_END_POINT, TEST_LOCATION );
810
811   END_TEST;
812 }
813
814 int UtcDaliTextActorDefaultProperties(void)
815 {
816   TestApplication application;
817   tet_infoline("Testing Dali::TextActor DefaultProperties");
818
819   TextActor actor = TextActor::New("@");
820
821   std::vector<Property::Index> indices ;
822   indices.push_back(TextActor::TEXT                     );
823   indices.push_back(TextActor::FONT                     );
824   indices.push_back(TextActor::FONT_STYLE               );
825   indices.push_back(TextActor::OUTLINE_ENABLE           );
826   indices.push_back(TextActor::OUTLINE_COLOR            );
827   indices.push_back(TextActor::OUTLINE_THICKNESS_WIDTH  );
828   indices.push_back(TextActor::SMOOTH_EDGE              );
829   indices.push_back(TextActor::GLOW_ENABLE              );
830   indices.push_back(TextActor::GLOW_COLOR               );
831   indices.push_back(TextActor::GLOW_INTENSITY           );
832   indices.push_back(TextActor::SHADOW_ENABLE            );
833   indices.push_back(TextActor::SHADOW_COLOR             );
834   indices.push_back(TextActor::SHADOW_OFFSET            );
835   indices.push_back(TextActor::ITALICS_ANGLE            );
836   indices.push_back(TextActor::UNDERLINE                );
837   indices.push_back(TextActor::WEIGHT                   );
838   indices.push_back(TextActor::FONT_DETECTION_AUTOMATIC );
839   indices.push_back(TextActor::GRADIENT_COLOR           );
840   indices.push_back(TextActor::GRADIENT_START_POINT     );
841   indices.push_back(TextActor::GRADIENT_END_POINT       );
842   indices.push_back(TextActor::SHADOW_SIZE              );
843   indices.push_back(TextActor::TEXT_COLOR               );
844
845   DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
846
847   for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
848   {
849     DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
850     DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
851     DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
852     DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) );  // just checking call succeeds
853   }
854
855   // set/get one of them
856   actor.SetUnderline(false);
857   DALI_TEST_CHECK(actor.GetUnderline() != true);
858
859   actor.SetProperty(TextActor::UNDERLINE, Property::Value(true));
860   Property::Value v = actor.GetProperty(TextActor::UNDERLINE);
861   DALI_TEST_CHECK(v.GetType() == Property::BOOLEAN);
862
863   DALI_TEST_CHECK(v.Get<bool>() == true);
864   END_TEST;
865 }
866
867 int UtcDaliTextActorSetGradientColor(void)
868 {
869   TestApplication application;
870
871   tet_infoline("Testing Dali::TextActor::SetGradientColor()");
872
873   TextActor actor = TextActor::New(TestTextHello);
874
875   DALI_TEST_CHECK(actor);
876
877   actor.SetGradientColor( Color::RED );
878   DALI_TEST_EQUALS( actor.GetGradientColor(), Color::RED, TEST_LOCATION );
879
880   actor.SetGradientColor( Color::BLUE );
881   DALI_TEST_EQUALS( actor.GetGradientColor(), Color::BLUE, TEST_LOCATION );
882   END_TEST;
883 }
884
885 int UtcDaliTextActorSetGradientStartPoint(void)
886 {
887   TestApplication application;
888
889   tet_infoline("Testing Dali::TextActor::SetGradientStartPoint()");
890
891   TextActor actor = TextActor::New(TestTextHello);
892
893   DALI_TEST_CHECK(actor);
894
895   actor.SetGradientStartPoint( Vector2(0.5f, 0.5f) );
896   DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(0.5f, 0.5f), TEST_LOCATION );
897
898   actor.SetGradientStartPoint( Vector2(1.0f, 0.0f) );
899   DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(1.0f, 0.0f), TEST_LOCATION );
900   END_TEST;
901 }
902
903 int UtcDaliTextActorSetGradientEndPoint(void)
904 {
905   TestApplication application;
906
907   tet_infoline("Testing Dali::TextActor::SetGradientEndPoint()");
908
909   TextActor actor = TextActor::New(TestTextHello);
910
911   DALI_TEST_CHECK(actor);
912
913   actor.SetGradientEndPoint( Vector2(0.25f, 0.25f) );
914   DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.25f, 0.25f), TEST_LOCATION );
915
916   actor.SetGradientEndPoint( Vector2(0.0f, 1.0f) );
917   DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.0f, 1.0f), TEST_LOCATION );
918   END_TEST;
919 }
920
921 int UtcDaliTextActorSynchronousGlyphLoading(void)
922 {
923   TestApplication application;
924
925   tet_infoline( "Testing synchronous loading of glyphs");
926
927   // All numerals 0 through 9 are 'fake' cached in the test abstraction glyphcache
928
929   // create text actor containg "Hello"
930   TextActor actor = TextActor::New(TestTextHello);
931
932   // no glyphs will be cached
933
934   // so..GetGlyphData should have been called to gather metrics
935   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:false" ) );
936   // ..but not to load glyph bitmap data
937   DALI_TEST_CHECK( ! application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
938   // ..also, cached high quality glyphs will not have been requested yet
939   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
940
941   // reset PlatformAbstraction function call traces
942   application.GetPlatform().ResetTrace();
943
944   // Invoke Core::ProcessEvent and tick the update/render threads
945   application.SendNotification();
946   application.Render();
947
948   // An attempt to load high quality glyphs will have been requested and loaded nothing
949   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
950   // low quality glyphs bitmap data will have now been generated
951   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
952
953   // request numerals
954   actor.SetText( "0123456789" );
955
956   // reset PlatformAbstraction function call traces
957   application.GetPlatform().ResetTrace();
958
959   application.SendNotification();
960   application.Render();
961
962   // An attempt to load high quality glyphs will have been requested and loaded all the numerals
963   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetCachedGlyphDataFunc) );
964   // ..therefore no low quality glyphs bitmap data will have been requested
965   DALI_TEST_CHECK( !application.GetPlatform().GetTrace().FindMethodAndParams( "GetGlyphData", "getBitmap:true" ) );
966   END_TEST;
967 }
968
969 int UtcDaliTextActorAutomaticSizeSet(void)
970 {
971   TestApplication application;
972
973   tet_infoline("Testing Dali::TextActor getting size based on text automatically");
974
975   // create empty text actor
976   TextActor actor = TextActor::New();
977   Stage::GetCurrent().Add(actor);
978
979   // initial size is zero
980   DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
981
982   // set some text
983   actor.SetText( "a" );
984   // render a frame
985   application.SendNotification();
986   application.Render();
987
988   // 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
989   Vector3 currentSize = actor.GetCurrentSize();
990   DALI_TEST_GREATER( currentSize.width, 0.0f, TEST_LOCATION );
991   DALI_TEST_GREATER( currentSize.height, 0.0f, TEST_LOCATION );
992
993   // set some more text
994   actor.SetText( "abba" );
995   // render a frame
996   application.SendNotification();
997   application.Render();
998
999   Vector3 biggerSize = actor.GetCurrentSize();
1000   DALI_TEST_GREATER( biggerSize.width, currentSize.width, TEST_LOCATION );
1001
1002   // set some shorter text
1003   actor.SetText( "i" );
1004   // render a frame
1005   application.SendNotification();
1006   application.Render();
1007
1008   // actor has shrunk
1009   DALI_TEST_GREATER( biggerSize.width, actor.GetCurrentSize().width, TEST_LOCATION );
1010
1011   // set a size from application side, from this point onwards text actor no longer uses the "natural" size of the text
1012   actor.SetSize( Vector2( 10.0f, 11.0f ) );
1013   // render a frame
1014   application.SendNotification();
1015   application.Render();
1016   // actor has the user set size
1017   DALI_TEST_EQUALS( Vector2( 10.0f, 11.0f ), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
1018
1019   // set some different text
1020   std::string longText( "jabba dabba duu" );
1021   actor.SetText( longText );
1022   // render a frame
1023   application.SendNotification();
1024   application.Render();
1025   // actor still has the user set size
1026   DALI_TEST_EQUALS( Vector2( 10.0f, 11.0f ), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
1027
1028   // set text to its natural size
1029   actor.SetToNaturalSize();
1030   // render a frame
1031   application.SendNotification();
1032   application.Render();
1033   // actor has the natural size
1034   Font defaultFont = Font::New();
1035   Vector3 naturalSize = defaultFont.MeasureText( longText );
1036   DALI_TEST_EQUALS( naturalSize.GetVectorXY(), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
1037   END_TEST;
1038 }
1039
1040 int UtcDaliTextActorAutomaticSizeSetAnimation(void)
1041 {
1042   TestApplication application;
1043
1044   tet_infoline("Testing Dali::TextActor getting size based on text automatically with animation");
1045
1046   // create empty text actor
1047   TextActor actor = TextActor::New();
1048   Stage::GetCurrent().Add(actor);
1049
1050   // initial size is zero
1051   DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
1052
1053   // set some text
1054   actor.SetText( "a" );
1055   // render a frame
1056   application.SendNotification();
1057   application.Render();
1058
1059   // 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
1060   Vector3 currentSize = actor.GetCurrentSize();
1061   DALI_TEST_GREATER( currentSize.width, 0.0f, TEST_LOCATION );
1062   DALI_TEST_GREATER( currentSize.height, 0.0f, TEST_LOCATION );
1063
1064   // animate size, from this point onwards text actor no longer uses the "natural" size of the text
1065   Animation sizeAnim = Animation::New( 0.1f ); // 0.1 seconds
1066   Vector3 animationTargetSize( 20.0f, 30.0f, 0.0f );
1067   sizeAnim.AnimateTo( Property( actor, Actor::SIZE ), animationTargetSize );
1068   sizeAnim.Play();
1069
1070   // set some more text
1071   actor.SetText( "abba" );
1072   // render a frame
1073   application.SendNotification();
1074   application.Render( 1000 ); // 1 second to complete the animation
1075
1076   DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
1077
1078   // set some more text
1079   std::string moreText( "something else" );
1080   actor.SetText( moreText );
1081   // render a frame
1082   application.SendNotification();
1083   application.Render();
1084
1085   DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
1086
1087   // set text to its natural size
1088   actor.SetToNaturalSize();
1089   // render a frame
1090   application.SendNotification();
1091   application.Render();
1092   // actor has the natural size
1093   Font defaultFont = Font::New();
1094   Vector3 naturalSize = defaultFont.MeasureText( moreText );
1095   DALI_TEST_EQUALS( naturalSize.GetVectorXY(), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
1096   END_TEST;
1097 }
1098
1099
1100 int UtcDaliTextActorPropertyIndices(void)
1101 {
1102   TestApplication application;
1103   Actor basicActor = Actor::New();
1104   TextActor textActor = TextActor::New("Text");
1105
1106   Property::IndexContainer indices;
1107   textActor.GetPropertyIndices( indices );
1108   DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() );
1109   DALI_TEST_EQUALS( indices.size(), textActor.GetPropertyCount(), TEST_LOCATION );
1110   END_TEST;
1111 }