Dali 3D User Interface Engine
utc-Dali-KeyEvent.cpp
Go to the documentation of this file.
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>
23 
24 #include <dali-test-suite-utils.h>
25 
26 using namespace Dali;
27 
29 {
31 }
32 
34 {
36 }
37 
38 namespace
39 {
40 
41 // Key Event Test references
42 const static int SHIFT_MODIFIER = 0x1;
43 const static int CTRL_MODIFIER = 0x2;
44 const static int ALT_MODIFIER = 0x4;
45 const static int SHIFT_AND_CTRL_MODIFIER = SHIFT_MODIFIER | CTRL_MODIFIER;
46 const static int SHIFT_AND_ALT_MODIFIER = SHIFT_MODIFIER | ALT_MODIFIER;
47 const static int CTRL_AND_ALT_MODIFIER = CTRL_MODIFIER | ALT_MODIFIER;
48 
49 const static char* TEST_STRING_1 = "alpha";
50 
51 
52 // Stores data that is populated in the callback and will be read by the TET cases
53 struct SignalData
54 {
56  : functorCalled(false)
57  {}
58 
59  void Reset()
60  {
61  functorCalled = false;
62 
63  receivedKeyEvent.keyModifier = 0;
64  receivedKeyEvent.keyPressedName.clear();
65  receivedKeyEvent.keyPressed.clear();
66 
67  keyedActor.Reset();
68  }
69 
73 };
74 
75 // Functor that sets the data when called
77 {
78  KeyEventReceivedFunctor( SignalData& data ) : signalData( data ) { }
79 
80  bool operator()( Actor actor, const KeyEvent& keyEvent )
81  {
82  signalData.functorCalled = true;
83  signalData.receivedKeyEvent = keyEvent;
84  signalData.keyedActor = actor;
85 
86  return true;
87  }
88 
90 };
91 
92 } // anon namespace
93 
95 {
96  TestApplication application; // Reset all test adapter return codes
97 
98  KeyEvent event(TEST_STRING_1,"i", 99, SHIFT_MODIFIER, 0, KeyEvent::Down); // set name to test, key string to i and modifier to shift
99 
100  DALI_TEST_EQUALS(TEST_STRING_1, event.keyPressedName, TEST_LOCATION); // check key name
101  DALI_TEST_EQUALS("i", event.keyPressed, TEST_LOCATION); // check key string
102  DALI_TEST_EQUALS(99, event.keyCode, TEST_LOCATION); // check keyCode
103  DALI_TEST_EQUALS(SHIFT_MODIFIER, event.keyModifier, TEST_LOCATION); // check modifier
104  DALI_TEST_EQUALS(KeyEvent::Down, event.state, TEST_LOCATION); // check state
105  END_TEST;
106 }
107 
108 // Positive test case for a method
110 {
111  TestApplication application; // Reset all test adapter return codes
112 
113  KeyEvent event;
115 
116  event.keyModifier = SHIFT_MODIFIER; // Set to Shift Modifier
117 
118  DALI_TEST_EQUALS(SHIFT_MODIFIER, event.keyModifier, TEST_LOCATION); // check able to set
119 
120  DALI_TEST_EQUALS(true, event.IsShiftModifier(), TEST_LOCATION); // check IsShiftModifier
121 
122  END_TEST;
123 }
124 
125 // Positive test case for a method
127 {
128  TestApplication application; // Reset all test adapter return codes
129 
130  KeyEvent event;
132 
133  event.keyModifier = CTRL_MODIFIER; // Set to Ctrl Modifier
134 
135  DALI_TEST_EQUALS(CTRL_MODIFIER, event.keyModifier, TEST_LOCATION); // check able to set
136 
137  DALI_TEST_EQUALS(true, event.IsCtrlModifier(), TEST_LOCATION); // check IsCtrlModifier
138  END_TEST;
139 }
140 
141 // Positive test case for a method
143 {
144  TestApplication application; // Reset all test adapter return codes
145 
146  KeyEvent event;
148 
149  event.keyModifier = ALT_MODIFIER; // Set to Alt Modifier
150 
151  DALI_TEST_EQUALS(ALT_MODIFIER, event.keyModifier, TEST_LOCATION); // check able to set
152 
153  DALI_TEST_EQUALS(true, event.IsAltModifier(), TEST_LOCATION); // IsAltModifier
154  END_TEST;
155 }
156 
157 // Positive fail test case for a method
159 {
160  TestApplication application; // Reset all test adapter return codes
161 
162  KeyEvent event("i","i", 0, CTRL_MODIFIER, 0, KeyEvent::Down);
163 
164  DALI_TEST_EQUALS(CTRL_MODIFIER, event.keyModifier, TEST_LOCATION); // check different modifier used
165 
167  END_TEST;
168 }
169 
170 // Positive fail test case for a method
172 {
173  TestApplication application; // Reset all test adapter return codes
174 
175  KeyEvent event("i","i", 0, ALT_MODIFIER, 0, KeyEvent::Up);
176 
177  DALI_TEST_EQUALS(ALT_MODIFIER, event.keyModifier, TEST_LOCATION); // check different modifier used
178 
180  END_TEST;
181 }
182 
183 // Positive fail test case for a method
185 {
186  TestApplication application; // Reset all test adapter return codes
187 
188  KeyEvent event("i","i", 0, SHIFT_MODIFIER, 0, KeyEvent::Up);
189 
190  DALI_TEST_EQUALS(SHIFT_MODIFIER, event.keyModifier, TEST_LOCATION); // check different modifier used
191 
193  END_TEST;
194 }
195 
196 // Positive test case for a method
198 {
199  TestApplication application; // Reset all test adapter return codes
200 
201  KeyEvent event("i","i", 0, SHIFT_AND_CTRL_MODIFIER, 0, KeyEvent::Down);
202  DALI_TEST_EQUALS(true, (bool)(event.IsCtrlModifier() & event.IsShiftModifier()), TEST_LOCATION);
203 
204  event.keyModifier = SHIFT_MODIFIER;
205 
206  DALI_TEST_EQUALS(false, (bool)(event.IsCtrlModifier() & event.IsShiftModifier()), TEST_LOCATION);
207  END_TEST;
208 }
209 
210 // Positive test case for a method
212 {
213  TestApplication application; // Reset all test adapter return codes
214 
215  KeyEvent event("i","i", 0, SHIFT_AND_CTRL_MODIFIER, 0, KeyEvent::Down);
216  DALI_TEST_EQUALS(true, (bool)(event.IsCtrlModifier() | event.IsAltModifier()), TEST_LOCATION);
217 
218  event.keyModifier = SHIFT_MODIFIER;
219 
220  DALI_TEST_EQUALS(false, (bool)(event.IsCtrlModifier() & event.IsAltModifier()), TEST_LOCATION);
221  END_TEST;
222 }
223 
224 // Positive test case for a method
226 {
227  TestApplication application; // Reset all test adapter return codes
228 
229  KeyEvent event("i","i", 0, SHIFT_AND_CTRL_MODIFIER, 0, KeyEvent::Down);
230  DALI_TEST_EQUALS(true, (bool)(event.IsCtrlModifier() | event.IsAltModifier()), TEST_LOCATION);
231 
232  event.keyModifier = SHIFT_MODIFIER;
233 
234  DALI_TEST_EQUALS(false, (bool)(event.IsCtrlModifier() & event.IsAltModifier()), TEST_LOCATION);
235  END_TEST;
236 }
237 
239 {
240  TestApplication application;
241 
242  {
243  Integration::KeyEvent keyEvent;
244  DALI_TEST_EQUALS( keyEvent.type, Integration::Event::Key, TEST_LOCATION );
245  DALI_TEST_CHECK( keyEvent.keyName == std::string() );
246  DALI_TEST_CHECK( keyEvent.keyString == std::string() );
247  DALI_TEST_EQUALS( keyEvent.keyCode, -1, TEST_LOCATION );
248  DALI_TEST_EQUALS( keyEvent.keyModifier, 0, TEST_LOCATION );
249  DALI_TEST_EQUALS( keyEvent.time, 0lu, TEST_LOCATION );
251  }
252 
253  {
254  const std::string keyName("keyName");
255  const std::string keyString("keyString");
256  const int keyCode(333);
257  const int keyModifier(312);
258  const unsigned long timeStamp(132);
259  const Integration::KeyEvent::State keyState(Integration::KeyEvent::Up);
260 
261  Integration::KeyEvent keyEvent(keyName, keyString, keyCode, keyModifier, timeStamp, keyState);
262  DALI_TEST_EQUALS( keyEvent.type, Integration::Event::Key, TEST_LOCATION );
263  DALI_TEST_CHECK( keyEvent.keyName == keyName );
264  DALI_TEST_CHECK( keyEvent.keyString == keyString );
265  DALI_TEST_EQUALS( keyEvent.keyCode, keyCode, TEST_LOCATION );
266  DALI_TEST_EQUALS( keyEvent.keyModifier, keyModifier, TEST_LOCATION );
267  DALI_TEST_EQUALS( keyEvent.time, timeStamp, TEST_LOCATION );
268  DALI_TEST_EQUALS( keyEvent.state, keyState, TEST_LOCATION);
269  }
270  END_TEST;
271 }
Dali Docs Home
Read more about Dali