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/dali-toolkit.h>
26 #include <dali/integration-api/events/key-event-integ.h>
29 #include <dali-toolkit-test-suite-utils.h>
32 using namespace Toolkit;
34 static void Startup();
35 static void Cleanup();
39 static bool gObjectCreatedCallBackCalled;
41 static void TestCallback(BaseHandle handle)
43 Actor actor = Actor::DownCast(handle);
47 TextInput handle = TextInput::DownCast(actor);
50 gObjectCreatedCallBackCalled = true;
58 void (*tet_startup)() = Startup;
59 void (*tet_cleanup)() = Cleanup;
63 static bool gHasEndSignalBeenReceived;
64 static bool gHasStartSignalBeenReceived;
68 POSITIVE_TC_IDX = 0x01,
72 #define MAX_NUMBER_OF_TESTS 10000
74 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
78 // Add test functionality for all APIs in the class (Positive and Negative)
79 TEST_FUNCTION( UtcDaliTextInputConstruction, POSITIVE_TC_IDX );
80 TEST_FUNCTION( UtcDaliTextInputDownCast, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliTextInputGetText, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliTextInputGetMarkupText, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliTextInputSetMaxCharacterLength, POSITIVE_TC_IDX );
84 TEST_FUNCTION( UtcDaliTextInputSetAndGetNumberOfLines, POSITIVE_TC_IDX );
85 TEST_FUNCTION( UtcDaliTextInputGetNumberOfCharacters, POSITIVE_TC_IDX );
86 TEST_FUNCTION( UtcDaliTextInputSetAndGetPlaceholderText, POSITIVE_TC_IDX );
87 TEST_FUNCTION( UtcDaliTextInputSetInitialText, POSITIVE_TC_IDX );
88 TEST_FUNCTION( UtcDaliTextInputSetEditableAndIsEditable, POSITIVE_TC_IDX );
89 TEST_FUNCTION( UtcDaliTextInputSetEditOnTouch, POSITIVE_TC_IDX );
91 TEST_FUNCTION( UtcDaliTextInputSetTextSelectable, POSITIVE_TC_IDX );
92 TEST_FUNCTION( UtcDaliTextInputTextSelection, POSITIVE_TC_IDX );
93 TEST_FUNCTION( UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled, POSITIVE_TC_IDX );
94 TEST_FUNCTION( UtcDaliTextInputSetAndGetBoundingRectangle, POSITIVE_TC_IDX );
95 TEST_FUNCTION( UtcDaliTextInputSetActiveStyle, POSITIVE_TC_IDX );
96 TEST_FUNCTION( UtcDaliTextInputApplyStyleToSelectedText, POSITIVE_TC_IDX );
97 TEST_FUNCTION( UtcDaliTextInputApplyStyleToAll, POSITIVE_TC_IDX );
98 TEST_FUNCTION( UtcDaliTextInputGetStyleAtCursor, POSITIVE_TC_IDX );
99 TEST_FUNCTION( UtcDaliTextInputSetAndGetTextAlignment, POSITIVE_TC_IDX );
100 TEST_FUNCTION( UtcDaliTextInputSetAndGetMultilinePolicy, POSITIVE_TC_IDX );
101 TEST_FUNCTION( UtcDaliTextInputSetAndGetExceedEnabled, POSITIVE_TC_IDX );
102 TEST_FUNCTION( UtcDaliTextInputSetSortModifier, POSITIVE_TC_IDX );
103 TEST_FUNCTION( UtcDaliTextInputSetAndGetSnapshotModeEnabled, POSITIVE_TC_IDX );
105 TEST_FUNCTION( UtcDaliTextInputEndSignalEmit, POSITIVE_TC_IDX );
106 TEST_FUNCTION( UtcDaliTextInputStartSignalEmit, POSITIVE_TC_IDX );
107 TEST_FUNCTION( UtcDaliTextInputExceedMaxCharacters, POSITIVE_TC_IDX );
108 TEST_FUNCTION( UtcDaliTextInputSetAndGetFadeBoundary, POSITIVE_TC_IDX );
109 TEST_FUNCTION( UtcDaliTextInputSetAndGetWidthExceedPolicy, POSITIVE_TC_IDX );
110 TEST_FUNCTION( UtcDaliTextInputSetAndGetHeightExceedPolicy, POSITIVE_TC_IDX );
111 TEST_FUNCTION( UtcDaliTextInputScroll, POSITIVE_TC_IDX );
113 // Called only once before first test is run.
114 static void Startup()
118 // Called only once after last test is run
119 static void Cleanup()
124 // Positive test case for a method
125 static void UtcDaliTextInputConstruction()
127 ToolkitTestApplication application;
129 tet_infoline("Testing New constructor");
131 TextInput textInput = TextInput::New();
132 DALI_TEST_CHECK(textInput);
134 //Additional check to ensure object is created by checking if it's registered
135 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
136 DALI_TEST_CHECK( registry );
138 gObjectCreatedCallBackCalled = false;
139 registry.ObjectCreatedSignal().Connect(&TestCallback);
141 TextInput textInput = TextInput::New();
143 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
147 static bool downCastToTextInput(Dali::Actor actor)
149 TextInput handle = TextInput::DownCast(actor);
152 tet_infoline("Downcasted to TextInput");
157 tet_infoline("Did not downcast to TextInput");
162 // Positive test case for a method
163 static void UtcDaliTextInputDownCast()
165 ToolkitTestApplication application;
167 TextInput textInput = TextInput::New();
169 tet_infoline("Testing Downcasting with a TextInput");
170 DALI_TEST_EQUALS(true,downCastToTextInput(textInput), TEST_LOCATION); // downcast a TextInput
172 Dali::TextActor badHandle = Dali::TextActor::New("test");
174 tet_infoline("Testing Downcasting with the wrong actor");
175 DALI_TEST_EQUALS(false, downCastToTextInput(badHandle), TEST_LOCATION); // downcast a TextActor to TextInput
178 // Positive test case for a method
179 static void UtcDaliTextInputGetText()
181 ToolkitTestApplication application;
183 tet_infoline("Testing GetText");
185 const std::string teststring = "test";
187 TextInput textInput = TextInput::New(); // create empty TextInput
189 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); // Get text which should be empty
191 textInput.SetInitialText(teststring);
193 DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be test string
197 static void UtcDaliTextInputGetMarkupText()
199 ToolkitTestApplication application;
201 tet_infoline("Testing retrieval of Markup text after style set");
203 const std::string markup = "<i>Text with italic style</i>" ;
204 const std::string teststring = "Text with italic style";
206 TextInput textInput = TextInput::New();
208 tet_infoline("Set initial text");
210 textInput.SetInitialText( teststring );
212 tet_infoline("Check initial text");
213 DALI_TEST_EQUALS( teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be empty
216 style.SetItalics( true );
218 tet_infoline("Apply style to TextInput");
219 textInput.ApplyStyleToAll( style );
221 tet_infoline("Retreive Markup Text");
222 const std::string retreivedMarkupString = textInput.GetMarkupText();
224 tet_infoline("Test Retreived text and Markup text match");
225 DALI_TEST_EQUALS( retreivedMarkupString , retreivedMarkupString, TEST_LOCATION);
228 // Positive test case for a method
229 static void UtcDaliTextInputSetMaxCharacterLength()
231 ToolkitTestApplication application;
233 tet_infoline("Testing Setting of max characters");
235 const int maxChars = 4;
236 const char* testChar = "v";
238 TextInput textInput = TextInput::New(); // create empty TextInput
240 Stage::GetCurrent().Add(textInput);
242 application.SendNotification();
243 application.Render();
245 textInput.SetMaxCharacterLength(maxChars);
247 Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down );
249 std::string testString = "";
251 tet_infoline("Starting editmode");
252 textInput.SetEditable( true );
254 tet_infoline("Sending Key Events");
255 // Send max number of characters
256 for (int i=0; i < maxChars; i++)
258 application.ProcessEvent( event );
259 testString.append(testChar);
262 tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
264 DALI_TEST_EQUALS(testString, textInput.GetText(), TEST_LOCATION);
266 tet_infoline("Sending Key Event which exceeds max characters");
268 application.ProcessEvent(event); // try to append additional character
270 DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
272 tet_infoline("Increase max characters limit");
274 textInput.SetMaxCharacterLength(maxChars+1); // increment max characters by 1
276 tet_infoline("Send character again which should now fit");
277 application.ProcessEvent(event); // append additional character
278 testString.append(testChar);
280 DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
284 static void UtcDaliTextInputSetAndGetNumberOfLines()
286 ToolkitTestApplication application;
288 tet_infoline("Ensuring API for setting and getting max number of lines is correct");
290 TextInput textInput = TextInput::New(); // create empty TextInput
292 unsigned int numberOfLines = 1;
294 textInput.SetNumberOfLinesLimit( numberOfLines );
296 DALI_TEST_EQUALS(numberOfLines ,textInput.GetNumberOfLinesLimit(), TEST_LOCATION);
299 static void UtcDaliTextInputGetNumberOfCharacters()
301 ToolkitTestApplication application;
303 tet_infoline("Testing Getting number of characters");
305 const std::string initialString = "initial text";
306 const std::string newInitialString = "initial text new";
308 TextInput textInput = TextInput::New(); // create empty TextInput
310 textInput.SetInitialText( initialString );
312 tet_infoline("Testing TextInput contains correct number of characters ");
314 DALI_TEST_EQUALS( initialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
316 tet_infoline("Testing TextInput contains correct number of characters second phase ");
318 textInput.SetInitialText( newInitialString );
320 DALI_TEST_EQUALS( newInitialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
323 static void UtcDaliTextInputSetAndGetPlaceholderText()
325 ToolkitTestApplication application;
327 tet_infoline("Testing Setting of PlaceholderText");
329 const std::string initialString = "initial text";
330 const std::string placeholderString = "placeholder";
332 TextInput textInput = TextInput::New(); // create empty TextInput
334 tet_infoline("Testing TextInput is empty at creation ");
336 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
338 tet_infoline("Set placeholder text");
340 textInput.SetPlaceholderText( placeholderString );
342 tet_infoline("Testing TextInput contains placeholder text");
344 DALI_TEST_EQUALS( placeholderString , textInput.GetPlaceholderText(), TEST_LOCATION);
346 tet_infoline("Set initial text which should replace placeholder text");
348 textInput.SetInitialText( initialString );
350 tet_infoline("Testing TextInput contains initial text when placeholder text set");
352 DALI_TEST_EQUALS( initialString,textInput.GetText(), TEST_LOCATION);
355 // Positive test case for a method
356 static void UtcDaliTextInputSetInitialText()
358 ToolkitTestApplication application;
360 tet_infoline("Testing Setting of Initial Text");
362 const std::string teststring = "test";
364 TextInput textInput = TextInput::New(); // create empty TextInput
366 tet_infoline("Testing TextInput is empty at creation ");
368 DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
370 tet_infoline("Set text to TextInput");
372 textInput.SetInitialText(teststring);
374 tet_infoline("Test TextInput contains set text");
376 DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION);
379 static void UtcDaliTextInputSetEditableAndIsEditable()
381 ToolkitTestApplication application;
383 tet_infoline("Testing SetEditable And IsEditable");
385 const std::string initialString = "initial text";
387 TextInput textInput = TextInput::New(); // create empty TextInput
389 Stage::GetCurrent().Add(textInput);
391 textInput.SetInitialText( initialString );
393 application.SendNotification();
394 application.Render();
396 bool editableStateFalse ( false );
397 bool editableStateTrue ( true );
399 textInput.SetEditable ( editableStateFalse );
400 DALI_TEST_EQUALS( editableStateFalse, textInput.IsEditable() , TEST_LOCATION);
402 textInput.SetEditable ( editableStateTrue );
403 DALI_TEST_EQUALS( editableStateTrue, textInput.IsEditable() , TEST_LOCATION);
406 static void UtcDaliTextInputSetEditOnTouch()
408 ToolkitTestApplication application;
410 tet_infoline("Testing SetEditOnTouch And IsEditOnTouch");
412 TextInput textInput = TextInput::New();
414 bool editableOnTouchOn ( true );
415 bool editableOnTouchOff( false );
417 tet_infoline("Testing SetEditOnTouch disabled");
418 textInput.SetEditOnTouch ( editableOnTouchOff );
419 DALI_TEST_EQUALS( editableOnTouchOff, textInput.IsEditOnTouch() , TEST_LOCATION);
421 tet_infoline("Testing SetEditOnTouch enabled");
422 textInput.SetEditOnTouch ( editableOnTouchOn );
423 DALI_TEST_EQUALS( editableOnTouchOn, textInput.IsEditOnTouch() , TEST_LOCATION);
426 static void UtcDaliTextInputSetTextSelectable()
428 ToolkitTestApplication application;
430 tet_infoline("Testing SetTextSelectable and IsTextSelectable");
432 const std::string initialString = "initial text";
434 TextInput textInput = TextInput::New();
435 textInput.SetInitialText( initialString );
437 tet_infoline("Testing SetTextSelectable");
438 textInput.SetTextSelectable();
439 DALI_TEST_EQUALS( true, textInput.IsTextSelectable() , TEST_LOCATION);
440 textInput.SetTextSelectable( false );
441 DALI_TEST_EQUALS( false, textInput.IsTextSelectable() , TEST_LOCATION);
444 static void UtcDaliTextInputTextSelection()
446 ToolkitTestApplication application;
448 tet_infoline("Testing Text Selection");
450 const std::string initialString = "initial text";
452 TextInput textInput = TextInput::New();
453 textInput.SetInitialText( initialString );
455 Stage::GetCurrent().Add(textInput);
457 application.SendNotification();
458 application.Render();
460 textInput.SetEditable( true );
462 tet_infoline("Testing IsTextSelected negative");
463 DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
465 textInput.SelectText(1,7);
466 DALI_TEST_EQUALS( true, textInput.IsTextSelected(), TEST_LOCATION);
468 textInput.DeSelectText();
469 DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
473 static void UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled()
475 ToolkitTestApplication application;
477 TextInput textInput = TextInput::New();
479 bool grabHandleState = false;
481 textInput.EnableGrabHandle( grabHandleState );
483 DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
485 grabHandleState = true;
486 textInput.EnableGrabHandle( grabHandleState );
488 DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
492 static void UtcDaliTextInputSetAndGetBoundingRectangle()
494 ToolkitTestApplication application;
496 TextInput textInput = TextInput::New();
498 Stage::GetCurrent().Add(textInput);
499 Vector2 stageSize = Stage::GetCurrent().GetSize();
501 const Rect<float> boundingRectangle( 100.0f, 100.0f, stageSize.width, stageSize.height );
503 textInput.SetBoundingRectangle( boundingRectangle );
505 const Rect<float> retreievedBoundingRectangle = textInput.GetBoundingRectangle();
507 DALI_TEST_EQUALS( boundingRectangle.x, retreievedBoundingRectangle.x, TEST_LOCATION);
508 DALI_TEST_EQUALS( boundingRectangle.y, retreievedBoundingRectangle.y, TEST_LOCATION);
509 DALI_TEST_EQUALS( boundingRectangle.width, retreievedBoundingRectangle.width, TEST_LOCATION);
510 DALI_TEST_EQUALS( boundingRectangle.height, retreievedBoundingRectangle.height, TEST_LOCATION);
513 static void UtcDaliTextInputSetActiveStyle()
515 ToolkitTestApplication application;
517 tet_infoline("Testing Setting of Style to newly added text");
519 TextInput textInput = TextInput::New(); // create empty TextInput
521 Stage::GetCurrent().Add(textInput);
523 const std::string styledString = "Test String<i>ab</i>" ;
524 const std::string plainString = "Test String";
525 textInput.SetInitialText( plainString );
527 application.SendNotification();
528 application.Render();
530 textInput.SetEditable(true);
532 std::string retreivedMarkupString = textInput.GetMarkupText();
534 tet_infoline("Confirm markup text is a plain string ");
535 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
538 style.SetItalics( true );
540 tet_infoline("Apply style to TextInput");
541 textInput.SetActiveStyle( style );
543 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
544 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
546 application.SendNotification();
547 application.Render();
549 application.ProcessEvent(eventA);
550 application.SendNotification();
551 application.Render();
553 application.ProcessEvent(eventB);
554 application.SendNotification();
555 application.Render();
557 retreivedMarkupString = textInput.GetMarkupText();
559 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
562 static void UtcDaliTextInputApplyStyleToSelectedText()
564 ToolkitTestApplication application;
566 tet_infoline("Testing application of style to selected text ");
568 TextInput textInput = TextInput::New(); // create empty TextInput
570 Stage::GetCurrent().Add(textInput);
572 const std::string styledString = "Test <i>String</i> to style";
573 const std::string plainString = "Test String to style";
574 textInput.SetInitialText( plainString );
576 application.SendNotification();
577 application.Render();
579 textInput.SetEditable(true);
581 std::string retreivedMarkupString = textInput.GetMarkupText();
583 tet_infoline("Confirm markup text is a plain string ");
584 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
587 style.SetItalics( true );
589 textInput.SelectText( 5, 11 );
591 tet_infoline("Apply style to selected text");
592 textInput.ApplyStyle( style );
594 application.Render();
596 retreivedMarkupString = textInput.GetMarkupText();
598 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
601 static void UtcDaliTextInputApplyStyleToAll()
603 ToolkitTestApplication application;
605 tet_infoline("Testing application of style to all text ");
607 TextInput textInput = TextInput::New(); // create empty TextInput
609 Stage::GetCurrent().Add(textInput);
611 const std::string styledString = "<i>Test String to style</i>";
612 const std::string plainString = "Test String to style";
613 textInput.SetInitialText( plainString );
615 application.SendNotification();
616 application.Render();
618 textInput.SetEditable(true);
620 std::string retreivedMarkupString = textInput.GetMarkupText();
622 tet_infoline("Confirm markup text is a plain string ");
623 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
626 style.SetItalics( true );
628 tet_infoline("Apply style to all text");
629 textInput.ApplyStyleToAll( style );
631 application.Render();
633 retreivedMarkupString = textInput.GetMarkupText();
635 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
638 static void UtcDaliTextInputGetStyleAtCursor()
640 ToolkitTestApplication application;
642 tet_infoline("Test getting style at cursor");
644 TextInput textInput = TextInput::New(); // create empty TextInput
646 Stage::GetCurrent().Add(textInput);
648 const std::string styledString = "Test Stringa<i>b</i>" ;
649 const std::string plainString = "Test String";
650 textInput.SetInitialText( plainString );
652 application.SendNotification();
653 application.Render();
655 textInput.SetEditable(true);
657 tet_infoline("Confirm style at cursor is default(plain)");
659 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
660 application.ProcessEvent(eventA);
661 application.SendNotification();
662 application.Render();
664 TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
666 DALI_TEST_CHECK( style == retreivedStyleAtCursor );
667 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetItalics() );
669 tet_infoline("Set style before adding new character");
670 style.SetItalics( true );
671 textInput.SetActiveStyle( style );
673 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
674 application.ProcessEvent(eventB);
675 application.SendNotification();
676 application.Render();
678 tet_infoline("Confirm style at cursor is correct style");
679 retreivedStyleAtCursor = textInput.GetStyleAtCursor();
681 DALI_TEST_CHECK( retreivedStyleAtCursor.GetItalics() );
683 tet_infoline("Confirm style at cursor is not a style that was not set");
684 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetUnderline() );
686 tet_infoline("Confirm markup text is correct");
687 DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
693 static void UtcDaliTextInputSetAndGetTextAlignment()
695 ToolkitTestApplication application;
697 TextInput textInput = TextInput::New();
698 textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
700 bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
702 DALI_TEST_CHECK( result );
704 result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
706 DALI_TEST_CHECK( !result );
709 static void UtcDaliTextInputSetAndGetMultilinePolicy()
711 ToolkitTestApplication application;
713 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
714 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
716 TextInput textInput = TextInput::New();
717 Stage::GetCurrent().Add(textInput);
718 textInput.SetInitialText( "Hello world!" );
720 for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
722 textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
724 DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
728 static void UtcDaliTextInputSetAndGetExceedEnabled()
730 ToolkitTestApplication application;
732 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
733 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
735 TextInput textInput = TextInput::New();
736 Stage::GetCurrent().Add(textInput);
737 textInput.SetInitialText( "Hello world!" );
739 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
741 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
743 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
747 static void UtcDaliTextInputSetSortModifier()
749 tet_infoline("Testing SetSortModifier does not cause TextInput failure");
751 ToolkitTestApplication application;
753 TextInput textInput = TextInput::New();
755 const float offsetToUse = 1.5f;
757 textInput.SetSortModifier( offsetToUse );
759 DALI_TEST_CHECK( textInput );
762 static void UtcDaliTextInputSetAndGetSnapshotModeEnabled()
764 ToolkitTestApplication application;
766 tet_infoline("Testing SetSnapshotModeEnabled and IsSnapshotModeEnabled");
768 TextInput textInput = TextInput::New(); // create empty TextInput
769 bool snapshotMode( true );
770 textInput.SetSnapshotModeEnabled( snapshotMode );
772 DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
774 snapshotMode = false;
775 textInput.SetSnapshotModeEnabled( snapshotMode );
777 DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
780 // Callback test function
781 void OnEndInput(TextInput textInput)
783 gHasEndSignalBeenReceived = true;
786 static void UtcDaliTextInputEndSignalEmit()
788 ToolkitTestApplication application;
790 tet_infoline("Testing Set editable false emits end signal");
792 TextInput textInput = TextInput::New(); // create empty TextInput
794 Stage::GetCurrent().Add(textInput);
796 textInput.InputFinishedSignal().Connect( &OnEndInput );
798 textInput.SetEditable(true) ;
800 gHasEndSignalBeenReceived = false;
802 textInput.SetEditable(false) ;
804 DALI_TEST_EQUALS(true, gHasEndSignalBeenReceived, TEST_LOCATION);
808 // Callback test function
809 void OnStartInput(TextInput textInput)
811 gHasStartSignalBeenReceived = true;
814 static void UtcDaliTextInputStartSignalEmit()
816 ToolkitTestApplication application;
818 tet_infoline("Testing SetEditable emits start signal");
820 TextInput textInput = TextInput::New(); // create empty TextInput
822 Stage::GetCurrent().Add(textInput);
824 textInput.InputStartedSignal().Connect( &OnStartInput );
826 gHasStartSignalBeenReceived = false;
828 textInput.SetEditable(true); // Set editable first time
830 DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
832 gHasStartSignalBeenReceived = false;
834 textInput.SetEditable(true); // Set editable second time, signal should not be sent again.
836 DALI_TEST_EQUALS(false, gHasStartSignalBeenReceived, TEST_LOCATION);
838 textInput.SetEditable(false);
840 gHasStartSignalBeenReceived = false;
842 textInput.SetEditable(true); // Set editable again
844 DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
849 static void UtcDaliTextInputExceedMaxCharacters()
851 ToolkitTestApplication application;
853 tet_infoline("Testing Max characters is obeyed when inputting key events ");
855 TextInput textInput = TextInput::New(); // create empty TextInput
857 Stage::GetCurrent().Add(textInput);
859 textInput.SetMaxCharacterLength(4);
861 textInput.SetInitialText("");
863 textInput.SetEditable(true);
865 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
866 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
868 application.SendNotification();
869 application.Render();
871 application.ProcessEvent(eventA);
872 application.ProcessEvent(eventB);
873 application.ProcessEvent(eventA);
874 application.ProcessEvent(eventB);
876 application.ProcessEvent(eventA);
877 application.ProcessEvent(eventB);
879 tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
881 DALI_TEST_EQUALS("abab",textInput.GetText(), TEST_LOCATION); // Get text which should be only 4 characters
886 static void UtcDaliTextInputSetAndGetFadeBoundary()
888 tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
890 ToolkitTestApplication application;
892 TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
894 TextInput textInput = TextInput::New();
895 textInput.SetInitialText( "Hello world!" );
897 textInput.SetFadeBoundary( fadeBoundary );
899 TextView::FadeBoundary fadeBoundary2 = textInput.GetFadeBoundary();
901 DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
902 DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
903 DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
904 DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
907 static void UtcDaliTextInputSetAndGetWidthExceedPolicy()
909 ToolkitTestApplication application;
911 tet_infoline("UtcDaliTextInputSetAndGetWidthExceedPolicy: ");
913 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
914 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
916 TextInput textInput = TextInput::New();
917 textInput.SetInitialText( "Hello world!" );
919 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
921 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
923 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
927 static void UtcDaliTextInputSetAndGetHeightExceedPolicy()
929 ToolkitTestApplication application;
931 tet_infoline("UtcDaliTextInputSetAndGetHeightExceedPolicy: ");
933 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
934 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
936 TextInput textInput = TextInput::New();
937 textInput.SetInitialText( "Hello world!" );
939 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
941 textInput.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
943 DALI_TEST_EQUALS( textInput.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
947 static void UtcDaliTextInputScroll()
949 tet_infoline("UtcDaliTextInputScroll: ");
950 ToolkitTestApplication application;
952 // Avoids the frame buffer texture to throw an exception.
953 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
955 TextInput view = TextInput::New();
956 view.SetMultilinePolicy( TextView::SplitByNewLineChar );
957 view.SetWidthExceedPolicy( TextView::Original );
958 view.SetHeightExceedPolicy( TextView::Original );
959 view.SetTextAlignment( static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ) );
960 view.SetInitialText( "Hello world! This is a scroll test." );
961 view.SetSize( 100.f, 100.f );
962 view.SetSnapshotModeEnabled( false );
964 Stage::GetCurrent().Add( view );
966 application.SendNotification();
967 application.Render();
969 DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
971 view.SetScrollEnabled( true );
973 DALI_TEST_CHECK( view.IsScrollEnabled() );
974 DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
976 view.SetScrollPosition( Vector2( 400.f, 400.f ) );
978 application.SendNotification();
979 application.Render();
981 const Vector2& scrollPosition = view.GetScrollPosition();
982 DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );