Remove redundant orientation settings as default camera already looks at stage
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextInput.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25
26 using namespace Dali;
27 using namespace Toolkit;
28
29 void utc_dali_toolkit_text_input_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_toolkit_text_input_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39 namespace
40 {
41 static bool gObjectCreatedCallBackCalled;
42
43 static void TestCallback(BaseHandle handle)
44 {
45   Actor actor = Actor::DownCast(handle);
46
47   if(actor)
48   {
49     TextInput handle = TextInput::DownCast(actor);
50      if (handle)
51      {
52        gObjectCreatedCallBackCalled = true;
53      }
54   }
55 }
56
57 static bool gHasEndSignalBeenReceived;
58 static bool gHasStartSignalBeenReceived;
59
60 // Callback test function
61 void OnStartInput(TextInput textInput)
62 {
63   gHasStartSignalBeenReceived = true;
64 }
65
66 // Callback test function
67 void OnEndInput(TextInput textInput)
68 {
69   gHasEndSignalBeenReceived = true;
70 }
71
72 }
73
74 // Positive test case for a method
75 int UtcDaliTextInputConstruction(void)
76 {
77   ToolkitTestApplication application;
78
79   tet_infoline("Testing New constructor");
80
81   TextInput textInput = TextInput::New();
82   DALI_TEST_CHECK(textInput);
83
84   //Additional check to ensure object is created by checking if it's registered
85   ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
86   DALI_TEST_CHECK( registry );
87
88   gObjectCreatedCallBackCalled = false;
89   registry.ObjectCreatedSignal().Connect(&TestCallback);
90   {
91     TextInput textInput = TextInput::New();
92   }
93   DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
94   END_TEST;
95 }
96
97
98 static bool downCastToTextInput(Dali::Actor actor)
99 {
100   TextInput handle = TextInput::DownCast(actor);
101   if (handle)
102   {
103     tet_infoline("Downcasted to TextInput");
104     return true;
105   }
106   else
107   {
108     tet_infoline("Did not downcast to TextInput");
109     return false;
110   }
111 }
112
113 // Positive test case for a method
114 int UtcDaliTextInputDownCast(void)
115 {
116   ToolkitTestApplication application;
117
118   TextInput textInput = TextInput::New();
119
120   tet_infoline("Testing Downcasting with a TextInput");
121   DALI_TEST_EQUALS(true,downCastToTextInput(textInput), TEST_LOCATION); // downcast a TextInput
122
123   Dali::TextActor badHandle = Dali::TextActor::New("test");
124
125   tet_infoline("Testing Downcasting with the wrong actor");
126   DALI_TEST_EQUALS(false, downCastToTextInput(badHandle), TEST_LOCATION); // downcast a TextActor to TextInput
127   END_TEST;
128 }
129
130 // Positive test case for a method
131 int UtcDaliTextInputGetText(void)
132 {
133   ToolkitTestApplication application;
134
135   tet_infoline("Testing GetText");
136
137   const std::string teststring = "test";
138
139   TextInput textInput = TextInput::New();  // create empty TextInput
140
141   DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION); // Get text which should be empty
142
143   textInput.SetInitialText(teststring);
144
145   DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be test string
146
147   END_TEST;
148 }
149
150 int UtcDaliTextInputGetMarkupText(void)
151 {
152   ToolkitTestApplication application;
153
154   tet_infoline("Testing retrieval of Markup text after style set");
155
156   const std::string markup = "<i>Text with italic style</i>" ;
157   const std::string teststring = "Text with italic style";
158
159   TextInput textInput = TextInput::New();
160
161   tet_infoline("Set initial text");
162
163   textInput.SetInitialText( teststring );
164
165   tet_infoline("Check initial text");
166   DALI_TEST_EQUALS( teststring,textInput.GetText(), TEST_LOCATION); // Get text which should be empty
167
168   TextStyle style;
169   style.SetItalics( true );
170
171   tet_infoline("Apply style to TextInput");
172   textInput.ApplyStyleToAll( style );
173
174   tet_infoline("Retreive Markup Text");
175   const std::string retreivedMarkupString = textInput.GetMarkupText();
176
177   tet_infoline("Test Retreived text and Markup text match");
178   DALI_TEST_EQUALS( retreivedMarkupString , retreivedMarkupString, TEST_LOCATION);
179   END_TEST;
180 }
181
182 int UtcDaliTextInputSetMaxCharacterLength(void)
183 {
184   ToolkitTestApplication application;
185
186   tet_infoline("Testing Setting of max characters");
187
188   const int maxChars = 4;
189   const char* testChar  = "v";
190
191   TextInput textInput = TextInput::New();  // create empty TextInput
192   Stage::GetCurrent().Add(textInput);
193   application.SendNotification();
194   application.Render();
195
196   textInput.SetMaxCharacterLength(maxChars);
197
198   Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down );
199
200   std::string testString = "";
201
202   tet_infoline("Starting editmode");
203   textInput.SetEditable( true );
204
205   tet_infoline("Sending Key Events");
206   // Send max number of characters
207   for (int i=0; i < maxChars; i++)
208     {
209       application.ProcessEvent(event);
210       testString.append(testChar);
211     }
212
213   tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
214
215   DALI_TEST_EQUALS(testString, textInput.GetText(), TEST_LOCATION);
216
217   tet_infoline("Sending Key Event which exceeds max characters");
218
219   application.ProcessEvent(event); // try to append additional character
220
221   DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
222
223   tet_infoline("Increase max characters limit");
224
225   textInput.SetMaxCharacterLength(maxChars+1); // increment max characters by 1
226
227   tet_infoline("Send character again which should now fit");
228   application.ProcessEvent(event); // append additional character
229   testString.append(testChar);
230
231   DALI_TEST_EQUALS(testString,textInput.GetText(), TEST_LOCATION);
232   END_TEST;
233 }
234
235
236 int UtcDaliTextInputSetAndGetNumberOfLines(void)
237 {
238   ToolkitTestApplication application;
239
240   tet_infoline("Ensuring API for setting and getting max number of lines is correct");
241
242   TextInput textInput = TextInput::New();  // create empty TextInput
243
244   unsigned int numberOfLines = 1;
245
246   textInput.SetNumberOfLinesLimit( numberOfLines );
247
248   DALI_TEST_EQUALS(numberOfLines ,textInput.GetNumberOfLinesLimit(),  TEST_LOCATION);
249   END_TEST;
250 }
251
252 int UtcDaliTextInputGetNumberOfCharacters(void)
253 {
254   ToolkitTestApplication application;
255
256   tet_infoline("Testing Getting number of characters");
257
258   const std::string initialString = "initial text";
259   const std::string newInitialString = "initial text new";
260
261   TextInput textInput = TextInput::New();  // create empty TextInput
262
263   textInput.SetInitialText( initialString );
264
265   tet_infoline("Testing TextInput contains correct number of characters ");
266
267   DALI_TEST_EQUALS( initialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
268
269   tet_infoline("Testing TextInput contains correct number of characters second phase ");
270
271   textInput.SetInitialText( newInitialString );
272
273   DALI_TEST_EQUALS( newInitialString.size() , textInput.GetNumberOfCharacters(), TEST_LOCATION);
274   END_TEST;
275 }
276
277 int UtcDaliTextInputSetAndGetPlaceholderText(void)
278 {
279   ToolkitTestApplication application;
280
281   tet_infoline("Testing Setting of PlaceholderText");
282
283   const std::string initialString = "initial text";
284   const std::string placeholderString = "placeholder";
285
286   TextInput textInput = TextInput::New();  // create empty TextInput
287
288   tet_infoline("Testing TextInput is empty at creation ");
289
290   DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
291
292   tet_infoline("Set placeholder text");
293
294   textInput.SetPlaceholderText( placeholderString );
295
296   tet_infoline("Testing TextInput contains placeholder text");
297
298   DALI_TEST_EQUALS( placeholderString , textInput.GetPlaceholderText(), TEST_LOCATION);
299
300   tet_infoline("Set initial text which should replace placeholder text");
301
302   textInput.SetInitialText( initialString );
303
304   tet_infoline("Testing TextInput contains initial text when placeholder text set");
305
306   DALI_TEST_EQUALS( initialString,textInput.GetText(), TEST_LOCATION);
307   END_TEST;
308 }
309
310 // Positive test case for a method
311 int UtcDaliTextInputSetInitialText(void)
312 {
313   ToolkitTestApplication application;
314
315   tet_infoline("Testing Setting of Initial Text");
316
317   const std::string teststring = "test";
318
319   TextInput textInput = TextInput::New();  // create empty TextInput
320
321   tet_infoline("Testing TextInput is empty at creation ");
322
323   DALI_TEST_EQUALS("",textInput.GetText(), TEST_LOCATION);
324
325   tet_infoline("Set text to TextInput");
326
327   textInput.SetInitialText(teststring);
328
329   tet_infoline("Test TextInput contains set text");
330
331   DALI_TEST_EQUALS(teststring,textInput.GetText(), TEST_LOCATION);
332   END_TEST;
333 }
334
335 int UtcDaliTextInputSetEditableAndIsEditable(void)
336 {
337   ToolkitTestApplication application;
338
339   tet_infoline("Testing SetEditable And IsEditable");
340
341   const std::string initialString = "initial text";
342
343   TextInput textInput = TextInput::New();  // create empty TextInput
344   textInput.SetInitialText( initialString );
345
346   Stage::GetCurrent().Add(textInput);
347   application.SendNotification();
348   application.Render();
349
350   bool editableStateFalse ( false );
351   bool editableStateTrue ( true );
352
353   textInput.SetEditable ( editableStateFalse );
354   application.SendNotification();
355   application.Render();
356   DALI_TEST_EQUALS( editableStateFalse, textInput.IsEditable() , TEST_LOCATION);
357
358   textInput.SetEditable ( editableStateTrue );
359   application.SendNotification();
360   application.Render();
361   DALI_TEST_EQUALS( editableStateTrue, textInput.IsEditable() , TEST_LOCATION);
362   END_TEST;
363 }
364
365 int UtcDaliTextInputSetEditOnTouch(void)
366 {
367   ToolkitTestApplication application;
368
369   tet_infoline("Testing SetEditOnTouch And IsEditOnTouch");
370
371   TextInput textInput = TextInput::New();
372
373   bool editableOnTouchOn ( true );
374   bool editableOnTouchOff( false );
375
376   tet_infoline("Testing SetEditOnTouch disabled");
377   textInput.SetEditOnTouch ( editableOnTouchOff );
378   DALI_TEST_EQUALS( editableOnTouchOff, textInput.IsEditOnTouch() , TEST_LOCATION);
379
380   tet_infoline("Testing SetEditOnTouch enabled");
381   textInput.SetEditOnTouch ( editableOnTouchOn );
382   DALI_TEST_EQUALS( editableOnTouchOn, textInput.IsEditOnTouch() , TEST_LOCATION);
383   END_TEST;
384 }
385
386 int UtcDaliTextInputSetTextSelectable(void)
387 {
388   ToolkitTestApplication application;
389
390   tet_infoline("Testing SetTextSelectable and IsTextSelectable");
391
392   const std::string initialString = "initial text";
393
394   TextInput textInput = TextInput::New();
395   textInput.SetInitialText( initialString );
396
397   tet_infoline("Testing SetTextSelectable");
398   textInput.SetTextSelectable();
399   DALI_TEST_EQUALS( true, textInput.IsTextSelectable() , TEST_LOCATION);
400   textInput.SetTextSelectable( false );
401   DALI_TEST_EQUALS( false, textInput.IsTextSelectable() , TEST_LOCATION);
402   END_TEST;
403 }
404
405 int UtcDaliTextInputTextSelection(void)
406 {
407   ToolkitTestApplication application;
408
409   tet_infoline("Testing Text Selection");
410
411   const std::string initialString = "initial text";
412
413   TextInput textInput = TextInput::New();
414   textInput.SetInitialText( initialString );
415
416   Stage::GetCurrent().Add(textInput);
417   application.SendNotification();
418   application.Render();
419
420   textInput.SetEditable( true );
421
422   tet_infoline("Testing IsTextSelected negative");
423   DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
424
425   textInput.SelectText(1,7);
426   DALI_TEST_EQUALS( true, textInput.IsTextSelected(), TEST_LOCATION);
427
428   textInput.DeSelectText();
429   DALI_TEST_EQUALS( false, textInput.IsTextSelected(), TEST_LOCATION);
430   END_TEST;
431 }
432
433 int UtcDaliTextInputEnableGrabHandleAndIsGrabHandleEnabled(void)
434 {
435   ToolkitTestApplication application;
436
437   TextInput textInput = TextInput::New();
438
439   bool grabHandleState = false;
440
441   textInput.EnableGrabHandle( grabHandleState );
442
443   DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
444
445   grabHandleState = true;
446   textInput.EnableGrabHandle( grabHandleState );
447
448   DALI_TEST_EQUALS( grabHandleState, textInput.IsGrabHandleEnabled(), TEST_LOCATION);
449
450   END_TEST;
451 }
452
453 int UtcDaliTextInputSetAndGetBoundingRectangle(void)
454 {
455   ToolkitTestApplication application;
456
457   TextInput textInput = TextInput::New();
458
459   Stage::GetCurrent().Add(textInput);
460   Vector2 stageSize = Stage::GetCurrent().GetSize();
461
462   const Rect<float> boundingRectangle( 100.0f, 100.0f, stageSize.width, stageSize.height );
463
464   textInput.SetBoundingRectangle( boundingRectangle );
465
466   const Rect<float> retreievedBoundingRectangle = textInput.GetBoundingRectangle();
467
468   DALI_TEST_EQUALS( boundingRectangle.x, retreievedBoundingRectangle.x, TEST_LOCATION);
469   DALI_TEST_EQUALS( boundingRectangle.y, retreievedBoundingRectangle.y, TEST_LOCATION);
470   DALI_TEST_EQUALS( boundingRectangle.width, retreievedBoundingRectangle.width, TEST_LOCATION);
471   DALI_TEST_EQUALS( boundingRectangle.height, retreievedBoundingRectangle.height, TEST_LOCATION);
472   END_TEST;
473 }
474
475
476 int UtcDaliTextInputSetAndGetTextAlignment01(void)
477 {
478   ToolkitTestApplication application;
479
480   TextInput textInput = TextInput::New();
481   Stage::GetCurrent().Add(textInput);
482   application.SendNotification();
483   application.Render();
484
485   textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
486   application.SendNotification();
487   application.Render();
488
489   DALI_TEST_CHECK( static_cast<Alignment::Type>( Alignment::HorizontalCenter) & textInput.GetTextAlignment()) ;
490   END_TEST;
491 }
492
493 int UtcDaliTextInputSetAndGetTextAlignment02(void)
494 {
495   ToolkitTestApplication application;
496
497   TextInput textInput = TextInput::New();
498   textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
499
500   bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
501
502   DALI_TEST_CHECK( result );
503
504   result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
505
506   DALI_TEST_CHECK( !result );
507   END_TEST;
508 }
509
510 int UtcDaliTextInputSetSortModifier(void)
511 {
512   tet_infoline("Testing SetSortModifier does not cause TextInput failure");
513
514   ToolkitTestApplication application;
515
516   TextInput textInput = TextInput::New();
517
518   const float offsetToUse = 1.5f;
519
520   textInput.SetSortModifier( offsetToUse );
521
522   DALI_TEST_CHECK( textInput );
523   END_TEST;
524 }
525
526 int UtcDaliTextInputSetAndGetSnapshotModeEnabled(void)
527 {
528   ToolkitTestApplication application;
529
530   tet_infoline("Testing SetSnapshotModeEnabled and IsSnapshotModeEnabled");
531
532   TextInput textInput = TextInput::New();  // create empty TextInput
533   bool snapshotMode( true );
534   textInput.SetSnapshotModeEnabled( snapshotMode );
535
536   DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
537
538   snapshotMode = false;
539   textInput.SetSnapshotModeEnabled( snapshotMode );
540
541   DALI_TEST_EQUALS( snapshotMode, textInput.IsSnapshotModeEnabled(), TEST_LOCATION);
542   END_TEST;
543 }
544
545
546 int UtcDaliTextInputEndSignalEmit(void)
547 {
548   ToolkitTestApplication application;
549
550   tet_infoline("Testing Set editable false emits end signal");
551
552   TextInput textInput = TextInput::New();  // create empty TextInput
553
554   Stage::GetCurrent().Add(textInput);
555
556   textInput.InputFinishedSignal().Connect( &OnEndInput );
557
558   textInput.SetEditable(true) ;
559
560   gHasEndSignalBeenReceived = false;
561
562   textInput.SetEditable(false) ;
563
564   DALI_TEST_EQUALS(true, gHasEndSignalBeenReceived, TEST_LOCATION);
565   END_TEST;
566 }
567
568
569
570 int UtcDaliTextInputStartSignalEmit(void)
571 {
572   ToolkitTestApplication application;
573
574   tet_infoline("Testing SetEditable emits start signal");
575
576   TextInput textInput = TextInput::New();  // create empty TextInput
577
578   Stage::GetCurrent().Add(textInput);
579
580   textInput.InputStartedSignal().Connect( &OnStartInput );
581
582   gHasStartSignalBeenReceived = false;
583
584   textInput.SetEditable(true);  // Set editable first time
585
586   DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
587
588   gHasStartSignalBeenReceived = false;
589
590   textInput.SetEditable(true); // Set editable second time, signal should not be sent again.
591
592   DALI_TEST_EQUALS(false, gHasStartSignalBeenReceived, TEST_LOCATION);
593
594   textInput.SetEditable(false);
595
596   gHasStartSignalBeenReceived = false;
597
598   textInput.SetEditable(true);  // Set editable again
599
600   DALI_TEST_EQUALS(true, gHasStartSignalBeenReceived, TEST_LOCATION);
601   END_TEST;
602 }
603
604 int UtcDaliTextInputExceedMaxCharacters(void)
605 {
606   ToolkitTestApplication application;
607
608   tet_infoline("Testing Max characters is obeyed when inputting key events ");
609
610   TextInput textInput = TextInput::New();  // create empty TextInput
611
612   Stage::GetCurrent().Add(textInput);
613   textInput.SetMaxCharacterLength(4);
614   textInput.SetInitialText("");
615   textInput.SetEditable(true);
616
617   application.SendNotification();
618   application.Render();
619
620   Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
621   Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
622
623   application.ProcessEvent(eventA);
624   application.ProcessEvent(eventB);
625   application.ProcessEvent(eventA);
626   application.ProcessEvent(eventB);
627
628   application.ProcessEvent(eventA);
629   application.ProcessEvent(eventB);
630
631   tet_printf( "Get text result : %s\n", textInput.GetText().c_str());
632
633   DALI_TEST_EQUALS("abab",textInput.GetText(), TEST_LOCATION); // Get text which should be only 4 characters
634   END_TEST;
635 }
636
637
638
639 int UtcDaliTextInputSetAndGetFadeBoundary(void)
640 {
641   tet_infoline("UtcDaliTextViewSetAndGetFadeBoundary: ");
642
643   ToolkitTestApplication application;
644
645   TextView::FadeBoundary fadeBoundary( PixelSize( 0 ), PixelSize( 20 ), PixelSize( 0 ), PixelSize( 10 ) );
646
647   TextInput textInput = TextInput::New();
648   textInput.SetInitialText( "Hello world!" );
649
650   Stage::GetCurrent().Add(textInput);
651   application.SendNotification();
652   application.Render();
653
654   textInput.SetFadeBoundary( fadeBoundary );
655
656   TextView::FadeBoundary fadeBoundary2 = textInput.GetFadeBoundary();
657
658   DALI_TEST_EQUALS( fadeBoundary.mLeft, fadeBoundary2.mLeft, TEST_LOCATION );
659   DALI_TEST_EQUALS( fadeBoundary.mRight, fadeBoundary2.mRight, TEST_LOCATION );
660   DALI_TEST_EQUALS( fadeBoundary.mTop, fadeBoundary2.mTop, TEST_LOCATION );
661   DALI_TEST_EQUALS( fadeBoundary.mBottom, fadeBoundary2.mBottom, TEST_LOCATION );
662   END_TEST;
663 }
664
665 int UtcDaliTextInputSetAndGetWidthExceedPolicy(void)
666 {
667   ToolkitTestApplication application;
668
669   tet_infoline("UtcDaliTextInputSetAndGetWidthExceedPolicy: ");
670
671   const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
672   const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
673
674   TextInput textInput = TextInput::New();
675   textInput.SetInitialText( "Hello world!" );
676
677   for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
678   {
679     textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
680
681     DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
682   }
683   END_TEST;
684 }
685
686 int UtcDaliTextInputSetAndGetHeightExceedPolicy(void)
687 {
688   ToolkitTestApplication application;
689
690   tet_infoline("UtcDaliTextInputSetAndGetHeightExceedPolicy: ");
691
692   const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::ShrinkToFit };
693   const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
694
695   TextInput textInput = TextInput::New();
696   textInput.SetInitialText( "Hello world!" );
697
698   for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
699   {
700     textInput.SetHeightExceedPolicy( EXCEED_POLICIES[epIndex] );
701
702     DALI_TEST_EQUALS( textInput.GetHeightExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
703   }
704   END_TEST;
705 }
706
707 int UtcDaliTextInputScroll(void)
708 {
709   tet_infoline("UtcDaliTextInputScroll: ");
710   ToolkitTestApplication application;
711
712   // Avoids the frame buffer texture to throw an exception.
713   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
714
715   TextInput view = TextInput::New();
716   view.SetMultilinePolicy( TextView::SplitByNewLineChar );
717   view.SetWidthExceedPolicy( TextView::Original );
718   view.SetHeightExceedPolicy( TextView::Original );
719   view.SetTextAlignment( static_cast<Toolkit::Alignment::Type>( Toolkit::Alignment::HorizontalCenter | Toolkit::Alignment::VerticalCenter ) );
720   view.SetInitialText( "Hello world! This is a scroll test." );
721   view.SetSize( 100.f, 100.f );
722   view.SetSnapshotModeEnabled( false );
723
724   Stage::GetCurrent().Add( view );
725
726   application.SendNotification();
727   application.Render();
728
729   DALI_TEST_CHECK( !view.IsScrollEnabled() ); // Scroll should be disabled by default.
730
731   view.SetScrollEnabled( true );
732
733   DALI_TEST_CHECK( view.IsScrollEnabled() );
734   DALI_TEST_CHECK( view.IsSnapshotModeEnabled() ); // Scroll should enable snapshot mode.
735
736   view.SetScrollPosition( Vector2( 400.f, 400.f ) );
737
738   application.SendNotification();
739   application.Render();
740
741   const Vector2& scrollPosition = view.GetScrollPosition();
742   DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
743   END_TEST;
744 }
745
746 int UtcDaliTextInputSetActiveStyle(void)
747 {
748   ToolkitTestApplication application;
749
750   tet_infoline("Testing Setting of Style to newly added text");
751
752   TextInput textInput = TextInput::New();  // create empty TextInput
753
754   Stage::GetCurrent().Add(textInput);
755
756   const std::string styledString = "Test String<i>ab</i>" ;
757   const std::string plainString = "Test String";
758   textInput.SetInitialText( plainString );
759
760   application.SendNotification();
761   application.Render();
762
763   textInput.SetEditable(true);
764
765   std::string retreivedMarkupString = textInput.GetMarkupText();
766
767   tet_infoline("Confirm markup text is a plain string ");
768   DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
769
770   TextStyle style;
771   style.SetItalics( true );
772
773   tet_infoline("Apply style to TextInput");
774   textInput.SetActiveStyle( style );
775
776   Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
777   Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
778
779   application.SendNotification();
780   application.Render();
781
782   application.ProcessEvent(eventA);
783   application.SendNotification();
784   application.Render();
785
786   application.ProcessEvent(eventB);
787   application.SendNotification();
788   application.Render();
789
790   retreivedMarkupString = textInput.GetMarkupText();
791
792   DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
793   END_TEST;
794 }
795
796 int UtcDaliTextInputApplyStyleToSelectedText(void)
797 {
798   ToolkitTestApplication application;
799
800   tet_infoline("Testing application of style to selected text ");
801
802   TextInput textInput = TextInput::New();  // create empty TextInput
803
804   Stage::GetCurrent().Add(textInput);
805
806   const std::string styledString = "Test <i>String</i> to style";
807   const std::string plainString = "Test String to style";
808   textInput.SetInitialText( plainString );
809
810   application.SendNotification();
811   application.Render();
812
813   textInput.SetEditable(true);
814
815   std::string retreivedMarkupString = textInput.GetMarkupText();
816
817   tet_infoline("Confirm markup text is a plain string ");
818   DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
819
820   TextStyle style;
821   style.SetItalics( true );
822
823   textInput.SelectText( 5, 11 );
824
825   tet_infoline("Apply style to selected text");
826   textInput.ApplyStyle( style );
827
828   application.Render();
829
830   retreivedMarkupString = textInput.GetMarkupText();
831
832   DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
833   END_TEST;
834 }
835
836 int UtcDaliTextInputApplyStyleToAll(void)
837 {
838   ToolkitTestApplication application;
839
840   tet_infoline("Testing application of style to all text ");
841
842   TextInput textInput = TextInput::New();  // create empty TextInput
843
844   Stage::GetCurrent().Add(textInput);
845
846   const std::string styledString = "<i>Test String to style</i>";
847   const std::string plainString = "Test String to style";
848   textInput.SetInitialText( plainString );
849
850   application.SendNotification();
851   application.Render();
852
853   textInput.SetEditable(true);
854
855   std::string retreivedMarkupString = textInput.GetMarkupText();
856
857   tet_infoline("Confirm markup text is a plain string ");
858   DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
859
860   TextStyle style;
861   style.SetItalics( true );
862
863   tet_infoline("Apply style to all text");
864   textInput.ApplyStyleToAll( style );
865
866   application.Render();
867
868   retreivedMarkupString = textInput.GetMarkupText();
869
870   DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
871   END_TEST;
872 }
873
874 int UtcDaliTextInputGetStyleAtCursor(void)
875 {
876   ToolkitTestApplication application;
877
878   tet_infoline("Test getting style at cursor");
879
880   TextInput textInput = TextInput::New();  // create empty TextInput
881
882   Stage::GetCurrent().Add(textInput);
883
884   const std::string styledString = "Test Stringa<i>b</i>" ;
885   const std::string plainString = "Test String";
886   textInput.SetInitialText( plainString );
887
888   application.SendNotification();
889   application.Render();
890
891   textInput.SetEditable(true);
892
893   tet_infoline("Confirm style at cursor is default(plain)");
894   TextStyle style;
895   Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
896   application.ProcessEvent(eventA);
897   application.SendNotification();
898   application.Render();
899
900   TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
901
902   DALI_TEST_CHECK( style == retreivedStyleAtCursor );
903   DALI_TEST_CHECK( !retreivedStyleAtCursor.IsItalicsEnabled() );
904
905   tet_infoline("Set style before adding new character");
906   style.SetItalics( true );
907   textInput.SetActiveStyle( style );
908
909   Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
910   application.ProcessEvent(eventB);
911   application.SendNotification();
912   application.Render();
913
914   tet_infoline("Confirm style at cursor is correct style");
915   retreivedStyleAtCursor = textInput.GetStyleAtCursor();
916
917   DALI_TEST_CHECK( retreivedStyleAtCursor.IsItalicsEnabled() );
918
919   tet_infoline("Confirm style at cursor is not a style that was not set");
920   DALI_TEST_CHECK( !retreivedStyleAtCursor.IsUnderlineEnabled() );
921
922   tet_infoline("Confirm markup text is correct");
923   DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
924
925
926
927   END_TEST;
928 }
929
930 int UtcDaliTextInputSetAndGetMultilinePolicy(void)
931 {
932   ToolkitTestApplication application;
933
934   const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
935   const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
936
937   TextInput textInput = TextInput::New();
938   Stage::GetCurrent().Add(textInput);
939   textInput.SetInitialText( "Hello world!" );
940
941   for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
942   {
943     textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
944
945     DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
946   }
947   END_TEST;
948 }
949
950 int UtcDaliTextInputSetAndGetExceedEnabled(void)
951 {
952   ToolkitTestApplication application;
953
954   const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
955   const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
956
957   TextInput textInput = TextInput::New();
958   Stage::GetCurrent().Add(textInput);
959   textInput.SetInitialText( "Hello world!" );
960
961   for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
962   {
963     textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
964
965     DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
966   }
967   END_TEST;
968 }