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