2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/dali.h>
22 #include <dali-test-suite-utils.h>
26 void text_actor_test_startup(void)
28 test_return_value = TET_UNDEF;
31 void text_actor_test_cleanup(void)
33 test_return_value = TET_PASS;
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";
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 );
66 int UtcDaliTextActorConstructorVoid(void)
68 TestApplication application;
70 tet_infoline("Testing Dali::TextActor::TextActor()");
74 DALI_TEST_CHECK(!actor);
78 int UtcDaliTextActorNew01(void)
80 TestApplication application;
82 tet_infoline("Testing Dali::TextActor::New()");
84 TextActor actor = TextActor::New(TestTextHello);
86 DALI_TEST_CHECK(actor);
88 actor = TextActor::New(Text(std::string(TestTextHello)));
90 DALI_TEST_CHECK(actor);
95 int UtcDaliTextActorNew02(void)
97 TestApplication application;
99 tet_infoline("Testing Dali::TextActor::New()");
101 TextActor actor = TextActor::New(TestTextHello, false);
103 DALI_TEST_CHECK(actor);
105 actor = TextActor::New(Text(std::string(TestTextHello)), false);
107 DALI_TEST_CHECK(actor);
111 int UtcDaliTextActorNew03(void)
113 TestApplication application;
115 tet_infoline("Testing Dali::TextActor::New()");
117 TextActor actor = TextActor::New(TestTextHello, false, false);
119 DALI_TEST_CHECK(actor);
121 actor = TextActor::New(Text(std::string(TestTextHello)), false, false);
123 DALI_TEST_CHECK(actor);
128 int UtcDaliTextActorNew04(void)
130 TestApplication application;
132 tet_infoline("Testing Dali::TextActor::New()");
134 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
135 Font freeSerif = Font::New( parameters );
137 TextActor actor = TextActor::New(TestTextHello, freeSerif);
139 DALI_TEST_CHECK(actor);
141 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif);
143 DALI_TEST_CHECK(actor);
147 int UtcDaliTextActorNew05(void)
149 TestApplication application;
151 tet_infoline("Testing Dali::TextActor::New()");
153 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
154 Font freeSerif = Font::New( parameters );
156 TextActor actor = TextActor::New(TestTextHello, freeSerif, false);
158 DALI_TEST_CHECK(actor);
160 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false);
162 DALI_TEST_CHECK(actor);
166 int UtcDaliTextActorNew06(void)
168 TestApplication application;
170 tet_infoline("Testing Dali::TextActor::New()");
172 FontParameters parameters( "FreeSerif", "Book", PointSize(8) );
173 Font freeSerif = Font::New( parameters );
175 TextActor actor = TextActor::New(TestTextHello, freeSerif, false, false);
177 DALI_TEST_CHECK(actor);
179 actor = TextActor::New(Text(std::string(TestTextHello)), freeSerif, false, false);
181 DALI_TEST_CHECK(actor);
185 int UtcDaliTextActorNew07(void)
187 TestApplication application;
189 tet_infoline("Testing Dali::TextActor::New()");
193 TextActor actor = TextActor::New(Text(TestTextHello), style, false, false);
195 DALI_TEST_CHECK(actor);
200 int UtcDaliTextActorDownCast(void)
202 TestApplication application;
203 tet_infoline("Testing Dali::TextActor::DownCast()");
205 TextActor actor1 = TextActor::New("Hello, World!");
206 Actor anActor = Actor::New();
209 Actor child = anActor.GetChildAt(0);
210 TextActor textActor = TextActor::DownCast(child);
212 DALI_TEST_CHECK(textActor);
213 DALI_TEST_CHECK(!textActor.GetText().compare("Hello, World!"));
217 int UtcDaliTextActorDownCast2(void)
219 TestApplication application;
220 tet_infoline("Testing Dali::TextActor::DownCast()");
222 Actor actor1 = Actor::New();
223 Actor anActor = Actor::New();
226 Actor child = anActor.GetChildAt(0);
227 TextActor textActor = TextActor::DownCast(child);
228 DALI_TEST_CHECK(!textActor);
230 Actor unInitialzedActor;
231 textActor = DownCast< TextActor >( unInitialzedActor );
232 DALI_TEST_CHECK(!textActor);
236 int UtcDaliTextActorSetText(void)
238 TestApplication application;
240 tet_infoline("Testing Dali::TextActor::SetText()");
242 TextActor actor01 = TextActor::New(TestTextHello);
244 actor01.SetText(TestTextHelloWorld);
246 std::string text = actor01.GetText();
248 DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
250 actor01.SetText(Text(std::string(TestTextHelloWorld)));
252 text = actor01.GetText();
254 DALI_TEST_EQUALS(text, TestTextHelloWorld, TEST_LOCATION);
258 text = actor01.GetText();
260 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
262 TextActor actor02 = TextActor::New("");
264 actor02.SetText( std::string() );
266 text = actor02.GetText();
268 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
270 actor02.SetText(TestTextHelloWorld);
271 actor02.SetText( std::string() );
273 text = actor02.GetText();
275 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
277 TextActor actor03 = TextActor::New("");
279 actor03.SetText(voidText);
281 text = actor03.GetText();
283 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
285 actor03.SetText(TestTextHelloWorld);
286 actor03.SetText(voidText);
288 text = actor03.GetText();
290 DALI_TEST_EQUALS(text, "", TEST_LOCATION);
294 int UtcDaliTextActorSetFont(void)
296 TestApplication application;
298 TextActor actor = TextActor::New(TestTextHello);
300 PointSize pointSize( POINT_SIZE );
301 FontParameters params( FAMILY_NAME, STYLE, pointSize);
303 Font font = Font::New( params );
305 actor.SetFont( font );
307 DALI_TEST_CHECK( actor.GetFont().GetName() == FAMILY_NAME );
311 int UtcDaliTextActorSetFontDetection(void)
313 TestApplication application;
315 TextActor actor = TextActor::New(TestTextHello);
317 actor.SetFontDetectionAutomatic( true );
319 DALI_TEST_CHECK( true == actor.IsFontDetectionAutomatic() );
324 int UtcDaliTextActorSetTextIndividualStyles(void)
326 TestApplication application;
328 TextActor actor = TextActor::New(TestTextHello);
330 actor.SetTextColor( FONT_TEXT_COLOR);
332 DALI_TEST_CHECK( actor.GetTextColor() == FONT_TEXT_COLOR );
334 actor.SetSmoothEdge( FONT_SMOOTH_EDGE );
336 actor.SetOutline( FONT_OUTLINE, FONT_OUTLINE_COLOR, FONT_OUTLINE_THICKNESS );
338 actor.SetShadow( FONT_SHADOW, FONT_SHADOW_COLOR, FONT_SHADOW_OFFSET, FONT_SHADOW_SIZE );
340 actor.SetItalics( FONT_ITALICS, FONT_ITALICS_ANGLE );
342 actor.SetGlow( FONT_GLOW, FONT_TEXT_GLOW_COLOR, FONT_GLOW_INTENSITY );
344 TextStyle style = actor.GetTextStyle();
346 DALI_TEST_CHECK( FONT_TEXT_COLOR == style.GetTextColor() );
348 DALI_TEST_CHECK( FONT_SMOOTH_EDGE == style.GetSmoothEdge() );
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() );
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() );
360 DALI_TEST_CHECK( FONT_ITALICS == style.GetItalics() );
361 DALI_TEST_CHECK( FONT_ITALICS_ANGLE == style.GetItalicsAngle() );
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() );
369 actor.SetItalics( FONT_ITALICS, FONT_ITALICS_RADIAN_ANGLE );
370 style = actor.GetTextStyle();
371 DALI_TEST_CHECK( FONT_ITALICS_RADIAN_ANGLE == style.GetItalicsAngle() );
377 int UtcDaliTextActorChangingText(void)
379 TestApplication application;
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);
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);
392 application.SendNotification();
393 application.Render();
395 // check that the size did not change
396 DALI_TEST_EQUALS( Vector3(200, 20, 0.0f), actor.GetCurrentSize(), TEST_LOCATION);
400 int UtcDaliTextActorGetLoadingState(void)
402 TestApplication application;
404 TextActor actor = TextActor::New(TestTextHello);
406 DALI_TEST_CHECK( ResourceLoading == actor.GetLoadingState());
408 application.SendNotification();
409 application.Render();
411 DALI_TEST_CHECK( ResourceLoadingSucceeded == actor.GetLoadingState());
416 int UtcDaliTextActorSetItalics(void)
418 TestApplication application;
420 tet_infoline("Testing Dali::TextActor::New()");
422 TextActor actor = TextActor::New(TestTextHello);
424 DALI_TEST_CHECK(actor);
426 actor.SetItalics( true );
428 DALI_TEST_CHECK( actor.GetItalics() );
430 DALI_TEST_EQUALS( static_cast<float>( Degree( actor.GetItalicsAngle() ) ), static_cast<float>(TextStyle::DEFAULT_ITALICS_ANGLE), 0.0001f, TEST_LOCATION );
432 actor.SetItalics( false );
434 DALI_TEST_CHECK( ! actor.GetItalics() );
436 // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
440 int UtcDaliTextActorSetUnderline(void)
442 TestApplication application;
444 tet_infoline("Testing Dali::TextActor::SetUnderline()");
446 TextActor actor = TextActor::New(TestTextHello);
448 DALI_TEST_CHECK(actor);
450 actor.SetUnderline( true );
452 DALI_TEST_CHECK( actor.GetUnderline() );
454 actor.SetUnderline( false );
456 DALI_TEST_CHECK( ! actor.GetUnderline() );
458 // TODO: Implement a why on the glAbstraction to check if the geometry was created correctly
462 int UtcDaliTextActorSetWeight(void)
464 TestApplication application;
466 tet_infoline("Testing Dali::TextActor::SetWeight()");
468 TextActor actor = TextActor::New(TestTextHello);
470 DALI_TEST_CHECK(actor);
472 actor.SetWeight( TextStyle::EXTRABOLD );
474 DALI_TEST_CHECK( TextStyle::EXTRABOLD == actor.GetWeight() );
476 actor.SetWeight( TextStyle::BOLD );
478 DALI_TEST_CHECK( TextStyle::BOLD == actor.GetWeight() );
482 int UtcDaliTextActorSetStyle(void)
484 TestApplication application;
486 tet_infoline("Testing Dali::TextActor::SetTextStyle()");
488 TextActor actor = TextActor::New(TestTextHello);
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() );
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);
507 actor.SetTextStyle( style );
508 // This is necessary since SetColor (via TextStyle) is asynchronous
509 application.SendNotification();
510 application.Render();
511 style = actor.GetTextStyle();
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() ),
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() );
526 int UtcDaliTextActorDefaultProperties(void)
528 TestApplication application;
529 tet_infoline("Testing Dali::TextActor DefaultProperties");
531 TextActor actor = TextActor::New("@");
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 );
557 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
559 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
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
567 // set/get one of them
568 actor.SetUnderline(false);
569 DALI_TEST_CHECK(actor.GetUnderline() != true);
571 actor.SetProperty(TextActor::UNDERLINE, Property::Value(true));
572 Property::Value v = actor.GetProperty(TextActor::UNDERLINE);
573 DALI_TEST_CHECK(v.GetType() == Property::BOOLEAN);
575 DALI_TEST_CHECK(v.Get<bool>() == true);
579 int UtcDaliTextActorSetGradientColor(void)
581 TestApplication application;
583 tet_infoline("Testing Dali::TextActor::SetGradientColor()");
585 TextActor actor = TextActor::New(TestTextHello);
587 DALI_TEST_CHECK(actor);
589 actor.SetGradientColor( Color::RED );
590 DALI_TEST_EQUALS( actor.GetGradientColor(), Color::RED, TEST_LOCATION );
592 actor.SetGradientColor( Color::BLUE );
593 DALI_TEST_EQUALS( actor.GetGradientColor(), Color::BLUE, TEST_LOCATION );
597 int UtcDaliTextActorSetGradientStartPoint(void)
599 TestApplication application;
601 tet_infoline("Testing Dali::TextActor::SetGradientStartPoint()");
603 TextActor actor = TextActor::New(TestTextHello);
605 DALI_TEST_CHECK(actor);
607 actor.SetGradientStartPoint( Vector2(0.5f, 0.5f) );
608 DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(0.5f, 0.5f), TEST_LOCATION );
610 actor.SetGradientStartPoint( Vector2(1.0f, 0.0f) );
611 DALI_TEST_EQUALS( actor.GetGradientStartPoint(), Vector2(1.0f, 0.0f), TEST_LOCATION );
615 int UtcDaliTextActorSetGradientEndPoint(void)
617 TestApplication application;
619 tet_infoline("Testing Dali::TextActor::SetGradientEndPoint()");
621 TextActor actor = TextActor::New(TestTextHello);
623 DALI_TEST_CHECK(actor);
625 actor.SetGradientEndPoint( Vector2(0.25f, 0.25f) );
626 DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.25f, 0.25f), TEST_LOCATION );
628 actor.SetGradientEndPoint( Vector2(0.0f, 1.0f) );
629 DALI_TEST_EQUALS( actor.GetGradientEndPoint(), Vector2(0.0f, 1.0f), TEST_LOCATION );
633 int UtcDaliTextActorSynchronousGlyphLoading(void)
635 TestApplication application;
637 tet_infoline( "Testing synchronous loading of glyphs");
639 // All numerals 0 through 9 are 'fake' cached in the test abstraction glyphcache
641 // create text actor containg "Hello"
642 TextActor actor = TextActor::New(TestTextHello);
644 // no glyphs will be cached
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) );
653 // reset PlatformAbstraction function call traces
654 application.GetPlatform().ResetTrace();
656 // Invoke Core::ProcessEvent and tick the update/render threads
657 application.SendNotification();
658 application.Render();
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" ) );
666 actor.SetText( "0123456789" );
668 // reset PlatformAbstraction function call traces
669 application.GetPlatform().ResetTrace();
671 application.SendNotification();
672 application.Render();
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" ) );
681 int UtcDaliTextActorAutomaticSizeSet(void)
683 TestApplication application;
685 tet_infoline("Testing Dali::TextActor getting size based on text automatically");
687 // create empty text actor
688 TextActor actor = TextActor::New();
689 Stage::GetCurrent().Add(actor);
691 // initial size is zero
692 DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
695 actor.SetText( "a" );
697 application.SendNotification();
698 application.Render();
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 );
705 // set some more text
706 actor.SetText( "abba" );
708 application.SendNotification();
709 application.Render();
711 Vector3 biggerSize = actor.GetCurrentSize();
712 DALI_TEST_GREATER( biggerSize.width, currentSize.width, TEST_LOCATION );
714 // set some shorter text
715 actor.SetText( "i" );
717 application.SendNotification();
718 application.Render();
721 DALI_TEST_GREATER( biggerSize.width, actor.GetCurrentSize().width, TEST_LOCATION );
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 ) );
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 );
731 // set some different text
732 std::string longText( "jabba dabba duu" );
733 actor.SetText( longText );
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 );
740 // set text to its natural size
741 actor.SetToNaturalSize();
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 );
752 int UtcDaliTextActorAutomaticSizeSetAnimation(void)
754 TestApplication application;
756 tet_infoline("Testing Dali::TextActor getting size based on text automatically with animation");
758 // create empty text actor
759 TextActor actor = TextActor::New();
760 Stage::GetCurrent().Add(actor);
762 // initial size is zero
763 DALI_TEST_EQUALS( Vector3::ZERO, actor.GetCurrentSize(), TEST_LOCATION );
766 actor.SetText( "a" );
768 application.SendNotification();
769 application.Render();
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 );
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 );
782 // set some more text
783 actor.SetText( "abba" );
785 application.SendNotification();
786 application.Render( 1000 ); // 1 second to complete the animation
788 DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
790 // set some more text
791 std::string moreText( "something else" );
792 actor.SetText( moreText );
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
799 // set text to its natural size
800 actor.SetToNaturalSize();
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 );
812 int UtcDaliTextActorPropertyIndices(void)
814 TestApplication application;
815 Actor basicActor = Actor::New();
816 TextActor textActor = TextActor::New("Text");
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 );