First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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
27 //! @SYMTestCaseID KBASE-T_DENYCLAMP-0329
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
37 RTest test(_L("T_DENYCLAMP"));
39 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
43 #include <e32ldr_private.h>
47 //_LIT(KFAT32Name,"FAT32");
48 _LIT(KROFSName,"ROFS");
49 _LIT(KLFFSName,"LFFS");
50 _LIT(KCOMPName,"COMPOSITE"); // Z: name if Composite File System
52 //_LIT(KROMName,"WIN32"); // Clamping is not supported for non-composite filing system on Z:
54 _LIT(KROMName,"ROM"); // Z: name if ROMFS (on hardware, not emulator)
65 // Basic clamp operation
66 test.Next(_L("T_DENYCLAMP - Test1()"));
69 TBuf<256> buf(_L("buffer for file used"));
71 fileName = _L("clampFile.tst");
73 TInt r=testFile.Replace(TheFs,fileName,EFileWrite);
75 TPtrC8 pBuf((TUint8*)&buf);
79 // Attempt to clamp file should be rejected
81 r=handle.Clamp(testFile);
82 test(r==KErrPermissionDenied);
84 // Attempt to unclamp a file should be rejected
85 // Using an invalid-content cookie is OK - the request should
86 // be rejected before the content is examined
87 handle.iCookie[0]=MAKE_TINT64(-1,-1);
89 r=handle.Close(TheFs);
90 test (r==KErrPermissionDenied);
94 r=TheFs.Delete(_L("clampFile.tst"));
101 // Invalid clamp requests
102 test.Next(_L("T_DENYCLAMP - Test2()"));
104 // Test attempt to clamp empty file is rejected
107 file2Name = _L("clampFile2.tst");
109 TInt r=testFile2.Replace(TheFs,file2Name,EFileWrite);
111 r=handle2.Clamp(testFile2);
112 test(r==KErrPermissionDenied);
115 // Try to unclamp non-existant file
116 // Using a invalid-content cookie is OK - the request should
117 // be rejected before the content is examined
118 handle2.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID
119 handle2.iCookie[1] = MAKE_TINT64(-1,-1);
120 r=handle2.Close(TheFs);
121 test (r==KErrPermissionDenied);
125 r=TheFs.Delete(_L("clampFile2.tst"));
130 LOCAL_C void Test4(TDesC& aRoot)
132 // Clamp tests for non-writable file system
133 test.Next(_L("T_DENYCLAMP - Test4()"));
137 if((aRoot[0]=='Z')||(aRoot[0]=='z'))
138 pathName=_L("clean.txt");
140 pathName=_L("root.txt");
142 if((aRoot[0]=='Z')||(aRoot[0]=='z'))
143 pathName=_L("UnicodeData.txt");
145 pathName=_L("\\Test\\clamp.txt"); // For (non-composite) ROFS drive
148 TInt r=testFile.Open(TheFs, pathName, EFileRead);
151 // Attempt to clamp file
153 r=handle.Clamp(testFile);
154 test(r==KErrPermissionDenied);
157 // Using an invalid-content cookie is OK - the request should
158 // be rejected before the content is examined
159 handle.iCookie[0]=MAKE_TINT64(-1,-1);
161 r=handle.Close(TheFs);
162 test (r==KErrPermissionDenied);
170 // Clamp requests on non-clamping file systems
171 test.Next(_L("T_DENYCLAMP - Test5()"));
173 TBuf<256> unsuppFile;
174 unsuppFile = _L("unsuppFile.tst");
176 TInt r=testFile.Replace(TheFs,unsuppFile,EFileWrite);
179 // Try to clamp a file on a file system that does
180 // not support clamping
182 r=handle.Clamp(testFile);
183 test(r==KErrPermissionDenied);
187 r=TheFs.Delete(_L("unsuppFile.tst"));
192 LOCAL_C void GetDriveLetters()
194 // Assign the first drive that matches the required criteria
195 test.Next(_L("T_DENYCLAMP - GetDriveLetters()"));
197 TDriveList driveList;
198 TDriveInfo driveInfo;
199 TInt r=TheFs.DriveList(driveList);
202 TBool drivesFound = EFalse;
203 for(drvNum=0; (drvNum<KMaxDrives) && !drivesFound; drvNum++)
206 TFileName fileSystem;
207 if(!driveList[drvNum])
209 test(TheFs.Drive(driveInfo, drvNum) == KErrNone);
210 test(TheFs.DriveToChar(drvNum,drvLetter) == KErrNone);
211 r=TheFs.FileSystemName(fileSystem,drvNum);
212 fileSystem.UpperCase();
213 test((r==KErrNone)||(r==KErrNotFound));
214 // Check for FAT on NAND
217 if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KFATName)==0))
218 NandFatDrv=drvLetter;
223 if((driveInfo.iType==EMediaNANDFlash) && (fileSystem.Compare(KROFSName)==0))
229 if((driveInfo.iType==EMediaFlash) && (fileSystem.Compare(KLFFSName)==0))
232 // Check for CompFSys
235 if((driveInfo.iType==EMediaRom) && ((fileSystem.Compare(KROMName)==0)||(fileSystem.Compare(KCOMPName)==0)))
238 drivesFound=((NandFatDrv!='?')&&(RofsDrv!='?')&&(LffsDrv!='?')&&(CompDrv!='?'));
241 test((NandFatDrv!=RofsDrv)&&(NandFatDrv!=LffsDrv)&&(NandFatDrv!=CompDrv));
243 test((RofsDrv!=LffsDrv)&&(RofsDrv!=CompDrv));
245 test(LffsDrv!=CompDrv);
247 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);
260 test.Start(_L("Starting T_DENYCLAMP ..."));
261 test(TheFs.Connect()==KErrNone);
266 //************************************************************************
268 // Test on FAT (writable file system)
270 //************************************************************************
273 pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND
274 pathName[0]=(TText)NandFatDrv;
275 r=TheFs.MkDirAll(pathName);
276 test(r==KErrNone || r== KErrAlreadyExists);
277 TheFs.SetSessionPath(pathName);
278 test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv);
280 Test1(); // Basic clamp operation
281 Test2(); // Invalid clamp requests
282 // Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP
284 r=TheFs.RmDir(pathName);
288 test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n"));
290 //************************************************************************
292 // Test on ROFS (non-writable file system)
294 //************************************************************************
298 pathName[0]=(TText)RofsDrv;
299 TheFs.SetSessionPath(pathName);
300 test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv);
302 Test4(pathName); // Clamp tests for non-writable file system
305 test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n"));
307 //************************************************************************
309 // Test on Z: - Composite File System, or ROMFS (non-writable file system)
311 //************************************************************************
314 pathName=_L("?:\\TEST\\");
315 pathName[0]=(TText)CompDrv;
316 TheFs.SetSessionPath(pathName);
317 test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv);
319 Test4(pathName); // Clamp tests for non-writable file system
322 test.Printf( _L("T_DENYCLAMP: Z drive not tested\n"));
324 //************************************************************************
326 // Test on LFFS (non-clampable file system)
328 //************************************************************************
331 TBuf<256> unsuppPath;
332 unsuppPath=_L("?:\\CLAMP-TST\\");
333 unsuppPath[0]=(TText)LffsDrv;
334 r=TheFs.MkDirAll(unsuppPath);
335 test(r==KErrNone || r== KErrAlreadyExists);
336 TheFs.SetSessionPath(unsuppPath);
337 test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv);
339 Test5(); // Clamp requests on non-clamping file systems
342 test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n"));
353 test.Start(_L("Test does not run on UREL builds."));