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