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_denyclamp.cpp
|
|
15 |
// This test suite has a reduced set of the tests in T_CLAMP, to verify
|
|
16 |
// the behaviour when file clamping is attempted by an invalid user.
|
|
17 |
// 002 GetDriveLetters() Assign the first drive that matches the required criteria
|
|
18 |
// 003 Test1() Basic clamp operation
|
|
19 |
// 004 Test2() Invalid clamp requests
|
|
20 |
// 005 Test4() Clamp tests for non-writable file system
|
|
21 |
// 006 Test5() Clamp requests on non-clamping file systems
|
|
22 |
// This file has a reduced set of tests present in T_CLAMP, to verify
|
|
23 |
// the behaviour when file clamping is attempted by an invalid user
|
|
24 |
//
|
|
25 |
//
|
|
26 |
|
|
27 |
//! @SYMTestCaseID KBASE-T_DENYCLAMP-0329
|
|
28 |
//! @SYMTestType UT
|
|
29 |
//! @SYMPREQ PREQ1110
|
|
30 |
//! @SYMTestCaseDesc Demand Paging File Clamp tests (Deny)
|
|
31 |
//! @SYMTestActions 001 Starting T_DENYCLAMP ...
|
|
32 |
//! @SYMTestExpectedResults All tests should pass.
|
|
33 |
//! @SYMTestPriority High
|
|
34 |
//! @SYMTestStatus Implemented
|
|
35 |
|
|
36 |
#include <e32test.h>
|
|
37 |
RTest test(_L("T_DENYCLAMP"));
|
|
38 |
|
|
39 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
40 |
|
|
41 |
#include <f32file.h>
|
|
42 |
#include <f32dbg.h>
|
|
43 |
RFs TheFs;
|
|
44 |
|
|
45 |
_LIT(KFATName,"FAT");
|
|
46 |
//_LIT(KFAT32Name,"FAT32");
|
|
47 |
_LIT(KROFSName,"ROFS");
|
|
48 |
_LIT(KLFFSName,"LFFS");
|
|
49 |
_LIT(KCOMPName,"COMPOSITE"); // Z: name if Composite File System
|
|
50 |
//#ifdef __WINS__
|
|
51 |
//_LIT(KROMName,"WIN32"); // Clamping is not supported for non-composite filing system on Z:
|
|
52 |
//#else
|
|
53 |
_LIT(KROMName,"ROM"); // Z: name if ROMFS (on hardware, not emulator)
|
|
54 |
//#endif
|
|
55 |
|
|
56 |
TChar NandFatDrv='?';
|
|
57 |
TChar RofsDrv='?';
|
|
58 |
TChar LffsDrv='?';
|
|
59 |
TChar CompDrv='?';
|
|
60 |
|
|
61 |
|
|
62 |
LOCAL_C void Test1()
|
|
63 |
{
|
|
64 |
// Basic clamp operation
|
|
65 |
test.Next(_L("T_DENYCLAMP - Test1()"));
|
|
66 |
|
|
67 |
TBuf<256> fileName;
|
|
68 |
TBuf<256> buf(_L("buffer for file used"));
|
|
69 |
|
|
70 |
fileName = _L("clampFile.tst");
|
|
71 |
RFile testFile;
|
|
72 |
TInt r=testFile.Replace(TheFs,fileName,EFileWrite);
|
|
73 |
test(r==KErrNone);
|
|
74 |
TPtrC8 pBuf((TUint8*)&buf);
|
|
75 |
testFile.Write(pBuf);
|
|
76 |
testFile.Flush();
|
|
77 |
|
|
78 |
// Attempt to clamp file should be rejected
|
|
79 |
RFileClamp handle;
|
|
80 |
r=handle.Clamp(testFile);
|
|
81 |
test(r==KErrPermissionDenied);
|
|
82 |
|
|
83 |
// Attempt to unclamp a file should be rejected
|
|
84 |
// Using an invalid-content cookie is OK - the request should
|
|
85 |
// be rejected before the content is examined
|
|
86 |
handle.iCookie[0]=MAKE_TINT64(-1,-1);
|
|
87 |
handle.iCookie[1]=0;
|
|
88 |
r=handle.Close(TheFs);
|
|
89 |
test (r==KErrPermissionDenied);
|
|
90 |
|
|
91 |
// Tidy up
|
|
92 |
testFile.Close();
|
|
93 |
r=TheFs.Delete(_L("clampFile.tst"));
|
|
94 |
test (r==KErrNone);
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
LOCAL_C void Test2()
|
|
99 |
{
|
|
100 |
// Invalid clamp requests
|
|
101 |
test.Next(_L("T_DENYCLAMP - Test2()"));
|
|
102 |
|
|
103 |
// Test attempt to clamp empty file is rejected
|
|
104 |
RFileClamp handle2;
|
|
105 |
TBuf<256> file2Name;
|
|
106 |
file2Name = _L("clampFile2.tst");
|
|
107 |
RFile testFile2;
|
|
108 |
TInt r=testFile2.Replace(TheFs,file2Name,EFileWrite);
|
|
109 |
test(r==KErrNone);
|
|
110 |
r=handle2.Clamp(testFile2);
|
|
111 |
test(r==KErrPermissionDenied);
|
|
112 |
|
|
113 |
|
|
114 |
// Try to unclamp non-existant file
|
|
115 |
// Using a invalid-content cookie is OK - the request should
|
|
116 |
// be rejected before the content is examined
|
|
117 |
handle2.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID
|
|
118 |
handle2.iCookie[1] = MAKE_TINT64(-1,-1);
|
|
119 |
r=handle2.Close(TheFs);
|
|
120 |
test (r==KErrPermissionDenied);
|
|
121 |
|
|
122 |
// Tidy up
|
|
123 |
testFile2.Close();
|
|
124 |
r=TheFs.Delete(_L("clampFile2.tst"));
|
|
125 |
test (r==KErrNone);
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
LOCAL_C void Test4(TDesC& aRoot)
|
|
130 |
{
|
|
131 |
// Clamp tests for non-writable file system
|
|
132 |
test.Next(_L("T_DENYCLAMP - Test4()"));
|
|
133 |
|
|
134 |
TBuf<256> pathName;
|
|
135 |
#ifdef __WINS__
|
|
136 |
if((aRoot[0]=='Z')||(aRoot[0]=='z'))
|
|
137 |
pathName=_L("clean.txt");
|
|
138 |
else
|
|
139 |
pathName=_L("root.txt");
|
|
140 |
#else
|
|
141 |
if((aRoot[0]=='Z')||(aRoot[0]=='z'))
|
|
142 |
pathName=_L("UnicodeData.txt");
|
|
143 |
else
|
|
144 |
pathName=_L("\\Test\\clamp.txt"); // For (non-composite) ROFS drive
|
|
145 |
#endif
|
|
146 |
RFile testFile;
|
|
147 |
TInt r=testFile.Open(TheFs, pathName, EFileRead);
|
|
148 |
test(r==KErrNone);
|
|
149 |
|
|
150 |
// Attempt to clamp file
|
|
151 |
RFileClamp handle;
|
|
152 |
r=handle.Clamp(testFile);
|
|
153 |
test(r==KErrPermissionDenied);
|
|
154 |
|
|
155 |
// Unclamp file
|
|
156 |
// Using an invalid-content cookie is OK - the request should
|
|
157 |
// be rejected before the content is examined
|
|
158 |
handle.iCookie[0]=MAKE_TINT64(-1,-1);
|
|
159 |
handle.iCookie[1]=0;
|
|
160 |
r=handle.Close(TheFs);
|
|
161 |
test (r==KErrPermissionDenied);
|
|
162 |
|
|
163 |
testFile.Close();
|
|
164 |
}
|
|
165 |
|
|
166 |
|
|
167 |
LOCAL_C void Test5()
|
|
168 |
{
|
|
169 |
// Clamp requests on non-clamping file systems
|
|
170 |
test.Next(_L("T_DENYCLAMP - Test5()"));
|
|
171 |
|
|
172 |
TBuf<256> unsuppFile;
|
|
173 |
unsuppFile = _L("unsuppFile.tst");
|
|
174 |
RFile testFile;
|
|
175 |
TInt r=testFile.Replace(TheFs,unsuppFile,EFileWrite);
|
|
176 |
test(r==KErrNone);
|
|
177 |
|
|
178 |
// Try to clamp a file on a file system that does
|
|
179 |
// not support clamping
|
|
180 |
RFileClamp handle;
|
|
181 |
r=handle.Clamp(testFile);
|
|
182 |
test(r==KErrPermissionDenied);
|
|
183 |
|
|
184 |
// Tidy up
|
|
185 |
testFile.Close();
|
|
186 |
r=TheFs.Delete(_L("unsuppFile.tst"));
|
|
187 |
test (r==KErrNone);
|
|
188 |
}
|
|
189 |
|
|
190 |
|
|
191 |
LOCAL_C void GetDriveLetters()
|
|
192 |
{
|
|
193 |
// Assign the first drive that matches the required criteria
|
|
194 |
test.Next(_L("T_DENYCLAMP - GetDriveLetters()"));
|
|
195 |
|
|
196 |
TDriveList driveList;
|
|
197 |
TDriveInfo driveInfo;
|
|
198 |
TInt r=TheFs.DriveList(driveList);
|
|
199 |
test(r==KErrNone);
|
|
200 |
TInt drvNum;
|
|
201 |
TBool drivesFound = EFalse;
|
|
202 |
for(drvNum=0; (drvNum<KMaxDrives) && !drivesFound; drvNum++)
|
|
203 |
{
|
|
204 |
TChar drvLetter='?';
|
|
205 |
TFileName fileSystem;
|
|
206 |
if(!driveList[drvNum])
|
|
207 |
continue;
|
|
208 |
test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
|
|
209 |
test(TheFs.DriveToChar(drvNum,drvLetter) == KErrNone);
|
|
210 |
r=TheFs.FileSystemName(fileSystem,drvNum);
|
|
211 |
fileSystem.UpperCase();
|
|
212 |
test((r==KErrNone)||(r==KErrNotFound));
|
|
213 |
// Check for FAT on NAND
|
|
214 |
if(NandFatDrv=='?')
|
|
215 |
{
|
|
216 |
if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KFATName)==0))
|
|
217 |
NandFatDrv=drvLetter;
|
|
218 |
}
|
|
219 |
// Check for ROFS
|
|
220 |
if(RofsDrv=='?')
|
|
221 |
{
|
|
222 |
if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KROFSName)==0))
|
|
223 |
RofsDrv=drvLetter;
|
|
224 |
}
|
|
225 |
// Check for LFFS
|
|
226 |
if(LffsDrv=='?')
|
|
227 |
{
|
|
228 |
if((driveInfo.iType==EMediaFlash) && (fileSystem.Compare(KLFFSName)==0))
|
|
229 |
LffsDrv=drvLetter;
|
|
230 |
}
|
|
231 |
// Check for CompFSys
|
|
232 |
if(CompDrv=='?')
|
|
233 |
{
|
|
234 |
if((driveInfo.iType==EMediaRom) && ((fileSystem.Compare(KROMName)==0)||(fileSystem.Compare(KCOMPName)==0)))
|
|
235 |
CompDrv=drvLetter;
|
|
236 |
}
|
|
237 |
drivesFound=((NandFatDrv!='?')&&(RofsDrv!='?')&&(LffsDrv!='?')&&(CompDrv!='?'));
|
|
238 |
}
|
|
239 |
if(NandFatDrv!='?')
|
|
240 |
test((NandFatDrv!=RofsDrv)&&(NandFatDrv!=LffsDrv)&&(NandFatDrv!=CompDrv));
|
|
241 |
if(RofsDrv!='?')
|
|
242 |
test((RofsDrv!=LffsDrv)&&(RofsDrv!=CompDrv));
|
|
243 |
if(LffsDrv!='?')
|
|
244 |
test(LffsDrv!=CompDrv);
|
|
245 |
|
|
246 |
RDebug::Printf("T_DENYCLAMP: FAT drive=%C, ROFS drive=%C, LFFS drive=%C, ROM-COMP drive=%C \n",(TText)NandFatDrv,(TText)RofsDrv,(TText)LffsDrv,(TText)CompDrv);
|
|
247 |
return;
|
|
248 |
}
|
|
249 |
|
|
250 |
|
|
251 |
//
|
|
252 |
// E32Main
|
|
253 |
//
|
|
254 |
|
|
255 |
TInt E32Main()
|
|
256 |
{
|
|
257 |
TInt r;
|
|
258 |
test.Title();
|
|
259 |
test.Start(_L("Starting T_DENYCLAMP ..."));
|
|
260 |
test(TheFs.Connect()==KErrNone);
|
|
261 |
|
|
262 |
GetDriveLetters();
|
|
263 |
TBuf<256> pathName;
|
|
264 |
|
|
265 |
//************************************************************************
|
|
266 |
//
|
|
267 |
// Test on FAT (writable file system)
|
|
268 |
//
|
|
269 |
//************************************************************************
|
|
270 |
if(NandFatDrv!='?')
|
|
271 |
{
|
|
272 |
pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND
|
|
273 |
pathName[0]=(TText)NandFatDrv;
|
|
274 |
r=TheFs.MkDirAll(pathName);
|
|
275 |
test(r==KErrNone || r== KErrAlreadyExists);
|
|
276 |
TheFs.SetSessionPath(pathName);
|
|
277 |
test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv);
|
|
278 |
|
|
279 |
Test1(); // Basic clamp operation
|
|
280 |
Test2(); // Invalid clamp requests
|
|
281 |
// Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP
|
|
282 |
|
|
283 |
r=TheFs.RmDir(pathName);
|
|
284 |
test(r==KErrNone);
|
|
285 |
}
|
|
286 |
else
|
|
287 |
test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n"));
|
|
288 |
|
|
289 |
//************************************************************************
|
|
290 |
//
|
|
291 |
// Test on ROFS (non-writable file system)
|
|
292 |
//
|
|
293 |
//************************************************************************
|
|
294 |
if(RofsDrv!='?')
|
|
295 |
{
|
|
296 |
pathName=_L("?:\\");
|
|
297 |
pathName[0]=(TText)RofsDrv;
|
|
298 |
TheFs.SetSessionPath(pathName);
|
|
299 |
test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv);
|
|
300 |
|
|
301 |
Test4(pathName); // Clamp tests for non-writable file system
|
|
302 |
}
|
|
303 |
else
|
|
304 |
test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n"));
|
|
305 |
|
|
306 |
//************************************************************************
|
|
307 |
//
|
|
308 |
// Test on Z: - Composite File System, or ROMFS (non-writable file system)
|
|
309 |
//
|
|
310 |
//************************************************************************
|
|
311 |
if(CompDrv!='?')
|
|
312 |
{
|
|
313 |
pathName=_L("?:\\TEST\\");
|
|
314 |
pathName[0]=(TText)CompDrv;
|
|
315 |
TheFs.SetSessionPath(pathName);
|
|
316 |
test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv);
|
|
317 |
|
|
318 |
Test4(pathName); // Clamp tests for non-writable file system
|
|
319 |
}
|
|
320 |
else
|
|
321 |
test.Printf( _L("T_DENYCLAMP: Z drive not tested\n"));
|
|
322 |
|
|
323 |
//************************************************************************
|
|
324 |
//
|
|
325 |
// Test on LFFS (non-clampable file system)
|
|
326 |
//
|
|
327 |
//************************************************************************
|
|
328 |
if(LffsDrv!='?')
|
|
329 |
{
|
|
330 |
TBuf<256> unsuppPath;
|
|
331 |
unsuppPath=_L("?:\\CLAMP-TST\\");
|
|
332 |
unsuppPath[0]=(TText)LffsDrv;
|
|
333 |
r=TheFs.MkDirAll(unsuppPath);
|
|
334 |
test(r==KErrNone || r== KErrAlreadyExists);
|
|
335 |
TheFs.SetSessionPath(unsuppPath);
|
|
336 |
test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv);
|
|
337 |
|
|
338 |
Test5(); // Clamp requests on non-clamping file systems
|
|
339 |
}
|
|
340 |
else
|
|
341 |
test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n"));
|
|
342 |
|
|
343 |
test.End();
|
|
344 |
return 0;
|
|
345 |
}
|
|
346 |
|
|
347 |
#else
|
|
348 |
|
|
349 |
TInt E32Main()
|
|
350 |
{
|
|
351 |
test.Title();
|
|
352 |
test.Start(_L("Test does not run on UREL builds."));
|
|
353 |
test.End();
|
|
354 |
return 0;
|
|
355 |
}
|
|
356 |
#endif
|