2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
24 #include <dali-test-suite-utils.h>
28 static void Startup();
29 static void Cleanup();
32 void (*tet_startup)() = Startup;
33 void (*tet_cleanup)() = Cleanup;
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";
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 );
63 POSITIVE_TC_IDX = 0x01,
67 #define MAX_NUMBER_OF_TESTS 10000
69 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
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 );
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 );
100 TEST_FUNCTION( UtcDaliTextActorSynchronousGlyphLoading, POSITIVE_TC_IDX );
102 TEST_FUNCTION( UtcDaliTextActorAutomaticSizeSet, POSITIVE_TC_IDX );
103 TEST_FUNCTION( UtcDaliTextActorAutomaticSizeSetAnimation, POSITIVE_TC_IDX );
105 TEST_FUNCTION( UtcDaliTextActorPropertyIndices, POSITIVE_TC_IDX );
107 // Called only once before first test is run.
108 static void Startup()
112 // Called only once after last test is run
113 static void Cleanup()
117 static void UtcDaliTextActorConstructorVoid()
119 TestApplication application;
121 tet_infoline("Testing Dali::TextActor::TextActor()");
125 DALI_TEST_CHECK(!actor);
128 static void UtcDaliTextActorConstructorRefObject()
130 TestApplication application;
132 tet_infoline("Testing Dali::TextActor::TextActor(Internal::TextActor*)");
134 TextActor actor(NULL);
136 DALI_TEST_CHECK(!actor);
139 static void UtcDaliTextActorNew01()
141 TestApplication application;
143 tet_infoline("Testing Dali::TextActor::New()");
145 TextActor actor = TextActor::New(TestTextHello);
147 DALI_TEST_CHECK(actor);
149 actor = TextActor::New(Text(std::string(TestTextHello)));
151 DALI_TEST_CHECK(actor);
155 static void UtcDaliTextActorNew02()
157 TestApplication application;
159 tet_infoline("Testing Dali::TextActor::New()");
161 TextActor actor = TextActor::New(TestTextHello, false);
163 DALI_TEST_CHECK(actor);
165 actor = TextActor::New(Text(std::string(TestTextHello)), false);
167 DALI_TEST_CHECK(actor);
170 static void UtcDaliTextActorNew03()
172 TestApplication application;
174 tet_infoline("Testing Dali::TextActor::New()");
176 TextActor actor = TextActor::New(TestTextHello, false, false);
178 DALI_TEST_CHECK(actor);
180 actor = TextActor::New(Text(std::string(TestTextHello)), false, false);
182 DALI_TEST_CHECK(actor);
186 static void UtcDaliTextActorNew04()
188 TestApplication application;
190 tet_infoline("Testing Dali::TextActor::New()");
192 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
193 Font freeSerif = Font::New( parameters );
195 TextActor actor = TextActor::New(TestTextHello, freeSerif);
197 DALI_TEST_CHECK(actor);
199 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif);
201 DALI_TEST_CHECK(actor);
204 static void UtcDaliTextActorNew05()
206 TestApplication application;
208 tet_infoline("Testing Dali::TextActor::New()");
210 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
211 Font freeSerif = Font::New( parameters );
213 TextActor actor = TextActor::New(TestTextHello, freeSerif, false);
215 DALI_TEST_CHECK(actor);
217 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false);
219 DALI_TEST_CHECK(actor);
222 static void UtcDaliTextActorNew06()
224 TestApplication application;
226 tet_infoline("Testing Dali::TextActor::New()");
228 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
229 Font freeSerif = Font::New( parameters );
231 TextActor actor = TextActor::New(TestTextHello, freeSerif, false, false);
233 DALI_TEST_CHECK(actor);
235 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false, false);
237 DALI_TEST_CHECK(actor);
240 static void UtcDaliTextActorNew07()
242 TestApplication application;
244 tet_infoline("Testing Dali::TextActor::New()");
248 TextActor actor = TextActor::New(Text(TestTextHello), style, false, false);
250 DALI_TEST_CHECK(actor);
254 static void UtcDaliTextActorDownCast()
256 TestApplication application;
257 tet_infoline("Testing Dali::TextActor::DownCast()");
259 TextActor actor1 = TextActor::New("Hello, World!");
260 Actor anActor = Actor::New();
263 Actor child = anActor.GetChildAt(0);
264 TextActor textActor = TextActor::DownCast(child);
266 DALI_TEST_CHECK(textActor);
267 DALI_TEST_CHECK(!textActor.GetText().compare("Hello, World!"));
270 static void UtcDaliTextActorDownCast2()
272 TestApplication application;
273 tet_infoline("Testing Dali::TextActor::DownCast()");
275 Actor actor1 = Actor::New();
276 Actor anActor = Actor::New();
279 Actor child = anActor.GetChildAt(0);
280 TextActor textActor = TextActor::DownCast(child);
281 DALI_TEST_CHECK(!textActor);
283 Actor unInitialzedActor;
284 textActor = DownCast< TextActor >( unInitialzedActor );
285 DALI_TEST_CHECK(!textActor);
288 static void UtcDaliTextActorSetText()
290 TestApplication application;
292 tet_infoline("Testing Dali::TextActor::SetText()");
294 TextActor actor01 = TextActor::New(TestTextHello);
296 actor01.SetText(TestTextHelloWorld);
298 std::string text = actor01.GetText();
300 DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
302 actor01.SetText(Text(std::string(TestTextHelloWorld)));
304 text = actor01.GetText();
306 DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
310 text = actor01.GetText();
312 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
314 TextActor actor02 = TextActor::New("");
316 actor02.SetText( std::string() );
318 text = actor02.GetText();
320 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
322 actor02.SetText(TestTextHelloWorld);
323 actor02.SetText( std::string() );
325 text = actor02.GetText();
327 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
329 TextActor actor03 = TextActor::New("");
331 actor03.SetText(voidText);
333 text = actor03.GetText();
335 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
337 actor03.SetText(TestTextHelloWorld);
338 actor03.SetText(voidText);
340 text = actor03.GetText();
342 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
345 static void UtcDaliTextActorSetFont()
347 TestApplication application;
349 TextActor actor = TextActor::New(TestTextHello);
351 PointSize pointSize( POINT_SIZE );
352 FontParameters params( FAMILY_NAME, STYLE, pointSize);
354 Font font = Font::New( params );
356 actor.SetFont( font );
358 DALI_TEST_CHECK( actor.GetFont().GetName() == FAMILY_NAME );
361 static void UtcDaliTextActorSetFontDetection()
363 TestApplication application;
365 TextActor actor = TextActor::New(TestTextHello);
367 actor.SetFontDetectionAutomatic( true );
369 DALI_TEST_CHECK( true == actor.IsFontDetectionAutomatic() );
373 static void UtcDaliTextActorSetTextIndividualStyles()
375 TestApplication application;
377 TextActor actor = TextActor::New(TestTextHello);
379 actor.SetTextColor( FONT_TEXT_COLOR);
381 DALI_TEST_CHECK( actor.GetTextColor() == FONT_TEXT_COLOR );
383 actor.SetSmoothEdge( FONT_SMOOTH_EDGE );
385 actor.SetOutline( FONT_OUTLINE, FONT_OUTLINE_COLOR, FONT_OUTLINE_THICKNESS );
387 actor.SetShadow( FONT_SHADOW, FONT_SHADOW_COLOR, FONT_SHADOW_OFFSET, FONT_SHADOW_SIZE );
389 actor.SetItalics( FONT_ITALICS, FONT_ITALICS_ANGLE );
391 actor.SetGlow( FONT_GLOW, FONT_TEXT_GLOW_COLOR, FONT_GLOW_INTENSITY );
393 TextStyle style = actor.GetTextStyle();
395 DALI_TEST_CHECK( FONT_TEXT_COLOR == style.GetTextColor() );
397 DALI_TEST_CHECK( FONT_SMOOTH_EDGE == style.GetSmoothEdge() );
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() );
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() );
409 DALI_TEST_CHECK( FONT_ITALICS == style.GetItalics() );
410 DALI_TEST_CHECK( FONT_ITALICS_ANGLE == style.GetItalicsAngle() );
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() );
418 actor.SetItalics( FONT_ITALICS, FONT_ITALICS_RADIAN_ANGLE );
419 style = actor.GetTextStyle();
420 DALI_TEST_CHECK( FONT_ITALICS_RADIAN_ANGLE == style.GetItalicsAngle() );
425 static void UtcDaliTextActorChangingText()
427 TestApplication application;
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);
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);
440 application.SendNotification();
441 application.Render();
443 // check that the size did not change
444 DALI_TEST_EQUALS( Vector3(200, 20, 0.0f), actor.GetCurrentSize(), TEST_LOCATION);
447 static void UtcDaliTextActorGetLoadingState()
449 TestApplication application;
451 TextActor actor = TextActor::New(TestTextHello);
453 DALI_TEST_CHECK( ResourceLoading == actor.GetLoadingState());
455 application.SendNotification();
456 application.Render();
458 DALI_TEST_CHECK( ResourceLoadingSucceeded == actor.GetLoadingState());
462 static void UtcDaliTextActorSetItalics()
464 TestApplication application;
466 tet_infoline("Testing Dali::TextActor::New()");
468 TextActor actor = TextActor::New(TestTextHello);
470 DALI_TEST_CHECK(actor);
472 actor.SetItalics( true );
474 DALI_TEST_CHECK( actor.GetItalics() );
476 DALI_TEST_EQUALS( static_cast<float>( Degree( actor.GetItalicsAngle() ) ), static_cast<float>(TextStyle::DEFAULT_ITALICS_ANGLE), 0.0001f, TEST_LOCATION );
478 actor.SetItalics( false );
480 DALI_TEST_CHECK( ! actor.GetItalics() );
482 // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
485 static void UtcDaliTextActorSetUnderline()
487 TestApplication application;
489 tet_infoline("Testing Dali::TextActor::SetUnderline()");
491 TextActor actor = TextActor::New(TestTextHello);
493 DALI_TEST_CHECK(actor);
495 actor.SetUnderline( true );
497 DALI_TEST_CHECK( actor.GetUnderline() );
499 actor.SetUnderline( false );
501 DALI_TEST_CHECK( ! actor.GetUnderline() );
503 // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
506 static void UtcDaliTextActorSetWeight()
508 TestApplication application;
510 tet_infoline("Testing Dali::TextActor::SetWeight()");
512 TextActor actor = TextActor::New(TestTextHello);
514 DALI_TEST_CHECK(actor);
516 actor.SetWeight( TextStyle::EXTRABOLD );
518 DALI_TEST_CHECK( TextStyle::EXTRABOLD == actor.GetWeight() );
520 actor.SetWeight( TextStyle::BOLD );
522 DALI_TEST_CHECK( TextStyle::BOLD == actor.GetWeight() );
525 static void UtcDaliTextActorSetStyle()
527 TestApplication application;
529 tet_infoline("Testing Dali::TextActor::SetTextStyle()");
531 TextActor actor = TextActor::New(TestTextHello);
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() );
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);
550 actor.SetTextStyle( style );
551 // This is necessary since SetColor (via TextStyle) is asynchronous
552 application.SendNotification();
553 application.Render();
554 style = actor.GetTextStyle();
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() ),
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() );
568 static void UtcDaliTextActorDefaultProperties()
570 TestApplication application;
571 tet_infoline("Testing Dali::TextActor DefaultProperties");
573 TextActor actor = TextActor::New("@");
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 );
599 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
601 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
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
609 // set/get one of them
610 actor.SetUnderline(false);
611 DALI_TEST_CHECK(actor.GetUnderline() != true);
613 actor.SetProperty(TextActor::UNDERLINE, Property::Value(true));
614 Property::Value v = actor.GetProperty(TextActor::UNDERLINE);
615 DALI_TEST_CHECK(v.GetType() == Property::BOOLEAN);
617 DALI_TEST_CHECK(v.Get<bool>() == true);
620 static void UtcDaliTextActorSetGradientColor()
622 TestApplication application;
624 tet_infoline("Testing Dali::TextActor::SetGradientColor()");
626 TextActor actor = TextActor::New(TestTextHello);
628 DALI_TEST_CHECK(actor);
630 actor.SetGradientColor( Color::RED );
631 DALI_TEST_EQUALS( actor.GetGradientColor(), Color::RED, TEST_LOCATION );
633 actor.SetGradientColor( Color::BLUE );
634 DALI_TEST_EQUALS( actor.GetGradientColor(), Color::BLUE, TEST_LOCATION );
637 static void UtcDaliTextActorSetGradientStartPoint()
639 TestApplication application;
641 tet_infoline("Testing Dali::TextActor::SetGradientStartPoint()");
643 TextActor actor = TextActor::New(TestTextHello);
645 DALI_TEST_CHECK(actor);
647 actor.SetGradientStartPoint( Vector2(0.5f, 0.5f) );
648 DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(0.5f, 0.5f), TEST_LOCATION );
650 actor.SetGradientStartPoint( Vector2(1.0f, 0.0f) );
651 DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(1.0f, 0.0f), TEST_LOCATION );
654 static void UtcDaliTextActorSetGradientEndPoint()
656 TestApplication application;
658 tet_infoline("Testing Dali::TextActor::SetGradientEndPoint()");
660 TextActor actor = TextActor::New(TestTextHello);
662 DALI_TEST_CHECK(actor);
664 actor.SetGradientEndPoint( Vector2(0.25f, 0.25f) );
665 DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.25f, 0.25f), TEST_LOCATION );
667 actor.SetGradientEndPoint( Vector2(0.0f, 1.0f) );
668 DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.0f, 1.0f), TEST_LOCATION );
671 static void UtcDaliTextActorSynchronousGlyphLoading()
673 TestApplication application;
675 tet_infoline( "Testing synchronous loading of glyphs");
677 // All numerals 0 through 9 are 'fake' cached in the test abstraction glyphcache
679 // create text actor containg "Hello"
680 TextActor actor = TextActor::New(TestTextHello);
682 // no glyphs will be cached
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) );
691 // reset PlatformAbstraction function call traces
692 application.GetPlatform().ResetTrace();
694 // Invoke Core::ProcessEvent and tick the update/render threads
695 application.SendNotification();
696 application.Render();
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" ) );
704 actor.SetText( "0123456789" );
706 // reset PlatformAbstraction function call traces
707 application.GetPlatform().ResetTrace();
709 application.SendNotification();
710 application.Render();
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" ) );
718 static void UtcDaliTextActorAutomaticSizeSet()
720 TestApplication application;
722 tet_infoline("Testing Dali::TextActor getting size based on text automatically");
724 // create empty text actor
725 TextActor actor = TextActor::New();
726 Stage::GetCurrent().Add(actor);
728 // initial size is zero
729 DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
732 actor.SetText( "a" );
734 application.SendNotification();
735 application.Render();
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 );
742 // set some more text
743 actor.SetText( "abba" );
745 application.SendNotification();
746 application.Render();
748 Vector3 biggerSize = actor.GetCurrentSize();
749 DALI_TEST_GREATER( biggerSize.width, currentSize.width, TEST_LOCATION );
751 // set some shorter text
752 actor.SetText( "i" );
754 application.SendNotification();
755 application.Render();
758 DALI_TEST_GREATER( biggerSize.width, actor.GetCurrentSize().width, TEST_LOCATION );
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 ) );
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 );
768 // set some different text
769 std::string longText( "jabba dabba duu" );
770 actor.SetText( longText );
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 );
777 // set text to its natural size
778 actor.SetToNaturalSize();
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 );
788 static void UtcDaliTextActorAutomaticSizeSetAnimation()
790 TestApplication application;
792 tet_infoline("Testing Dali::TextActor getting size based on text automatically with animation");
794 // create empty text actor
795 TextActor actor = TextActor::New();
796 Stage::GetCurrent().Add(actor);
798 // initial size is zero
799 DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
802 actor.SetText( "a" );
804 application.SendNotification();
805 application.Render();
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 );
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 );
818 // set some more text
819 actor.SetText( "abba" );
821 application.SendNotification();
822 application.Render( 1000 ); // 1 second to complete the animation
824 DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
826 // set some more text
827 std::string moreText( "something else" );
828 actor.SetText( moreText );
830 application.SendNotification();
831 application.Render();
833 DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
835 // set text to its natural size
836 actor.SetToNaturalSize();
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 );
846 void UtcDaliTextActorPropertyIndices()
848 TestApplication application;
849 Actor basicActor = Actor::New();
850 TextActor textActor = TextActor::New("Text");
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 );