author | hgs |
Mon, 11 Oct 2010 19:11:06 +0100 | |
changeset 287 | ddfd5aa0d58f |
parent 286 | 48e57fb1237e |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2006-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\demandpaging\t_clamp.cpp |
|
15 |
// Test suite for file clamping, file clamping is used to prevent files |
|
16 |
// (exes or dlls) from being deleted whilst in use. |
|
17 |
// 002 GetDriveLetters() |
|
18 |
// 003 Test1() Basic clamp operation |
|
19 |
// 004 Test2() Invalid clamp requests |
|
20 |
// 005 Test3() Denied FS requests when file(s) are clamped |
|
21 |
// 006 Test3Operations() Test other RFile, RFs operations |
|
22 |
// 007 Test3Operations() Increase number of clamps to MY_N |
|
23 |
// 008 Test3Operations() Decrease number of clamps by MY_M |
|
24 |
// 009 Test3Operations() Increase number of clamps by MY_M |
|
25 |
// 010 TestDeferredDismount() Open and clamp file, register for dismount |
|
26 |
// notification, then issue dismount instruction. |
|
27 |
// 011 Test4() Clamp tests for non-writable file system |
|
28 |
// 012 Test5() Clamp requests on non-clamping file systems |
|
29 |
// |
|
30 |
// |
|
31 |
||
32 |
//! @SYMTestCaseID KBASE-T_CLAMP-0328 |
|
33 |
//! @SYMTestType UT |
|
34 |
//! @SYMPREQ PREQ1110 |
|
35 |
//! @SYMTestCaseDesc Demand Paging File Clamp tests |
|
36 |
//! @SYMTestActions 001 Starting T_CLAMP |
|
37 |
//! @SYMTestExpectedResults All tests should pass. |
|
38 |
//! @SYMTestPriority High |
|
39 |
//! @SYMTestStatus Implemented |
|
40 |
||
41 |
#define __E32TEST_EXTENSION__ |
|
42 |
||
43 |
#include <e32test.h> |
|
44 |
RTest test(_L("T_CLAMP")); |
|
45 |
||
46 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
47 |
||
48 |
#include <f32file.h> |
|
49 |
#include <f32dbg.h> |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
#include <e32ldr_private.h> |
0 | 51 |
RFs TheFs; |
52 |
||
53 |
_LIT(KFATName,"FAT"); |
|
54 |
//_LIT(KFAT32Name,"FAT32"); |
|
55 |
_LIT(KROFSName,"ROFS"); |
|
56 |
_LIT(KLFFSName,"LFFS"); |
|
57 |
_LIT(KCOMPName,"COMPOSITE"); // Z: name if Composite File System |
|
58 |
//#ifdef __WINS__ |
|
59 |
//_LIT(KROMName,"WIN32"); // Clamping is not supported for non-composite filing system on Z: |
|
60 |
//#else |
|
61 |
_LIT(KROMName,"ROM"); // Z: name if ROMFS (on hardware, not emulator) |
|
62 |
//#endif |
|
63 |
||
64 |
TChar NandFatDrv='?'; |
|
65 |
TChar RofsDrv='?'; |
|
66 |
TChar LffsDrv='?'; |
|
67 |
TChar CompDrv='?'; |
|
68 |
||
69 |
||
70 |
LOCAL_C void Test1() |
|
71 |
{ |
|
72 |
// Basic clamp operation |
|
73 |
test.Next(_L("T_Clamp - Test1()")); |
|
74 |
||
75 |
TBuf<256> fileName; |
|
76 |
TBuf<256> buf(_L("buffer for file used")); |
|
77 |
||
78 |
fileName = _L("clampFile.tst"); |
|
79 |
RFile testFile; |
|
80 |
TInt r=testFile.Replace(TheFs,fileName,EFileWrite); |
|
81 |
test(r==KErrNone); |
|
82 |
TPtrC8 pBuf((TUint8*)&buf); |
|
83 |
testFile.Write(pBuf); |
|
84 |
testFile.Flush(); |
|
85 |
||
86 |
// Clamp file |
|
87 |
RFileClamp handle; |
|
88 |
r=handle.Clamp(testFile); |
|
89 |
test(r==KErrNone); |
|
90 |
TInt64 storedCookie_0=handle.iCookie[0]; |
|
91 |
TInt64 storedCookie_1=handle.iCookie[1]; |
|
92 |
||
93 |
// Try to clamp previously-clamped file |
|
94 |
RFileClamp handle1; |
|
95 |
r=handle1.Clamp(testFile); |
|
96 |
test(r==KErrNone); |
|
97 |
||
98 |
// Unclamp file |
|
99 |
r=handle.Close(TheFs); |
|
100 |
test (r==KErrNone); |
|
101 |
// Check cookie content has been re-initialised |
|
102 |
test((0==handle.iCookie[0])&&(0==handle.iCookie[1])); |
|
103 |
||
104 |
// Try to unclamp a file that is not clamped |
|
105 |
handle.iCookie[0]=storedCookie_0; |
|
106 |
handle.iCookie[1]=storedCookie_1; |
|
107 |
r=handle.Close(TheFs); |
|
108 |
test (r==KErrNotFound); |
|
109 |
||
110 |
// Check that attempting to unclamp with a zero-content cookie |
|
111 |
// yields no error |
|
112 |
handle.iCookie[0]=0; |
|
113 |
handle.iCookie[1]=0; |
|
114 |
r=handle.Close(TheFs); |
|
115 |
test (r==KErrNone); |
|
116 |
||
117 |
// Clamp the file (again) |
|
118 |
r=handle.Clamp(testFile); |
|
119 |
test(r==KErrNone); |
|
120 |
||
121 |
// Create and clamp a second file ... |
|
122 |
fileName = _L("clampFile2.tst"); |
|
123 |
RFile testFile2; |
|
124 |
r=testFile2.Replace(TheFs,fileName,EFileWrite); |
|
125 |
test(r==KErrNone); |
|
126 |
buf=_L("buffer for file 2"); |
|
127 |
testFile2.Write(pBuf); |
|
128 |
testFile2.Flush(); |
|
129 |
RFileClamp handle2; |
|
130 |
r=handle2.Clamp(testFile2); |
|
131 |
test(r==KErrNone); |
|
132 |
||
133 |
// Create and clamp a third file ... |
|
134 |
RFileClamp handle3; |
|
135 |
fileName = _L("clampFile3.tst"); |
|
136 |
RFile testFile3; |
|
137 |
r=testFile3.Replace(TheFs,fileName,EFileWrite); |
|
138 |
test(r==KErrNone); |
|
139 |
buf=_L("buffer for file 3"); |
|
140 |
testFile3.Write(pBuf); |
|
141 |
testFile3.Flush(); |
|
142 |
r=handle3.Clamp(testFile3); |
|
143 |
test(r==KErrNone); |
|
144 |
||
145 |
// Test can unclamp then reclamp first file |
|
146 |
// then repeat for the third file |
|
147 |
r=handle.Close(TheFs); |
|
148 |
test (r==KErrNone); |
|
149 |
r=handle.Clamp(testFile); |
|
150 |
test(r==KErrNone); |
|
151 |
r=handle3.Close(TheFs); |
|
152 |
test (r==KErrNone); |
|
153 |
r=handle3.Clamp(testFile3); |
|
154 |
test(r==KErrNone); |
|
155 |
||
156 |
// Tidy up |
|
157 |
r=handle.Close(TheFs); |
|
158 |
test (r==KErrNone); |
|
159 |
r=handle1.Close(TheFs); |
|
160 |
test (r==KErrNone); |
|
161 |
testFile.Close(); |
|
162 |
r=TheFs.Delete(_L("clampFile.tst")); |
|
163 |
test (r==KErrNone); |
|
164 |
||
165 |
r=handle2.Close(TheFs); |
|
166 |
test (r==KErrNone); |
|
167 |
testFile2.Close(); |
|
168 |
r=TheFs.Delete(_L("clampFile2.tst")); |
|
169 |
test (r==KErrNone); |
|
170 |
||
171 |
r=handle3.Close(TheFs); |
|
172 |
test (r==KErrNone); |
|
173 |
testFile3.Close(); |
|
174 |
r=TheFs.Delete(_L("clampFile3.tst")); |
|
175 |
test (r==KErrNone); |
|
176 |
} |
|
177 |
||
178 |
||
179 |
LOCAL_C void Test2() |
|
180 |
{ |
|
181 |
// Invalid clamp requests |
|
182 |
test.Next(_L("T_Clamp - Test2()")); |
|
183 |
||
184 |
// Test attempt to clamp empty file is rejected |
|
185 |
RFileClamp handle4; |
|
186 |
TBuf<256> file4Name; |
|
187 |
file4Name = _L("clampFile4.tst"); |
|
188 |
RFile testFile4; |
|
189 |
TInt r=testFile4.Replace(TheFs,file4Name,EFileWrite); |
|
190 |
test(r==KErrNone); |
|
191 |
r=handle4.Clamp(testFile4); |
|
192 |
test(r==KErrEof); |
|
193 |
||
194 |
// Preparation for next test - create a valid clamp handle |
|
195 |
TBuf<256> buf4(_L("buffer for file 4")); |
|
196 |
TPtrC8 pBuf4((TUint8*)&buf4); |
|
197 |
testFile4.Write(pBuf4); |
|
198 |
testFile4.Flush(); |
|
199 |
r=handle4.Clamp(testFile4); |
|
200 |
test(r==KErrNone); |
|
201 |
||
202 |
// Try to unclamp non-existant file |
|
203 |
RFileClamp handle5; |
|
204 |
memcpy((TAny*)&handle5,(TAny*)&handle4,sizeof(RFileClamp)); |
|
205 |
handle5.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID |
|
206 |
r=handle5.Close(TheFs); |
|
207 |
test (r==KErrNotFound); |
|
208 |
||
209 |
// Tidy up |
|
210 |
r=handle4.Close(TheFs); |
|
211 |
test (r==KErrNone); |
|
212 |
testFile4.Close(); |
|
213 |
r=TheFs.Delete(_L("clampFile4.tst")); |
|
214 |
test (r==KErrNone); |
|
215 |
} |
|
216 |
||
217 |
||
218 |
||
286 | 219 |
void RemountFileSystem(TInt aDriveNo, TDesC& aFsName, TDesC& aFsExtName0, TDesC& aFsExtName1) |
220 |
{ |
|
221 |
TInt r; |
|
222 |
if(aFsExtName0.Length() > 0) |
|
223 |
{ |
|
224 |
r=TheFs.MountFileSystem(aFsName,aFsExtName0,aDriveNo); |
|
225 |
test(r==KErrNone); |
|
226 |
} |
|
227 |
else if(aFsExtName1.Length() > 0) // untested ! |
|
228 |
{ |
|
229 |
r=TheFs.MountFileSystem(aFsName,aFsExtName1,aDriveNo); |
|
230 |
test(r==KErrNone); |
|
231 |
} |
|
232 |
else |
|
233 |
{ |
|
234 |
r=TheFs.MountFileSystem(aFsName,aDriveNo); |
|
235 |
test(r==KErrNone); |
|
236 |
} |
|
237 |
} |
|
238 |
||
0 | 239 |
LOCAL_C void TestDeferredDismount(TDesC& aRoot, TDesC& aFileName, RFileClamp* handlePtr) |
240 |
{ |
|
241 |
// Open and clamp file, register for dismount notification, then issue |
|
242 |
// dismount instruction. |
|
243 |
// Since there are no other clients registered for dismount notification, |
|
244 |
// this would normally lead too dismount being instigated. However, since |
|
245 |
// the file is clamped, dismount should be deferred |
|
246 |
test.Next(_L("T_Clamp - TestDeferredDismount()")); |
|
247 |
||
248 |
// File system details required for clean-up |
|
249 |
const TInt KMaxFileSystemNameLength=100; // Arbitrary length |
|
250 |
const TInt KMaxFileSystemExtNameLength=100; // Arbitrary length |
|
251 |
TBuf<KMaxFileSystemNameLength> fsName; |
|
252 |
TBuf<KMaxFileSystemExtNameLength> fsExtName_0; |
|
253 |
TBuf<KMaxFileSystemExtNameLength> fsExtName_1; |
|
254 |
TInt driveNo, r; |
|
255 |
r=TheFs.CharToDrive(aRoot[0], driveNo); |
|
256 |
test(r==KErrNone); |
|
257 |
r=TheFs.FileSystemName(fsName, driveNo); |
|
258 |
test(r==KErrNone); |
|
259 |
||
286 | 260 |
//******************************************************************************************************* |
0 | 261 |
// Create a file & write to it so that we can test whether dismounting works correctly with dirty data |
286 | 262 |
//******************************************************************************************************* |
263 |
test.Next(_L("T_Clamp - TestDeferredDismount(), testing unmounting with dirty data, registered clients & clamped files")); |
|
264 |
||
0 | 265 |
TDriveInfo driveInfo; |
266 |
test(TheFs.Drive(driveInfo, driveNo) == KErrNone); |
|
267 |
TFileName dirtyFileName(_L("dirtyFile.tst")); |
|
268 |
RFile dirtyFile; |
|
286 | 269 |
TBool writeProtectedMedia = driveInfo.iMediaAtt & KMediaAttWriteProtected; |
270 |
if (!writeProtectedMedia) |
|
0 | 271 |
{ |
272 |
r=dirtyFile.Replace(TheFs, dirtyFileName, EFileWrite); |
|
273 |
test(r==KErrNone); |
|
274 |
r=dirtyFile.Write(_L8("My name is Michael Caine")); |
|
275 |
test(r==KErrNone); |
|
276 |
} |
|
277 |
||
278 |
||
279 |
RFile testFile; |
|
280 |
r=testFile.Open(TheFs,aFileName,EFileRead); |
|
281 |
test(r==KErrNone); |
|
282 |
r=handlePtr->Clamp(testFile); |
|
283 |
test(r==KErrNone); |
|
284 |
testFile.Close(); |
|
285 |
||
286 |
TRequestStatus clientNotify=KErrNone; |
|
287 |
TRequestStatus clientDismount=KErrNone; |
|
286 | 288 |
TheFs.NotifyDismount(driveNo, clientNotify); // Register for dismount notification |
0 | 289 |
test(clientNotify == KRequestPending); |
286 | 290 |
|
291 |
// register for disk change notifcation, so we can detect when dismount has actually taken place |
|
292 |
TRequestStatus diskChangeStatus; |
|
293 |
TheFs.NotifyChange(ENotifyDisk, diskChangeStatus); |
|
294 |
test.Printf(_L("diskChangeStatus %d"), diskChangeStatus.Int()); |
|
295 |
test(diskChangeStatus == KRequestPending); // no disk change yet |
|
0 | 296 |
|
286 | 297 |
|
0 | 298 |
TheFs.NotifyDismount(driveNo, clientDismount, EFsDismountNotifyClients); |
299 |
test(clientDismount == KRequestPending); |
|
300 |
User::WaitForRequest(clientNotify); |
|
301 |
test(clientNotify == KErrNone); |
|
302 |
||
303 |
r=TheFs.AllowDismount(driveNo); // Respond to dismount notification |
|
304 |
test(r == KErrNone); |
|
305 |
test(clientDismount == KRequestPending); // Dismount is deferred |
|
286 | 306 |
test(diskChangeStatus == KRequestPending); // no disk change yet |
0 | 307 |
|
308 |
// |
|
309 |
// Now unclamp the file, and check that the deferred dismount is performed. |
|
310 |
r=handlePtr->Close(TheFs); |
|
311 |
test(r==KErrNone); |
|
312 |
User::WaitForRequest(clientDismount); |
|
313 |
test(clientDismount == KErrNone); |
|
314 |
||
286 | 315 |
// wait for disk change notification following dismount |
316 |
User::WaitForRequest(diskChangeStatus); |
|
317 |
test(diskChangeStatus == KErrNone); // should have got a disk change notification after dismount |
|
318 |
r = TheFs.Drive(driveInfo, driveNo); |
|
319 |
test (r==KErrNone); |
|
320 |
test (driveInfo.iType == EMediaNotPresent); |
|
321 |
||
322 |
// re-register for disk change notifcation, so we can detect when remount has actually taken place |
|
323 |
TheFs.NotifyChange(ENotifyDisk, diskChangeStatus); |
|
324 |
test.Printf(_L("diskChangeStatus %d"), diskChangeStatus.Int()); |
|
325 |
test(diskChangeStatus == KRequestPending); // no disk change yet |
|
326 |
||
0 | 327 |
// Try to write to the opened file: this should return KErrNotReady as there is no drive thread |
286 | 328 |
if (!writeProtectedMedia) |
0 | 329 |
{ |
330 |
r=dirtyFile.Write(_L8("My name isn't really Michael Caine")); |
|
331 |
test(r==KErrNotReady); |
|
332 |
} |
|
333 |
||
334 |
// Re-mount the file system |
|
286 | 335 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
336 |
||
337 |
// wait for disk change notification following remount |
|
338 |
User::WaitForRequest(diskChangeStatus); |
|
339 |
test(diskChangeStatus == KErrNone); // should have got a disk change notification after dismount |
|
340 |
r = TheFs.Drive(driveInfo, driveNo); |
|
341 |
test (r==KErrNone); |
|
342 |
test (driveInfo.iType != EMediaNotPresent); |
|
0 | 343 |
|
344 |
// create some more dirty data to verify that the file server can cope with the drive thread |
|
345 |
// having gone & come back again |
|
286 | 346 |
if (!writeProtectedMedia) |
0 | 347 |
{ |
348 |
r=dirtyFile.Write(_L8("My name is Michael Phelps and I'm a fish.")); |
|
349 |
test(r==KErrDisMounted); |
|
350 |
||
351 |
dirtyFile.Close(); |
|
352 |
r = TheFs.Delete(dirtyFileName); |
|
353 |
test(r == KErrNone); |
|
354 |
} |
|
355 |
||
286 | 356 |
//******************************************************************************************************* |
0 | 357 |
// Issue a EFsDismountNotifyClients with no clients but with files clamped |
358 |
// & verify that the dismount request completes when clamps are removed |
|
286 | 359 |
//******************************************************************************************************* |
360 |
test.Next(_L("T_Clamp - TestDeferredDismount(), testing unmounting with no registered clients & clamped files")); |
|
361 |
||
0 | 362 |
r=testFile.Open(TheFs,aFileName,EFileRead); |
363 |
test(r==KErrNone); |
|
364 |
r=handlePtr->Clamp(testFile); |
|
365 |
test(r==KErrNone); |
|
366 |
testFile.Close(); |
|
367 |
TheFs.NotifyDismount(driveNo, clientDismount, EFsDismountNotifyClients); |
|
368 |
||
369 |
test(clientDismount == KRequestPending); |
|
370 |
r=handlePtr->Close(TheFs); |
|
371 |
test(r==KErrNone); |
|
372 |
User::WaitForRequest(clientDismount); |
|
373 |
test(clientDismount == KErrNone); |
|
374 |
// Re-mount the file system again |
|
286 | 375 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
0 | 376 |
|
377 |
||
378 |
// Issue a EFsDismountForceDismount with no clients but with files clamped |
|
379 |
// & verify that the dismount request completes when clamps are removed |
|
380 |
r=testFile.Open(TheFs,aFileName,EFileRead); |
|
381 |
test(r==KErrNone); |
|
382 |
r=handlePtr->Clamp(testFile); |
|
383 |
test(r==KErrNone); |
|
384 |
testFile.Close(); |
|
385 |
TheFs.NotifyDismount(driveNo, clientDismount, EFsDismountForceDismount); |
|
386 |
||
387 |
test(clientDismount == KRequestPending); |
|
388 |
r=handlePtr->Close(TheFs); |
|
389 |
test(r==KErrNone); |
|
390 |
User::WaitForRequest(clientDismount); |
|
391 |
test(clientDismount == KErrNone); |
|
286 | 392 |
|
393 |
||
0 | 394 |
// Re-mount the file system again |
286 | 395 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
396 |
||
397 |
||
398 |
const TInt KNumClients = 5; |
|
399 |
RFs clientFs[KNumClients]; |
|
400 |
TRequestStatus clientNotifies[KNumClients]; |
|
401 |
TRequestStatus clientDiskChanges[KNumClients]; |
|
402 |
TRequestStatus clientComplete; |
|
403 |
||
404 |
#define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("lvalue %d, rvalue%d\n\r"), a,e); test(EFalse);}} |
|
405 |
||
406 |
//******************************************************************************************************* |
|
407 |
// Test unmounting with multiple registered clients which do not respond & close their sessions |
|
408 |
//******************************************************************************************************* |
|
409 |
test.Next(_L("T_Clamp - TestDeferredDismount(), testing unmounting with multiple registered clients which do not respond & close their sessions")); |
|
410 |
||
411 |
TheFs.NotifyChange(ENotifyDisk, diskChangeStatus); |
|
412 |
test.Printf(_L("diskChangeStatus %d"), diskChangeStatus.Int()); |
|
413 |
||
414 |
TInt i; |
|
415 |
for (i=0; i< KNumClients; i++) |
|
0 | 416 |
{ |
286 | 417 |
LOG_AND_TEST(KErrNone, clientFs[i].Connect()); |
418 |
clientFs[i].NotifyDismount(driveNo, clientNotifies[i]); |
|
419 |
test(clientNotifies[i] == KRequestPending); |
|
420 |
} |
|
421 |
||
422 |
test.Next(_L("Close all but one client sessions with outstanding notifiers")); |
|
423 |
for (i=0; i< KNumClients-1; i++) |
|
424 |
clientFs[i].Close(); |
|
425 |
||
426 |
// Since all clients have NOT been closed, the next stage should not yet complete |
|
427 |
test.Next(_L("Notify clients of pending media removal and check status - should not complete")); |
|
428 |
TheFs.NotifyDismount(driveNo, clientComplete, EFsDismountNotifyClients); |
|
429 |
test(clientComplete == KRequestPending); |
|
430 |
||
431 |
||
432 |
test.Next(_L("Close the remaining sessions with an outstanding notifier")); |
|
433 |
clientFs[KNumClients-1].Close(); |
|
434 |
||
435 |
// Check that the dismount completes now that all session have been closed |
|
436 |
test.Next(_L("Check that the dismount completes")); |
|
437 |
User::WaitForRequest(clientComplete); |
|
438 |
test_KErrNone(clientComplete.Int()); |
|
439 |
||
440 |
// wait for disk change notification following dismount |
|
441 |
User::WaitForRequest(diskChangeStatus); |
|
442 |
test(diskChangeStatus == KErrNone); // should have got a disk change notification after dismount |
|
443 |
r = TheFs.Drive(driveInfo, driveNo); |
|
444 |
test (r==KErrNone); |
|
445 |
test (driveInfo.iType == EMediaNotPresent); |
|
446 |
||
447 |
// re-register for disk change notifcation, so we can detect when remount has actually taken place |
|
448 |
TheFs.NotifyChange(ENotifyDisk, diskChangeStatus); |
|
449 |
test.Printf(_L("diskChangeStatus %d"), diskChangeStatus.Int()); |
|
450 |
test(diskChangeStatus == KRequestPending); // no disk change yet |
|
451 |
||
452 |
||
453 |
// Re-mount the file system again |
|
454 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
|
455 |
||
456 |
// wait for disk change notification following remount |
|
457 |
User::WaitForRequest(diskChangeStatus); |
|
458 |
test(diskChangeStatus == KErrNone); // should have got a disk change notification after dismount |
|
459 |
r = TheFs.Drive(driveInfo, driveNo); |
|
460 |
test (r==KErrNone); |
|
461 |
test (driveInfo.iType != EMediaNotPresent); |
|
462 |
||
463 |
||
464 |
||
465 |
//******************************************************************************************************* |
|
466 |
// Issue a EFsDismountNotifyClients with multiple clients |
|
467 |
// Verify that the dismount completes if a client re-registers for dismount notifications BEFORE calling AllowDismount |
|
468 |
//******************************************************************************************************* |
|
469 |
||
470 |
test.Next(_L("T_Clamp - TestDeferredDismount(), testing unmounting with multiple registered clients & a re-registration")); |
|
471 |
||
472 |
for(i=0; i< KNumClients; i++) |
|
473 |
{ |
|
474 |
r=clientFs[i].Connect(); |
|
475 |
test(r==KErrNone); |
|
476 |
} |
|
477 |
// Cancel any deferred dismount in preparation for the next test |
|
478 |
TheFs.NotifyDismountCancel(); |
|
479 |
||
480 |
// All clients register for dismount notification |
|
481 |
for(i=0; i< KNumClients; i++) |
|
482 |
{ |
|
483 |
clientNotifies[i] = KErrNone; |
|
484 |
clientFs[i].NotifyDismount(driveNo, clientNotifies[i]); |
|
485 |
test(clientNotifies[i] == KRequestPending); |
|
486 |
} |
|
487 |
||
488 |
// Issue a EFsDismountNotifyClients & wait for clients to respond |
|
489 |
clientDismount = KErrNone; |
|
490 |
TheFs.NotifyDismount(driveNo, clientDismount, EFsDismountNotifyClients); |
|
491 |
test(clientDismount == KRequestPending); |
|
492 |
||
493 |
// Check all clients have received the notification |
|
494 |
for(i=0; i< KNumClients; i++) |
|
495 |
{ |
|
496 |
User::WaitForRequest(clientNotifies[i]); |
|
497 |
test(clientNotifies[i] == KErrNone); |
|
498 |
} |
|
499 |
// All clients - except first one - invoke AllowDismount |
|
500 |
for(i=1; i< KNumClients; i++) |
|
501 |
{ |
|
502 |
r=clientFs[i].AllowDismount(driveNo); |
|
0 | 503 |
test(r==KErrNone); |
504 |
} |
|
286 | 505 |
|
506 |
||
507 |
// verify dismount has not yet completed |
|
508 |
test(clientDismount == KRequestPending); |
|
509 |
||
510 |
||
511 |
// first client re-registers for dismount notifications |
|
512 |
clientFs[0].NotifyDismount(driveNo, clientNotifies[0]); |
|
513 |
test(clientNotifies[0] == KRequestPending); |
|
514 |
||
515 |
// first client allows dismount |
|
516 |
clientFs[0].AllowDismount(driveNo); |
|
517 |
test(r==KErrNone); |
|
518 |
||
519 |
// Wait for dismount |
|
520 |
User::WaitForRequest(clientDismount); |
|
521 |
test(clientDismount == KErrNone); |
|
522 |
||
523 |
||
524 |
// verify the first client's re-issued dismount notification is still pending |
|
525 |
test(clientNotifies[0] == KRequestPending); |
|
526 |
||
527 |
||
528 |
// Re-mount the file system again |
|
529 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
|
530 |
||
531 |
||
532 |
// Issue a EFsDismountNotifyClients again & check previously re-registered notification completes |
|
533 |
test(clientNotifies[0] == KRequestPending); |
|
534 |
clientDismount = KErrNone; |
|
535 |
TheFs.NotifyDismount(driveNo, clientDismount, EFsDismountNotifyClients); |
|
536 |
test(clientDismount == KRequestPending); |
|
537 |
||
538 |
// wait for notification |
|
539 |
User::WaitForRequest(clientNotifies[0]); |
|
540 |
||
541 |
// first client allows dismount |
|
542 |
clientFs[0].AllowDismount(driveNo); |
|
543 |
test(r==KErrNone); |
|
544 |
||
545 |
// Wait for dismount |
|
546 |
User::WaitForRequest(clientDismount); |
|
547 |
test(clientDismount == KErrNone); |
|
548 |
||
549 |
||
550 |
||
551 |
// Re-mount the file system again |
|
552 |
RemountFileSystem(driveNo, fsName, fsExtName_0, fsExtName_1); |
|
553 |
||
554 |
||
555 |
||
556 |
//******************************************************************************************************* |
|
557 |
// Issue a EFsDismountNotifyClients again with a multiple clients & then call RFs::NotifyDismountCancel() |
|
558 |
// Verify that all clients receive a disk change notification |
|
559 |
//******************************************************************************************************* |
|
560 |
test.Next(_L("T_Clamp - TestDeferredDismount(), testing unmounting with registered clients, a re-registration & a cancel")); |
|
561 |
||
562 |
// All clients register for dismount notification & disk change notification |
|
563 |
for(i=0; i< KNumClients; i++) |
|
0 | 564 |
{ |
286 | 565 |
clientNotifies[i] = KErrNone; |
566 |
clientFs[i].NotifyDismount(driveNo, clientNotifies[i], EFsDismountRegisterClient); |
|
567 |
test(clientNotifies[i] == KRequestPending); |
|
568 |
||
569 |
clientFs[i].NotifyChange(ENotifyDisk, clientDiskChanges[i]); |
|
570 |
test.Printf(_L("diskChangeStatus %d"), clientDiskChanges[i].Int()); |
|
571 |
test(clientDiskChanges[i] == KRequestPending); |
|
572 |
} |
|
573 |
||
574 |
||
575 |
// Issue a EFsDismountNotifyClients |
|
576 |
TheFs.NotifyDismount(driveNo, clientComplete, EFsDismountNotifyClients); |
|
577 |
test(clientComplete == KRequestPending); |
|
578 |
||
579 |
||
580 |
// Check all clients have received the notification |
|
581 |
for(i=0; i< KNumClients; i++) |
|
582 |
{ |
|
583 |
User::WaitForRequest(clientNotifies[i]); |
|
584 |
test(clientNotifies[i] == KErrNone); |
|
585 |
||
586 |
test.Printf(_L("diskChangeStatus %d"), clientDiskChanges[i].Int()); |
|
587 |
test(clientDiskChanges[i] == KRequestPending); |
|
588 |
} |
|
589 |
||
590 |
// verify dismount has not yet completed |
|
591 |
test(clientComplete == KRequestPending); |
|
592 |
||
593 |
||
594 |
// first client re-registers for dismount notifications |
|
595 |
clientFs[0].NotifyDismount(driveNo, clientNotifies[0]); |
|
596 |
test(clientNotifies[0] == KRequestPending); |
|
597 |
||
598 |
// first client acknowledges the dismount request |
|
599 |
r = clientFs[0].AllowDismount(driveNo); |
|
600 |
test(r == KErrNone); |
|
601 |
||
602 |
||
603 |
// cancel dismount |
|
604 |
// TheFs.NotifyDismountCancel(clientComplete); |
|
605 |
TheFs.NotifyDismountCancel(); |
|
606 |
test(clientComplete == KErrCancel); |
|
607 |
User::WaitForRequest(clientComplete); |
|
608 |
||
609 |
// Check all clients have received a disk change notification - |
|
610 |
// the file server should send a disk change notification when RFs::NotifyDismountCancel() is called |
|
611 |
for(i=0; i< KNumClients; i++) |
|
612 |
{ |
|
613 |
User::WaitForRequest(clientDiskChanges[i]); |
|
614 |
test.Printf(_L("diskChangeStatus %d"), clientDiskChanges[i].Int()); |
|
615 |
test(clientDiskChanges[i] == KErrNone); |
|
616 |
} |
|
617 |
||
618 |
||
619 |
// cleanup |
|
620 |
for(i=0; i< KNumClients; i++) |
|
621 |
{ |
|
622 |
clientFs[i].Close(); |
|
0 | 623 |
test(r==KErrNone); |
624 |
} |
|
625 |
} |
|
626 |
||
627 |
||
628 |
||
629 |
LOCAL_C void Test3Operations(TDesC& aRoot, TDesC& aFileName) |
|
630 |
{ |
|
631 |
test.Next(_L("T_Clamp - Test3Operations()")); |
|
632 |
// RFormat::Open |
|
633 |
#ifdef __WINS__ |
|
634 |
if (User::UpperCase(aRoot[0]) != 'C') |
|
635 |
#endif |
|
636 |
{ |
|
637 |
TBuf<4> driveBuf=_L("?:\\"); |
|
638 |
driveBuf[0] = aRoot[0]; |
|
639 |
RFormat format; |
|
640 |
TInt count; |
|
641 |
TInt r=format.Open(TheFs,driveBuf,EFullFormat,count); |
|
642 |
test(r==KErrInUse); |
|
643 |
format.Close(); |
|
644 |
} |
|
645 |
||
646 |
// Dismount: synchronous requests |
|
647 |
// RFs::DismountFileSystem, RFs::SwapFileSystem |
|
648 |
const TInt KMaxFileSystemNameLength=100; // Arbitrary length |
|
649 |
TBuf<KMaxFileSystemNameLength> fileSysName; |
|
650 |
TInt driveNo, r; |
|
651 |
r=TheFs.CharToDrive(aRoot[0], driveNo); |
|
652 |
test(r==KErrNone); |
|
653 |
r=TheFs.FileSystemName(fileSysName,driveNo); |
|
654 |
test(r==KErrNone); |
|
655 |
||
656 |
r=TheFs.DismountFileSystem(fileSysName,driveNo); |
|
657 |
test(r==KErrInUse); |
|
658 |
||
659 |
r=TheFs.SwapFileSystem(fileSysName,fileSysName,driveNo); |
|
660 |
test(r==KErrInUse); |
|
661 |
||
662 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
663 |
// The cancellation of deferred dismounts requires controlIO |
|
664 |
// functionality available in debug versions of the code. |
|
665 |
||
666 |
// Dismount: asynchronous requests |
|
667 |
// RFs::NotifyDismount, RFs::AllowDismount |
|
668 |
const TInt KNumClients = 5; |
|
669 |
RFs clientFs[KNumClients]; |
|
670 |
TRequestStatus clientNotify[KNumClients]; |
|
671 |
TRequestStatus clientComplete; |
|
672 |
TInt i=0; |
|
673 |
for(i=0; i< KNumClients; i++) |
|
674 |
{ |
|
675 |
r=clientFs[i].Connect(); |
|
676 |
test(r==KErrNone); |
|
677 |
} |
|
678 |
// Cancel any deferred dismount in preparation for the next test |
|
679 |
r=TheFs.ControlIo(driveNo,KControlIoCancelDeferredDismount); |
|
680 |
test(r==KErrNone); |
|
681 |
||
682 |
// Use case 1: Orderly dismount |
|
683 |
// All clients register for dismount notification |
|
684 |
for(i=0; i< KNumClients; i++) |
|
685 |
{ |
|
686 |
clientNotify[i] = KErrNone; |
|
687 |
clientFs[i].NotifyDismount(driveNo, clientNotify[i]); |
|
688 |
test(clientNotify[i] == KRequestPending); |
|
689 |
} |
|
690 |
// First client notifies intent to dismount |
|
691 |
clientComplete = KErrNone; |
|
692 |
clientFs[0].NotifyDismount(driveNo, clientComplete, EFsDismountNotifyClients); |
|
693 |
test(clientComplete == KRequestPending); |
|
694 |
// Check all clients have received the notification |
|
695 |
for(i=0; i< KNumClients; i++) |
|
696 |
{ |
|
697 |
test(clientNotify[i] == KErrNone); |
|
698 |
} |
|
699 |
// All clients invoke AllowDismount |
|
700 |
for(i=0; i< KNumClients; i++) |
|
701 |
{ |
|
702 |
r=clientFs[i].AllowDismount(driveNo); |
|
703 |
test(r==KErrNone); |
|
704 |
} |
|
705 |
// Dismount is deferred |
|
706 |
test(clientComplete == KRequestPending); |
|
707 |
||
708 |
||
709 |
// Cancel the deferred dismount in preparation for the next test |
|
710 |
clientFs[0].NotifyDismountCancel(clientComplete); |
|
711 |
test(clientComplete == KErrCancel); |
|
712 |
r=TheFs.ControlIo(driveNo,KControlIoCancelDeferredDismount); |
|
713 |
test(r==KErrNone); |
|
714 |
clientComplete=KErrNone; // Re-initialise the TRequestStatus |
|
715 |
||
716 |
||
717 |
// Use case 2: Forced dismount |
|
718 |
// All clients register for dismount notification |
|
719 |
for(i=0; i< KNumClients; i++) |
|
720 |
{ |
|
721 |
clientFs[i].NotifyDismount(driveNo, clientNotify[i]); |
|
722 |
test(clientNotify[i] == KRequestPending); |
|
723 |
} |
|
724 |
// First client notifies intent to dismount |
|
725 |
clientFs[0].NotifyDismount(driveNo, clientComplete, EFsDismountNotifyClients); |
|
726 |
test(clientComplete == KRequestPending); |
|
727 |
// Check all clients have received the notification |
|
728 |
for(i=0; i< KNumClients; i++) |
|
729 |
{ |
|
730 |
test(clientNotify[i] == KErrNone); |
|
731 |
} |
|
732 |
// Not all other clients invoke AllowDismount |
|
733 |
for(i=0; i< KNumClients-1; i++) |
|
734 |
{ |
|
735 |
clientFs[i].AllowDismount(driveNo); |
|
736 |
} |
|
737 |
// First client attempts forced dismount |
|
738 |
test(clientComplete == KRequestPending); |
|
739 |
clientFs[0].NotifyDismount(driveNo, clientComplete, EFsDismountForceDismount); |
|
740 |
// Dismount is deferred |
|
741 |
test(clientComplete == KRequestPending); |
|
742 |
||
743 |
// Cancel the deferred dismount in preparation for the next test |
|
744 |
// Also cancel the 'un-Allowed' notification request |
|
745 |
clientFs[0].NotifyDismountCancel(clientComplete); |
|
746 |
test(clientComplete == KErrCancel); |
|
747 |
r=TheFs.ControlIo(driveNo,KControlIoCancelDeferredDismount); |
|
748 |
test(r==KErrNone); |
|
749 |
clientComplete=KErrNone; // Re-initialise the TRequestStatus |
|
750 |
#endif |
|
751 |
||
752 |
// RFile::Open with EFileWrite |
|
753 |
RFile testFile; |
|
754 |
r=testFile.Open(TheFs,aFileName,EFileWrite|EFileShareReadersOrWriters); |
|
755 |
test(r==KErrInUse); |
|
756 |
||
757 |
// RFile::Replace |
|
758 |
RFile testFile2; |
|
759 |
r=testFile2.Replace(TheFs,aFileName,EFileRead); |
|
760 |
test(r==KErrInUse); |
|
761 |
testFile2.Close(); |
|
762 |
||
763 |
// RFile::Set - this should not be prevented by clamping |
|
764 |
r=testFile.Open(TheFs,aFileName,EFileRead|EFileShareAny); |
|
765 |
test(r == KErrNone); |
|
766 |
||
767 |
TTime origTime; |
|
768 |
TUint origAtt; |
|
769 |
r=testFile.Att(origAtt); |
|
770 |
test(r==KErrNone); |
|
771 |
r=testFile.Modified(origTime); |
|
772 |
test(r==KErrNone); |
|
773 |
||
774 |
TTime time; // Arbitrary value |
|
775 |
TUint setMask=0xA5A5&~KEntryAttReadOnly; // Not read-only, otherwise arbitrary value |
|
776 |
TUint clearMask=0x5A5A & KEntryAttReadOnly; // Not read-only, otherwise arbitrary value |
|
777 |
r=testFile.Set(time,setMask,clearMask); |
|
778 |
test(r==KErrNone); |
|
779 |
||
780 |
r=testFile.Set(origTime,origAtt,~origAtt); // restore original values |
|
781 |
test(r==KErrNone); |
|
782 |
testFile.Close(); |
|
783 |
||
784 |
// RFs::Rename - this should not be prevented by clamping |
|
785 |
r=TheFs.Rename(aFileName,_L("aDummyName")); |
|
786 |
test(r==KErrNone); |
|
787 |
r=TheFs.Rename(_L("aDummyName"),aFileName); // restore original name |
|
788 |
test(r==KErrNone); |
|
789 |
||
790 |
// RFs::Replace |
|
791 |
r=TheFs.Replace(aFileName,_L("aDummyName")); |
|
792 |
test(r==KErrInUse); |
|
793 |
||
794 |
// RFs::SetEntry - this should not be prevented by clamping |
|
795 |
r=TheFs.SetEntry(aFileName,time,setMask,clearMask); |
|
796 |
test(r==KErrNone); |
|
797 |
r=TheFs.SetEntry(aFileName,origTime,origAtt,~origAtt); // restore original values |
|
798 |
test(r==KErrNone); |
|
799 |
||
800 |
// RFs::Delete |
|
801 |
r=TheFs.Delete(aFileName); |
|
802 |
test(r==KErrInUse); |
|
803 |
||
804 |
// RRawDisk::Open (*** no longer required ***) |
|
805 |
} |
|
806 |
||
807 |
LOCAL_C void Test3(TDesC& aRoot) |
|
808 |
{ |
|
809 |
// Denied FS requests when file(s) are clamped. |
|
810 |
test.Next(_L("T_Clamp - Test3()")); |
|
811 |
||
812 |
// Clamping is reference counted, so we need a test to check that |
|
813 |
// a file clamped N times cannot be modified until it has been unclamped N times. |
|
814 |
// Should also check |
|
815 |
// - Clamp N times |
|
816 |
// - Unclamp M times (M<N) |
|
817 |
// - Clamp M times. |
|
818 |
// - Unclamp N times |
|
819 |
||
820 |
#define MY_N 16 |
|
821 |
#define MY_M 12 |
|
822 |
||
823 |
// Create a file for use |
|
824 |
TBuf<256> fileName; |
|
825 |
TBuf<256> buf(_L("buffer for file used")); |
|
826 |
fileName = _L("clampFile.tst"); |
|
827 |
RFile testFile; |
|
828 |
TInt r=testFile.Replace(TheFs,fileName,EFileWrite); |
|
829 |
test(r==KErrNone); |
|
830 |
TPtrC8 pBuf((TUint8*)&buf); |
|
831 |
testFile.Write(pBuf); |
|
832 |
testFile.Flush(); |
|
833 |
// Close file,then re-open (to support clamping) in sharable mode |
|
834 |
// (to allow testing of RFile::Open with EFileWrite) |
|
835 |
testFile.Close(); |
|
836 |
r=testFile.Open(TheFs,fileName,EFileWrite|EFileShareReadersOrWriters); |
|
837 |
test(r==KErrNone); |
|
838 |
// Show, prior to clamping, that the file can be opened with EFileWrite |
|
839 |
RFile testFile2; |
|
840 |
r=testFile2.Open(TheFs,fileName,EFileWrite|EFileShareReadersOrWriters); |
|
841 |
test(r==KErrNone); |
|
842 |
// Close the second RFile instance |
|
843 |
testFile2.Close(); |
|
844 |
||
845 |
// Clamp and unclamp a number of times, and invoke the |
|
846 |
// operations to test |
|
847 |
RFileClamp myHandles[MY_N]; |
|
848 |
RFileClamp *handlePtr = myHandles; |
|
849 |
TInt i = 0; |
|
850 |
||
851 |
// Clamp once |
|
852 |
r=handlePtr->Clamp(testFile); |
|
853 |
test(r==KErrNone); |
|
854 |
i++; |
|
855 |
||
856 |
// RFile::SetAtt - this should not be prevented by clamping |
|
857 |
TTime origTime; |
|
858 |
TUint origAtt; |
|
859 |
r=testFile.Att(origAtt); |
|
860 |
test(r==KErrNone); |
|
861 |
r=testFile.Modified(origTime); |
|
862 |
test(r==KErrNone); |
|
863 |
TTime time; // Arbitrary value |
|
864 |
TUint setMask=0xA5A5&~KEntryAttReadOnly; // Not read-only, otherwise arbitrary value |
|
865 |
TUint clearMask=0x5A5A & KEntryAttReadOnly; // Not read-only, otherwise arbitrary value |
|
866 |
r=testFile.Att(origAtt); |
|
867 |
test(r==KErrNone); |
|
868 |
r=testFile.SetAtt(setMask,clearMask); |
|
869 |
test(r==KErrNone); |
|
870 |
r=testFile.Set(origTime,origAtt,~origAtt); // restore original values |
|
871 |
test(r==KErrNone); |
|
872 |
||
873 |
// RFile::SetModified - this should not be prevented by clamping |
|
874 |
r=testFile.Modified(origTime); |
|
875 |
test(r==KErrNone); |
|
876 |
r=testFile.SetModified(time); |
|
877 |
test(r==KErrNone); |
|
878 |
r=testFile.SetModified(origTime); // restore original value |
|
879 |
test(r==KErrNone); |
|
880 |
||
881 |
// RFile::Rename - this should not be prevented by clamping |
|
882 |
// Need file to be opened in EFileShareExclusive sharing mode, |
|
883 |
// so close, unclamp, re-open appropriately and re-clamp |
|
884 |
testFile.Close(); |
|
885 |
r=handlePtr->Close(TheFs); |
|
886 |
test(r==KErrNone); |
|
887 |
i--; |
|
888 |
r=testFile.Open(TheFs,fileName,EFileWrite|EFileShareExclusive); |
|
889 |
test(r==KErrNone); |
|
890 |
r=handlePtr->Clamp(testFile); |
|
891 |
test(r==KErrNone); |
|
892 |
i++; |
|
893 |
r=testFile.Rename(_L("aDummyName")); |
|
894 |
test(r==KErrNone); |
|
895 |
r=testFile.Rename(fileName); |
|
896 |
test(r==KErrNone); |
|
897 |
||
898 |
// RFile::SetSize |
|
899 |
r=testFile.SetSize(1000); // Arbitrary value |
|
900 |
test(r==KErrInUse); |
|
901 |
||
902 |
// Test other RFile, RFs operations |
|
903 |
testFile.Close(); |
|
904 |
Test3Operations(aRoot,fileName); |
|
905 |
||
906 |
// Increase number of clamps to MY_N |
|
907 |
r=testFile.Open(TheFs,fileName,EFileRead); |
|
908 |
test(r==KErrNone); |
|
909 |
for(; i < MY_N; i++) |
|
910 |
{ |
|
911 |
handlePtr++; |
|
912 |
r=handlePtr->Clamp(testFile); |
|
913 |
test(r==KErrNone); |
|
914 |
} |
|
915 |
testFile.Close(); |
|
916 |
Test3Operations(aRoot,fileName); |
|
917 |
||
918 |
// Decrease number of clamps by MY_M |
|
919 |
for(;i > (MY_N - MY_M); i--) |
|
920 |
{ |
|
921 |
r=handlePtr->Close(TheFs); |
|
922 |
test(r==KErrNone); |
|
923 |
if(handlePtr!=myHandles) |
|
924 |
handlePtr--; |
|
925 |
else |
|
926 |
break; |
|
927 |
} |
|
928 |
Test3Operations(aRoot,fileName); |
|
929 |
||
930 |
// Increase number of clamps by MY_M |
|
931 |
r=testFile.Open(TheFs,fileName,EFileRead); |
|
932 |
test(r == KErrNone); |
|
933 |
TInt j=0; |
|
934 |
for(;j < MY_M; j++) |
|
935 |
{ |
|
936 |
handlePtr++; |
|
937 |
r=handlePtr->Clamp(testFile); |
|
938 |
test(r==KErrNone); |
|
939 |
i++; |
|
940 |
} |
|
941 |
testFile.Close(); |
|
942 |
Test3Operations(aRoot,fileName); |
|
943 |
||
944 |
// Decrease number of clamps by MY_N |
|
945 |
for(;i > 0; i--) |
|
946 |
{ |
|
947 |
r=handlePtr->Close(TheFs); |
|
948 |
test(r==KErrNone); |
|
949 |
if(handlePtr!=myHandles) |
|
950 |
handlePtr--; |
|
951 |
else |
|
952 |
break; |
|
953 |
} |
|
954 |
||
955 |
// Test deferred dismount - use next free handle |
|
956 |
TestDeferredDismount(aRoot,fileName,handlePtr); |
|
957 |
||
958 |
// Re-create the test directory |
|
959 |
r=TheFs.MkDirAll(aRoot); |
|
960 |
test(r==KErrNone || r== KErrAlreadyExists); |
|
961 |
TheFs.SetSessionPath(aRoot); |
|
962 |
||
963 |
// No clamps remain - prove RFile::Open with EFileWrite |
|
964 |
r=testFile2.Open(TheFs,fileName,EFileWrite|EFileShareReadersOrWriters); |
|
965 |
test(r==KErrNone); |
|
966 |
testFile2.Close(); |
|
967 |
||
968 |
// No clamps remain - prove that file can now be deleted |
|
969 |
r=TheFs.Delete(_L("clampFile.tst")); |
|
970 |
test (r==KErrNone); |
|
971 |
} |
|
972 |
||
973 |
||
974 |
LOCAL_C void Test4(TDesC& aRoot) |
|
975 |
{ |
|
976 |
// Clamp tests for non-writable file system |
|
977 |
test.Next(_L("T_Clamp - Test4()")); |
|
978 |
||
979 |
// Tests are limited to clamp, unclamp and denied requests |
|
980 |
// when clamps are present. |
|
981 |
TBuf<256> pathName; |
|
982 |
#ifdef __WINS__ |
|
983 |
if((aRoot[0]=='Z')||(aRoot[0]=='z')) |
|
984 |
pathName=_L("clean.txt"); |
|
985 |
else |
|
986 |
pathName=_L("root.txt"); |
|
987 |
#else |
|
988 |
if((aRoot[0]=='Z')||(aRoot[0]=='z')) |
|
989 |
pathName=_L("UnicodeData.txt"); |
|
990 |
else |
|
991 |
pathName=_L("\\Test\\clamp.txt"); // For (non-composite) ROFS drive |
|
992 |
#endif |
|
993 |
RFile testFile; |
|
994 |
TInt r=testFile.Open(TheFs, pathName, EFileRead); |
|
995 |
test(r==KErrNone); |
|
996 |
||
997 |
// Clamp file |
|
998 |
RFileClamp handle; |
|
999 |
r=handle.Clamp(testFile); |
|
1000 |
test(r==KErrNone); |
|
1001 |
TInt64 storedCookie_0=handle.iCookie[0]; |
|
1002 |
TInt64 storedCookie_1=handle.iCookie[1]; |
|
1003 |
||
1004 |
// Try to clamp previously-clamped file |
|
1005 |
RFileClamp handle1; |
|
1006 |
r=handle1.Clamp(testFile); |
|
1007 |
test(r==KErrNone); |
|
1008 |
||
1009 |
// Unclamp file |
|
1010 |
r=handle.Close(TheFs); |
|
1011 |
test (r==KErrNone); |
|
1012 |
// Check cookie content has been re-initialised |
|
1013 |
test((0==handle.iCookie[0])&&(0==handle.iCookie[1])); |
|
1014 |
||
1015 |
// Try to unclamp a file that is not clamped |
|
1016 |
handle.iCookie[0]=storedCookie_0; |
|
1017 |
handle.iCookie[1]=storedCookie_1; |
|
1018 |
r=handle.Close(TheFs); |
|
1019 |
test (r==KErrNotFound); |
|
1020 |
// Remove remaining clamp |
|
1021 |
r=handle1.Close(TheFs); |
|
1022 |
test (r==KErrNone); |
|
1023 |
||
1024 |
testFile.Close(); |
|
1025 |
||
1026 |
if((aRoot[0]!='Z')&&(aRoot[0]!='z')) // Can not dismount Z: |
|
1027 |
TestDeferredDismount(aRoot,pathName,&handle); |
|
1028 |
} |
|
1029 |
||
1030 |
||
1031 |
LOCAL_C void Test5() |
|
1032 |
{ |
|
1033 |
// Clamp requests on non-clamping file systems |
|
1034 |
test.Next(_L("T_Clamp - Test5()")); |
|
1035 |
||
1036 |
TBuf<256> unsuppFile; |
|
1037 |
unsuppFile = _L("unsuppFile.tst"); |
|
1038 |
RFile testFile; |
|
1039 |
TInt r=testFile.Replace(TheFs,unsuppFile,EFileWrite); |
|
1040 |
test(r==KErrNone); |
|
1041 |
||
1042 |
// Try to clamp a file on a file system that does |
|
1043 |
// not support clamping |
|
1044 |
RFileClamp handle; |
|
1045 |
r=handle.Clamp(testFile); |
|
1046 |
test(r==KErrNotSupported); |
|
1047 |
||
1048 |
// Tidy up |
|
1049 |
testFile.Close(); |
|
1050 |
r=TheFs.Delete(_L("unsuppFile.tst")); |
|
1051 |
test (r==KErrNone); |
|
1052 |
} |
|
1053 |
||
1054 |
||
1055 |
LOCAL_C void GetDriveLetters() |
|
1056 |
{ |
|
1057 |
// Assign the first drive that matches the required criteria |
|
1058 |
test.Next(_L("T_Clamp - GetDriveLetters()")); |
|
1059 |
||
1060 |
TDriveList driveList; |
|
1061 |
TDriveInfo driveInfo; |
|
1062 |
TInt r=TheFs.DriveList(driveList); |
|
1063 |
test(r==KErrNone); |
|
1064 |
TInt drvNum; |
|
1065 |
TBool drivesFound = EFalse; |
|
1066 |
for(drvNum=0; (drvNum<KMaxDrives) && !drivesFound; drvNum++) |
|
1067 |
{ |
|
1068 |
TChar drvLetter='?'; |
|
1069 |
TFileName fileSystem; |
|
1070 |
if(!driveList[drvNum]) |
|
1071 |
continue; |
|
1072 |
test(TheFs.Drive(driveInfo, drvNum) == KErrNone); |
|
1073 |
test(TheFs.DriveToChar(drvNum,drvLetter) == KErrNone); |
|
1074 |
r=TheFs.FileSystemName(fileSystem,drvNum); |
|
1075 |
fileSystem.UpperCase(); |
|
1076 |
test((r==KErrNone)||(r==KErrNotFound)); |
|
1077 |
if (!(driveInfo.iDriveAtt & KDriveAttInternal)) |
|
1078 |
continue; |
|
1079 |
// Check for FAT on NAND |
|
1080 |
if(NandFatDrv=='?') |
|
1081 |
{ |
|
1082 |
if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KFATName)==0)) |
|
1083 |
NandFatDrv=drvLetter; |
|
1084 |
} |
|
1085 |
// Check for ROFS |
|
1086 |
if(RofsDrv=='?') |
|
1087 |
{ |
|
1088 |
if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KROFSName)==0)) |
|
1089 |
RofsDrv=drvLetter; |
|
1090 |
} |
|
1091 |
// Check for LFFS |
|
1092 |
if(LffsDrv=='?') |
|
1093 |
{ |
|
1094 |
if((driveInfo.iType==EMediaFlash) && (fileSystem.Compare(KLFFSName)==0)) |
|
1095 |
LffsDrv=drvLetter; |
|
1096 |
} |
|
1097 |
// Check for CompFSys |
|
1098 |
if(CompDrv=='?') |
|
1099 |
{ |
|
1100 |
if((driveInfo.iType==EMediaRom) && ((fileSystem.Compare(KROMName)==0)||(fileSystem.Compare(KCOMPName)==0))) |
|
1101 |
CompDrv=drvLetter; |
|
1102 |
} |
|
1103 |
drivesFound=((NandFatDrv!='?')&&(RofsDrv!='?')&&(LffsDrv!='?')&&(CompDrv!='?')); |
|
1104 |
} |
|
1105 |
if(NandFatDrv!='?') |
|
1106 |
test((NandFatDrv!=RofsDrv)&&(NandFatDrv!=LffsDrv)&&(NandFatDrv!=CompDrv)); |
|
1107 |
if(RofsDrv!='?') |
|
1108 |
test((RofsDrv!=LffsDrv)&&(RofsDrv!=CompDrv)); |
|
1109 |
if(LffsDrv!='?') |
|
1110 |
test(LffsDrv!=CompDrv); |
|
1111 |
||
1112 |
RDebug::Printf("T_CLAMP: FAT drive=%C, ROFS drive=%C, LFFS drive=%C, ROM-COMP drive=%C \n",(TText)NandFatDrv,(TText)RofsDrv,(TText)LffsDrv,(TText)CompDrv); |
|
1113 |
return; |
|
1114 |
} |
|
1115 |
||
1116 |
||
1117 |
// |
|
1118 |
// E32Main |
|
1119 |
// |
|
1120 |
||
1121 |
TInt E32Main() |
|
1122 |
{ |
|
1123 |
TInt r; |
|
1124 |
test.Title(); |
|
1125 |
test.Start(_L("Starting T_CLAMP ...")); |
|
1126 |
test(TheFs.Connect()==KErrNone); |
|
1127 |
||
1128 |
GetDriveLetters(); |
|
1129 |
TBuf<256> pathName; |
|
1130 |
||
1131 |
//************************************************************************ |
|
1132 |
// |
|
1133 |
// Test on FAT (writable file system) |
|
1134 |
// |
|
1135 |
//************************************************************************ |
|
1136 |
if(NandFatDrv!='?') |
|
1137 |
{ |
|
1138 |
pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND |
|
1139 |
pathName[0]=(TText)NandFatDrv; |
|
1140 |
r=TheFs.MkDirAll(pathName); |
|
1141 |
test(r==KErrNone || r== KErrAlreadyExists); |
|
1142 |
TheFs.SetSessionPath(pathName); |
|
1143 |
test.Printf( _L("T_CLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv); |
|
1144 |
||
1145 |
Test1(); // Basic clamp operation |
|
1146 |
Test2(); // Invalid clamp requests |
|
1147 |
Test3(pathName);// Denied FS requests when files are clamped |
|
1148 |
||
1149 |
r=TheFs.RmDir(pathName); |
|
1150 |
test(r==KErrNone); |
|
1151 |
} |
|
1152 |
else |
|
1153 |
test.Printf( _L("T_CLAMP: FAT drive not tested\n")); |
|
1154 |
||
1155 |
//************************************************************************ |
|
1156 |
// |
|
1157 |
// Test on ROFS (non-writable file system) |
|
1158 |
// |
|
1159 |
//************************************************************************ |
|
1160 |
if(RofsDrv!='?') |
|
1161 |
{ |
|
1162 |
pathName=_L("?:\\"); |
|
1163 |
pathName[0]=(TText)RofsDrv; |
|
1164 |
TheFs.SetSessionPath(pathName); |
|
1165 |
test.Printf( _L("T_CLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv); |
|
1166 |
||
1167 |
Test4(pathName); // Clamp tests for non-writable file system |
|
1168 |
} |
|
1169 |
else |
|
1170 |
test.Printf( _L("T_CLAMP: ROFS drive not tested\n")); |
|
1171 |
||
1172 |
//************************************************************************ |
|
1173 |
// |
|
1174 |
// Test on Z: - Composite File System, or ROMFS (non-writable file system) |
|
1175 |
// |
|
1176 |
//************************************************************************ |
|
1177 |
if(CompDrv!='?') |
|
1178 |
{ |
|
1179 |
pathName=_L("?:\\TEST\\"); |
|
1180 |
pathName[0]=(TText)CompDrv; |
|
1181 |
TheFs.SetSessionPath(pathName); |
|
1182 |
test.Printf( _L("T_CLAMP: testing Z drive (on %C)\n"),(TText)CompDrv); |
|
1183 |
||
1184 |
Test4(pathName); // Clamp tests for non-writable file system |
|
1185 |
} |
|
1186 |
else |
|
1187 |
test.Printf( _L("T_CLAMP: Z drive not tested\n")); |
|
1188 |
||
1189 |
//************************************************************************ |
|
1190 |
// |
|
1191 |
// Test on LFFS (non-clampable file system) |
|
1192 |
// |
|
1193 |
//************************************************************************ |
|
1194 |
if(LffsDrv!='?') |
|
1195 |
{ |
|
1196 |
TBuf<256> unsuppPath; |
|
1197 |
unsuppPath=_L("?:\\CLAMP-TST\\"); |
|
1198 |
unsuppPath[0]=(TText)LffsDrv; |
|
1199 |
r=TheFs.MkDirAll(unsuppPath); |
|
1200 |
test(r==KErrNone || r== KErrAlreadyExists); |
|
1201 |
TheFs.SetSessionPath(unsuppPath); |
|
1202 |
test.Printf( _L("T_CLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv); |
|
1203 |
||
1204 |
Test5(); // Clamp requests on non-clamping file systems |
|
1205 |
} |
|
1206 |
else |
|
1207 |
test.Printf( _L("T_CLAMP: LFFS drive not tested\n")); |
|
1208 |
||
1209 |
test.End(); |
|
1210 |
return 0; |
|
1211 |
} |
|
1212 |
||
1213 |
#else |
|
1214 |
||
1215 |
TInt E32Main() |
|
1216 |
{ |
|
1217 |
test.Title(); |
|
1218 |
test.Start(_L("Test does not run on UREL builds.")); |
|
1219 |
test.End(); |
|
1220 |
return 0; |
|
1221 |
} |
|
1222 |
#endif |