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/dali-toolkit.h>
27 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali-toolkit-test-suite-utils.h>
33 using namespace Toolkit;
35 static void Startup();
36 static void Cleanup();
40 static bool gObjectCreatedCallBackCalled;
42 static void TestCallback(BaseHandle handle)
44 Actor actor = Actor::DownCast(handle);
48 TextInput handle = TextInput::DownCast(actor);
51 gObjectCreatedCallBackCalled = true;
59 void (*tet_startup)() = Startup;
60 void (*tet_cleanup)() = Cleanup;
64 static bool gHasEndSignalBeenReceived;
65 static bool gHasStartSignalBeenReceived;
69 POSITIVE_TC_IDX = 0x01,
73 #define MAX_NUMBER_OF_TESTS 10000
75 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( UtcDaliTextInputConstruction, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliTextInputDownCast, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliTextInputGetText, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliTextInputGetMarkupText, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliTextInputSetMaxCharacterLength, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliTextInputSetAndGetNumberOfLines, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliTextInputGetNumberOfCharacters, POSITIVE_TC_IDX );
87 TEST_FUNCTION( UtcDaliTextInputSetAndGetPlaceholderText, POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliTextInputSetInitialText, POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliTextInputSetEditableAndIsEditable, POSITIVE_TC_IDX );
90 TEST_FUNCTION( UtcDaliTextInputSetEditOnTouch, POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliTextInputSetTextSelectable, POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliTextInputTextSelection, POSITIVE_TC_IDX );
94 TEST_FUNCTION( UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled, POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextInputSetAndGetBoundingRectangle, POSITIVE_TC_IDX );
96 TEST_FUNCTION( UtcDaliTextInputSetActiveStyle, POSITIVE_TC_IDX );
97 TEST_FUNCTION( UtcDaliTextInputApplyStyleToSelectedText, POSITIVE_TC_IDX );
98 TEST_FUNCTION( UtcDaliTextInputApplyStyleToAll, POSITIVE_TC_IDX );
99 TEST_FUNCTION( UtcDaliTextInputGetStyleAtCursor, POSITIVE_TC_IDX );
100 TEST_FUNCTION( UtcDaliTextInputSetAndGetTextAlignment, POSITIVE_TC_IDX );
101 TEST_FUNCTION( UtcDaliTextInputSetAndGetMultilinePolicy, POSITIVE_TC_IDX );
102 TEST_FUNCTION( UtcDaliTextInputSetAndGetExceedEnabled, POSITIVE_TC_IDX );
103 TEST_FUNCTION( UtcDaliTextInputSetSortModifier, POSITIVE_TC_IDX );
104 TEST_FUNCTION( UtcDaliTextInputSetAndGetSnapshotModeEnabled, POSITIVE_TC_IDX );
106 TEST_FUNCTION( UtcDaliTextInputEndSignalEmit, POSITIVE_TC_IDX );
107 TEST_FUNCTION( UtcDaliTextInputStartSignalEmit, POSITIVE_TC_IDX );
108 TEST_FUNCTION( UtcDaliTextInputExceedMaxCharacters, POSITIVE_TC_IDX );
109 TEST_FUNCTION( UtcDaliTextInputSetAndGetFadeBoundary, POSITIVE_TC_IDX );
110 TEST_FUNCTION( UtcDaliTextInputSetAndGetWidthExceedPolicy, POSITIVE_TC_IDX );
111 TEST_FUNCTION( UtcDaliTextInputSetAndGetHeightExceedPolicy, POSITIVE_TC_IDX );
112 TEST_FUNCTION( UtcDaliTextInputScroll, POSITIVE_TC_IDX );
114 // Called only once before first test is run.
115 static void Startup()
119 // Called only once after last test is run
120 static void Cleanup()
125 // Positive test case for a method
126 static void UtcDaliTextInputConstruction()
128 ToolkitTestApplication application;
130 tet_infoline("Testing New constructor");
132 TextInput textInput = TextInput::New();
133 DALI_TEST_CHECK(textInput);
135 //Additional check to ensure object is created by checking if it's registered
136 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
137 DALI_TEST_CHECK( registry );
139 gObjectCreatedCallBackCalled = false;
140 registry.ObjectCreatedSignal().Connect(&TestCallback);
142 TextInput textInput = TextInput::New();
144 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
148 static bool downCastToTextInput(Dali::Actor actor)
150 TextInput handle = TextInput::DownCast(actor);
153 tet_infoline("Downcasted to TextInput");
158 tet_infoline("Did not downcast to TextInput");
163 // Positive test case for a method
164 static void UtcDaliTextInputDownCast()
166 ToolkitTestApplication application;
168 TextInput textInput = TextInput::New();
170 tet_infoline("Testing Downcasting with a TextInput");
171 DALI_TEST_EQUALS(true,downCastToTextInput(textInput), TEST_LOCATION); // downcast a TextInput
173 Dali::TextActor badHandle = Dali::TextActor::New("test");
175 tet_infoline("Testing Downcasting with the wrong actor");
176 DALI_TEST_EQUALS(false, downCastToTextInput(badHandle), TEST_LOCATION); // downcast a TextActor to TextInput
179 // Positive test case for a method
180 static void UtcDaliTextInputGetText()
182 ToolkitTestApplication application;
184 tet_infoline("Testing GetText");
186 const std::string teststring = "test";
188 TextInput textInput = TextInput::New(); // create empty TextInput
190 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); // Get text which should be empty
192 textInput.SetInitialText(teststring);
194 DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be test string
198 static void UtcDaliTextInputGetMarkupText()
200 ToolkitTestApplication application;
202 tet_infoline("Testing retrieval of Markup text after style set");
204 const std::string markup = "<i>Text with italic style</i>" ;
205 const std::string teststring = "Text with italic style";
207 TextInput textInput = TextInput::New();
209 tet_infoline("Set initial text");
211 textInput.SetInitialText( teststring );
213 tet_infoline("Check initial text");
214 DALI_TEST_EQUALS( teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be empty
217 style.SetItalics( true );
219 tet_infoline("Apply style to TextInput");
220 textInput.ApplyStyleToAll( style );
222 tet_infoline("Retreive Markup Text");
223 const std::string retreivedMarkupString = textInput.GetMarkupText();
225 tet_infoline("Test Retreived text and Markup text match");
226 DALI_TEST_EQUALS( retreivedMarkupString , retreivedMarkupString, TEST_LOCATION);
229 // Positive test case for a method
230 static void UtcDaliTextInputSetMaxCharacterLength()
232 ToolkitTestApplication application;
234 tet_infoline("Testing Setting of max characters");
236 const int maxChars = 4;
237 const char* testChar = "v";
239 TextInput textInput = TextInput::New(); // create empty TextInput
241 Stage::GetCurrent().Add(textInput);
243 application.SendNotification();
244 application.Render();
246 textInput.SetMaxCharacterLength(maxChars);
248 Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down );
250 std::string testString = "";
252 tet_infoline("Starting editmode");
253 textInput.SetEditable( true );
255 tet_infoline("Sending Key Events");
256 // Send max number of characters
257 for (int i=0; i < maxChars; i++)
259 application.ProcessEvent( event );
260 testString.append(testChar);
263 tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
265 DALI_TEST_EQUALS(testString, textInput.GetText(), TEST_LOCATION);
267 tet_infoline("Sending Key Event which exceeds max characters");
269 application.ProcessEvent(event); // try to append additional character
271 DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
273 tet_infoline("Increase max characters limit");
275 textInput.SetMaxCharacterLength(maxChars+1); // increment max characters by 1
277 tet_infoline("Send character again which should now fit");
278 application.ProcessEvent(event); // append additional character
279 testString.append(testChar);
281 DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
285 static void UtcDaliTextInputSetAndGetNumberOfLines()
287 ToolkitTestApplication application;
289 tet_infoline("Ensuring API for setting and getting max number of lines is correct");
291 TextInput textInput = TextInput::New(); // create empty TextInput
293 unsigned int numberOfLines = 1;
295 textInput.SetNumberOfLinesLimit( numberOfLines );
297 DALI_TEST_EQUALS(numberOfLines ,textInput.GetNumberOfLinesLimit(), TEST_LOCATION);
300 static void UtcDaliTextInputGetNumberOfCharacters()
302 ToolkitTestApplication application;
304 tet_infoline("Testing Getting number of characters");
306 const std::string initialString = "initial text";
307 const std::string newInitialString = "initial text new";
309 TextInput textInput = TextInput::New(); // create empty TextInput
311 textInput.SetInitialText( initialString );
313 tet_infoline("Testing TextInput contains correct number of characters ");
315 DALI_TEST_EQUALS( initialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
317 tet_infoline("Testing TextInput contains correct number of characters second phase ");
319 textInput.SetInitialText( newInitialString );
321 DALI_TEST_EQUALS( newInitialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
324 static void UtcDaliTextInputSetAndGetPlaceholderText()
326 ToolkitTestApplication application;
328 tet_infoline("Testing Setting of PlaceholderText");
330 const std::string initialString = "initial text";
331 const std::string placeholderString = "placeholder";
333 TextInput textInput = TextInput::New(); // create empty TextInput
335 tet_infoline("Testing TextInput is empty at creation ");
337 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
339 tet_infoline("Set placeholder text");
341 textInput.SetPlaceholderText( placeholderString );
343 tet_infoline("Testing TextInput contains placeholder text");
345 DALI_TEST_EQUALS( placeholderString , textInput.GetPlaceholderText(), TEST_LOCATION);
347 tet_infoline("Set initial text which should replace placeholder text");
349 textInput.SetInitialText( initialString );
351 tet_infoline("Testing TextInput contains initial text when placeholder text set");
353 DALI_TEST_EQUALS( initialString,textInput.GetText(), TEST_LOCATION);
356 // Positive test case for a method
357 static void UtcDaliTextInputSetInitialText()
359 ToolkitTestApplication application;
361 tet_infoline("Testing Setting of Initial Text");
363 const std::string teststring = "test";
365 TextInput textInput = TextInput::New(); // create empty TextInput
367 tet_infoline("Testing TextInput is empty at creation ");
369 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
371 tet_infoline("Set text to TextInput");
373 textInput.SetInitialText(teststring);
375 tet_infoline("Test TextInput contains set text");
377 DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION);
380 static void UtcDaliTextInputSetEditableAndIsEditable()
382 ToolkitTestApplication application;
384 tet_infoline("Testing SetEditable And IsEditable");
386 const std::string initialString = "initial text";
388 TextInput textInput = TextInput::New(); // create empty TextInput
390 Stage::GetCurrent().Add(textInput);
392 textInput.SetInitialText( initialString );
394 application.SendNotification();
395 application.Render();
397 bool editableStateFalse ( false );
398 bool editableStateTrue ( true );
400 textInput.SetEditable ( editableStateFalse );
401 DALI_TEST_EQUALS( editableStateFalse, textInput.IsEditable() , TEST_LOCATION);
403 textInput.SetEditable ( editableStateTrue );
404 DALI_TEST_EQUALS( editableStateTrue, textInput.IsEditable() , TEST_LOCATION);
407 static void UtcDaliTextInputSetEditOnTouch()
409 ToolkitTestApplication application;
411 tet_infoline("Testing SetEditOnTouch And IsEditOnTouch");
413 TextInput textInput = TextInput::New();
415 bool editableOnTouchOn ( true );
416 bool editableOnTouchOff( false );
418 tet_infoline("Testing SetEditOnTouch disabled");
419 textInput.SetEditOnTouch ( editableOnTouchOff );
420 DALI_TEST_EQUALS( editableOnTouchOff, textInput.IsEditOnTouch() , TEST_LOCATION);
422 tet_infoline("Testing SetEditOnTouch enabled");
423 textInput.SetEditOnTouch ( editableOnTouchOn );
424 DALI_TEST_EQUALS( editableOnTouchOn, textInput.IsEditOnTouch() , TEST_LOCATION);
427 static void UtcDaliTextInputSetTextSelectable()
429 ToolkitTestApplication application;
431 tet_infoline("Testing SetTextSelectable and IsTextSelectable");
433 const std::string initialString = "initial text";
435 TextInput textInput = TextInput::New();
436 textInput.SetInitialText( initialString );
438 tet_infoline("Testing SetTextSelectable");
439 textInput.SetTextSelectable();
440 DALI_TEST_EQUALS( true, textInput.IsTextSelectable() , TEST_LOCATION);
441 textInput.SetTextSelectable( false );
442 DALI_TEST_EQUALS( false, textInput.IsTextSelectable() , TEST_LOCATION);
445 static void UtcDaliTextInputTextSelection()
447 ToolkitTestApplication application;
449 tet_infoline("Testing Text Selection");
451 const std::string initialString = "initial text";
453 TextInput textInput = TextInput::New();
454 textInput.SetInitialText( initialString );
456 Stage::GetCurrent().Add(textInput);
458 application.SendNotification();
459 application.Render();
461 textInput.SetEditable( true );
463 tet_infoline("Testing IsTextSelected negative");
464 DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
466 textInput.SelectText(1,7);
467 DALI_TEST_EQUALS( true, textInput.IsTextSelected(), TEST_LOCATION);
469 textInput.DeSelectText();
470 DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
474 static void UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled()
476 ToolkitTestApplication application;
478 TextInput textInput = TextInput::New();
480 bool grabHandleState = false;
482 textInput.EnableGrabHandle( grabHandleState );
484 DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
486 grabHandleState = true;
487 textInput.EnableGrabHandle( grabHandleState );
489 DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
493 static void UtcDaliTextInputSetAndGetBoundingRectangle()
495 ToolkitTestApplication application;
497 TextInput textInput = TextInput::New();
499 Stage::GetCurrent().Add(textInput);
500 Vector2 stageSize = Stage::GetCurrent().GetSize();
502 const Rect<float> boundingRectangle( 100.0f, 100.0f, stageSize.width, stageSize.height );
504 textInput.SetBoundingRectangle( boundingRectangle );
506 const Rect<float> retreievedBoundingRectangle = textInput.GetBoundingRectangle();
508 DALI_TEST_EQUALS( boundingRectangle.x, retreievedBoundingRectangle.x, TEST_LOCATION);
509 DALI_TEST_EQUALS( boundingRectangle.y, retreievedBoundingRectangle.y, TEST_LOCATION);
510 DALI_TEST_EQUALS( boundingRectangle.width, retreievedBoundingRectangle.width, TEST_LOCATION);
511 DALI_TEST_EQUALS( boundingRectangle.height, retreievedBoundingRectangle.height, TEST_LOCATION);
514 static void UtcDaliTextInputSetActiveStyle()
516 ToolkitTestApplication application;
518 tet_infoline("Testing Setting of Style to newly added text");
520 TextInput textInput = TextInput::New(); // create empty TextInput
522 Stage::GetCurrent().Add(textInput);
524 const std::string styledString = "Test String<i>ab</i>" ;
525 const std::string plainString = "Test String";
526 textInput.SetInitialText( plainString );
528 application.SendNotification();
529 application.Render();
531 textInput.SetEditable(true);
533 std::string retreivedMarkupString = textInput.GetMarkupText();
535 tet_infoline("Confirm markup text is a plain string ");
536 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
539 style.SetItalics( true );
541 tet_infoline("Apply style to TextInput");
542 textInput.SetActiveStyle( style );
544 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
545 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
547 application.SendNotification();
548 application.Render();
550 application.ProcessEvent(eventA);
551 application.SendNotification();
552 application.Render();
554 application.ProcessEvent(eventB);
555 application.SendNotification();
556 application.Render();
558 retreivedMarkupString = textInput.GetMarkupText();
560 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
563 static void UtcDaliTextInputApplyStyleToSelectedText()
565 ToolkitTestApplication application;
567 tet_infoline("Testing application of style to selected text ");
569 TextInput textInput = TextInput::New(); // create empty TextInput
571 Stage::GetCurrent().Add(textInput);
573 const std::string styledString = "Test <i>String</i> to style";
574 const std::string plainString = "Test String to style";
575 textInput.SetInitialText( plainString );
577 application.SendNotification();
578 application.Render();
580 textInput.SetEditable(true);
582 std::string retreivedMarkupString = textInput.GetMarkupText();
584 tet_infoline("Confirm markup text is a plain string ");
585 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
588 style.SetItalics( true );
590 textInput.SelectText( 5, 11 );
592 tet_infoline("Apply style to selected text");
593 textInput.ApplyStyle( style );
595 application.Render();
597 retreivedMarkupString = textInput.GetMarkupText();
599 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
602 static void UtcDaliTextInputApplyStyleToAll()
604 ToolkitTestApplication application;
606 tet_infoline("Testing application of style to all text ");
608 TextInput textInput = TextInput::New(); // create empty TextInput
610 Stage::GetCurrent().Add(textInput);
612 const std::string styledString = "<i>Test String to style</i>";
613 const std::string plainString = "Test String to style";
614 textInput.SetInitialText( plainString );
616 application.SendNotification();
617 application.Render();
619 textInput.SetEditable(true);
621 std::string retreivedMarkupString = textInput.GetMarkupText();
623 tet_infoline("Confirm markup text is a plain string ");
624 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
627 style.SetItalics( true );
629 tet_infoline("Apply style to all text");
630 textInput.ApplyStyleToAll( style );
632 application.Render();
634 retreivedMarkupString = textInput.GetMarkupText();
636 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
639 static void UtcDaliTextInputGetStyleAtCursor()
641 ToolkitTestApplication application;
643 tet_infoline("Test getting style at cursor");
645 TextInput textInput = TextInput::New(); // create empty TextInput
647 Stage::GetCurrent().Add(textInput);
649 const std::string styledString = "Test Stringa<i>b</i>" ;
650 const std::string plainString = "Test String";
651 textInput.SetInitialText( plainString );
653 application.SendNotification();
654 application.Render();
656 textInput.SetEditable(true);
658 tet_infoline("Confirm style at cursor is default(plain)");
660 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
661 application.ProcessEvent(eventA);
662 application.SendNotification();
663 application.Render();
665 TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
667 DALI_TEST_CHECK( style == retreivedStyleAtCursor );
668 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetItalics() );
670 tet_infoline("Set style before adding new character");
671 style.SetItalics( true );
672 textInput.SetActiveStyle( style );
674 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
675 application.ProcessEvent(eventB);
676 application.SendNotification();
677 application.Render();
679 tet_infoline("Confirm style at cursor is correct style");
680 retreivedStyleAtCursor = textInput.GetStyleAtCursor();
682 DALI_TEST_CHECK( retreivedStyleAtCursor.GetItalics() );
684 tet_infoline("Confirm style at cursor is not a style that was not set");
685 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetUnderline() );
687 tet_infoline("Confirm markup text is correct");
688 DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
694 static void UtcDaliTextInputSetAndGetTextAlignment()
696 ToolkitTestApplication application;
698 TextInput textInput = TextInput::New();
699 textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
701 bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
703 DALI_TEST_CHECK( result );
705 result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
707 DALI_TEST_CHECK( !result );
710 static void UtcDaliTextInputSetAndGetMultilinePolicy()
712 ToolkitTestApplication application;
714 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
715 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
717 TextInput textInput = TextInput::New();
718 Stage::GetCurrent().Add(textInput);
719 textInput.SetInitialText( "Hello world!" );
721 for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
723 textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
725 DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
729 static void UtcDaliTextInputSetAndGetExceedEnabled()
731 ToolkitTestApplication application;
733 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
734 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
736 TextInput textInput = TextInput::New();
737 Stage::GetCurrent().Add(textInput);
738 textInput.SetInitialText( "Hello world!" );
740 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
742 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
744 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
748 static void UtcDaliTextInputSetSortModifier()
750 tet_infoline("Testing SetSortModifier does not cause TextInput failure");
752 ToolkitTestApplication application;
754 TextInput textInput = TextInput::New();
756 const float offsetToUse = 1.5f;
758 textInput.SetSortModifier( offsetToUse );
760 DALI_TEST_CHECK( textInput );
763 static void UtcDaliTextInputSetAndGetSnapshotModeEnabled()
765 ToolkitTestApplication application;
767 tet_infoline("Testing SetSnapshotModeEnabled and IsSnapshotModeEnabled");
769 TextInput textInput = TextInput::New(); // create empty TextInput
770 bool snapshotMode( true );
771 textInput.SetSnapshotModeEnabled( snapshotMode );
773 DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
775 snapshotMode = false;
776 textInput.SetSnapshotModeEnabled( snapshotMode );
778 DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
781 // Callback test function
782 void OnEndInput(TextInput textInput)
784 gHasEndSignalBeenReceived = true;
787 static void UtcDaliTextInputEndSignalEmit()
789 ToolkitTestApplication application;
791 tet_infoline("Testing Set editable false emits end signal");
793 TextInput textInput = TextInput::New(); // create empty TextInput
795 Stage::GetCurrent().Add(textInput);
797 textInput.InputFinishedSignal().Connect( &OnEndInput );
799 textInput.SetEditable(true) ;
801 gHasEndSignalBeenReceived = false;
803 textInput.SetEditable(false) ;
805 DALI_TEST_EQUALS(true, gHasEndSignalBeenReceived, TEST_LOCATION);
809 // Callback test function
810 void OnStartInput(TextInput textInput)
812 gHasStartSignalBeenReceived = true;
815 static void UtcDaliTextInputStartSignalEmit()
817 ToolkitTestApplication application;
819 tet_infoline("Testing SetEditable emits start signal");
821 TextInput textInput = TextInput::New(); // create empty TextInput
823 Stage::GetCurrent().Add(textInput);
825 textInput.InputStartedSignal().Connect( &OnStartInput );
827 gHasStartSignalBeenReceived = false;
829 textInput.SetEditable(true); // Set editable first time
831 DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
833 gHasStartSignalBeenReceived = false;
835 textInput.SetEditable(true); // Set editable second time, signal should not be sent again.
837 DALI_TEST_EQUALS(false, gHasStartSignalBeenReceived, TEST_LOCATION);
839 textInput.SetEditable(false);
841 gHasStartSignalBeenReceived = false;
843 textInput.SetEditable(true); // Set editable again
845 DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
850 static void UtcDaliTextInputExceedMaxCharacters()
852 ToolkitTestApplication application;
854 tet_infoline("Testing Max characters is obeyed when inputting key events ");
856 TextInput textInput = TextInput::New(); // create empty TextInput
858 Stage::GetCurrent().Add(textInput);
860 textInput.SetMaxCharacterLength(4);
862 textInput.SetInitialText("");
864 textInput.SetEditable(true);
866 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
867 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
869 application.SendNotification();
870 application.Render();
872 application.ProcessEvent(eventA);
873 application.ProcessEvent(eventB);
874 application.ProcessEvent(eventA);
875 application.ProcessEvent(eventB);
877 application.ProcessEvent(eventA);
878 application.ProcessEvent(eventB);
880 tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
882 DALI_TEST_EQUALS("abab",textInput.GetText(), TEST_LOCATION); // Get text which should be only 4 characters
887 static void UtcDaliTextInputSetAndGetFadeBoundary()
889 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
891 ToolkitTestApplication application;
893 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
895 TextInput textInput = TextInput::New();
896 textInput.SetInitialText( "Hello world!" );
898 textInput.SetFadeBoundary( fadeBoundary );
900 TextView::FadeBoundary fadeBoundary2 = textInput.GetFadeBoundary();
902 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
903 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
904 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
905 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
908 static void UtcDaliTextInputSetAndGetWidthExceedPolicy()
910 ToolkitTestApplication application;
912 tet_infoline("UtcDaliTextInputSetAndGetWidthExceedPolicy: ");
914 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
915 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
917 TextInput textInput = TextInput::New();
918 textInput.SetInitialText( "Hello world!" );
920 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
922 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
924 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
928 static void UtcDaliTextInputSetAndGetHeightExceedPolicy()
930 ToolkitTestApplication application;
932 tet_infoline("UtcDaliTextInputSetAndGetHeightExceedPolicy: ");
934 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
935 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
937 TextInput textInput = TextInput::New();
938 textInput.SetInitialText( "Hello world!" );
940 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
942 textInput.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
944 DALI_TEST_EQUALS( textInput.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
948 static void UtcDaliTextInputScroll()
950 tet_infoline("UtcDaliTextInputScroll: ");
951 ToolkitTestApplication application;
953 // Avoids the frame buffer texture to throw an exception.
954 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
956 TextInput view = TextInput::New();
957 view.SetMultilinePolicy( TextView::SplitByNewLineChar );
958 view.SetWidthExceedPolicy( TextView::Original );
959 view.SetHeightExceedPolicy( TextView::Original );
960 view.SetTextAlignment( static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ) );
961 view.SetInitialText( "Hello world! This is a scroll test." );
962 view.SetSize( 100.f, 100.f );
963 view.SetSnapshotModeEnabled( false );
965 Stage::GetCurrent().Add( view );
967 application.SendNotification();
968 application.Render();
970 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
972 view.SetScrollEnabled( true );
974 DALI_TEST_CHECK( view.IsScrollEnabled() );
975 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
977 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
979 application.SendNotification();
980 application.Render();
982 const Vector2& scrollPosition = view.GetScrollPosition();
983 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );