6315dde9b02c15a3f9e788e1ff62f33cd71c6ca9
[platform/core/uifw/dali-toolkit.git] / automated-tests / dali-internal-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 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 #include <dali/integration-api/events/key-event-integ.h>
28
29 // Internal includes
30 #include <dali-toolkit/internal/controls/text-input/text-input-impl.h>
31
32 using namespace Dali;
33 using namespace Dali::Toolkit;
34
35 static void Startup();
36 static void Cleanup();
37
38 extern "C" {
39   void (*tet_startup)() = Startup;
40   void (*tet_cleanup)() = Cleanup;
41 }
42
43 enum {
44   POSITIVE_TC_IDX = 0x01,
45   NEGATIVE_TC_IDX,
46 };
47
48 #define MAX_NUMBER_OF_TESTS 10000
49 extern "C" {
50   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
51 }
52
53 // Add test functionality for all APIs in the class (Positive and Negative)
54 TEST_FUNCTION( UtcDaliInternalTextInputTextSelection, POSITIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliTextInputSetGetExceedEnabled, POSITIVE_TC_IDX );
56 // TEST_FUNCTION( UtcDaliTextInputMethod02, NEGATIVE_TC_IDX );
57
58 // Called only once before first test is run.
59 static void Startup()
60 {
61 }
62
63 // Called only once after last test is run
64 static void Cleanup()
65 {
66 }
67
68
69 /**
70  *  Test: Selected is replaced by new input text.
71  **/
72 static void UtcDaliInternalTextInputTextSelection()
73 {
74   const char* testChar  = "v";
75
76   ToolkitTestApplication application;
77
78   Dali::Integration::Core& core ( application.GetCore() );
79
80   tet_infoline("Testing Text Selection with replace.");
81
82   Toolkit::TextInput textInput = Toolkit::TextInput::New();
83
84   DALI_TEST_CHECK(textInput);
85
86   Stage::GetCurrent().Add(textInput);
87
88   textInput.SetInitialText("Test String");
89
90   std::string initialText = textInput.GetText();
91
92   tet_printf("Set Initial text: %s\n", initialText.c_str() );
93
94   textInput.SetKeyInputFocus();
95
96   GetImpl(textInput).SelectText(0,11);
97
98   tet_printf("Select all of Initial text\n");
99
100   Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down );
101
102   core.SendEvent( event );
103
104   tet_printf("Simulate pressing of a key: %s\n", testChar );
105
106   std::string newText = textInput.GetText();
107
108   tet_printf("Check current text (%s) is the new text \n", newText.c_str() );
109
110   DALI_TEST_EQUALS("v",textInput.GetText(), TEST_LOCATION);
111 }
112
113 static void UtcDaliTextInputSetGetExceedEnabled()
114 {
115   tet_infoline("UtcDaliTextInputSetGetExceedEnabled: ");
116
117   ToolkitTestApplication application;
118
119   Toolkit::TextInput textInput = Toolkit::TextInput::New();
120   textInput.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
121   textInput.SetWidthExceedPolicy( Toolkit::TextView::Split );
122   textInput.SetHeightExceedPolicy( Toolkit::TextView::Original );
123
124   DALI_TEST_CHECK( textInput.GetExceedEnabled() );
125
126   Toolkit::Internal::TextInput& textInputImpl = static_cast<Toolkit::Internal::TextInput&>( textInput.GetImplementation() );
127
128   textInput.SetSize( 50.f, 50.f );
129   textInput.SetExceedEnabled( false );
130
131   DALI_TEST_CHECK( !textInput.GetExceedEnabled() );
132
133
134   textInputImpl.InsertAt( Text("He"), 0 );
135
136   DALI_TEST_EQUALS("He",textInput.GetText(), TEST_LOCATION);
137
138   textInputImpl.InsertAt( Text("llo"), 2 );
139
140   DALI_TEST_EQUALS("Hello",textInput.GetText(), TEST_LOCATION);
141
142   textInputImpl.InsertAt( Text(" world! hello world hello world hello world"), 5 ); // Doesn't fit so is not added.
143
144   DALI_TEST_EQUALS("Hello",textInput.GetText(), TEST_LOCATION);
145 }