|
1 /* |
|
2 * Copyright (c) 2006 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: test case |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <w32std.h> |
|
20 #include <coecntrl.h> |
|
21 #include <eikenv.h> |
|
22 #include <ptikeymappings.h> |
|
23 #include <BARSREAD.H> |
|
24 |
|
25 #include "BCTestQwertymap.h" |
|
26 #include "BCTestPtiEngcontainer.h" |
|
27 #include "BCTestPtiEng.hrh" |
|
28 #include "streamlogger.h" |
|
29 #include "PtiLanguage.h" |
|
30 |
|
31 _LIT( KQwertyDir, "z:\\resource\\qwerty\\" ); |
|
32 _LIT( KMultiTapWildName, "*.rsc" ); |
|
33 |
|
34 _LIT( KNewMapLower, "`" ); |
|
35 _LIT( KNewMapUpper, "~" ); |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS ============================ |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Symbian 2nd static Constructor |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CBCTestQwertyMap* CBCTestQwertyMap::NewL() |
|
48 { |
|
49 CBCTestQwertyMap* self = new( ELeave ) CBCTestQwertyMap(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // C++ default constructor |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CBCTestQwertyMap::CBCTestQwertyMap():iMap(NULL) |
|
61 { |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Destructor |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CBCTestQwertyMap::~CBCTestQwertyMap() |
|
69 { |
|
70 Teardown(); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Symbian 2nd Constructor |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CBCTestQwertyMap::ConstructL() |
|
78 { |
|
79 BuildScriptL(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CBCTestQwertyMap::BuildScriptL |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CBCTestQwertyMap::BuildScriptL() |
|
87 { |
|
88 // Add script as your need. |
|
89 AddTestL( LeftCBA, |
|
90 REP(Down, 3), |
|
91 KeyOK, TEND ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CBCTestQwertyMap::RunL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CBCTestQwertyMap::RunL( TInt aCmd ) |
|
99 { |
|
100 if ( aCmd != EBCTestCmdQwertyMap) |
|
101 { |
|
102 return; |
|
103 } |
|
104 if( !ValidQwertyMode() ) |
|
105 { |
|
106 AssertTrueL( ETrue, _L("QwertyKeyBoard not surported!") ); |
|
107 return; |
|
108 } |
|
109 TestFunctionL(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CBCTestQwertyMap::TestLayoutDecorator |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CBCTestQwertyMap::TestFunctionL() |
|
117 { |
|
118 SetupL(); |
|
119 if ( iMap ) |
|
120 { |
|
121 TestMapping(); |
|
122 TestReplaceMappingL(); |
|
123 TestReverseMapping(); |
|
124 TestKeyData(); |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CBCTestQwertyMap::SetupL() |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void CBCTestQwertyMap::SetupL() |
|
133 { |
|
134 TRAPD(err, iMap = static_cast<CPtiQwertyKeyMappings*>(CreateKeyMapL())); |
|
135 if(err == KErrCorrupt) |
|
136 { |
|
137 AssertTrueL(ETrue, _L("data format err")); |
|
138 } |
|
139 else if ( KErrNotFound == err ) |
|
140 { |
|
141 iMap = NULL; |
|
142 AssertTrueL(ETrue, _L("data format err KErrNotFound")); |
|
143 } |
|
144 else |
|
145 { |
|
146 AssertNotNullL(iMap, _L("created by NewL from descriptor")); |
|
147 } |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CBCTestQwertyMap::Teardown() |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CBCTestQwertyMap::Teardown() |
|
155 { |
|
156 delete iMap; |
|
157 iMap = NULL; |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CBCTestQwertyMap::TestMapping() |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CBCTestQwertyMap::TestMapping() |
|
166 { |
|
167 TestStartMapping(); |
|
168 TestNextKey(); |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CBCTestQwertyMap::TestStartMapping() |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CBCTestQwertyMap::TestStartMapping() |
|
177 { |
|
178 |
|
179 TPtrC keydata(_L('a')); |
|
180 TInt size = keydata.Length(); |
|
181 |
|
182 iMap->StartMapping( (TPtiKey)keydata[size/2+1], EPtiCaseLower ); |
|
183 _LIT( KStartMapping, "StartMapping is invoked" ); |
|
184 AssertTrueL( ETrue, KStartMapping ); |
|
185 |
|
186 iMap->StartMapping( (TPtiKey)keydata[0], EPtiCaseLower ); |
|
187 _LIT( KStartMapping1, "StartMapping1 is invoked" ); |
|
188 AssertTrueL( ETrue, KStartMapping1 ); |
|
189 |
|
190 } |
|
191 |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CBCTestQwertyMap::TestNextKey() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CBCTestQwertyMap::TestNextKey() |
|
198 { |
|
199 |
|
200 TPtrC keydata(_L('a')); |
|
201 TInt size = keydata.Length(); |
|
202 |
|
203 TBool isAppend = ETrue; |
|
204 iMap->StartMapping( (TPtiKey)keydata[size/2+1], EPtiCaseLower); |
|
205 |
|
206 iMap->NextKey( (TPtiKey)keydata[size/2+1], isAppend, EPtiCaseLower ); |
|
207 _LIT( KNextKey, "NextKey is invoked" ); |
|
208 AssertTrueL( ETrue, KNextKey ); |
|
209 |
|
210 iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseLower ); |
|
211 _LIT( KNextKey1, "NextKey1 is invoked" ); |
|
212 AssertTrueL( ETrue, KNextKey1 ); |
|
213 |
|
214 } |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CBCTestQwertyMap::TestReplaceMappingL() |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CBCTestQwertyMap::TestReplaceMappingL() |
|
222 { |
|
223 TBool isAppend = ETrue; |
|
224 TBuf<5> lowerMap( KNewMapLower ); |
|
225 TBuf<5> upperMap( KNewMapUpper ); |
|
226 |
|
227 TPtrC keydata(_L('a')); |
|
228 TInt size = keydata.Length(); |
|
229 |
|
230 iMap->ReplaceKeyMapL( (TPtiKey)keydata[0], lowerMap, EPtiCaseLower ); |
|
231 _LIT( KReplaceKeyMapL, "ReplaceKeyMapL is invoked" ); |
|
232 AssertTrueL( ETrue, KReplaceKeyMapL ); |
|
233 |
|
234 iMap->ReplaceKeyMapL( (TPtiKey)keydata[0], upperMap, EPtiCaseUpper ); |
|
235 _LIT( KReplaceKeyMapL1, "ReplaceKeyMapL1 is invoked" ); |
|
236 AssertTrueL( ETrue, KReplaceKeyMapL1 ); |
|
237 |
|
238 iMap->StartMapping( (TPtiKey)keydata[0], EPtiCaseLower ); |
|
239 _LIT( KStartMapping, "StartMapping is invoked" ); |
|
240 AssertTrueL( ETrue, KStartMapping ); |
|
241 |
|
242 iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseLower); |
|
243 _LIT( KNextKey, "NextKey is invoked" ); |
|
244 AssertTrueL( ETrue, KNextKey ); |
|
245 |
|
246 iMap->NextKey( (TPtiKey)keydata[0], isAppend, EPtiCaseUpper); |
|
247 _LIT( KNextKey1, "NextKey1 is invoked" ); |
|
248 AssertTrueL( ETrue, KNextKey1 ); |
|
249 |
|
250 } |
|
251 |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // CBCTestQwertyMap::TestReverseMapping() |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CBCTestQwertyMap::TestReverseMapping() |
|
258 { |
|
259 |
|
260 |
|
261 TPtrC keydata(_L('a')); |
|
262 TInt size = keydata.Length(); |
|
263 |
|
264 iMap->KeyForCharacter( keydata[1] ); |
|
265 _LIT( KKeyForCharacter, "KeyForCharacter is invoked" ); |
|
266 AssertTrueL( ETrue, KKeyForCharacter ); |
|
267 |
|
268 iMap->KeyForCharacter( keydata[2] ); |
|
269 _LIT( KKeyForCharacter1, "KeyForCharacter1 is invoked" ); |
|
270 AssertTrueL( ETrue, KKeyForCharacter1 ); |
|
271 } |
|
272 |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CBCTestQwertyMap::TestKeyData() |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CBCTestQwertyMap::TestKeyData() |
|
279 { |
|
280 |
|
281 TPtrC keydata(_L('a')); |
|
282 TInt size = keydata.Length(); |
|
283 |
|
284 TBuf<8> mapStr; |
|
285 |
|
286 iMap->GetDataForKey( (TPtiKey)keydata[0], mapStr, EPtiCaseLower ); |
|
287 AssertTrueL( ETrue, _L("Lower case data for key 1 is `") ); |
|
288 |
|
289 iMap->GetDataForKey( (TPtiKey)keydata[0], mapStr, EPtiCaseUpper ); |
|
290 AssertTrueL( ETrue, _L("Upper case data for key 1 is ~") ); |
|
291 } |
|
292 |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // CBCTestQwertyMap::CreateKeyMapL() |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 MPtiKeyMappings* CBCTestQwertyMap::CreateKeyMapL() |
|
299 { |
|
300 |
|
301 MPtiKeyMappings* keyMappings = NULL; |
|
302 RFs fsSession; |
|
303 User::LeaveIfError( fsSession.Connect() ); // Start session |
|
304 CleanupClosePushL( fsSession ); |
|
305 |
|
306 fsSession.SetSessionPath( KQwertyDir ); |
|
307 |
|
308 TResourceReader reader; |
|
309 RResourceFile resFile; |
|
310 |
|
311 TFindFile fileFinder( fsSession ); |
|
312 CDir* fileList = NULL; |
|
313 TInt err; |
|
314 err = fileFinder.FindWildByPath( KMultiTapWildName, &KQwertyDir, fileList ); |
|
315 |
|
316 TInt code = User::Language(); |
|
317 TInt lcode; |
|
318 |
|
319 if ( err == KErrNoMemory ) |
|
320 { |
|
321 delete fileList; |
|
322 User::Leave( KErrNoMemory ); |
|
323 } |
|
324 |
|
325 else if ( err == KErrNone ) |
|
326 { |
|
327 CleanupStack::PushL( fileList ); |
|
328 TParse fileName; |
|
329 HBufC8* rBuffer = NULL; |
|
330 |
|
331 TInt i; |
|
332 for ( i = 0; i < fileList->Count(); i++ ) |
|
333 { |
|
334 fileName.Set( (*fileList)[i].iName, &fileFinder.File(), NULL ); |
|
335 resFile.OpenL( fsSession, fileName.FullName() ); |
|
336 CleanupClosePushL( resFile ); |
|
337 |
|
338 rBuffer = resFile.AllocReadLC( 1 ); |
|
339 reader.SetBuffer( rBuffer ); |
|
340 |
|
341 lcode = *( (TInt16*)rBuffer->Ptr() ); |
|
342 if ( lcode == code ) |
|
343 { |
|
344 break; |
|
345 } |
|
346 CleanupStack::PopAndDestroy(2); // rBuffer, resFile |
|
347 } |
|
348 if ( i >= fileList->Count() ) |
|
349 { |
|
350 User::Leave( KErrNotFound ); |
|
351 } |
|
352 |
|
353 TPtrC mtdata( (TUint16*)( rBuffer->Ptr() + ( 2 * sizeof( TUint16 ) ) ), |
|
354 ( rBuffer->Length() - (2 * sizeof(TUint16) ) ) / 2 ); |
|
355 keyMappings = CPtiQwertyKeyMappings::NewL( mtdata ); |
|
356 |
|
357 CleanupStack::PopAndDestroy(3); // fileList, rBuffer, resFile |
|
358 } |
|
359 |
|
360 CleanupStack::PopAndDestroy(); // fsSession |
|
361 |
|
362 return keyMappings; |
|
363 |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // CBCTestQwertyMap::ValidQwertyMode() |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 bool CBCTestQwertyMap::ValidQwertyMode() |
|
371 { |
|
372 |
|
373 RFs fsSession; |
|
374 User::LeaveIfError( fsSession.Connect() ); // Start session |
|
375 CleanupClosePushL( fsSession ); |
|
376 |
|
377 fsSession.SetSessionPath( KQwertyDir ); |
|
378 |
|
379 TFindFile fileFinder( fsSession ); |
|
380 CDir* fileList = NULL; |
|
381 TInt err = fileFinder.FindWildByPath( KMultiTapWildName, &KQwertyDir, fileList ); |
|
382 delete fileList; |
|
383 CleanupStack::PopAndDestroy(); // fsSession |
|
384 if( err == KErrNone ) |
|
385 { |
|
386 return true; |
|
387 } |
|
388 else |
|
389 { |
|
390 return false; |
|
391 } |
|
392 |
|
393 } |