Builder templated constant expansion
[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 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   tet_infoline("Testing Text Selection with replace.");
79
80   Toolkit::TextInput textInput = Toolkit::TextInput::New();
81
82   DALI_TEST_CHECK(textInput);
83
84   Stage::GetCurrent().Add(textInput);
85
86   textInput.SetInitialText("Test String");
87
88   std::string initialText = textInput.GetText();
89
90   tet_printf("Set Initial text: %s\n", initialText.c_str() );
91
92   textInput.SetKeyInputFocus();
93
94   GetImpl(textInput).SelectText(0,11);
95
96   tet_printf("Select all of Initial text\n");
97
98   Integration::KeyEvent event(testChar, testChar, 0, 0, 0, Integration::KeyEvent::Down );
99
100   application.ProcessEvent( event );
101
102   tet_printf("Simulate pressing of a key: %s\n", testChar );
103
104   std::string newText = textInput.GetText();
105
106   tet_printf("Check current text (%s) is the new text \n", newText.c_str() );
107
108   DALI_TEST_EQUALS("v",textInput.GetText(), TEST_LOCATION);
109 }
110
111 static void UtcDaliTextInputSetGetExceedEnabled()
112 {
113   tet_infoline("UtcDaliTextInputSetGetExceedEnabled: ");
114
115   ToolkitTestApplication application;
116
117   Toolkit::TextInput textInput = Toolkit::TextInput::New();
118   textInput.SetMultilinePolicy( Toolkit::TextView::SplitByWord );
119   textInput.SetWidthExceedPolicy( Toolkit::TextView::Split );
120   textInput.SetHeightExceedPolicy( Toolkit::TextView::Original );
121
122   DALI_TEST_CHECK( textInput.GetExceedEnabled() );
123
124   Toolkit::Internal::TextInput& textInputImpl = static_cast<Toolkit::Internal::TextInput&>( textInput.GetImplementation() );
125
126   textInput.SetSize( 50.f, 50.f );
127   textInput.SetExceedEnabled( false );
128
129   DALI_TEST_CHECK( !textInput.GetExceedEnabled() );
130
131
132   textInputImpl.InsertAt( Text("He"), 0 );
133
134   DALI_TEST_EQUALS("He",textInput.GetText(), TEST_LOCATION);
135
136   textInputImpl.InsertAt( Text("llo"), 2 );
137
138   DALI_TEST_EQUALS("Hello",textInput.GetText(), TEST_LOCATION);
139
140   textInputImpl.InsertAt( Text(" world! hello world hello world hello world"), 5 ); // Doesn't fit so is not added.
141
142   DALI_TEST_EQUALS("Hello",textInput.GetText(), TEST_LOCATION);
143 }