|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <e32base.h> |
|
21 #include <e32cmn.h> |
|
22 #include <e32event.h> |
|
23 #include <e32keys.h> |
|
24 #include <e32property.h> |
|
25 #include <aknfepinternalcrkeys.h> |
|
26 |
|
27 #include <digia/eunit/eunitmacros.h> |
|
28 #include <digia/eunit/teunitassertioninfo.h> |
|
29 #include <digia/eunit/eunitdecorators.h> |
|
30 |
|
31 // User includes |
|
32 #include "numerickeyhandler.h" |
|
33 |
|
34 #include <activeidle2domainpskeys.h> |
|
35 #include "eventhandler.h" |
|
36 |
|
37 #include "ut_numerickeyhandler.h" |
|
38 #include "animgeneralfunctions_stub.h" |
|
39 |
|
40 using namespace AiWsPlugin; |
|
41 |
|
42 // ======== LOCAL FUNCTIONS ======== |
|
43 |
|
44 // ======== MEMBER FUNCTIONS ======== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // UT_MofifierKeyTracker::NewL() |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 |
|
52 |
|
53 // CLASS HEADER |
|
54 |
|
55 // EXTERNAL INCLUDES |
|
56 //#include <telephonyinternalpskeys.h> |
|
57 |
|
58 |
|
59 _LIT( fileName, "C:\\keyhandler.txt"); |
|
60 // INTERNAL INCLUDES |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 // CONSTRUCTION |
|
66 UT_NumericKeyHandler* UT_NumericKeyHandler::NewL() |
|
67 { |
|
68 UT_NumericKeyHandler* self = UT_NumericKeyHandler::NewLC(); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 UT_NumericKeyHandler* UT_NumericKeyHandler::NewLC() |
|
75 { |
|
76 UT_NumericKeyHandler* self = new( ELeave ) UT_NumericKeyHandler(); |
|
77 CleanupStack::PushL( self ); |
|
78 |
|
79 self->ConstructL(); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // Destructor (virtual by CBase) |
|
85 UT_NumericKeyHandler::~UT_NumericKeyHandler() |
|
86 { |
|
87 } |
|
88 |
|
89 // Default constructor |
|
90 UT_NumericKeyHandler::UT_NumericKeyHandler() |
|
91 { |
|
92 } |
|
93 |
|
94 // Second phase construct |
|
95 void UT_NumericKeyHandler::ConstructL() |
|
96 { |
|
97 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
98 // It generates the test case table. |
|
99 CEUnitTestSuiteClass::ConstructL(); |
|
100 } |
|
101 |
|
102 // METHODS |
|
103 |
|
104 void UT_NumericKeyHandler::EmptySetupL( ) |
|
105 { |
|
106 |
|
107 } |
|
108 |
|
109 void UT_NumericKeyHandler::SetupL( ) |
|
110 { |
|
111 if ( !iAnimGeneralFunctions ) |
|
112 { |
|
113 iAnimGeneralFunctions = CAnimGeneralFunctionsStub::NewL(); |
|
114 } |
|
115 |
|
116 iModifiers = NULL; |
|
117 MAnimGeneralFunctionsWindowExtension* ext = |
|
118 static_cast<MAnimGeneralFunctionsWindowExtension*>( |
|
119 iAnimGeneralFunctions->ExtendedInterface |
|
120 ( MAnimGeneralFunctions::EWindowExtensionInterface ) ); |
|
121 |
|
122 iNumericKeyHandler = AiWsPlugin::CNumericKeyHandler::NewLC( 0, ext); |
|
123 CleanupStack::Pop(); |
|
124 } |
|
125 |
|
126 void UT_NumericKeyHandler::Teardown( ) |
|
127 { |
|
128 if( iNumericKeyHandler ) |
|
129 { |
|
130 delete iNumericKeyHandler; |
|
131 iNumericKeyHandler = NULL; |
|
132 } |
|
133 if ( iAnimGeneralFunctions ) |
|
134 { |
|
135 delete iAnimGeneralFunctions; |
|
136 iAnimGeneralFunctions = NULL; |
|
137 } |
|
138 _LIT( fileName, "C:\\keyhandler.txt"); |
|
139 RFs fs; |
|
140 fs.Connect(); |
|
141 fs.Delete( fileName ); |
|
142 fs.Close(); |
|
143 } |
|
144 |
|
145 void UT_NumericKeyHandler::TestNumericKeyCreationL( ) |
|
146 { |
|
147 EUNIT_ASSERT( iNumericKeyHandler ); |
|
148 } |
|
149 |
|
150 void UT_NumericKeyHandler::TestFocusChangeL( ) |
|
151 { |
|
152 // The fuction that this test tests is unnecessary |
|
153 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
154 handler->FocusChanged( ETrue ); |
|
155 EUNIT_ASSERT( ETrue ); |
|
156 } |
|
157 |
|
158 void UT_NumericKeyHandler::TestNumericKeyEventL() |
|
159 { |
|
160 |
|
161 TRawEvent event; |
|
162 event.Set( TRawEvent::EKeyDown, EStdKeyHash ); |
|
163 |
|
164 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
165 CleanupStack::PushL( handler ); |
|
166 |
|
167 handler->SetUiStateQuery( *this ); |
|
168 handler->OfferRawEvent(event); |
|
169 |
|
170 CleanupStack::Pop( handler ); |
|
171 |
|
172 TUid uidi(KNullUid); |
|
173 TUint uintti(0); |
|
174 |
|
175 RProperty::Get(uidi, uintti, iTestValue ); |
|
176 |
|
177 //EUNIT_ASSERT_EQUALS( iTestValue, TInt(EPSAiNumberEntry)); |
|
178 } |
|
179 |
|
180 |
|
181 void UT_NumericKeyHandler::TestNumericKeyEventQwertyModeL() |
|
182 { |
|
183 // Write file to enable qwertymode |
|
184 RFs fs; |
|
185 RFile file; |
|
186 TInt err = fs.Connect(); |
|
187 err = file.Replace( fs, fileName, EFileShareAny); |
|
188 TBuf8<30> txt; |
|
189 txt.Num( TInt(1) ); |
|
190 err = file.Write( 0,txt); |
|
191 file.Close(); |
|
192 fs.Close(); |
|
193 |
|
194 if ( !iAnimGeneralFunctions ) |
|
195 { |
|
196 iAnimGeneralFunctions = CAnimGeneralFunctionsStub::NewL(); |
|
197 } |
|
198 |
|
199 iModifiers = NULL; |
|
200 MAnimGeneralFunctionsWindowExtension* ext = |
|
201 static_cast<MAnimGeneralFunctionsWindowExtension*>( |
|
202 iAnimGeneralFunctions->ExtendedInterface |
|
203 ( MAnimGeneralFunctions::EWindowExtensionInterface ) ); |
|
204 |
|
205 iNumericKeyHandler = AiWsPlugin::CNumericKeyHandler::NewLC( 0, ext); |
|
206 CleanupStack::Pop(); |
|
207 |
|
208 TRawEvent event; |
|
209 event.Set( TRawEvent::EKeyDown, EStdKeyHash ); |
|
210 |
|
211 |
|
212 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
213 handler->SetUiStateQuery( *this ); |
|
214 handler->OfferRawEvent(event); |
|
215 TUid uidi(KNullUid); |
|
216 TUint uintti(0); |
|
217 RProperty::Get(uidi, uintti, iTestValue ); |
|
218 |
|
219 EUNIT_ASSERT_EQUALS( iTestValue, TInt(EPSAiNumberEntry )); |
|
220 } |
|
221 |
|
222 void UT_NumericKeyHandler::TestHandlerFunctions1L() |
|
223 { |
|
224 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
225 handler->SetUiStateQuery( *this ); |
|
226 TRawEvent event; |
|
227 event.Set( TRawEvent::EKeyDown, EStdKeyHash ); |
|
228 iNumericKeyHandler->iQwertyMode = ETrue; |
|
229 iNumericKeyHandler->CheckPostToTarget( event ); |
|
230 |
|
231 iNumericKeyHandler->iQwertyMode = EFalse; |
|
232 iNumericKeyHandler->CheckPostToTarget( event ); |
|
233 |
|
234 event.Set( TRawEvent::EKeyDown, '5' ); |
|
235 iNumericKeyHandler->iQwertyMode = ETrue; |
|
236 iNumericKeyHandler->CheckPostToTarget( event ); |
|
237 |
|
238 event.Set( TRawEvent::EKeyDown, '5' ); |
|
239 iNumericKeyHandler->iQwertyMode = EFalse; |
|
240 iNumericKeyHandler->CheckPostToTarget( event ); |
|
241 } |
|
242 void UT_NumericKeyHandler::TestHandlerFunctions2L() |
|
243 { |
|
244 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
245 handler->SetUiStateQuery( *this ); |
|
246 iNumericKeyHandler->LoadInputLanguageKeyBindings(0); |
|
247 iNumericKeyHandler->LoadInputLanguageKeyBindings(1); |
|
248 iNumericKeyHandler->LoadInputLanguageKeyBindings(2); |
|
249 iNumericKeyHandler->LoadInputLanguageKeyBindings(3); |
|
250 iNumericKeyHandler->LoadInputLanguageKeyBindings(4); |
|
251 iNumericKeyHandler->LoadInputLanguageKeyBindings(5); |
|
252 iNumericKeyHandler->LoadInputLanguageKeyBindings(6); |
|
253 } |
|
254 void UT_NumericKeyHandler::TestHandlerFunctions3L() |
|
255 { |
|
256 AiWsPlugin::CEventHandler* handler = iNumericKeyHandler; |
|
257 handler->SetUiStateQuery( *this ); |
|
258 iNumericKeyHandler->HandleQwertyModeChanged(iNumericKeyHandler); |
|
259 iNumericKeyHandler->HandleNotifyGeneric(0); |
|
260 iNumericKeyHandler->HandleNotifyGeneric(1); |
|
261 iNumericKeyHandler->HandleNotifyGeneric(KAknFepInputTxtLang); |
|
262 } |
|
263 |
|
264 TUint UT_NumericKeyHandler::Modifiers() const |
|
265 { |
|
266 return iModifiers; |
|
267 } |
|
268 |
|
269 |
|
270 TBool UT_NumericKeyHandler::HasFocus() const |
|
271 { |
|
272 return ETrue; |
|
273 } |
|
274 |
|
275 |
|
276 // TEST TABLE |
|
277 |
|
278 EUNIT_BEGIN_TEST_TABLE( |
|
279 UT_NumericKeyHandler, |
|
280 "Add test suite description here.", |
|
281 "MODULE" ) |
|
282 |
|
283 EUNIT_TEST( |
|
284 "Test creation", |
|
285 "CNumericKeyHandler", |
|
286 "", |
|
287 "FUNCTIONALITY", |
|
288 SetupL, TestNumericKeyCreationL, Teardown) |
|
289 |
|
290 EUNIT_TEST( |
|
291 "Test Numeric event", |
|
292 "CNumericKeyHandler", |
|
293 "", |
|
294 "FUNCTIONALITY", |
|
295 SetupL, TestNumericKeyEventL, Teardown) |
|
296 |
|
297 EUNIT_TEST( |
|
298 "Test Focus Change", |
|
299 "CNumericKeyHandler", |
|
300 "", |
|
301 "FUNCTIONALITY", |
|
302 SetupL, TestFocusChangeL, Teardown) |
|
303 |
|
304 EUNIT_TEST( |
|
305 "Test Functions", |
|
306 "CNumericKeyHandler", |
|
307 "", |
|
308 "FUNCTIONALITY", |
|
309 SetupL, TestHandlerFunctions1L, Teardown) |
|
310 |
|
311 EUNIT_TEST( |
|
312 "Test Functions", |
|
313 "CNumericKeyHandler", |
|
314 "", |
|
315 "FUNCTIONALITY", |
|
316 SetupL, TestHandlerFunctions2L, Teardown) |
|
317 |
|
318 EUNIT_TEST( |
|
319 "Test Functions", |
|
320 "CNumericKeyHandler", |
|
321 "", |
|
322 "FUNCTIONALITY", |
|
323 SetupL, TestHandlerFunctions3L, Teardown) |
|
324 |
|
325 |
|
326 // Enable this test when memory leak in CTpiEngine has bee fixed.(TSW:VRIA-6V7B4W) |
|
327 /*EUNIT_TEST( |
|
328 "Qwerty Mode Numeric event", |
|
329 "CNumericKeyHandler", |
|
330 "", |
|
331 "FUNCTIONALITY", |
|
332 EmptySetupL, TestNumericKeyEventQwertyModeL, Teardown)*/ |
|
333 |
|
334 EUNIT_END_TEST_TABLE |
|
335 |
|
336 // END OF FILE |