2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
27 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
30 using namespace Toolkit;
35 bool TestEqual( float x, float y )
37 return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 );
40 static bool gObjectCreatedCallBackCalled;
41 static unsigned int gNumberObjectCreated;
43 static void TestCallback(BaseHandle handle)
45 gObjectCreatedCallBackCalled = true;
46 ++gNumberObjectCreated;
49 static bool gTextScrolled;
50 static Vector2 gScrollDelta;
51 static void TestTextScrolled( TextView textView, Vector2 scrollDelta )
54 gScrollDelta = scrollDelta;
59 static void Startup();
60 static void Cleanup();
64 void (*tet_startup)() = Startup;
65 void (*tet_cleanup)() = Cleanup;
70 POSITIVE_TC_IDX = 0x01,
74 #define MAX_NUMBER_OF_TESTS 10000
76 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
79 // Add test functionality for all APIs in the class (Positive and Negative)
80 TEST_FUNCTION( UtcDaliTextViewNew, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliTextViewSetAndGetText, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliTextViewSetStyleToCurrentText, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliTextViewSetAndGetLineHeight, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliTextViewSetAndGetFadeBoundary, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliTextViewSetAndGetEllipsizeText, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliTextViewSetAndGetWidthExceedPolicy, POSITIVE_TC_IDX );
87 TEST_FUNCTION( UtcDaliTextViewSetAndGetHeightExceedPolicy, POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions01, POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions02, POSITIVE_TC_IDX );
90 TEST_FUNCTION( UtcDaliTextViewInsertRemoveText, POSITIVE_TC_IDX );
91 TEST_FUNCTION( UtcDaliTextViewSnapshotEnable, POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliTextViewScroll, POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliTextViewSetProperty, POSITIVE_TC_IDX );
94 TEST_FUNCTION( UtcDaliTextViewSetSortModifier, POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextViewUnderlineText, POSITIVE_TC_IDX );
97 // Called only once before first test is run.
103 // Called only once after last test is run
105 static void Cleanup()
109 static void UtcDaliTextViewNew()
111 tet_infoline("UtcDaliTextViewNew: ");
112 ToolkitTestApplication application;
114 // Test default constructor.
117 DALI_TEST_CHECK( !view );
119 // Test default initialization.
120 view = TextView::New();
122 DALI_TEST_CHECK( view );
124 // Test copy constructor and asignment operator.
129 DALI_TEST_CHECK( viewCopy1 );
131 TextView viewCopy2( view );
133 DALI_TEST_CHECK( viewCopy2 );
140 TextView downCastView = TextView::DownCast( actorView );
142 DALI_TEST_CHECK( downCastView );
144 // Test constructor with a given text.
146 const std::string text( "Hello world!" );
148 const float DESCENDER = 8.0f;
150 TextView view1 = TextView::New( text );
152 DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION );
154 MarkupProcessor::StyledTextArray styledText;
155 MarkupProcessor::GetStyledTextArray( text, styledText );
157 TextView view2 = TextView::New( styledText );
159 DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION );
161 // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage.
162 TextView::CharacterLayoutInfo characterLayoutInfo;
164 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
165 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
166 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION );
167 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION );
168 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION );
170 TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ),
171 Vector3( 3.f, 4.f, 5.f ),
177 characterLayoutInfo = characterLayoutInfo2;
179 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
180 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
181 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION );
182 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION );
183 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION );
184 DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION );
187 TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo );
189 DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
190 DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
191 DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION );
192 DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION );
193 DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION );
195 // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage.
197 TextView::TextLayoutInfo textLayoutInfo;
198 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION );
199 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION );
200 DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION );
201 DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
202 DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
204 textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo );
205 textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 );
206 textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 );
207 textLayoutInfo.mTextSize = Size( 10.f, 10.f );
208 textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f );
210 TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo );
212 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
213 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
214 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
215 DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
216 DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
218 TextView::TextLayoutInfo textLayoutInfo3;
220 textLayoutInfo3 = textLayoutInfo2;
222 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
223 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
224 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
225 DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
226 DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
228 //Additional check to ensure object is created by checking if it's registered
229 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
230 DALI_TEST_CHECK( registry );
232 gObjectCreatedCallBackCalled = false;
233 registry.ObjectCreatedSignal().Connect(&TestCallback);
235 TextView view = TextView::New();
237 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
240 static void UtcDaliTextViewSetAndGetText()
242 tet_infoline("UtcDaliTextViewSetAndGetText: ");
243 ToolkitTestApplication application;
245 TextView view = TextView::New();
246 view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
248 std::string str( "Text with differing aCeNdEr and dEcEnDeR" );
251 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
253 MarkupProcessor::StyledTextArray styledText;
254 MarkupProcessor::GetStyledTextArray( str, styledText );
256 view.SetText( styledText );
257 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
259 // Test the number of text actor created.
261 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
262 DALI_TEST_CHECK( registry );
264 gNumberObjectCreated = 0;
265 registry.ObjectCreatedSignal().Connect(&TestCallback);
267 // Following string should create three text-actors ([Hel], [lo wo] and [rld]).
268 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
271 Stage::GetCurrent().Add( view );
272 view.SetText( text );
274 application.SendNotification();
275 application.Render();
277 DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION );
280 static void UtcDaliTextViewSetStyleToCurrentText()
282 tet_infoline("UtcDaliTextViewSetStyleToCurrentText: ");
283 ToolkitTestApplication application;
286 style.SetItalics( true );
288 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
290 "민관합동조사단은 지난달 30일부터\n"
291 "12일간의 현지 조사활동을 마치고\n"
293 TextView view = TextView::New( text );
298 view.SetStyleToCurrentText( style );
302 tet_printf( "Tet case fails\n" );
304 tet_result(TET_FAIL);
307 DALI_TEST_CHECK( !fail );
310 static void UtcDaliTextViewSetAndGetLineHeight()
312 tet_infoline("UtcDaliTextViewSetAndGetLineHeight: ");
314 ToolkitTestApplication application;
316 const float lineHeightOffset( 9.f );
318 TextView textView = TextView::New();
320 textView.SetLineHeightOffset( PointSize( lineHeightOffset ) );
322 DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
325 static void UtcDaliTextViewSetAndGetFadeBoundary()
327 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
329 ToolkitTestApplication application;
331 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
333 TextView textView = TextView::New( "Hello world!" );
335 textView.SetFadeBoundary( fadeBoundary );
337 TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary();
339 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
340 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
341 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
342 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
345 static void UtcDaliTextViewSetAndGetEllipsizeText()
347 tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: ");
349 ToolkitTestApplication application;
351 TextView textView = TextView::New( "Hello world!" );
353 textView.SetEllipsizeText( std::string( "..." ) );
355 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
357 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
359 GetStyledTextArray( std::string( "..." ), styledTextArray );
361 textView.SetEllipsizeText( styledTextArray );
363 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
367 static void UtcDaliTextViewSetAndGetWidthExceedPolicy()
369 tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: ");
371 ToolkitTestApplication application;
373 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
374 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
376 TextView textView = TextView::New( "Hello world!" );
378 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
380 textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
382 DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
386 static void UtcDaliTextViewSetAndGetHeightExceedPolicy()
388 tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: ");
390 ToolkitTestApplication application;
392 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
393 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
395 TextView textView = TextView::New( "Hello world!" );
397 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
399 textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
401 DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
405 static void UtcDaliTextViewTestLayoutOptions01()
407 tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
409 ToolkitTestApplication application;
411 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
413 "민관합동조사단은 지난달 30일부터\n"
414 "12일간의 현지 조사활동을 마치고\n"
417 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
418 const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
419 const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
420 const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
421 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
422 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
423 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
424 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
425 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
426 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
427 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
428 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
429 const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
431 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
432 const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
433 const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
434 const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
435 const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
437 TextView textView = TextView::New( text );
438 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
440 Stage::GetCurrent().Add( textView );
442 TextView::TextLayoutInfo textLayoutInfo;
444 for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
446 textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
447 for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
449 textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
450 for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
452 textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
453 for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
455 textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
456 for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
458 textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
462 textView.GetTextLayoutInfo( textLayoutInfo );
464 application.SendNotification();
465 application.Render();
467 catch( Dali::DaliException& e )
469 DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
473 tet_printf( "Tet case fails\n" );
474 tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
475 tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
476 tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
477 tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
478 tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
479 tet_result(TET_FAIL);
482 DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
484 DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
486 DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
488 DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
490 DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
494 static void UtcDaliTextViewTestLayoutOptions02()
496 tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
497 ToolkitTestApplication application;
499 // Check some configurations.
501 TextView textView = TextView::New();
502 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
504 Stage::GetCurrent().Add( textView );
506 // SplitByWord and ShrinkToFit.
507 // Centered alignment.
508 // Centered justification.
509 // Don't create a text actor per character.
511 textView.SetMultilinePolicy( TextView::SplitByWord );
512 textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
513 textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
514 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
515 textView.SetLineJustification( TextView::Center );
516 textView.SetSize( 136.56252f, 100.f );
518 textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
520 application.SendNotification();
521 application.Render();
523 std::vector<Size> sizes;
524 sizes.push_back( Size( 34.14063f, 11.380210f ) ); //
525 sizes.push_back( Size( 56.90105f, 11.380210f ) ); //
526 sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210.
527 // The result should be a line with the text 'Hello world' as shown below.
528 std::vector<Vector3> positions; // ____________
529 positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!|
530 positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------
531 positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); //
533 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
535 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
537 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
538 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
540 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
541 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
542 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
543 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
546 textView.SetSize( 50.f, 50.f );
547 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
548 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
549 textView.SetLineJustification( Toolkit::TextView::Left );
551 application.SendNotification();
552 application.Render();
555 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
556 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
557 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.
558 sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333.
559 // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
560 positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and
561 positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
562 positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______
563 positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | |
564 positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello |
569 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
571 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
573 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
574 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
576 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
577 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
578 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
579 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
582 // TODO: Add more tests when TextView implementation is finished.
585 static void UtcDaliTextViewInsertRemoveText()
587 tet_infoline("UtcDaliTextViewInsertRemoveText: ");
588 ToolkitTestApplication application;
590 std::string text("Hello ");
592 MarkupProcessor::StyledTextArray styledText;
593 MarkupProcessor::GetStyledTextArray( text, styledText );
595 TextView view = TextView::New( "world!" );
597 view.InsertTextAt( 0, styledText );
599 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
601 view.RemoveTextFrom( 4, 5 );
603 DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
605 view.InsertTextAt( 0, "Hello " );
607 DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
610 view.InsertTextAt( 0, "Hello " );
611 view.InsertTextAt( 0, "Hello " );
612 view.InsertTextAt( 0, "Hello " );
613 view.InsertTextAt( 0, "Hello " );
614 view.RemoveTextFrom( 4, 2 );
615 view.RemoveTextFrom( 4, 2 );
616 view.RemoveTextFrom( 4, 2 );
617 view.RemoveTextFrom( 4, 2 );
618 view.RemoveTextFrom( 4, 2 );
619 view.SetText( "Hello world!" );
621 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
623 view.ReplaceTextFromTo( 5, 1, "" );
625 DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
627 view.ReplaceTextFromTo( 0, 11, styledText );
629 DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
632 static void UtcDaliTextViewSnapshotEnable()
634 tet_infoline("UtcDaliTextViewSnapshotEnable: ");
635 ToolkitTestApplication application;
637 // Avoids the frame buffer texture to throw an exception.
638 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
640 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." );
642 Stage::GetCurrent().Add( view );
644 view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
645 // This line should be removed when text-view is set to use the snapshot mode by default.
647 // Snapshot is enabled by default.
648 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
650 application.SendNotification();
651 application.Render();
653 // TextView should have only two actors:
654 // the root (Actor) and the image (ImageActor).
656 DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
658 view.SetSnapshotModeEnabled( false );
659 DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
661 application.SendNotification();
662 application.Render();
664 // TextView should have one text-actor per word.
666 DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
669 static void UtcDaliTextViewScroll()
671 tet_infoline("UtcDaliTextViewScroll: ");
672 ToolkitTestApplication application;
674 // Avoids the frame buffer texture to throw an exception.
675 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
677 TextView view = TextView::New( "Hello world! This is a scroll test." );
678 view.SetSize( 100.f, 100.f );
679 view.SetSnapshotModeEnabled( false );
681 Stage::GetCurrent().Add( view );
683 application.SendNotification();
684 application.Render();
686 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
688 view.SetScrollEnabled( true );
689 view.ScrolledSignal().Connect( &TestTextScrolled );
691 DALI_TEST_CHECK( view.IsScrollEnabled() );
692 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
694 gTextScrolled = false;
695 gScrollDelta = Vector2::ZERO;
696 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
698 application.SendNotification();
699 application.Render();
701 const Vector2& scrollPosition = view.GetScrollPosition();
702 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
704 DALI_TEST_CHECK( gTextScrolled );
705 DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
707 DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
710 static void UtcDaliTextViewSetProperty()
712 tet_infoline("UtcDaliTextViewSetAndGetText: ");
713 ToolkitTestApplication application;
715 TextView view = TextView::New( "Hello world!" );
716 Stage::GetCurrent().Add( view );
718 //Test multiline policy property
719 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
720 DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
722 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByWord");
723 DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
725 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_MULTILINE_POLICY), "SplitByChar");
726 DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
728 //Test width exceed policy property
729 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "Original");
730 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
731 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
732 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
734 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
735 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
736 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
737 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
739 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
740 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
741 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
742 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
744 //Test line justification property
745 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Left");
746 DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
748 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Center");
749 DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
751 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Right");
752 DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
754 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_JUSTIFICATION), "Justified");
755 DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
757 //Test fade boundary property
758 unsigned int testValue = 23;
759 PixelSize leftFadeBoundary(testValue);
760 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_LEFT), testValue);
761 DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
764 PixelSize rightFadeBoundary(testValue);
765 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
766 DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
769 PixelSize topFadeBoundary(testValue);
770 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_TOP), testValue);
771 DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
774 PixelSize bottomFadeBoundary(testValue);
775 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
776 DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
778 //Test Line height offset property
779 float testOffsetValue = 14.04f;
780 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
781 DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
783 //Test alignment property
784 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
785 view.SetProperty(view.GetPropertyIndex(TextView::PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
786 DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
789 static void UtcDaliTextViewSetSortModifier()
791 tet_infoline("UtcDaliTextViewSetAndGetText: ");
792 ToolkitTestApplication application;
794 TextView view = TextView::New( "Hello world!" );
795 Stage::GetCurrent().Add( view );
797 view.SetSortModifier( 10.f );
798 view.SetSnapshotModeEnabled( false );
800 application.SendNotification();
801 application.Render();
803 DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
806 static void UtcDaliTextViewUnderlineText()
808 std::cout << "##############################" << std::endl;
810 tet_infoline("UtcDaliTextViewUnderlineText: ");
811 ToolkitTestApplication application;
813 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>" );
814 textView.SetSnapshotModeEnabled( false );
816 textView.SetSize( 150.f, 100.f );
818 Stage::GetCurrent().Add( textView );
820 application.SendNotification();
821 application.Render();
823 std::vector<float> positions;
824 positions.push_back( 6.448784f );
825 positions.push_back( 9.862847f );
826 positions.push_back( 13.276909f );
827 positions.push_back( 16.690973f );
828 positions.push_back( 13.276909f );
829 positions.push_back( 9.862847f );
830 positions.push_back( 6.448784f );
832 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
834 TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
836 DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
837 DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );