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.
23 #include <dali/public-api/dali-core.h>
25 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
31 using namespace Toolkit;
36 const char* const PROPERTY_TEXT = "text";
37 const char* const PROPERTY_MULTILINE_POLICY = "multiline-policy";
38 const char* const PROPERTY_WIDTH_EXCEED_POLICY = "width-exceed-policy";
39 const char* const PROPERTY_HEIGHT_EXCEED_POLICY = "height-exceed-policy";
40 const char* const PROPERTY_LINE_JUSTIFICATION = "line-justification";
41 const char* const PROPERTY_FADE_BOUNDARY_LEFT = "fade-boundary-left";
42 const char* const PROPERTY_FADE_BOUNDARY_RIGHT = "fade-boundary-right";
43 const char* const PROPERTY_FADE_BOUNDARY_TOP = "fade-boundary-top";
44 const char* const PROPERTY_FADE_BOUNDARY_BOTTOM = "fade-boundary-bottom";
45 const char* const PROPERTY_LINE_HEIGHT_OFFSET = "line-height-offset";
46 const char* const PROPERTY_HORIZONTAL_ALIGNMENT = "horizontal-alignment";
47 const char* const PROPERTY_VERTICAL_ALIGNMENT = "vertical-alignment";
49 bool TestEqual( float x, float y )
51 return !( fabsf( x - y ) > Math::MACHINE_EPSILON_1000 );
54 static bool gObjectCreatedCallBackCalled;
55 static unsigned int gNumberObjectCreated;
57 static void TestCallback(BaseHandle handle)
59 gObjectCreatedCallBackCalled = true;
60 ++gNumberObjectCreated;
63 static bool gTextScrolled;
64 static Vector2 gScrollDelta;
65 static void TestTextScrolled( TextView textView, Vector2 scrollDelta )
68 gScrollDelta = scrollDelta;
73 static void Startup();
74 static void Cleanup();
78 void (*tet_startup)() = Startup;
79 void (*tet_cleanup)() = Cleanup;
84 POSITIVE_TC_IDX = 0x01,
88 #define MAX_NUMBER_OF_TESTS 10000
90 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
93 // Add test functionality for all APIs in the class (Positive and Negative)
94 TEST_FUNCTION( UtcDaliTextViewNew, POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextViewSetAndGetText, POSITIVE_TC_IDX );
96 TEST_FUNCTION( UtcDaliTextViewSetStyleToCurrentText, POSITIVE_TC_IDX );
97 TEST_FUNCTION( UtcDaliTextViewSetAndGetLineHeight, POSITIVE_TC_IDX );
98 TEST_FUNCTION( UtcDaliTextViewSetAndGetFadeBoundary, POSITIVE_TC_IDX );
99 TEST_FUNCTION( UtcDaliTextViewSetAndGetEllipsizeText, POSITIVE_TC_IDX );
100 TEST_FUNCTION( UtcDaliTextViewSetAndGetWidthExceedPolicy, POSITIVE_TC_IDX );
101 TEST_FUNCTION( UtcDaliTextViewSetAndGetHeightExceedPolicy, POSITIVE_TC_IDX );
102 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions01, POSITIVE_TC_IDX );
103 TEST_FUNCTION( UtcDaliTextViewTestLayoutOptions02, POSITIVE_TC_IDX );
104 TEST_FUNCTION( UtcDaliTextViewInsertRemoveText, POSITIVE_TC_IDX );
105 TEST_FUNCTION( UtcDaliTextViewSnapshotEnable, POSITIVE_TC_IDX );
106 TEST_FUNCTION( UtcDaliTextViewScroll, POSITIVE_TC_IDX );
107 TEST_FUNCTION( UtcDaliTextViewSetProperty, POSITIVE_TC_IDX );
108 TEST_FUNCTION( UtcDaliTextViewSetSortModifier, POSITIVE_TC_IDX );
109 TEST_FUNCTION( UtcDaliTextViewUnderlineText, POSITIVE_TC_IDX );
111 // Called only once before first test is run.
113 static void Startup()
117 // Called only once after last test is run
119 static void Cleanup()
123 static void UtcDaliTextViewNew()
125 tet_infoline("UtcDaliTextViewNew: ");
126 ToolkitTestApplication application;
128 // Test default constructor.
131 DALI_TEST_CHECK( !view );
133 // Test default initialization.
134 view = TextView::New();
136 DALI_TEST_CHECK( view );
138 // Test copy constructor and asignment operator.
143 DALI_TEST_CHECK( viewCopy1 );
145 TextView viewCopy2( view );
147 DALI_TEST_CHECK( viewCopy2 );
154 TextView downCastView = TextView::DownCast( actorView );
156 DALI_TEST_CHECK( downCastView );
158 // Test constructor with a given text.
160 const std::string text( "Hello world!" );
162 const float DESCENDER = 8.0f;
164 TextView view1 = TextView::New( text );
166 DALI_TEST_EQUALS( view1.GetText(), text, TEST_LOCATION );
168 MarkupProcessor::StyledTextArray styledText;
169 MarkupProcessor::GetStyledTextArray( text, styledText, true );
171 TextView view2 = TextView::New( styledText );
173 DALI_TEST_EQUALS( view2.GetText(), text, TEST_LOCATION );
175 // Check the default Toolkit::TextView::CharacterLayoutInfo::CharacterLayoutInfo() to increase coverage.
176 TextView::CharacterLayoutInfo characterLayoutInfo;
178 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
179 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
180 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, false, TEST_LOCATION );
181 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, false, TEST_LOCATION );
182 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, true, TEST_LOCATION );
184 TextView::CharacterLayoutInfo characterLayoutInfo2( Size( 2.f, 2.f ),
185 Vector3( 3.f, 4.f, 5.f ),
191 characterLayoutInfo = characterLayoutInfo2;
193 DALI_TEST_EQUALS( characterLayoutInfo.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
194 DALI_TEST_EQUALS( characterLayoutInfo.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
195 DALI_TEST_EQUALS( characterLayoutInfo.mIsNewLineChar, true, TEST_LOCATION );
196 DALI_TEST_EQUALS( characterLayoutInfo.mIsRightToLeftCharacter, true, TEST_LOCATION );
197 DALI_TEST_EQUALS( characterLayoutInfo.mIsVisible, false, TEST_LOCATION );
198 DALI_TEST_EQUALS( characterLayoutInfo.mDescender, DESCENDER , TEST_LOCATION );
201 TextView::CharacterLayoutInfo characterLayoutInfo3( characterLayoutInfo );
203 DALI_TEST_EQUALS( characterLayoutInfo3.mSize, Size( 2.f, 2.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
204 DALI_TEST_EQUALS( characterLayoutInfo3.mPosition, Vector3( 3.f, 4.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
205 DALI_TEST_EQUALS( characterLayoutInfo3.mIsNewLineChar, true, TEST_LOCATION );
206 DALI_TEST_EQUALS( characterLayoutInfo3.mIsRightToLeftCharacter, true, TEST_LOCATION );
207 DALI_TEST_EQUALS( characterLayoutInfo3.mIsVisible, false, TEST_LOCATION );
209 // Check the default Toolkit::TextView::TextLayoutInfo::TextLayoutInfo() to increase coverage.
211 TextView::TextLayoutInfo textLayoutInfo;
212 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLayoutInfoTable.size(), 0u, TEST_LOCATION );
213 DALI_TEST_EQUALS( textLayoutInfo.mCharacterLogicalToVisualMap.size(), 0u, TEST_LOCATION );
214 DALI_TEST_EQUALS( textLayoutInfo.mCharacterVisualToLogicalMap.size(), 0u, TEST_LOCATION );
215 DALI_TEST_EQUALS( textLayoutInfo.mTextSize, Size::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
216 DALI_TEST_EQUALS( textLayoutInfo.mScrollOffset, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
218 textLayoutInfo.mCharacterLayoutInfoTable.push_back( characterLayoutInfo );
219 textLayoutInfo.mCharacterLogicalToVisualMap.push_back( 1 );
220 textLayoutInfo.mCharacterVisualToLogicalMap.push_back( 1 );
221 textLayoutInfo.mTextSize = Size( 10.f, 10.f );
222 textLayoutInfo.mScrollOffset = Vector2( 5.f, 5.f );
224 TextView::TextLayoutInfo textLayoutInfo2( textLayoutInfo );
226 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
227 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
228 DALI_TEST_EQUALS( textLayoutInfo2.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
229 DALI_TEST_EQUALS( textLayoutInfo2.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
230 DALI_TEST_EQUALS( textLayoutInfo2.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
232 TextView::TextLayoutInfo textLayoutInfo3;
234 textLayoutInfo3 = textLayoutInfo2;
236 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLayoutInfoTable.size(), 1u, TEST_LOCATION );
237 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterLogicalToVisualMap.size(), 1u, TEST_LOCATION );
238 DALI_TEST_EQUALS( textLayoutInfo3.mCharacterVisualToLogicalMap.size(), 1u, TEST_LOCATION );
239 DALI_TEST_EQUALS( textLayoutInfo3.mTextSize, Size( 10.f, 10.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
240 DALI_TEST_EQUALS( textLayoutInfo3.mScrollOffset, Vector2( 5.f, 5.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
242 //Additional check to ensure object is created by checking if it's registered
243 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
244 DALI_TEST_CHECK( registry );
246 gObjectCreatedCallBackCalled = false;
247 registry.ObjectCreatedSignal().Connect(&TestCallback);
249 TextView view = TextView::New();
251 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
254 static void UtcDaliTextViewSetAndGetText()
256 tet_infoline("UtcDaliTextViewSetAndGetText: ");
257 ToolkitTestApplication application;
259 TextView view = TextView::New();
260 view.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
262 std::string str( "Text with differing aCeNdEr and dEcEnDeR" );
265 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
267 MarkupProcessor::StyledTextArray styledText;
268 MarkupProcessor::GetStyledTextArray( str, styledText, true );
270 view.SetText( styledText );
271 DALI_TEST_EQUALS( view.GetText(), str, TEST_LOCATION );
273 // Test the number of text actor created.
275 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
276 DALI_TEST_CHECK( registry );
278 gNumberObjectCreated = 0;
279 registry.ObjectCreatedSignal().Connect(&TestCallback);
281 // Following string should create three text-actors ([Hel], [lo wo] and [rld]).
282 std::string text( "Hel<font size='10'>lo wo</font>rld!\n"
285 Stage::GetCurrent().Add( view );
286 view.SetText( text );
288 application.SendNotification();
289 application.Render();
291 DALI_TEST_EQUALS( 3u, gNumberObjectCreated, TEST_LOCATION );
294 static void UtcDaliTextViewSetStyleToCurrentText()
296 tet_infoline("UtcDaliTextViewSetStyleToCurrentText: ");
297 ToolkitTestApplication application;
300 style.SetItalics( true );
302 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
304 "민관합동조사단은 지난달 30일부터\n"
305 "12일간의 현지 조사활동을 마치고\n"
307 TextView view = TextView::New( text );
312 view.SetStyleToCurrentText( style );
316 tet_printf( "Tet case fails\n" );
318 tet_result(TET_FAIL);
321 DALI_TEST_CHECK( !fail );
324 static void UtcDaliTextViewSetAndGetLineHeight()
326 tet_infoline("UtcDaliTextViewSetAndGetLineHeight: ");
328 ToolkitTestApplication application;
330 const float lineHeightOffset( 9.f );
332 TextView textView = TextView::New();
334 textView.SetLineHeightOffset( PointSize( lineHeightOffset ) );
336 DALI_TEST_EQUALS( float(textView.GetLineHeightOffset()), lineHeightOffset, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
339 static void UtcDaliTextViewSetAndGetFadeBoundary()
341 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
343 ToolkitTestApplication application;
345 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
347 TextView textView = TextView::New( "Hello world!" );
349 textView.SetFadeBoundary( fadeBoundary );
351 TextView::FadeBoundary fadeBoundary2 = textView.GetFadeBoundary();
353 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
354 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
355 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
356 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
359 static void UtcDaliTextViewSetAndGetEllipsizeText()
361 tet_infoline("UtcDaliTextViewSetAndGetEllipsizeText: ");
363 ToolkitTestApplication application;
365 TextView textView = TextView::New( "Hello world!" );
367 textView.SetEllipsizeText( std::string( "..." ) );
369 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
371 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
373 GetStyledTextArray( std::string( "..." ), styledTextArray, true );
375 textView.SetEllipsizeText( styledTextArray );
377 DALI_TEST_EQUALS( std::string( "..." ), textView.GetEllipsizeText(), TEST_LOCATION );
381 static void UtcDaliTextViewSetAndGetWidthExceedPolicy()
383 tet_infoline("UtcDaliTextViewSetAndGetWidthExceedPolicy: ");
385 ToolkitTestApplication application;
387 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
388 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
390 TextView textView = TextView::New( "Hello world!" );
392 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
394 textView.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
396 DALI_TEST_EQUALS( textView.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
400 static void UtcDaliTextViewSetAndGetHeightExceedPolicy()
402 tet_infoline("UtcDaliTextViewSetAndGetHeightExceedPolicy: ");
404 ToolkitTestApplication application;
406 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
407 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
409 TextView textView = TextView::New( "Hello world!" );
411 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
413 textView.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
415 DALI_TEST_EQUALS( textView.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
419 static void UtcDaliTextViewTestLayoutOptions01()
421 tet_infoline("UtcDaliTextViewTestLayoutOptions01: ");
423 ToolkitTestApplication application;
425 const std::string text( "앞서 농식품부 주이석 검역검사본부\n"
427 "민관합동조사단은 지난달 30일부터\n"
428 "12일간의 현지 조사활동을 마치고\n"
431 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
432 const TextView::ExceedPolicy EXCEED_WIDTH_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit, TextView::EllipsizeEnd };
433 const TextView::ExceedPolicy EXCEED_HEIGHT_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
434 const Alignment::Type TEXT_ALIGNMENT[] = { static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalTop ),
435 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalCenter ),
436 static_cast<Alignment::Type>( Alignment::HorizontalLeft | Alignment::VerticalBottom ),
437 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ),
438 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ),
439 static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalBottom ),
440 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalTop ),
441 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalCenter ),
442 static_cast<Alignment::Type>( Alignment::HorizontalRight | Alignment::VerticalBottom ) };
443 const TextView::LineJustification LINE_JUSTIFICATION[] = { TextView::Left, TextView::Center, TextView::Right, TextView::Justified };
445 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
446 const unsigned int NUM_WIDTH_EXCEED_POLICIES = sizeof( EXCEED_WIDTH_POLICIES ) / sizeof( unsigned int );
447 const unsigned int NUM_HEIGHT_EXCEED_POLICIES = sizeof( EXCEED_HEIGHT_POLICIES ) / sizeof( unsigned int );
448 const unsigned int NUM_TEXT_ALIGNMENT = sizeof( TEXT_ALIGNMENT ) / sizeof( unsigned int );
449 const unsigned int NUM_LINE_JUSTIFICATION = sizeof( LINE_JUSTIFICATION ) / sizeof( unsigned int );
451 TextView textView = TextView::New( text );
452 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
454 Stage::GetCurrent().Add( textView );
456 TextView::TextLayoutInfo textLayoutInfo;
458 for( unsigned int mlpIndex = 0; mlpIndex < NUM_MULTILINE_POLICIES; ++mlpIndex )
460 textView.SetMultilinePolicy( MULTILINE_POLICIES[mlpIndex] );
461 for( unsigned int ewpIndex = 0; ewpIndex < NUM_WIDTH_EXCEED_POLICIES; ++ewpIndex )
463 textView.SetWidthExceedPolicy( EXCEED_WIDTH_POLICIES[ewpIndex] );
464 for( unsigned int ehpIndex = 0; ehpIndex < NUM_HEIGHT_EXCEED_POLICIES; ++ehpIndex )
466 textView.SetHeightExceedPolicy( EXCEED_HEIGHT_POLICIES[ehpIndex] );
467 for( unsigned int taIndex = 0; taIndex < NUM_TEXT_ALIGNMENT; ++taIndex )
469 textView.SetTextAlignment( TEXT_ALIGNMENT[taIndex] );
470 for( unsigned int ljIndex = 0; ljIndex < NUM_LINE_JUSTIFICATION; ++ljIndex )
472 textView.SetLineJustification( LINE_JUSTIFICATION[ljIndex] );
476 textView.GetTextLayoutInfo( textLayoutInfo );
478 application.SendNotification();
479 application.Render();
481 catch( Dali::DaliException& e )
483 DALI_TEST_EQUALS( e.mCondition, "!\"TextView::CombineExceedPolicies() Invalid width and height exceed policies combination\"", TEST_LOCATION );
487 tet_printf( "Tet case fails\n" );
488 tet_printf( " MultilinePolicy : %d\n", MULTILINE_POLICIES[mlpIndex] );
489 tet_printf( " Width ExceedPolicy : %d\n", EXCEED_WIDTH_POLICIES[ewpIndex] );
490 tet_printf( " Height ExceedPolicy : %d\n", EXCEED_HEIGHT_POLICIES[ehpIndex] );
491 tet_printf( " TextAlignment : %d\n", TEXT_ALIGNMENT[taIndex] );
492 tet_printf( " LineJustification : %d\n", LINE_JUSTIFICATION[ljIndex] );
493 tet_result(TET_FAIL);
496 DALI_TEST_CHECK( LINE_JUSTIFICATION[ljIndex] == textView.GetLineJustification() );
498 DALI_TEST_CHECK( TEXT_ALIGNMENT[taIndex] == textView.GetTextAlignment() );
500 DALI_TEST_CHECK( EXCEED_HEIGHT_POLICIES[ehpIndex] == textView.GetHeightExceedPolicy() );
502 DALI_TEST_CHECK( EXCEED_WIDTH_POLICIES[ewpIndex] == textView.GetWidthExceedPolicy() );
504 DALI_TEST_CHECK( MULTILINE_POLICIES[mlpIndex] == textView.GetMultilinePolicy() );
508 static void UtcDaliTextViewTestLayoutOptions02()
510 tet_infoline("UtcDaliTextViewTestLayoutOptions02: ");
511 ToolkitTestApplication application;
513 // Check some configurations.
515 TextView textView = TextView::New();
516 textView.SetSnapshotModeEnabled( false ); // Disables offscreen rendering.
518 Stage::GetCurrent().Add( textView );
520 // SplitByWord and ShrinkToFit.
521 // Centered alignment.
522 // Centered justification.
523 // Don't create a text actor per character.
525 textView.SetMultilinePolicy( TextView::SplitByWord );
526 textView.SetWidthExceedPolicy( TextView::ShrinkToFit );
527 textView.SetHeightExceedPolicy( TextView::ShrinkToFit );
528 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalTop ) );
529 textView.SetLineJustification( TextView::Center );
530 textView.SetSize( 136.56252f, 100.f );
532 textView.SetText( "Hel<font color='green'>lo wo</font>rld!" );
534 application.SendNotification();
535 application.Render();
537 std::vector<Size> sizes;
538 sizes.push_back( Size( 34.14063f, 11.380210f ) ); //
539 sizes.push_back( Size( 56.90105f, 11.380210f ) ); //
540 sizes.push_back( Size( 45.52084f, 11.380210f ) ); // By default characters have width and height values of 11.380210.
541 // The result should be a line with the text 'Hello world' as shown below.
542 std::vector<Vector3> positions; // ____________
543 positions.push_back( Vector3( 0.000008f, 11.380209f, 0.f ) ); // |Hello world!|
544 positions.push_back( Vector3( 34.14063f, 11.380209f, 0.f ) ); // ------------
545 positions.push_back( Vector3( 91.04168f, 11.380209f, 0.f ) ); //
547 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
549 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
551 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
552 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
554 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
555 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
556 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
557 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
560 textView.SetSize( 50.f, 50.f );
561 textView.SetTextAlignment( static_cast<Alignment::Type>( Alignment::HorizontalCenter | Alignment::VerticalCenter ) );
562 textView.SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed );
563 textView.SetLineJustification( Toolkit::TextView::Left );
565 application.SendNotification();
566 application.Render();
569 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
570 sizes.push_back( Size( 24.999999f, 8.333333f ) ); //
571 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.
572 sizes.push_back( Size( 33.333332f, 8.333333f ) ); // The scale factor is 0.732265339, so the character size is 8.333333.
573 // Text should be split in two lines, centered in the vertical dimension and fitted in the horizontal one.
574 positions.clear(); // As shown below, the text is two lines and centered in the vertical dimension and
575 positions.push_back( Vector3( 0.000008f, 25.223114f, 0.f ) ); // it should start in middle height (~25).
576 positions.push_back( Vector3( 24.999999f, 25.223114f, 0.f ) ); // ______
577 positions.push_back( Vector3( 0.000006f, 33.556446f, 0.f ) ); // | |
578 positions.push_back( Vector3( 16.666666f, 33.556446f, 0.f ) ); // |Hello |
583 DALI_TEST_CHECK( positions.size() == textView.GetChildCount() ); // Check text has two text-actors.
585 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
587 const Vector3& size = textView.GetChildAt(index).GetCurrentSize();
588 const Vector3& position = textView.GetChildAt(index).GetCurrentPosition();
590 DALI_TEST_EQUALS( size.width, sizes[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
591 DALI_TEST_EQUALS( size.height, sizes[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
592 DALI_TEST_EQUALS( position.width, positions[index].width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
593 DALI_TEST_EQUALS( position.height, positions[index].height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
596 // TODO: Add more tests when TextView implementation is finished.
599 static void UtcDaliTextViewInsertRemoveText()
601 tet_infoline("UtcDaliTextViewInsertRemoveText: ");
602 ToolkitTestApplication application;
604 std::string text("Hello ");
606 MarkupProcessor::StyledTextArray styledText;
607 MarkupProcessor::GetStyledTextArray( text, styledText, true );
609 TextView view = TextView::New( "world!" );
611 view.InsertTextAt( 0, styledText );
613 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
615 view.RemoveTextFrom( 4, 5 );
617 DALI_TEST_EQUALS( view.GetText(), std::string("Hellld!"), TEST_LOCATION );
619 view.InsertTextAt( 0, "Hello " );
621 DALI_TEST_EQUALS( view.GetText(), std::string("Hello Hellld!"), TEST_LOCATION );
624 view.InsertTextAt( 0, "Hello " );
625 view.InsertTextAt( 0, "Hello " );
626 view.InsertTextAt( 0, "Hello " );
627 view.InsertTextAt( 0, "Hello " );
628 view.RemoveTextFrom( 4, 2 );
629 view.RemoveTextFrom( 4, 2 );
630 view.RemoveTextFrom( 4, 2 );
631 view.RemoveTextFrom( 4, 2 );
632 view.RemoveTextFrom( 4, 2 );
633 view.SetText( "Hello world!" );
635 DALI_TEST_EQUALS( view.GetText(), std::string("Hello world!"), TEST_LOCATION );
637 view.ReplaceTextFromTo( 5, 1, "" );
639 DALI_TEST_EQUALS( view.GetText(), std::string("Helloworld!"), TEST_LOCATION );
641 view.ReplaceTextFromTo( 0, 11, styledText );
643 DALI_TEST_EQUALS( view.GetText(), std::string("Hello "), TEST_LOCATION );
646 static void UtcDaliTextViewSnapshotEnable()
648 tet_infoline("UtcDaliTextViewSnapshotEnable: ");
649 ToolkitTestApplication application;
651 // Avoids the frame buffer texture to throw an exception.
652 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
654 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." );
656 Stage::GetCurrent().Add( view );
658 view.SetSnapshotModeEnabled( true ); // VCC. By default the snapshot mode should be enabled but it has been temporary disabled.
659 // This line should be removed when text-view is set to use the snapshot mode by default.
661 // Snapshot is enabled by default.
662 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() );
664 application.SendNotification();
665 application.Render();
667 // TextView should have only two actors:
668 // the root (Actor) and the image (ImageActor).
670 DALI_TEST_EQUALS( view.GetChildCount(), 2u, TEST_LOCATION );
672 view.SetSnapshotModeEnabled( false );
673 DALI_TEST_CHECK( !view.IsSnapshotModeEnabled() );
675 application.SendNotification();
676 application.Render();
678 // TextView should have one text-actor per word.
680 DALI_TEST_EQUALS( view.GetChildCount(), 7u, TEST_LOCATION );
683 static void UtcDaliTextViewScroll()
685 tet_infoline("UtcDaliTextViewScroll: ");
686 ToolkitTestApplication application;
688 // Avoids the frame buffer texture to throw an exception.
689 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
691 TextView view = TextView::New( "Hello world! This is a scroll test." );
692 view.SetSize( 100.f, 100.f );
693 view.SetSnapshotModeEnabled( false );
695 Stage::GetCurrent().Add( view );
697 application.SendNotification();
698 application.Render();
700 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
702 view.SetScrollEnabled( true );
703 view.ScrolledSignal().Connect( &TestTextScrolled );
705 DALI_TEST_CHECK( view.IsScrollEnabled() );
706 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
708 gTextScrolled = false;
709 gScrollDelta = Vector2::ZERO;
710 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
712 application.SendNotification();
713 application.Render();
715 const Vector2& scrollPosition = view.GetScrollPosition();
716 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
718 DALI_TEST_CHECK( gTextScrolled );
719 DALI_TEST_EQUALS( gScrollDelta, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
721 DALI_TEST_CHECK( view.IsScrollPositionTrimmed() );
724 static void UtcDaliTextViewSetProperty()
726 tet_infoline("UtcDaliTextViewSetAndGetText: ");
727 ToolkitTestApplication application;
729 TextView view = TextView::New( "Hello world!" );
730 Stage::GetCurrent().Add( view );
732 //Test multiline policy property
733 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByNewLineChar");
734 DALI_TEST_CHECK( Toolkit::TextView::SplitByNewLineChar == view.GetMultilinePolicy() );
736 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByWord");
737 DALI_TEST_CHECK( Toolkit::TextView::SplitByWord == view.GetMultilinePolicy() );
739 view.SetProperty(view.GetPropertyIndex(PROPERTY_MULTILINE_POLICY), "SplitByChar");
740 DALI_TEST_CHECK( Toolkit::TextView::SplitByChar == view.GetMultilinePolicy() );
742 //Test width exceed policy property
743 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Original");
744 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Original");
745 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetWidthExceedPolicy() );
746 DALI_TEST_CHECK( Toolkit::TextView::Original == view.GetHeightExceedPolicy() );
748 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "Fade");
749 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "Fade");
750 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetWidthExceedPolicy() );
751 DALI_TEST_CHECK( Toolkit::TextView::Fade == view.GetHeightExceedPolicy() );
753 view.SetProperty(view.GetPropertyIndex(PROPERTY_WIDTH_EXCEED_POLICY), "ShrinkToFit");
754 view.SetProperty(view.GetPropertyIndex(PROPERTY_HEIGHT_EXCEED_POLICY), "ShrinkToFit");
755 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetWidthExceedPolicy() );
756 DALI_TEST_CHECK( Toolkit::TextView::ShrinkToFit == view.GetHeightExceedPolicy() );
758 //Test line justification property
759 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Left");
760 DALI_TEST_CHECK( Toolkit::TextView::Left == view.GetLineJustification() );
762 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Center");
763 DALI_TEST_CHECK( Toolkit::TextView::Center == view.GetLineJustification() );
765 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Right");
766 DALI_TEST_CHECK( Toolkit::TextView::Right == view.GetLineJustification() );
768 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_JUSTIFICATION), "Justified");
769 DALI_TEST_CHECK( Toolkit::TextView::Justified == view.GetLineJustification() );
771 //Test fade boundary property
772 unsigned int testValue = 23;
773 PixelSize leftFadeBoundary(testValue);
774 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_LEFT), testValue);
775 DALI_TEST_CHECK( leftFadeBoundary == view.GetFadeBoundary().mLeft );
778 PixelSize rightFadeBoundary(testValue);
779 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_RIGHT), testValue);
780 DALI_TEST_CHECK( rightFadeBoundary == view.GetFadeBoundary().mRight );
783 PixelSize topFadeBoundary(testValue);
784 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_TOP), testValue);
785 DALI_TEST_CHECK( topFadeBoundary == view.GetFadeBoundary().mTop );
788 PixelSize bottomFadeBoundary(testValue);
789 view.SetProperty(view.GetPropertyIndex(PROPERTY_FADE_BOUNDARY_BOTTOM), testValue);
790 DALI_TEST_CHECK( bottomFadeBoundary == view.GetFadeBoundary().mBottom );
792 //Test Line height offset property
793 float testOffsetValue = 14.04f;
794 view.SetProperty(view.GetPropertyIndex(PROPERTY_LINE_HEIGHT_OFFSET), testOffsetValue);
795 DALI_TEST_CHECK( PointSize(testOffsetValue) == view.GetLineHeightOffset() );
797 //Test alignment property
798 view.SetProperty(view.GetPropertyIndex(PROPERTY_HORIZONTAL_ALIGNMENT), "HorizontalLeft");
799 view.SetProperty(view.GetPropertyIndex(PROPERTY_VERTICAL_ALIGNMENT), "VerticalTop");
800 DALI_TEST_CHECK( (Toolkit::Alignment::HorizontalLeft | Toolkit::Alignment::VerticalTop) == view.GetTextAlignment() );
803 static void UtcDaliTextViewSetSortModifier()
805 tet_infoline("UtcDaliTextViewSetAndGetText: ");
806 ToolkitTestApplication application;
808 TextView view = TextView::New( "Hello world!" );
809 Stage::GetCurrent().Add( view );
811 view.SetSortModifier( 10.f );
812 view.SetSnapshotModeEnabled( false );
814 application.SendNotification();
815 application.Render();
817 DALI_TEST_EQUALS( RenderableActor::DownCast(view.GetChildAt(0)).GetSortModifier(), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
820 static void UtcDaliTextViewUnderlineText()
822 std::cout << "##############################" << std::endl;
824 tet_infoline("UtcDaliTextViewUnderlineText: ");
825 ToolkitTestApplication application;
827 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>" );
828 textView.SetSnapshotModeEnabled( false );
830 textView.SetSize( 150.f, 100.f );
832 Stage::GetCurrent().Add( textView );
834 application.SendNotification();
835 application.Render();
837 std::vector<float> positions;
838 positions.push_back( 6.448784f );
839 positions.push_back( 9.862847f );
840 positions.push_back( 13.276909f );
841 positions.push_back( 16.690973f );
842 positions.push_back( 13.276909f );
843 positions.push_back( 9.862847f );
844 positions.push_back( 6.448784f );
846 for( std::size_t index = 0, num = textView.GetChildCount(); index < num; ++index )
848 TextStyle style = TextActor::DownCast( textView.GetChildAt(index) ).GetTextStyle();
850 DALI_TEST_EQUALS( 4.17274f, style.GetUnderlineThickness(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
851 DALI_TEST_EQUALS( positions[index], style.GetUnderlinePosition(), Math::MACHINE_EPSILON_1000, TEST_LOCATION );