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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Toolkit;
30 void utc_dali_toolkit_text_view_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_text_view_cleanup(void)
37 test_return_value = TET_PASS;
44 const char* const PROPERTY_TEXT = "text";
45 const char* const PROPERTY_MULTILINE_POLICY = "multiline-policy";
46 const char* const PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy";
47 const char* const PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy";
48 const char* const PROPERTY_LINE_JUSTIFICATION = "line-justification";
49 const char* const PROPERTY_FADE_BOUNDARY_LEFT = "fade-boundary-left";
50 const char* const PROPERTY_FADE_BOUNDARY_RIGHT = "fade-boundary-right";
51 const char* const PROPERTY_FADE_BOUNDARY_TOP = "fade-boundary-top";
52 const char* const PROPERTY_FADE_BOUNDARY_BOTTOM = "fade-boundary-bottom";
53 const char* const PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset";
54 const char* const PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment";
55 const char* const PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment";
57 bool TestEqual( float x, float y )
59 return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 );
62 static bool gObjectCreatedCallBackCalled;
63 static unsigned int gNumberObjectCreated;
65 static void TestCallback(BaseHandle handle)
67 gObjectCreatedCallBackCalled = true;
68 ++gNumberObjectCreated;
71 static bool gTextScrolled;
72 static Vector2 gScrollDelta;
73 static void TestTextScrolled( TextView textView, Vector2 scrollDelta )
76 gScrollDelta = scrollDelta;
82 int UtcDaliTextViewNew(void)
84 tet_infoline("UtcDaliTextViewNew: ");
85 ToolkitTestApplication application;
87 // Test default constructor.
90 DALI_TEST_CHECK( !view );
92 // Test default initialization.
93 view = TextView::New();
95 DALI_TEST_CHECK( view );
97 // Test copy constructor and asignment operator.
102 DALI_TEST_CHECK( viewCopy1 );
104 TextView viewCopy2( view );
106 DALI_TEST_CHECK( viewCopy2 );
113 TextView downCastView = TextView::DownCast( actorView );
115 DALI_TEST_CHECK( downCastView );
117 // Test constructor with a given text.
119 const std::string text( "Hello world!" );
121 const float DESCENDER = 8.0f;
123 TextView view1 = TextView::New( text );
125 DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION );
127 MarkupProcessor::StyledTextArray styledText;
128 MarkupProcessor::GetStyledTextArray( text, styledText, true );
130 TextView view2 = TextView::New( styledText );
132 DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION );
134 // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage.
135 TextView::CharacterLayoutInfo characterLayoutInfo;
137 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
138 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
139 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION );
140 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION );
141 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION );
143 TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ),
144 Vector3( 3.f, 4.f, 5.f ),
150 characterLayoutInfo = characterLayoutInfo2;
152 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
153 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
154 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION );
155 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION );
156 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION );
157 DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION );
160 TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo );
162 DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
163 DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
164 DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION );
165 DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION );
166 DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION );
168 // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage.
170 TextView::TextLayoutInfo textLayoutInfo;
171 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION );
172 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION );
173 DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION );
174 DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
175 DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
177 textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo );
178 textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 );
179 textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 );
180 textLayoutInfo.mTextSize = Size( 10.f, 10.f );
181 textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f );
183 TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo );
185 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
186 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
187 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
188 DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
189 DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
191 TextView::TextLayoutInfo textLayoutInfo3;
193 textLayoutInfo3 = textLayoutInfo2;
195 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
196 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
197 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
198 DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
199 DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
201 //Additional check to ensure object is created by checking if it's registered
202 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
203 DALI_TEST_CHECK( registry );
205 gObjectCreatedCallBackCalled = false;
206 registry.ObjectCreatedSignal().Connect(&TestCallback);
208 TextView view = TextView::New();
210 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
214 int UtcDaliTextViewSetAndGetText(void)
216 tet_infoline("UtcDaliTextViewSetAndGetText: ");
217 ToolkitTestApplication application;
219 TextView view = TextView::New();
220 view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
222 std::string str( "Text with differing aCeNdEr and dEcEnDeR" );
225 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
227 MarkupProcessor::StyledTextArray styledText;
228 MarkupProcessor::GetStyledTextArray( str, styledText, true );
230 view.SetText( styledText );
231 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
233 // Test the number of text actor created.
235 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
236 DALI_TEST_CHECK( registry );
238 gNumberObjectCreated = 0;
239 registry.ObjectCreatedSignal().Connect(&TestCallback);
241 // Following string should create three text-actors ([Hel], [lo wo] and [rld]).
242 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
245 Stage::GetCurrent().Add( view );
246 view.SetText( text );
248 application.SendNotification();
249 application.Render();
251 DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION );
255 int UtcDaliTextViewSetStyleToCurrentText(void)
257 tet_infoline("UtcDaliTextViewSetStyleToCurrentText: ");
258 ToolkitTestApplication application;
261 style.SetItalics( true );
263 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
265 "민관합동조사단은 지난달 30일부터\n"
266 "12일간의 현지 조사활동을 마치고\n"
268 TextView view = TextView::New( text );
273 view.SetStyleToCurrentText( style );
277 tet_printf( "Tet case fails\n" );
279 tet_result(TET_FAIL);
282 DALI_TEST_CHECK( !fail );
286 int UtcDaliTextViewSetAndGetLineHeight(void)
288 tet_infoline("UtcDaliTextViewSetAndGetLineHeight: ");
290 ToolkitTestApplication application;
292 const float lineHeightOffset( 9.f );
294 TextView textView = TextView::New();
296 textView.SetLineHeightOffset( PointSize( lineHeightOffset ) );
298 DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
302 int UtcDaliTextViewSetAndGetFadeBoundary(void)
304 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
306 ToolkitTestApplication application;
308 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
310 TextView textView = TextView::New( "Hello world!" );
312 textView.SetFadeBoundary( fadeBoundary );
314 TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary();
316 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
317 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
318 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
319 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
323 int UtcDaliTextViewSetAndGetEllipsizeText(void)
325 tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: ");
327 ToolkitTestApplication application;
329 TextView textView = TextView::New( "Hello world!" );
331 textView.SetEllipsizeText( std::string( "..." ) );
333 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
335 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
337 GetStyledTextArray( std::string( "..." ), styledTextArray, true );
339 textView.SetEllipsizeText( styledTextArray );
341 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
346 int UtcDaliTextViewSetAndGetWidthExceedPolicy(void)
348 tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: ");
350 ToolkitTestApplication application;
352 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
353 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
355 TextView textView = TextView::New( "Hello world!" );
357 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
359 textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
361 DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
366 int UtcDaliTextViewSetAndGetHeightExceedPolicy(void)
368 tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: ");
370 ToolkitTestApplication application;
372 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
373 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
375 TextView textView = TextView::New( "Hello world!" );
377 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
379 textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
381 DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
387 // Re-enable this test case when ALL layout options work in TextView, currently this breaks TCT
388 // output because too many warnings/errors are printed out
389 //int UtcDaliTextViewTestLayoutOptions01(void)
391 tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
393 ToolkitTestApplication application;
395 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
397 "민관합동조사단은 지난달 30일부터\n"
398 "12일간의 현지 조사활동을 마치고\n"
401 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
402 const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
403 const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
404 const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
405 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
406 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
407 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
408 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
409 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
410 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
411 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
412 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
413 const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
415 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
416 const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
417 const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
418 const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
419 const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
421 TextView textView = TextView::New( text );
422 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
424 Stage::GetCurrent().Add( textView );
426 TextView::TextLayoutInfo textLayoutInfo;
428 for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
430 textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
431 for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
433 textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
434 for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
436 textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
437 for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
439 textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
440 for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
442 textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
446 textView.GetTextLayoutInfo( textLayoutInfo );
448 application.SendNotification();
449 application.Render();
451 catch( Dali::DaliException& e )
453 DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
457 tet_printf( "Tet case fails\n" );
458 tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
459 tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
460 tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
461 tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
462 tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
463 tet_result(TET_FAIL);
466 DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
468 DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
470 DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
472 DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
474 DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
480 int UtcDaliTextViewTestLayoutOptions02(void)
482 tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
483 ToolkitTestApplication application;
485 // Check some configurations.
487 TextView textView = TextView::New();
488 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
490 Stage::GetCurrent().Add( textView );
492 // SplitByWord and ShrinkToFit.
493 // Centered alignment.
494 // Centered justification.
495 // Don't create a text actor per character.
497 textView.SetMultilinePolicy( TextView::SplitByWord );
498 textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
499 textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
500 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
501 textView.SetLineJustification( TextView::Center );
502 textView.SetSize( 136.56252f, 100.f );
504 textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
506 application.SendNotification();
507 application.Render();
509 std::vector<Size> sizes;
510 sizes.push_back( Size( 34.14063f, 11.380210f ) ); //
511 sizes.push_back( Size( 56.90105f, 11.380210f ) ); //
512 sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210.
513 // The result should be a line with the text 'Hello world' as shown below.
514 std::vector<Vector3> positions; // ____________
515 positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!|
516 positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------
517 positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); //
519 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
521 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
523 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
524 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
526 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
527 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
528 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
529 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
532 textView.SetSize( 50.f, 50.f );
533 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
534 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
535 textView.SetLineJustification( Toolkit::TextView::Left );
537 application.SendNotification();
538 application.Render();
541 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
542 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
543 sizes.push_back( Size( 16.666666f, 8.333333f ) ); // Longest word is 'world!' (6 characters x 11.380210) which doesn't fit in the 50x50 box.
544 sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333.
545 // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
546 positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and
547 positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
548 positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______
549 positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | |
550 positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello |
555 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
557 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
559 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
560 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
562 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
563 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
564 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
565 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
568 // TODO: Add more tests when TextView implementation is finished.
572 int UtcDaliTextViewInsertRemoveText(void)
574 tet_infoline("UtcDaliTextViewInsertRemoveText: ");
575 ToolkitTestApplication application;
577 std::string text("Hello ");
579 MarkupProcessor::StyledTextArray styledText;
580 MarkupProcessor::GetStyledTextArray( text, styledText, true );
582 TextView view = TextView::New( "world!" );
584 view.InsertTextAt( 0, styledText );
586 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
588 view.RemoveTextFrom( 4, 5 );
590 DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
592 view.InsertTextAt( 0, "Hello " );
594 DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
597 view.InsertTextAt( 0, "Hello " );
598 view.InsertTextAt( 0, "Hello " );
599 view.InsertTextAt( 0, "Hello " );
600 view.InsertTextAt( 0, "Hello " );
601 view.RemoveTextFrom( 4, 2 );
602 view.RemoveTextFrom( 4, 2 );
603 view.RemoveTextFrom( 4, 2 );
604 view.RemoveTextFrom( 4, 2 );
605 view.RemoveTextFrom( 4, 2 );
606 view.SetText( "Hello world!" );
608 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
610 view.ReplaceTextFromTo( 5, 1, "" );
612 DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
614 view.ReplaceTextFromTo( 0, 11, styledText );
616 DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
620 int UtcDaliTextViewSnapshotEnable(void)
622 tet_infoline("UtcDaliTextViewSnapshotEnable: ");
623 ToolkitTestApplication application;
625 // Avoids the frame buffer texture to throw an exception.
626 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
628 TextView view = TextView::New( "Hel<font color='green'>lo world!</font> This <font color='green'>is</font> a sna<font color='green'>psho</font>t test." );
630 Stage::GetCurrent().Add( view );
632 view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
633 // This line should be removed when text-view is set to use the snapshot mode by default.
635 // Snapshot is enabled by default.
636 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
638 application.SendNotification();
639 application.Render();
641 // TextView should have only two actors:
642 // the root (Actor) and the image (ImageActor).
644 DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
646 view.SetSnapshotModeEnabled( false );
647 DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
649 application.SendNotification();
650 application.Render();
652 // TextView should have one text-actor per word.
654 DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
658 int UtcDaliTextViewScroll(void)
660 tet_infoline("UtcDaliTextViewScroll: ");
661 ToolkitTestApplication application;
663 // Avoids the frame buffer texture to throw an exception.
664 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
666 TextView view = TextView::New( "Hello world! This is a scroll test." );
667 view.SetSize( 100.f, 100.f );
668 view.SetSnapshotModeEnabled( false );
670 Stage::GetCurrent().Add( view );
672 application.SendNotification();
673 application.Render();
675 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
677 view.SetScrollEnabled( true );
678 view.ScrolledSignal().Connect( &TestTextScrolled );
680 DALI_TEST_CHECK( view.IsScrollEnabled() );
681 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
683 gTextScrolled = false;
684 gScrollDelta = Vector2::ZERO;
685 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
687 application.SendNotification();
688 application.Render();
690 const Vector2& scrollPosition = view.GetScrollPosition();
691 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
693 DALI_TEST_CHECK( gTextScrolled );
694 DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
696 DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
700 int UtcDaliTextViewSetProperty(void)
702 tet_infoline("UtcDaliTextViewSetAndGetText: ");
703 ToolkitTestApplication application;
705 TextView view = TextView::New( "Hello world!" );
706 Stage::GetCurrent().Add( view );
708 //Test multiline policy property
709 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
710 DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
712 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByWord");
713 DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
715 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByChar");
716 DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
718 //Test width exceed policy property
719 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Original");
720 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
721 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
722 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
724 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
725 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
726 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
727 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
729 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
730 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
731 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
732 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
734 //Test line justification property
735 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Left");
736 DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
738 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Center");
739 DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
741 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Right");
742 DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
744 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Justified");
745 DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
747 //Test fade boundary property
748 unsigned int testValue = 23;
749 PixelSize leftFadeBoundary(testValue);
750 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_LEFT), testValue);
751 DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
754 PixelSize rightFadeBoundary(testValue);
755 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
756 DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
759 PixelSize topFadeBoundary(testValue);
760 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_TOP), testValue);
761 DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
764 PixelSize bottomFadeBoundary(testValue);
765 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
766 DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
768 //Test Line height offset property
769 float testOffsetValue = 14.04f;
770 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
771 DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
773 //Test alignment property
774 view.SetProperty(view.GetPropertyIndex(PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
775 view.SetProperty(view.GetPropertyIndex(PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
776 DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
780 int UtcDaliTextViewSetSortModifier(void)
782 tet_infoline("UtcDaliTextViewSetAndGetText: ");
783 ToolkitTestApplication application;
785 TextView view = TextView::New( "Hello world!" );
786 Stage::GetCurrent().Add( view );
788 view.SetSortModifier( 10.f );
789 view.SetSnapshotModeEnabled( false );
791 application.SendNotification();
792 application.Render();
794 DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
798 int UtcDaliTextViewUnderlineText(void)
800 tet_infoline("UtcDaliTextViewUnderlineText: ");
801 ToolkitTestApplication application;
803 TextView textView = TextView::New( "<u><font size='10'>gg<font size='14'>gg<font size='18'>gg<font size='22'>gg</font>gg</font>gg</font>gg</font></u>" );
804 textView.SetSnapshotModeEnabled( false );
806 textView.SetSize( 150.f, 100.f );
808 Stage::GetCurrent().Add( textView );
810 application.SendNotification();
811 application.Render();
813 std::vector<float> positions;
814 positions.push_back( 6.448784f );
815 positions.push_back( 9.862847f );
816 positions.push_back( 13.276909f );
817 positions.push_back( 16.690973f );
818 positions.push_back( 13.276909f );
819 positions.push_back( 9.862847f );
820 positions.push_back( 6.448784f );
822 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
824 TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
826 DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
827 DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );