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