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 );
386 int UtcDaliTextViewTestLayoutOptions01(void)
388 tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
390 ToolkitTestApplication application;
392 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
394 "민관합동조사단은 지난달 30일부터\n"
395 "12일간의 현지 조사활동을 마치고\n"
398 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
399 const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
400 const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
401 const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
402 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
403 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
404 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
405 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
406 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
407 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
408 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
409 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
410 const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
412 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
413 const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
414 const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
415 const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
416 const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
418 TextView textView = TextView::New( text );
419 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
421 Stage::GetCurrent().Add( textView );
423 TextView::TextLayoutInfo textLayoutInfo;
425 for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
427 textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
428 for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
430 textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
431 for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
433 textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
434 for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
436 textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
437 for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
439 textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
443 textView.GetTextLayoutInfo( textLayoutInfo );
445 application.SendNotification();
446 application.Render();
448 catch( Dali::DaliException& e )
450 DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
454 tet_printf( "Tet case fails\n" );
455 tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
456 tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
457 tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
458 tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
459 tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
460 tet_result(TET_FAIL);
463 DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
465 DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
467 DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
469 DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
471 DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
476 int UtcDaliTextViewTestLayoutOptions02(void)
478 tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
479 ToolkitTestApplication application;
481 // Check some configurations.
483 TextView textView = TextView::New();
484 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
486 Stage::GetCurrent().Add( textView );
488 // SplitByWord and ShrinkToFit.
489 // Centered alignment.
490 // Centered justification.
491 // Don't create a text actor per character.
493 textView.SetMultilinePolicy( TextView::SplitByWord );
494 textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
495 textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
496 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
497 textView.SetLineJustification( TextView::Center );
498 textView.SetSize( 136.56252f, 100.f );
500 textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
502 application.SendNotification();
503 application.Render();
505 std::vector<Size> sizes;
506 sizes.push_back( Size( 34.14063f, 11.380210f ) ); //
507 sizes.push_back( Size( 56.90105f, 11.380210f ) ); //
508 sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210.
509 // The result should be a line with the text 'Hello world' as shown below.
510 std::vector<Vector3> positions; // ____________
511 positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!|
512 positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------
513 positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); //
515 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
517 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
519 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
520 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
522 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
523 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
524 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
525 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
528 textView.SetSize( 50.f, 50.f );
529 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
530 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
531 textView.SetLineJustification( Toolkit::TextView::Left );
533 application.SendNotification();
534 application.Render();
537 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
538 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
539 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.
540 sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333.
541 // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
542 positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and
543 positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
544 positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______
545 positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | |
546 positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello |
551 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
553 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
555 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
556 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
558 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
559 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
560 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
561 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
564 // TODO: Add more tests when TextView implementation is finished.
568 int UtcDaliTextViewInsertRemoveText(void)
570 tet_infoline("UtcDaliTextViewInsertRemoveText: ");
571 ToolkitTestApplication application;
573 std::string text("Hello ");
575 MarkupProcessor::StyledTextArray styledText;
576 MarkupProcessor::GetStyledTextArray( text, styledText, true );
578 TextView view = TextView::New( "world!" );
580 view.InsertTextAt( 0, styledText );
582 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
584 view.RemoveTextFrom( 4, 5 );
586 DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
588 view.InsertTextAt( 0, "Hello " );
590 DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
593 view.InsertTextAt( 0, "Hello " );
594 view.InsertTextAt( 0, "Hello " );
595 view.InsertTextAt( 0, "Hello " );
596 view.InsertTextAt( 0, "Hello " );
597 view.RemoveTextFrom( 4, 2 );
598 view.RemoveTextFrom( 4, 2 );
599 view.RemoveTextFrom( 4, 2 );
600 view.RemoveTextFrom( 4, 2 );
601 view.RemoveTextFrom( 4, 2 );
602 view.SetText( "Hello world!" );
604 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
606 view.ReplaceTextFromTo( 5, 1, "" );
608 DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
610 view.ReplaceTextFromTo( 0, 11, styledText );
612 DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
616 int UtcDaliTextViewSnapshotEnable(void)
618 tet_infoline("UtcDaliTextViewSnapshotEnable: ");
619 ToolkitTestApplication application;
621 // Avoids the frame buffer texture to throw an exception.
622 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
624 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." );
626 Stage::GetCurrent().Add( view );
628 view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
629 // This line should be removed when text-view is set to use the snapshot mode by default.
631 // Snapshot is enabled by default.
632 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
634 application.SendNotification();
635 application.Render();
637 // TextView should have only two actors:
638 // the root (Actor) and the image (ImageActor).
640 DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
642 view.SetSnapshotModeEnabled( false );
643 DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
645 application.SendNotification();
646 application.Render();
648 // TextView should have one text-actor per word.
650 DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
654 int UtcDaliTextViewScroll(void)
656 tet_infoline("UtcDaliTextViewScroll: ");
657 ToolkitTestApplication application;
659 // Avoids the frame buffer texture to throw an exception.
660 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
662 TextView view = TextView::New( "Hello world! This is a scroll test." );
663 view.SetSize( 100.f, 100.f );
664 view.SetSnapshotModeEnabled( false );
666 Stage::GetCurrent().Add( view );
668 application.SendNotification();
669 application.Render();
671 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
673 view.SetScrollEnabled( true );
674 view.ScrolledSignal().Connect( &TestTextScrolled );
676 DALI_TEST_CHECK( view.IsScrollEnabled() );
677 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
679 gTextScrolled = false;
680 gScrollDelta = Vector2::ZERO;
681 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
683 application.SendNotification();
684 application.Render();
686 const Vector2& scrollPosition = view.GetScrollPosition();
687 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
689 DALI_TEST_CHECK( gTextScrolled );
690 DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
692 DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
696 int UtcDaliTextViewSetProperty(void)
698 tet_infoline("UtcDaliTextViewSetAndGetText: ");
699 ToolkitTestApplication application;
701 TextView view = TextView::New( "Hello world!" );
702 Stage::GetCurrent().Add( view );
704 //Test multiline policy property
705 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
706 DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
708 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByWord");
709 DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
711 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByChar");
712 DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
714 //Test width exceed policy property
715 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Original");
716 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
717 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
718 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
720 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
721 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
722 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
723 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
725 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
726 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
727 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
728 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
730 //Test line justification property
731 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Left");
732 DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
734 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Center");
735 DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
737 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Right");
738 DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
740 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Justified");
741 DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
743 //Test fade boundary property
744 unsigned int testValue = 23;
745 PixelSize leftFadeBoundary(testValue);
746 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_LEFT), testValue);
747 DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
750 PixelSize rightFadeBoundary(testValue);
751 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
752 DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
755 PixelSize topFadeBoundary(testValue);
756 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_TOP), testValue);
757 DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
760 PixelSize bottomFadeBoundary(testValue);
761 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
762 DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
764 //Test Line height offset property
765 float testOffsetValue = 14.04f;
766 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
767 DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
769 //Test alignment property
770 view.SetProperty(view.GetPropertyIndex(PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
771 view.SetProperty(view.GetPropertyIndex(PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
772 DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
776 int UtcDaliTextViewSetSortModifier(void)
778 tet_infoline("UtcDaliTextViewSetAndGetText: ");
779 ToolkitTestApplication application;
781 TextView view = TextView::New( "Hello world!" );
782 Stage::GetCurrent().Add( view );
784 view.SetSortModifier( 10.f );
785 view.SetSnapshotModeEnabled( false );
787 application.SendNotification();
788 application.Render();
790 DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
794 int UtcDaliTextViewUnderlineText(void)
796 tet_infoline("UtcDaliTextViewUnderlineText: ");
797 ToolkitTestApplication application;
799 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>" );
800 textView.SetSnapshotModeEnabled( false );
802 textView.SetSize( 150.f, 100.f );
804 Stage::GetCurrent().Add( textView );
806 application.SendNotification();
807 application.Render();
809 std::vector<float> positions;
810 positions.push_back( 6.448784f );
811 positions.push_back( 9.862847f );
812 positions.push_back( 13.276909f );
813 positions.push_back( 16.690973f );
814 positions.push_back( 13.276909f );
815 positions.push_back( 9.862847f );
816 positions.push_back( 6.448784f );
818 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
820 TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
822 DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
823 DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );