author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 May 2010 14:17:14 +0300 | |
changeset 139 | 95f71bcdcdb7 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32test\server\t_mmc.cpp |
|
15 |
// Tests locking, unlocking and clearing of a password on a suitable |
|
16 |
// device. Currently, this device is a MultiMediaCard. The RFs API |
|
17 |
// allows the user to store the password. |
|
18 |
// This is a manual test, and the operator must observe that the notifier |
|
19 |
// appears exactly when indicated by the program. |
|
20 |
// |
|
21 |
// |
|
22 |
||
23 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#define __E32TEST_EXTENSION__ |
0 | 25 |
#include <f32file.h> |
26 |
#include <e32test.h> |
|
27 |
#include <f32dbg.h> |
|
28 |
#include <f32fsys.h> |
|
29 |
||
30 |
// definitions from p32mmc.h |
|
31 |
||
32 |
const TInt KMMCCIDLength = 16; |
|
33 |
||
34 |
class TMMC |
|
35 |
{ |
|
36 |
public: |
|
37 |
static inline TUint32 BigEndian32(const TUint8*); |
|
38 |
static inline void BigEndian4Bytes(TUint8* aPtr, TUint32 aVal); |
|
39 |
}; |
|
40 |
||
41 |
||
42 |
inline TUint32 TMMC::BigEndian32(const TUint8* aPtr) |
|
43 |
{return( (aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | (aPtr[3]) );} |
|
44 |
||
45 |
inline void TMMC::BigEndian4Bytes(TUint8* aPtr, TUint32 aVal) |
|
46 |
{ |
|
47 |
aPtr[0] = (TUint8)((aVal >> 24) & 0xFF); |
|
48 |
aPtr[1] = (TUint8)((aVal >> 16) & 0xFF); |
|
49 |
aPtr[2] = (TUint8)((aVal >> 8) & 0xFF); |
|
50 |
aPtr[3] = (TUint8)(aVal & 0xFF); |
|
51 |
} |
|
52 |
||
53 |
||
54 |
||
55 |
// local test data |
|
56 |
||
57 |
LOCAL_D RTest test(_L("t_mmc")); |
|
58 |
||
59 |
LOCAL_D RFs TheFs; |
|
60 |
LOCAL_D RFile TheFile; |
|
61 |
||
62 |
#if defined(__WINS__) |
|
63 |
_LIT(KSessionPath, "X:\\"); |
|
64 |
const TInt KDrv = EDriveX; |
|
65 |
const TText KDrvLtr = 'x'; |
|
66 |
#else |
|
67 |
_LIT(KSessionPath, "D:\\"); |
|
68 |
const TInt KDrv = EDriveD; |
|
69 |
const TText KDrvLtr = 'd'; |
|
70 |
#endif |
|
71 |
||
72 |
_LIT(KTestFileName, "testFile"); |
|
73 |
||
74 |
enum TAccessType {EAccessUnlock, EAccessStore, EAccessCancel, EAccessWrongPw, EAccessNoNotifier}; |
|
75 |
||
76 |
LOCAL_D TMediaPassword KNul, KPw1, KPw2, KPw3, KPw4, KPw5; |
|
77 |
||
78 |
#ifdef __WINS__ |
|
79 |
const static TUint8 cid0[KMMCCIDLength] = // "CID0ccccccccccc#"; |
|
80 |
{ |
|
81 |
'C', 'I', 'D', '0', |
|
82 |
'c', 'c', 'c', 'c', |
|
83 |
'c', 'c', 'c', 'c', |
|
84 |
'c', 'c', 'c', '#' |
|
85 |
}; |
|
86 |
#else |
|
87 |
const static TUint8 cid0[KMMCCIDLength] = // big-endian, CID0 |
|
88 |
{ |
|
89 |
0x06, 0x00, 0x00, 0x31, |
|
90 |
0x36, 0x4d, 0x20, 0x20, |
|
91 |
0x20, 0x00, 0xb4, 0xff, |
|
92 |
0xff, 0xff, 0x63, 0xd9 |
|
93 |
}; |
|
94 |
#endif |
|
95 |
||
96 |
// local test functions |
|
97 |
||
98 |
LOCAL_C void RemountMedia(); |
|
99 |
LOCAL_C void ClearControllerStore(); |
|
100 |
LOCAL_C void DeletePasswordFile(); |
|
101 |
LOCAL_C TInt CreateFile(); |
|
102 |
LOCAL_C TInt PWFileSize(TInt &aLength); |
|
103 |
LOCAL_C TInt AccessDisk(TAccessType aAccess, const TDesC8 &aPWD); |
|
104 |
LOCAL_C void TestHasPassword(TBool aIL, TBool aHP); |
|
105 |
||
106 |
LOCAL_C void TestLockUnlockR(); |
|
107 |
LOCAL_C void TestNullPasswords(); |
|
108 |
LOCAL_C void TestLockUnlock(); |
|
109 |
||
110 |
LOCAL_C void TestPasswordStore(); |
|
111 |
LOCAL_C void TestWriteToDisk(); |
|
112 |
||
113 |
LOCAL_C void TestFormat(); |
|
114 |
LOCAL_C void TestRemount(); |
|
115 |
||
116 |
||
117 |
/** force a remount on the removable media. */ |
|
118 |
||
119 |
LOCAL_C void RemountMedia() |
|
120 |
{ |
|
121 |
#ifdef __WINS__ |
|
122 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); |
|
123 |
User::After(1 * 1500 * 1000); |
|
124 |
#else |
|
125 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); |
|
126 |
// User::After(1 * 1500 * 1000); |
|
127 |
test.Printf(_L("Remove and re-insert card. Press \'z\' when finished.\n")); |
|
128 |
while (test.Getch() != 'z') |
|
129 |
{ /* empty. */ } |
|
130 |
#endif |
|
131 |
} |
|
132 |
||
133 |
||
134 |
/** ask the user to replace the current lockable media with another */ |
|
135 |
||
136 |
LOCAL_C void ChangeMedia() |
|
137 |
{ |
|
138 |
#ifdef __WINS__ |
|
139 |
test.Printf(_L("Press f4 whilst holding down f5\n")); |
|
140 |
test.Printf(_L("Press z when completed\n")); |
|
141 |
while(test.Getch() != 'z') |
|
142 |
{ /* empty */ } |
|
143 |
#else |
|
144 |
test.Printf(_L("Remove and insert other card. Press \'z\' when finished.\n")); |
|
145 |
while (test.Getch() != 'z') |
|
146 |
{ /* empty. */ } |
|
147 |
#endif |
|
148 |
} |
|
149 |
||
150 |
||
151 |
/** disable auto-unlock by clearing controller store */ |
|
152 |
||
153 |
LOCAL_C void ClearControllerStore() |
|
154 |
{ |
|
155 |
TBuf8<1> nulSt; |
|
156 |
test(TBusLocalDrive::WritePasswordData(nulSt) == KErrNone);// empty |
|
157 |
test(TBusLocalDrive::PasswordStoreLengthInBytes() == 0); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
/** delete the password store file. Does not affect the auto-unlock mechanism. */ |
|
162 |
||
163 |
LOCAL_C void DeletePasswordFile() |
|
164 |
{ |
|
165 |
TInt r; |
|
166 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile); |
|
167 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
168 |
do |
|
169 |
{ |
|
170 |
User::After(100 * 1000); |
|
171 |
r = TheFs.Delete(mediaPWrdFile); |
|
172 |
} while (r == KErrInUse); |
|
173 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 175 |
} |
176 |
||
177 |
||
178 |
/** attempt to create a file on the removable media and return any error code */ |
|
179 |
||
180 |
LOCAL_C TInt CreateFile() |
|
181 |
{ |
|
182 |
RFile f; |
|
183 |
TInt r = f.Replace(TheFs, KTestFileName, EFileShareAny); |
|
184 |
if (r == KErrNone) |
|
185 |
f.Close(); |
|
186 |
return r; |
|
187 |
} |
|
188 |
||
189 |
||
190 |
/** get size of the media store file in bytes, and return any error code */ |
|
191 |
||
192 |
LOCAL_C TInt PWFileSize(TInt &aLength) |
|
193 |
{ |
|
194 |
TInt r; // error code |
|
195 |
||
196 |
// allow low priority background writer thread to start and finish |
|
197 |
||
198 |
User::After(1 * 1000 * 1000); |
|
199 |
||
200 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile); |
|
201 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
202 |
RFile f; |
|
203 |
if ((r = f.Open(TheFs, mediaPWrdFile, EFileShareAny)) == KErrNone) |
|
204 |
{ |
|
205 |
r = f.Size(aLength); |
|
206 |
f.Close(); |
|
207 |
} |
|
208 |
||
209 |
return r; |
|
210 |
} |
|
211 |
||
212 |
||
213 |
/** |
|
214 |
* write message to screen and attempt to access disk. If card is locked then async |
|
215 |
* notifier will be brought up from within file server. |
|
216 |
*/ |
|
217 |
||
218 |
LOCAL_C TInt AccessDisk(TAccessType aAccess, const TDesC8 &aPWD) |
|
219 |
{ |
|
220 |
TBuf16<16> pwd; |
|
221 |
pwd.Copy((const TUint16 *)aPWD.Ptr(), aPWD.Length() / 2); |
|
222 |
||
223 |
if (aAccess == EAccessUnlock || aAccess == EAccessStore) |
|
224 |
test.Printf(_L("\"%S\": "), &pwd); |
|
225 |
||
226 |
switch(aAccess) |
|
227 |
{ |
|
228 |
case EAccessUnlock: |
|
229 |
test.Printf(_L("unlock\n")); |
|
230 |
break; |
|
231 |
||
232 |
case EAccessStore: |
|
233 |
test.Printf(_L("store\n")); |
|
234 |
break; |
|
235 |
||
236 |
case EAccessCancel: |
|
237 |
test.Printf(_L("cancel\n")); |
|
238 |
break; |
|
239 |
||
240 |
case EAccessWrongPw: |
|
241 |
test.Printf(_L("wrong\n")); |
|
242 |
break; |
|
243 |
||
244 |
case EAccessNoNotifier: |
|
245 |
test.Printf(_L("** no notifier **\n")); |
|
246 |
break; |
|
247 |
||
248 |
default: |
|
249 |
test(EFalse); |
|
250 |
break; |
|
251 |
} |
|
252 |
||
253 |
TInt r = TheFile.Open(TheFs, KTestFileName, EFileShareAny); |
|
254 |
if(r == KErrNone) |
|
255 |
TheFile.Close(); |
|
256 |
||
257 |
return r; |
|
258 |
} |
|
259 |
||
260 |
||
261 |
/** |
|
262 |
* uses RFs::DriveInfo() to test if the card has a password. Is checking |
|
263 |
* that iHasPassword in TMMCCard is maintained properly. |
|
264 |
*/ |
|
265 |
||
266 |
inline TBool bits_set(TUint aMsk, TUint aSel) |
|
267 |
{ |
|
268 |
return (aMsk & aSel) == aSel; |
|
269 |
} |
|
270 |
||
271 |
LOCAL_C void TestHasPassword(TBool aIL, TBool aHP) |
|
272 |
{ |
|
273 |
const TInt d = KDrv; |
|
274 |
RFs &fs = TheFs; |
|
275 |
||
276 |
TDriveInfo di; |
|
277 |
test(fs.Drive(di, d) == KErrNone); |
|
278 |
||
279 |
#ifdef __WINS__ |
|
280 |
test(aIL == bits_set(di.iMediaAtt, KMediaAttLocked | KMediaAttLockable | KMediaAttHasPassword)); |
|
281 |
test(aHP == bits_set(di.iMediaAtt, KMediaAttLockable | KMediaAttHasPassword)); |
|
282 |
#else |
|
283 |
test(aIL == bits_set(di.iMediaAtt, KMediaAttLocked | KMediaAttHasPassword)); |
|
284 |
test(aHP == bits_set(di.iMediaAtt, KMediaAttHasPassword)); |
|
285 |
#endif |
|
286 |
} |
|
287 |
||
288 |
||
289 |
// -------- test functions -------- |
|
290 |
||
291 |
||
292 |
/** |
|
293 |
* test return values of LockDrive(), UnlockDrive() and ClearPassword() |
|
294 |
* without trying use the disk. This tests that the functions return the |
|
295 |
* same values as the TBusLocalDrive functions. |
|
296 |
* |
|
297 |
* EPbPswdUnlock EPbPswdLock EPbPswdClear |
|
298 |
* right wrong right wrong right wrong |
|
299 |
* locked None AccDen AccDec AccDen AccDen AccDen |
|
300 |
* unlocked AldExst AldExst None AccDec None AccDen |
|
301 |
* |
|
302 |
* Locked means inaccessible, not just has password. |
|
303 |
*/ |
|
304 |
||
305 |
LOCAL_C void TestLockUnlockR() |
|
306 |
{ |
|
307 |
test.Start(_L("TestLockUnlockR")); |
|
308 |
||
309 |
const TInt d = KDrv; |
|
310 |
RFs &fs = TheFs; |
|
311 |
||
312 |
test.Next(_L("assign password")); |
|
313 |
test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // assign test password |
|
314 |
TestHasPassword(EFalse, ETrue); |
|
315 |
RemountMedia(); // card is now locked |
|
316 |
TestHasPassword(ETrue, ETrue); |
|
317 |
||
318 |
test.Next(_L("lock locked card")); |
|
319 |
test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrAccessDenied); // lock locked wrong |
|
320 |
TestHasPassword(ETrue, ETrue); |
|
321 |
test(fs.LockDrive(d, KPw1, KPw1, EFalse) == KErrAccessDenied); // lock locked right |
|
322 |
TestHasPassword(ETrue, ETrue); |
|
323 |
||
324 |
test.Next(_L("unlock locked card")); |
|
325 |
test(fs.UnlockDrive(d, KPw2, EFalse) == KErrAccessDenied); // unlock locked wrong |
|
326 |
TestHasPassword(ETrue, ETrue); |
|
327 |
test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone); // unlock locked right |
|
328 |
TestHasPassword(EFalse, ETrue); |
|
329 |
||
330 |
test.Next(_L("unlock unlocked card")); |
|
331 |
test(fs.UnlockDrive(d, KPw1, EFalse) == KErrAlreadyExists); // unlock unlocked right |
|
332 |
TestHasPassword(EFalse, ETrue); |
|
333 |
test(fs.UnlockDrive(d, KPw2, EFalse) == KErrAlreadyExists); // unlock unlocked wrong |
|
334 |
TestHasPassword(EFalse, ETrue); |
|
335 |
||
336 |
test.Next(_L("lock unlocked card")); |
|
337 |
test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrAccessDenied); // lock unlocked wrong |
|
338 |
TestHasPassword(EFalse, ETrue); |
|
339 |
test(fs.LockDrive(d, KPw1, KPw1, EFalse) == KErrNone); // lock unlocked right |
|
340 |
TestHasPassword(EFalse, ETrue); |
|
341 |
||
342 |
test.Next(_L("clear unlocked card")); |
|
343 |
test(fs.ClearPassword(d, KPw2) == KErrAccessDenied); // clear unlocked wrong |
|
344 |
TestHasPassword(EFalse, ETrue); |
|
345 |
||
346 |
RemountMedia(); |
|
347 |
test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone); |
|
348 |
TestHasPassword(EFalse, ETrue); |
|
349 |
test(fs.ClearPassword(d, KPw1) == KErrNone); // clear unlocked right |
|
350 |
TestHasPassword(EFalse, EFalse); |
|
351 |
||
352 |
test.Next(_L("assign password")); |
|
353 |
test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // assign test password |
|
354 |
TestHasPassword(EFalse, ETrue); |
|
355 |
RemountMedia(); // card is now locked |
|
356 |
TestHasPassword(ETrue, ETrue); |
|
357 |
||
358 |
test.Next(_L("clear locked card")); |
|
359 |
test(fs.ClearPassword(d, KPw2) == KErrAccessDenied); // clear locked wrong |
|
360 |
TestHasPassword(ETrue, ETrue); |
|
361 |
test(fs.ClearPassword(d, KPw1) == KErrAccessDenied); // clear locked right |
|
362 |
TestHasPassword(ETrue, ETrue); |
|
363 |
||
364 |
test.Next(_L("clean up for following tests")); |
|
365 |
test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone); |
|
366 |
TestHasPassword(EFalse, ETrue); |
|
367 |
test(fs.ClearPassword(d, KPw1) == KErrNone); |
|
368 |
TestHasPassword(EFalse, EFalse); |
|
369 |
||
370 |
ClearControllerStore(); |
|
371 |
DeletePasswordFile(); |
|
372 |
||
373 |
test.End(); |
|
374 |
} |
|
375 |
||
376 |
||
377 |
/** test the special cases where null passwords are used. */ |
|
378 |
||
379 |
LOCAL_C void TestNullPasswords() |
|
380 |
{ |
|
381 |
test.Start(_L("TestNullPasswords")); |
|
382 |
||
383 |
test.Next(_L("card has no password")); |
|
384 |
test(TheFs.LockDrive(KDrv, KNul, KNul, ETrue) == KErrAccessDenied); |
|
385 |
test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAlreadyExists); |
|
386 |
test(TheFs.ClearPassword(KDrv, KNul) == KErrAccessDenied); |
|
387 |
||
388 |
test.Next(_L("card has password and is unlocked")); |
|
389 |
test(TheFs.LockDrive(KDrv, KNul, KPw1, ETrue) == KErrNone); |
|
390 |
RemountMedia(); |
|
391 |
test(TheFs.LockDrive(KDrv, KNul, KNul, ETrue) == KErrAccessDenied); |
|
392 |
test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAlreadyExists); |
|
393 |
test(TheFs.ClearPassword(KDrv, KNul) == KErrAccessDenied); |
|
394 |
test(TheFs.ClearPassword(KDrv, KPw1) == KErrNone); |
|
395 |
||
396 |
test.Next(_L("unlock with null disallowed")); |
|
397 |
RemountMedia(); |
|
398 |
test(TheFs.UnlockDrive(KDrv, KNul, ETrue) == KErrAccessDenied); |
|
399 |
test.Next(_L("check can still use card")); |
|
400 |
test(TheFs.LockDrive(KDrv, KNul, KPw1, ETrue) == KErrNone); // check can still use |
|
401 |
test(TheFs.ClearPassword(KDrv, KPw1) == KErrNone); |
|
402 |
||
403 |
test.Next(_L("clean up for following tests")); |
|
404 |
ClearControllerStore(); |
|
405 |
DeletePasswordFile(); |
|
406 |
||
407 |
test.End(); |
|
408 |
} |
|
409 |
||
410 |
||
411 |
/** test LockDrive(), UnlockDrive() and ClearPassword() with locked media notifier */ |
|
412 |
||
413 |
LOCAL_C void TestLockUnlock() |
|
414 |
{ |
|
415 |
test.Start(_L("TestLockUnlock")); |
|
416 |
||
417 |
const TInt d = KDrv; |
|
418 |
RFs &fs = TheFs; |
|
419 |
||
420 |
test.Next(_L("create test file")); |
|
421 |
test(CreateFile() == KErrNone); |
|
422 |
||
423 |
test.Next(_L("lock card and don't store")); |
|
424 |
test(fs.LockDrive(d, KNul, KPw1, EFalse) == KErrNone); // unlocked KPw1 |
|
425 |
TestHasPassword(EFalse, ETrue); |
|
426 |
||
427 |
test.Next(_L("access with right pwd")); |
|
428 |
RemountMedia(); // locked KPw1 |
|
429 |
TestHasPassword(ETrue, ETrue); |
|
430 |
test(AccessDisk(EAccessUnlock, KPw1) == KErrNone); |
|
431 |
TestHasPassword(EFalse, ETrue); |
|
432 |
||
433 |
test.Next(_L("access with cancelled pwd")); |
|
434 |
RemountMedia(); // locked KPw1 |
|
435 |
TestHasPassword(ETrue, ETrue); |
|
436 |
test(AccessDisk(EAccessCancel, KNul) == KErrLocked); |
|
437 |
TestHasPassword(ETrue, ETrue); |
|
438 |
||
439 |
test.Next(_L("access with new stored pwd")); |
|
440 |
RemountMedia(); |
|
441 |
TestHasPassword(ETrue, ETrue); |
|
442 |
test(AccessDisk(EAccessStore, KPw1) == KErrNone); // unlocked KPw1 |
|
443 |
TestHasPassword(EFalse, ETrue); |
|
444 |
||
445 |
test.Next(_L("access with stored pwd")); |
|
446 |
RemountMedia(); // unlocked KPw1 (use store) |
|
447 |
TestHasPassword(EFalse, ETrue); |
|
448 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
449 |
TestHasPassword(EFalse, ETrue); |
|
450 |
||
451 |
test.Next(_L("lock wrong pwd")); |
|
452 |
test(fs.LockDrive(d, KPw3, KPw2, EFalse) == KErrAccessDenied); // unlocked KPw1 |
|
453 |
TestHasPassword(EFalse, ETrue); |
|
454 |
||
455 |
test.Next(_L("change pwd")); |
|
456 |
test(fs.LockDrive(d, KPw1, KPw2, EFalse) == KErrNone); // unlocked KPw2 (rem from store) |
|
457 |
TestHasPassword(EFalse, ETrue); |
|
458 |
||
459 |
test.Next(_L("mapping removed from store")); |
|
460 |
RemountMedia(); |
|
461 |
test(AccessDisk(EAccessUnlock, KPw2) == KErrNone); |
|
462 |
TestHasPassword(EFalse, ETrue); |
|
463 |
||
464 |
test.Next(_L("wrong password")); |
|
465 |
RemountMedia(); // locked KPw2 |
|
466 |
TestHasPassword(ETrue, ETrue); |
|
467 |
test(AccessDisk(EAccessWrongPw, KNul) == KErrLocked); |
|
468 |
TestHasPassword(ETrue, ETrue); |
|
469 |
||
470 |
test.Next(_L("unlocked card")); |
|
471 |
test(fs.UnlockDrive(d, KPw2, ETrue) == KErrNone); // unlocked KPw2 (add to store) |
|
472 |
TestHasPassword(EFalse, ETrue); |
|
473 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); // before power down |
|
474 |
TestHasPassword(EFalse, ETrue); |
|
475 |
||
476 |
test.Next(_L("clear wrong pwd")); |
|
477 |
test(fs.ClearPassword(d, KPw1) == KErrAccessDenied); // KPw2 backup kept |
|
478 |
TestHasPassword(EFalse, ETrue); |
|
479 |
RemountMedia(); // unlocked KPw2 (use store) |
|
480 |
TestHasPassword(EFalse, ETrue); |
|
481 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
482 |
TestHasPassword(EFalse, ETrue); |
|
483 |
||
484 |
test.Next(_L("change pwd")); |
|
485 |
test(fs.LockDrive(d, KPw2, KPw1, EFalse) == KErrNone); // locked KPw1 (rem from store) |
|
486 |
TestHasPassword(EFalse, ETrue); |
|
487 |
RemountMedia(); |
|
488 |
TestHasPassword(ETrue, ETrue); |
|
489 |
test(AccessDisk(EAccessUnlock, KPw1) == KErrNone); |
|
490 |
TestHasPassword(EFalse, ETrue); |
|
491 |
||
492 |
test.Next(_L("cancelled pwd")); |
|
493 |
RemountMedia(); |
|
494 |
TestHasPassword(ETrue, ETrue); |
|
495 |
test(AccessDisk(EAccessCancel, KNul) == KErrLocked); |
|
496 |
TestHasPassword(ETrue, ETrue); |
|
497 |
||
498 |
test.Next(_L("clean up for following tests")); |
|
499 |
test(fs.UnlockDrive(d, KPw1, EFalse) == KErrNone); |
|
500 |
TestHasPassword(EFalse, ETrue); |
|
501 |
test(fs.ClearPassword(KDrv, KPw1) == KErrNone); |
|
502 |
TestHasPassword(EFalse, EFalse); |
|
503 |
RemountMedia(); |
|
504 |
TestHasPassword(EFalse, EFalse); |
|
505 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
506 |
TestHasPassword(EFalse, EFalse); |
|
507 |
ClearControllerStore(); |
|
508 |
DeletePasswordFile(); |
|
509 |
||
510 |
test.End(); |
|
511 |
} |
|
512 |
||
513 |
||
514 |
/** |
|
515 |
* test password store by accessing disk in various states. Ensures password |
|
516 |
* store file is right size after each operation. More detailed checking of |
|
517 |
* the TBusLocalDrive::ReadPasswordData() ouput is done in t_pwstr. |
|
518 |
*/ |
|
519 |
||
520 |
LOCAL_C void TestPasswordStore() |
|
521 |
{ |
|
522 |
test.Start(_L("TestPasswordStore")); |
|
523 |
||
524 |
// TInt r; // general error code |
|
525 |
RFs &fs = TheFs; |
|
526 |
const TInt d = KDrv; |
|
527 |
||
528 |
test.Next(_L("create test file on first media")); |
|
529 |
test(CreateFile() == KErrNone); |
|
530 |
||
531 |
test.Next(_L("lock card and don't store")); |
|
532 |
test(fs.LockDrive(d, KNul, KPw5, EFalse) == KErrNone); // {} |
|
533 |
TestHasPassword(EFalse, ETrue); |
|
534 |
TInt size1; |
|
535 |
test(PWFileSize(size1) == KErrNotFound); |
|
536 |
||
537 |
test.Next(_L("lock card and store")); |
|
538 |
test(fs.LockDrive(d, KPw5, KPw3, ETrue) == KErrNone); // {0 |-> 3} |
|
539 |
TestHasPassword(EFalse, ETrue); |
|
540 |
test.Next(_L("access media1 with stored password")); |
|
541 |
||
542 |
RemountMedia(); |
|
543 |
TestHasPassword(EFalse, ETrue); |
|
544 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
545 |
TestHasPassword(EFalse, ETrue); |
|
546 |
||
547 |
test.Next(_L("test password file exists")); |
|
548 |
test(PWFileSize(size1) == KErrNone); |
|
549 |
test(size1 == 16 + 4 + KPw3.Length()); |
|
550 |
||
551 |
test.Next(_L("change cards and add second password to store")); |
|
552 |
ChangeMedia(); |
|
553 |
||
554 |
test.Next(_L("create test file on second media")); |
|
555 |
test(CreateFile() == KErrNone); |
|
556 |
||
557 |
test.Next(_L("lock card and store")); |
|
558 |
test(fs.LockDrive(d, KNul, KPw4, ETrue) == KErrNone); // {0 |-> 3, 1 |-> 4} |
|
559 |
TestHasPassword(EFalse, ETrue); |
|
560 |
||
561 |
TInt size2; |
|
562 |
test(PWFileSize(size2) == KErrNone); |
|
563 |
test(size2 == 16 + 4 + KPw3.Length() + 16 + 4 + KPw4.Length()); |
|
564 |
||
565 |
test.Next(_L("access media2 with stored password")); |
|
566 |
RemountMedia(); |
|
567 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
568 |
TestHasPassword(EFalse, ETrue); |
|
569 |
||
570 |
test.Next(_L("change password")); |
|
571 |
test(fs.LockDrive(d, KPw4, KPw5, ETrue) == KErrNone); // {0 |-> 3, 1 |-> 5} |
|
572 |
TestHasPassword(EFalse, ETrue); |
|
573 |
||
574 |
TInt size3; |
|
575 |
test(PWFileSize(size3) == KErrNone); |
|
576 |
test(size3 == 16 + 4 + KPw3.Length() + 16 + 4 + KPw5.Length()); |
|
577 |
||
578 |
test.Next(_L("access media1 with stored password")); |
|
579 |
ChangeMedia(); |
|
580 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
581 |
||
582 |
test.Next(_L("remove password from media 1")); |
|
583 |
test(fs.ClearPassword(d, KPw3) == KErrNone); // {1 |-> 5} - 0 |-> 3 |
|
584 |
TestHasPassword(EFalse, EFalse); |
|
585 |
test(PWFileSize(size3) == KErrNone); |
|
586 |
test(size3 == 16 + 4 + KPw5.Length()); |
|
587 |
||
588 |
test.Next(_L("clean up for following tests")); |
|
589 |
ChangeMedia(); |
|
590 |
test(fs.ClearPassword(d, KPw5) == KErrNone); // {} - 1 |-> 5 |
|
591 |
TestHasPassword(EFalse, EFalse); |
|
592 |
test(PWFileSize(size3) == KErrNone); |
|
593 |
test(size3 == 0); |
|
594 |
test.Printf(_L("replace original card\n")); |
|
595 |
ChangeMedia(); // use original card |
|
596 |
ClearControllerStore(); |
|
597 |
DeletePasswordFile(); |
|
598 |
||
599 |
test.End(); |
|
600 |
} |
|
601 |
||
602 |
||
603 |
/** |
|
604 |
* check the spin off delayed writer thread can work when many requests are queued. |
|
605 |
* |
|
606 |
* The background writer runs at EPriorityMuchLess, so it will not be executed until |
|
607 |
* this thread sleeps. |
|
608 |
*/ |
|
609 |
||
610 |
LOCAL_C void TestWriteToDisk() |
|
611 |
{ |
|
612 |
test.Start(_L("TestWriteToDisk")); |
|
613 |
||
614 |
TInt r; // error code |
|
615 |
TBuf8<1> noMappings; |
|
616 |
||
617 |
test.Next(_L("Queuing threads")); |
|
618 |
test.Printf(_L("Queuing 100 writes\n")); |
|
619 |
||
620 |
const TInt KQueueCnt = 100; |
|
621 |
||
622 |
TInt i; |
|
623 |
TMediaPassword oldPswd; // empty - no password at start |
|
624 |
TMediaPassword newPswd; |
|
625 |
for (i = 0; i < KQueueCnt; ++i) |
|
626 |
{ |
|
627 |
newPswd.Fill(i, KMaxMediaPassword); |
|
628 |
test(TheFs.LockDrive(KDrv, oldPswd, newPswd, ETrue) == KErrNone); |
|
629 |
oldPswd.Copy(newPswd); |
|
630 |
} |
|
631 |
||
632 |
test.Printf(_L("Waiting 20 seconds for threads to complete\n")); |
|
633 |
User::After(20 * 1000 * 1000); |
|
634 |
||
635 |
// check password file contains the last writing. |
|
636 |
||
637 |
test.Next(_L("check password file contains last writing")); |
|
638 |
const TInt KFileLen = 16 + sizeof(TUint32) + KMaxMediaPassword; |
|
639 |
RFile f; |
|
640 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile); |
|
641 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
642 |
test(f.Open(TheFs, mediaPWrdFile, EFileShareExclusive | EFileStream | EFileRead) == KErrNone); |
|
643 |
TInt sz; |
|
644 |
test(f.Size(sz) == KErrNone); |
|
645 |
test(sz == KFileLen); |
|
646 |
||
647 |
TBuf8<KFileLen> chkBuf; |
|
648 |
test(f.Read(chkBuf, KFileLen) == KErrNone); |
|
649 |
// defer checking buffer contents until after password cleared so not left |
|
650 |
// with locked card if test fails. |
|
651 |
f.Close(); |
|
652 |
||
653 |
test(TheFs.ClearPassword(KDrv, oldPswd) == KErrNone); |
|
654 |
User::After(1 * 1000 * 1000); // wait to finish writing |
|
655 |
||
656 |
r = TheFs.Delete(mediaPWrdFile); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
0 | 658 |
test(TBusLocalDrive::WritePasswordData(noMappings) == KErrNone); |
659 |
||
660 |
// check contents of password file correspond to last written buffer. |
|
661 |
||
662 |
test(chkBuf.Length() == KFileLen); |
|
663 |
test(chkBuf.Mid(0, KMMCCIDLength) == TPtrC8(cid0, KMMCCIDLength)); |
|
664 |
const TUint32 len = TMMC::BigEndian32(chkBuf.Mid(KMMCCIDLength, sizeof(TUint32)).Ptr()); |
|
665 |
test(len == TInt(KMaxMediaPassword)); |
|
666 |
test(chkBuf.Mid(KMMCCIDLength + sizeof(TUint32), KMMCCIDLength) == oldPswd); |
|
667 |
||
668 |
test.Next(_L("clean up for following tests")); |
|
669 |
ClearControllerStore(); |
|
670 |
DeletePasswordFile(); |
|
671 |
||
672 |
test.End(); |
|
673 |
} |
|
674 |
||
675 |
||
676 |
/** test unable to format locked card */ |
|
677 |
||
678 |
LOCAL_C void TestFormat() |
|
679 |
{ |
|
680 |
test.Start(_L("TestFormat")); |
|
681 |
||
682 |
// TInt r; // error code |
|
683 |
RFs &fs = TheFs; |
|
684 |
const TInt d = KDrv; |
|
685 |
||
686 |
TBuf<3> bfDrv; |
|
687 |
bfDrv.Append(KDrvLtr); |
|
688 |
_LIT(KBP, ":\\"); |
|
689 |
bfDrv.Append(KBP); |
|
690 |
||
691 |
test.Next(_L("create test file")); |
|
692 |
test(CreateFile() == KErrNone); |
|
693 |
||
694 |
test.Next(_L("lock drive")); |
|
695 |
test(TheFs.LockDrive(KDrv, KNul, KPw2, EFalse) == KErrNone); |
|
696 |
RemountMedia(); |
|
697 |
||
698 |
test.Next(_L("unlock card and don't store")); |
|
699 |
test(AccessDisk(EAccessUnlock, KPw2) == KErrNone); |
|
700 |
||
701 |
// format unlocked drive |
|
702 |
test.Next(_L("format unlocked card")); |
|
703 |
RFormat fmt; |
|
704 |
TInt count; |
|
705 |
test(fmt.Open(fs, bfDrv, EHighDensity, count) == KErrNone); |
|
706 |
while (count > 0) |
|
707 |
{ |
|
708 |
test.Printf(_L("\rfmt:%d "), count); |
|
709 |
test(fmt.Next(count) == KErrNone); |
|
710 |
} |
|
711 |
test.Printf(_L("\n")); |
|
712 |
fmt.Close(); |
|
713 |
||
714 |
test.Next(_L("format locked media")); |
|
715 |
RemountMedia(); // locked KPw2 |
|
716 |
test.Printf(_L("Notifier: No password required. Press cancel. \n")); |
|
717 |
test(fmt.Open(fs, bfDrv, EHighDensity, count) == KErrLocked); |
|
718 |
||
719 |
test.Next(_L("unlock locked card")); |
|
720 |
test(fs.UnlockDrive(d, KPw2, EFalse) == KErrNone); |
|
721 |
test(fs.ClearPassword(d, KPw2) == KErrNone); |
|
722 |
||
723 |
test.Next(_L("create test file")); |
|
724 |
test(CreateFile() == KErrNone); |
|
725 |
||
726 |
test.Next(_L("remount media, check not locked")); |
|
727 |
RemountMedia(); |
|
728 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
729 |
||
730 |
test.Next(_L("clean up for following tests")); |
|
731 |
ClearControllerStore(); |
|
732 |
DeletePasswordFile(); |
|
733 |
||
734 |
test.End(); |
|
735 |
} |
|
736 |
||
737 |
||
738 |
/** do media change with file open */ |
|
739 |
||
740 |
LOCAL_C void TestRemount() |
|
741 |
{ |
|
742 |
test.Start(_L("TestRemount")); |
|
743 |
||
744 |
// TInt r; // general error code |
|
745 |
RFs &fs = TheFs; |
|
746 |
const TInt d = KDrv; |
|
747 |
||
748 |
test.Next(_L("create file")); |
|
749 |
TFileName fn; |
|
750 |
fn.Append(KDrvLtr); |
|
751 |
_LIT(KFN, ":\\openfile"); |
|
752 |
fn.Append(KFN); |
|
753 |
test.Printf(_L("fn = \"%S\"\n"), &fn); |
|
754 |
||
755 |
RFile f; |
|
756 |
test(f.Replace(fs, fn, EFileShareAny) == KErrNone); |
|
757 |
||
758 |
test.Next(_L("lock card")); |
|
759 |
test(fs.LockDrive(d, KNul, KPw5, EFalse) == KErrNone); |
|
760 |
||
761 |
test.Next(_L("access with right pwd")); |
|
762 |
RemountMedia(); |
|
763 |
test(AccessDisk(EAccessUnlock, KPw5) == KErrNone); |
|
764 |
||
765 |
test.Next(_L("access with wrong pwd")); |
|
766 |
RemountMedia(); |
|
767 |
test(AccessDisk(EAccessWrongPw, KNul) == KErrLocked); |
|
768 |
||
769 |
test.Next(_L("access with cancelled pwd")); |
|
770 |
RemountMedia(); |
|
771 |
test(AccessDisk(EAccessCancel, KNul) == KErrLocked); |
|
772 |
||
773 |
test.Next(_L("clear password")); |
|
774 |
test(fs.UnlockDrive(d, KPw5, EFalse) == KErrNone); |
|
775 |
test(fs.ClearPassword(d, KPw5) == KErrNone); |
|
776 |
||
777 |
test(AccessDisk(EAccessNoNotifier, KNul) == KErrNone); |
|
778 |
||
779 |
test.Next(_L("close and delete file")); |
|
780 |
f.Close(); |
|
781 |
test(fs.Delete(fn) == KErrNone); |
|
782 |
||
783 |
test.Next(_L("clean up for following tests")); |
|
784 |
ClearControllerStore(); |
|
785 |
DeletePasswordFile(); |
|
786 |
||
787 |
test.End(); |
|
788 |
} |
|
789 |
||
790 |
||
791 |
/** |
|
792 |
* entry point. Displays instructions; sets up heap checking; sets up |
|
793 |
* file server session and calls individual tests. Mounts drive for WINS. |
|
794 |
*/ |
|
795 |
||
796 |
_LIT(KSDProtDriverFileName,"MEDSDP"); |
|
797 |
_LIT(KSDProtDriverObjName,"Media.SdP"); |
|
798 |
GLDEF_C TInt E32Main() |
|
799 |
{ |
|
800 |
__UHEAP_MARK; |
|
801 |
||
802 |
test.Title(); |
|
803 |
test.Start(_L("Starting T_MMC")); |
|
804 |
||
805 |
test.Printf(_L("The notifier should only apear along with user instructions.\n")); |
|
806 |
test.Printf(_L("The test has failed otherwise.\n")); |
|
807 |
test.Printf(_L("\n")); |
|
808 |
test.Printf(_L("Use return to simulate unlock button on notifier\n")); |
|
809 |
test.Printf(_L("Use space to simulate store button on notifier\n")); |
|
810 |
test.Printf(_L("Use escape to simulate cancel button on notifier\n")); |
|
811 |
test.Printf(_L("Press a key to continue ...\n\n")); |
|
812 |
test.Getch(); |
|
813 |
||
814 |
test(TheFs.Connect() == KErrNone); |
|
815 |
||
816 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile); |
|
817 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
818 |
TParsePtrC ppc(mediaPWrdFile); |
|
819 |
TInt r = TheFs.MkDir(ppc.DriveAndPath()); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
820 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
0 | 821 |
|
822 |
// The media driver for the protected area of the SD card uses mount |
|
823 |
// info. This is also used for password unlocking by the MMC media driver. |
|
824 |
// Due to a temporary problem with the way mount info. is assigned to DMedia |
|
825 |
// objects which results in a conflict between the two drivers, unload |
|
826 |
// the protected area SD card driver for duration of test. |
|
827 |
TheFs.RemountDrive(KDrv,NULL,KLocDrvRemountPostponeRemount); |
|
828 |
User::FreePhysicalDevice(KSDProtDriverObjName); |
|
829 |
||
830 |
test(TheFs.SetSessionPath(KSessionPath) == KErrNone); |
|
831 |
||
832 |
// initialize the TMediaPassword data |
|
833 |
KNul.Copy(reinterpret_cast<const TUint8 *>(L""), 0); |
|
834 |
KPw1.Copy(reinterpret_cast<const TUint8 *>(L"b"), 2); |
|
835 |
KPw2.Copy(reinterpret_cast<const TUint8 *>(L"cd"), 4); |
|
836 |
KPw3.Copy(reinterpret_cast<const TUint8 *>(L"def"), 6); |
|
837 |
KPw4.Copy(reinterpret_cast<const TUint8 *>(L"efgh"), 8); |
|
838 |
KPw5.Copy(reinterpret_cast<const TUint8 *>(L"fghij"), 10); |
|
839 |
||
840 |
test.Next(_L("calling ClearControllerStore")); |
|
841 |
ClearControllerStore(); |
|
842 |
test.Next(_L("calling DeletePasswordFile")); |
|
843 |
DeletePasswordFile(); |
|
844 |
||
845 |
test.Next(_L("calling TestLockUnlockR")); |
|
846 |
TestLockUnlockR(); |
|
847 |
test.Next(_L("calling TestNullPasswords")); |
|
848 |
TestNullPasswords(); |
|
849 |
test.Next(_L("calling TestLockUnlock")); |
|
850 |
TestLockUnlock(); |
|
851 |
||
852 |
test.Next(_L("calling TestPasswordStore")); |
|
853 |
TestPasswordStore(); |
|
854 |
test.Next(_L("calling TestWriteToDisk")); |
|
855 |
TestWriteToDisk(); |
|
856 |
||
857 |
test.Next(_L("calling TestFormat")); |
|
858 |
TestFormat(); |
|
859 |
test.Next(_L("calling TestRemount")); |
|
860 |
TestRemount(); |
|
861 |
||
862 |
// Restore SD Card protected area media driver |
|
863 |
User::LoadPhysicalDevice(KSDProtDriverFileName); |
|
864 |
||
865 |
TheFs.Close(); |
|
866 |
test.End(); |
|
867 |
test.Close(); |
|
868 |
||
869 |
__UHEAP_MARKEND; |
|
870 |
||
871 |
return KErrNone; |
|
872 |
} |
|
873 |