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