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 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
31 void utc_dali_toolkit_text_view_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_text_view_cleanup(void)
38 test_return_value = TET_PASS;
45 const char* const PROPERTY_TEXT = "text";
46 const char* const PROPERTY_MULTILINE_POLICY = "multiline-policy";
47 const char* const PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy";
48 const char* const PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy";
49 const char* const PROPERTY_LINE_JUSTIFICATION = "line-justification";
50 const char* const PROPERTY_FADE_BOUNDARY_LEFT = "fade-boundary-left";
51 const char* const PROPERTY_FADE_BOUNDARY_RIGHT = "fade-boundary-right";
52 const char* const PROPERTY_FADE_BOUNDARY_TOP = "fade-boundary-top";
53 const char* const PROPERTY_FADE_BOUNDARY_BOTTOM = "fade-boundary-bottom";
54 const char* const PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset";
55 const char* const PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment";
56 const char* const PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment";
58 bool TestEqual( float x, float y )
60 return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 );
63 static bool gObjectCreatedCallBackCalled;
64 static unsigned int gNumberObjectCreated;
66 static void TestCallback(BaseHandle handle)
68 gObjectCreatedCallBackCalled = true;
69 ++gNumberObjectCreated;
72 static bool gTextScrolled;
73 static Vector2 gScrollDelta;
74 static void TestTextScrolled( TextView textView, Vector2 scrollDelta )
77 gScrollDelta = scrollDelta;
83 int UtcDaliTextViewNew(void)
85 tet_infoline("UtcDaliTextViewNew: ");
86 ToolkitTestApplication application;
88 // Test default constructor.
91 DALI_TEST_CHECK( !view );
93 // Test default initialization.
94 view = TextView::New();
96 DALI_TEST_CHECK( view );
98 // Test copy constructor and asignment operator.
103 DALI_TEST_CHECK( viewCopy1 );
105 TextView viewCopy2( view );
107 DALI_TEST_CHECK( viewCopy2 );
114 TextView downCastView = TextView::DownCast( actorView );
116 DALI_TEST_CHECK( downCastView );
118 // Test constructor with a given text.
120 const std::string text( "Hello world!" );
122 const float DESCENDER = 8.0f;
124 TextView view1 = TextView::New( text );
126 DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION );
128 MarkupProcessor::StyledTextArray styledText;
129 MarkupProcessor::GetStyledTextArray( text, styledText, true );
131 TextView view2 = TextView::New( styledText );
133 DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION );
135 // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage.
136 TextView::CharacterLayoutInfo characterLayoutInfo;
138 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
139 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
140 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION );
141 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION );
142 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION );
144 TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ),
145 Vector3( 3.f, 4.f, 5.f ),
151 characterLayoutInfo = characterLayoutInfo2;
153 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
154 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
155 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION );
156 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION );
157 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION );
158 DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION );
161 TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo );
163 DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
164 DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
165 DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION );
166 DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION );
167 DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION );
169 // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage.
171 TextView::TextLayoutInfo textLayoutInfo;
172 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION );
173 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION );
174 DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION );
175 DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
176 DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
178 textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo );
179 textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 );
180 textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 );
181 textLayoutInfo.mTextSize = Size( 10.f, 10.f );
182 textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f );
184 TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo );
186 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
187 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
188 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
189 DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
190 DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
192 TextView::TextLayoutInfo textLayoutInfo3;
194 textLayoutInfo3 = textLayoutInfo2;
196 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
197 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
198 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
199 DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
200 DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
202 //Additional check to ensure object is created by checking if it's registered
203 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
204 DALI_TEST_CHECK( registry );
206 gObjectCreatedCallBackCalled = false;
207 registry.ObjectCreatedSignal().Connect(&TestCallback);
209 TextView view = TextView::New();
211 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
215 int UtcDaliTextViewSetAndGetText(void)
217 tet_infoline("UtcDaliTextViewSetAndGetText: ");
218 ToolkitTestApplication application;
220 TextView view = TextView::New();
221 view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
223 std::string str( "Text with differing aCeNdEr and dEcEnDeR" );
226 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
228 MarkupProcessor::StyledTextArray styledText;
229 MarkupProcessor::GetStyledTextArray( str, styledText, true );
231 view.SetText( styledText );
232 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
234 // Test the number of text actor created.
236 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
237 DALI_TEST_CHECK( registry );
239 gNumberObjectCreated = 0u;
240 registry.ObjectCreatedSignal().Connect(&TestCallback);
242 // Following string should create three text-actors ([Hel], [lo wo] and [rld]).
243 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
246 view.SetMarkupProcessingEnabled( true ); // Enables markup processing.
248 Stage::GetCurrent().Add( view );
249 view.SetText( text );
251 application.SendNotification();
252 application.Render();
254 DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION );
258 int UtcDaliTextViewSetStyleToCurrentText(void)
260 tet_infoline("UtcDaliTextViewSetStyleToCurrentText: ");
261 ToolkitTestApplication application;
264 style.SetItalics( true );
266 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
268 "민관합동조사단은 지난달 30일부터\n"
269 "12일간의 현지 조사활동을 마치고\n"
271 TextView view = TextView::New( text );
276 view.SetStyleToCurrentText( style );
280 tet_printf( "Tet case fails\n" );
282 tet_result(TET_FAIL);
285 DALI_TEST_CHECK( !fail );
289 int UtcDaliTextViewSetAndGetLineHeight(void)
291 tet_infoline("UtcDaliTextViewSetAndGetLineHeight: ");
293 ToolkitTestApplication application;
295 const float lineHeightOffset( 9.f );
297 TextView textView = TextView::New();
299 textView.SetLineHeightOffset( PointSize( lineHeightOffset ) );
301 DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
305 int UtcDaliTextViewSetAndGetFadeBoundary(void)
307 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
309 ToolkitTestApplication application;
311 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
313 TextView textView = TextView::New( "Hello world!" );
315 textView.SetFadeBoundary( fadeBoundary );
317 TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary();
319 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
320 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
321 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
322 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
326 int UtcDaliTextViewSetAndGetEllipsizeText(void)
328 tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: ");
330 ToolkitTestApplication application;
332 TextView textView = TextView::New( "Hello world!" );
334 textView.SetEllipsizeText( std::string( "..." ) );
336 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
338 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
340 GetStyledTextArray( std::string( "..." ), styledTextArray, true );
342 textView.SetEllipsizeText( styledTextArray );
344 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
349 int UtcDaliTextViewSetAndGetWidthExceedPolicy(void)
351 tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: ");
353 ToolkitTestApplication application;
355 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
356 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
358 TextView textView = TextView::New( "Hello world!" );
360 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
362 textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
364 DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
369 int UtcDaliTextViewSetAndGetHeightExceedPolicy(void)
371 tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: ");
373 ToolkitTestApplication application;
375 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
376 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
378 TextView textView = TextView::New( "Hello world!" );
380 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
382 textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
384 DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
390 // Re-enable this test case when ALL layout options work in TextView, currently this breaks TCT
391 // output because too many warnings/errors are printed out
392 //int UtcDaliTextViewTestLayoutOptions01(void)
394 tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
396 ToolkitTestApplication application;
398 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
400 "민관합동조사단은 지난달 30일부터\n"
401 "12일간의 현지 조사활동을 마치고\n"
404 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
405 const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
406 const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
407 const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
408 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
409 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
410 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
411 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
412 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
413 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
414 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
415 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
416 const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
418 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
419 const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
420 const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
421 const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
422 const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
424 TextView textView = TextView::New( text );
425 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
427 Stage::GetCurrent().Add( textView );
429 TextView::TextLayoutInfo textLayoutInfo;
431 for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
433 textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
434 for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
436 textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
437 for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
439 textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
440 for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
442 textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
443 for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
445 textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
449 textView.GetTextLayoutInfo( textLayoutInfo );
451 application.SendNotification();
452 application.Render();
454 catch( Dali::DaliException& e )
456 DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
460 tet_printf( "Tet case fails\n" );
461 tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
462 tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
463 tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
464 tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
465 tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
466 tet_result(TET_FAIL);
469 DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
471 DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
473 DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
475 DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
477 DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
483 int UtcDaliTextViewTestLayoutOptions02(void)
485 tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
486 ToolkitTestApplication application;
488 // Check some configurations.
490 TextView textView = TextView::New();
491 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
492 textView.SetMarkupProcessingEnabled( true ); // Enables markup processing.
494 Stage::GetCurrent().Add( textView );
496 // SplitByWord and ShrinkToFit.
497 // Centered alignment.
498 // Centered justification.
499 // Don't create a text actor per character.
501 textView.SetMultilinePolicy( TextView::SplitByWord );
502 textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
503 textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
504 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
505 textView.SetLineJustification( TextView::Center );
506 textView.SetSize( 136.56252f, 100.f );
508 textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
510 application.SendNotification();
511 application.Render();
513 std::vector<Size> sizes;
514 sizes.push_back( Size( 34.14063f, 11.380210f ) ); //
515 sizes.push_back( Size( 56.90105f, 11.380210f ) ); //
516 sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210.
517 // The result should be a line with the text 'Hello world' as shown below.
518 std::vector<Vector3> positions; // ____________
519 positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!|
520 positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------
521 positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); //
523 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
525 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
527 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
528 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
530 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
531 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
532 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
533 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
536 textView.SetSize( 50.f, 50.f );
537 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
538 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
539 textView.SetLineJustification( Toolkit::TextView::Left );
541 application.SendNotification();
542 application.Render();
545 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
546 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
547 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.
548 sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333.
549 // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
550 positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and
551 positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
552 positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______
553 positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | |
554 positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello |
559 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
561 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
563 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
564 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
566 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
567 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
568 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
569 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
572 // TODO: Add more tests when TextView implementation is finished.
576 int UtcDaliTextViewInsertRemoveText(void)
578 tet_infoline("UtcDaliTextViewInsertRemoveText: ");
579 ToolkitTestApplication application;
581 std::string text("Hello ");
583 MarkupProcessor::StyledTextArray styledText;
584 MarkupProcessor::GetStyledTextArray( text, styledText, true );
586 TextView view = TextView::New( "world!" );
588 view.InsertTextAt( 0, styledText );
590 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
592 view.RemoveTextFrom( 4, 5 );
594 DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
596 view.InsertTextAt( 0, "Hello " );
598 DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
601 view.InsertTextAt( 0, "Hello " );
602 view.InsertTextAt( 0, "Hello " );
603 view.InsertTextAt( 0, "Hello " );
604 view.InsertTextAt( 0, "Hello " );
605 view.RemoveTextFrom( 4, 2 );
606 view.RemoveTextFrom( 4, 2 );
607 view.RemoveTextFrom( 4, 2 );
608 view.RemoveTextFrom( 4, 2 );
609 view.RemoveTextFrom( 4, 2 );
610 view.SetText( "Hello world!" );
612 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
614 view.ReplaceTextFromTo( 5, 1, "" );
616 DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
618 view.ReplaceTextFromTo( 0, 11, styledText );
620 DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
624 int UtcDaliTextViewSnapshotEnable(void)
626 tet_infoline("UtcDaliTextViewSnapshotEnable: ");
627 ToolkitTestApplication application;
629 // Avoids the frame buffer texture to throw an exception.
630 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
632 TextView view = TextView::New();
633 view.SetMarkupProcessingEnabled( true ); // Enables markup processing.
634 view.SetText( "Hel<font color='green'>lo world!</font> This <font color='green'>is</font> a sna<font color='green'>psho</font>t test." );
636 Stage::GetCurrent().Add( view );
638 view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
639 // This line should be removed when text-view is set to use the snapshot mode by default.
641 // Snapshot is enabled by default.
642 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
644 application.SendNotification();
645 application.Render();
647 // TextView should have only two actors:
648 // the root (Actor) and the image (ImageActor).
650 DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
652 view.SetSnapshotModeEnabled( false );
653 DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
655 application.SendNotification();
656 application.Render();
658 // TextView should have one text-actor per word.
660 DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
664 int UtcDaliTextViewScroll(void)
666 tet_infoline("UtcDaliTextViewScroll: ");
667 ToolkitTestApplication application;
669 // Avoids the frame buffer texture to throw an exception.
670 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
672 TextView view = TextView::New( "Hello world! This is a scroll test." );
673 view.SetSize( 100.f, 100.f );
674 view.SetSnapshotModeEnabled( false );
676 Stage::GetCurrent().Add( view );
678 application.SendNotification();
679 application.Render();
681 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
683 view.SetScrollEnabled( true );
684 view.ScrolledSignal().Connect( &TestTextScrolled );
686 DALI_TEST_CHECK( view.IsScrollEnabled() );
687 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
689 gTextScrolled = false;
690 gScrollDelta = Vector2::ZERO;
691 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
693 application.SendNotification();
694 application.Render();
696 const Vector2& scrollPosition = view.GetScrollPosition();
697 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
699 DALI_TEST_CHECK( gTextScrolled );
700 DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
702 DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
706 int UtcDaliTextViewSetProperty(void)
708 tet_infoline("UtcDaliTextViewSetAndGetText: ");
709 ToolkitTestApplication application;
711 TextView view = TextView::New( "Hello world!" );
712 Stage::GetCurrent().Add( view );
714 //Test multiline policy property
715 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
716 DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
718 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByWord");
719 DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
721 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByChar");
722 DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
724 //Test width exceed policy property
725 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Original");
726 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
727 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
728 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
730 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
731 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
732 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
733 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
735 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
736 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
737 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
738 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
740 //Test line justification property
741 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Left");
742 DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
744 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Center");
745 DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
747 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Right");
748 DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
750 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Justified");
751 DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
753 //Test fade boundary property
754 unsigned int testValue = 23;
755 PixelSize leftFadeBoundary(testValue);
756 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_LEFT), testValue);
757 DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
760 PixelSize rightFadeBoundary(testValue);
761 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
762 DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
765 PixelSize topFadeBoundary(testValue);
766 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_TOP), testValue);
767 DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
770 PixelSize bottomFadeBoundary(testValue);
771 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
772 DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
774 //Test Line height offset property
775 float testOffsetValue = 14.04f;
776 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
777 DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
779 //Test alignment property
780 view.SetProperty(view.GetPropertyIndex(PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
781 view.SetProperty(view.GetPropertyIndex(PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
782 DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
786 int UtcDaliTextViewSetSortModifier(void)
788 tet_infoline("UtcDaliTextViewSetAndGetText: ");
789 ToolkitTestApplication application;
791 TextView view = TextView::New( "Hello world!" );
792 Stage::GetCurrent().Add( view );
794 view.SetSortModifier( 10.f );
795 view.SetSnapshotModeEnabled( false );
797 application.SendNotification();
798 application.Render();
800 DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
804 int UtcDaliTextViewUnderlineText(void)
806 tet_infoline("UtcDaliTextViewUnderlineText: ");
807 ToolkitTestApplication application;
809 TextView textView = TextView::New();
810 textView.SetSnapshotModeEnabled( false );
811 textView.SetMarkupProcessingEnabled( true );
812 textView.SetText( "<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>" );
814 textView.SetSize( 150.f, 100.f );
816 Stage::GetCurrent().Add( textView );
818 application.SendNotification();
819 application.Render();
821 std::vector<float> positions;
822 positions.push_back( 6.448784f );
823 positions.push_back( 9.862847f );
824 positions.push_back( 13.276909f );
825 positions.push_back( 16.690973f );
826 positions.push_back( 13.276909f );
827 positions.push_back( 9.862847f );
828 positions.push_back( 6.448784f );
830 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
832 TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
834 DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
835 DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );