sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\demandpaging\t_denyclamp.cpp sl@0: // This test suite has a reduced set of the tests in T_CLAMP, to verify sl@0: // the behaviour when file clamping is attempted by an invalid user. sl@0: // 002 GetDriveLetters() Assign the first drive that matches the required criteria sl@0: // 003 Test1() Basic clamp operation sl@0: // 004 Test2() Invalid clamp requests sl@0: // 005 Test4() Clamp tests for non-writable file system sl@0: // 006 Test5() Clamp requests on non-clamping file systems sl@0: // This file has a reduced set of tests present in T_CLAMP, to verify sl@0: // the behaviour when file clamping is attempted by an invalid user sl@0: // sl@0: // sl@0: sl@0: //! @SYMTestCaseID KBASE-T_DENYCLAMP-0329 sl@0: //! @SYMTestType UT sl@0: //! @SYMPREQ PREQ1110 sl@0: //! @SYMTestCaseDesc Demand Paging File Clamp tests (Deny) sl@0: //! @SYMTestActions 001 Starting T_DENYCLAMP ... sl@0: //! @SYMTestExpectedResults All tests should pass. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: sl@0: #include sl@0: RTest test(_L("T_DENYCLAMP")); sl@0: sl@0: #if defined(_DEBUG) || defined(_DEBUG_RELEASE) sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: RFs TheFs; sl@0: sl@0: _LIT(KFATName,"FAT"); sl@0: //_LIT(KFAT32Name,"FAT32"); sl@0: _LIT(KROFSName,"ROFS"); sl@0: _LIT(KLFFSName,"LFFS"); sl@0: _LIT(KCOMPName,"COMPOSITE"); // Z: name if Composite File System sl@0: //#ifdef __WINS__ sl@0: //_LIT(KROMName,"WIN32"); // Clamping is not supported for non-composite filing system on Z: sl@0: //#else sl@0: _LIT(KROMName,"ROM"); // Z: name if ROMFS (on hardware, not emulator) sl@0: //#endif sl@0: sl@0: TChar NandFatDrv='?'; sl@0: TChar RofsDrv='?'; sl@0: TChar LffsDrv='?'; sl@0: TChar CompDrv='?'; sl@0: sl@0: sl@0: LOCAL_C void Test1() sl@0: { sl@0: // Basic clamp operation sl@0: test.Next(_L("T_DENYCLAMP - Test1()")); sl@0: sl@0: TBuf<256> fileName; sl@0: TBuf<256> buf(_L("buffer for file used")); sl@0: sl@0: fileName = _L("clampFile.tst"); sl@0: RFile testFile; sl@0: TInt r=testFile.Replace(TheFs,fileName,EFileWrite); sl@0: test(r==KErrNone); sl@0: TPtrC8 pBuf((TUint8*)&buf); sl@0: testFile.Write(pBuf); sl@0: testFile.Flush(); sl@0: sl@0: // Attempt to clamp file should be rejected sl@0: RFileClamp handle; sl@0: r=handle.Clamp(testFile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: // Attempt to unclamp a file should be rejected sl@0: // Using an invalid-content cookie is OK - the request should sl@0: // be rejected before the content is examined sl@0: handle.iCookie[0]=MAKE_TINT64(-1,-1); sl@0: handle.iCookie[1]=0; sl@0: r=handle.Close(TheFs); sl@0: test (r==KErrPermissionDenied); sl@0: sl@0: // Tidy up sl@0: testFile.Close(); sl@0: r=TheFs.Delete(_L("clampFile.tst")); sl@0: test (r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void Test2() sl@0: { sl@0: // Invalid clamp requests sl@0: test.Next(_L("T_DENYCLAMP - Test2()")); sl@0: sl@0: // Test attempt to clamp empty file is rejected sl@0: RFileClamp handle2; sl@0: TBuf<256> file2Name; sl@0: file2Name = _L("clampFile2.tst"); sl@0: RFile testFile2; sl@0: TInt r=testFile2.Replace(TheFs,file2Name,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=handle2.Clamp(testFile2); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: sl@0: // Try to unclamp non-existant file sl@0: // Using a invalid-content cookie is OK - the request should sl@0: // be rejected before the content is examined sl@0: handle2.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID sl@0: handle2.iCookie[1] = MAKE_TINT64(-1,-1); sl@0: r=handle2.Close(TheFs); sl@0: test (r==KErrPermissionDenied); sl@0: sl@0: // Tidy up sl@0: testFile2.Close(); sl@0: r=TheFs.Delete(_L("clampFile2.tst")); sl@0: test (r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void Test4(TDesC& aRoot) sl@0: { sl@0: // Clamp tests for non-writable file system sl@0: test.Next(_L("T_DENYCLAMP - Test4()")); sl@0: sl@0: TBuf<256> pathName; sl@0: #ifdef __WINS__ sl@0: if((aRoot[0]=='Z')||(aRoot[0]=='z')) sl@0: pathName=_L("clean.txt"); sl@0: else sl@0: pathName=_L("root.txt"); sl@0: #else sl@0: if((aRoot[0]=='Z')||(aRoot[0]=='z')) sl@0: pathName=_L("UnicodeData.txt"); sl@0: else sl@0: pathName=_L("\\Test\\clamp.txt"); // For (non-composite) ROFS drive sl@0: #endif sl@0: RFile testFile; sl@0: TInt r=testFile.Open(TheFs, pathName, EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: // Attempt to clamp file sl@0: RFileClamp handle; sl@0: r=handle.Clamp(testFile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: // Unclamp file sl@0: // Using an invalid-content cookie is OK - the request should sl@0: // be rejected before the content is examined sl@0: handle.iCookie[0]=MAKE_TINT64(-1,-1); sl@0: handle.iCookie[1]=0; sl@0: r=handle.Close(TheFs); sl@0: test (r==KErrPermissionDenied); sl@0: sl@0: testFile.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void Test5() sl@0: { sl@0: // Clamp requests on non-clamping file systems sl@0: test.Next(_L("T_DENYCLAMP - Test5()")); sl@0: sl@0: TBuf<256> unsuppFile; sl@0: unsuppFile = _L("unsuppFile.tst"); sl@0: RFile testFile; sl@0: TInt r=testFile.Replace(TheFs,unsuppFile,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: // Try to clamp a file on a file system that does sl@0: // not support clamping sl@0: RFileClamp handle; sl@0: r=handle.Clamp(testFile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: // Tidy up sl@0: testFile.Close(); sl@0: r=TheFs.Delete(_L("unsuppFile.tst")); sl@0: test (r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void GetDriveLetters() sl@0: { sl@0: // Assign the first drive that matches the required criteria sl@0: test.Next(_L("T_DENYCLAMP - GetDriveLetters()")); sl@0: sl@0: TDriveList driveList; sl@0: TDriveInfo driveInfo; sl@0: TInt r=TheFs.DriveList(driveList); sl@0: test(r==KErrNone); sl@0: TInt drvNum; sl@0: TBool drivesFound = EFalse; sl@0: for(drvNum=0; (drvNum pathName; sl@0: sl@0: //************************************************************************ sl@0: // sl@0: // Test on FAT (writable file system) sl@0: // sl@0: //************************************************************************ sl@0: if(NandFatDrv!='?') sl@0: { sl@0: pathName=_L("?:\\CLAMP-TST\\"); // FAT on NAND sl@0: pathName[0]=(TText)NandFatDrv; sl@0: r=TheFs.MkDirAll(pathName); sl@0: test(r==KErrNone || r== KErrAlreadyExists); sl@0: TheFs.SetSessionPath(pathName); sl@0: test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv); sl@0: sl@0: Test1(); // Basic clamp operation sl@0: Test2(); // Invalid clamp requests sl@0: // Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP sl@0: sl@0: r=TheFs.RmDir(pathName); sl@0: test(r==KErrNone); sl@0: } sl@0: else sl@0: test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n")); sl@0: sl@0: //************************************************************************ sl@0: // sl@0: // Test on ROFS (non-writable file system) sl@0: // sl@0: //************************************************************************ sl@0: if(RofsDrv!='?') sl@0: { sl@0: pathName=_L("?:\\"); sl@0: pathName[0]=(TText)RofsDrv; sl@0: TheFs.SetSessionPath(pathName); sl@0: test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv); sl@0: sl@0: Test4(pathName); // Clamp tests for non-writable file system sl@0: } sl@0: else sl@0: test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n")); sl@0: sl@0: //************************************************************************ sl@0: // sl@0: // Test on Z: - Composite File System, or ROMFS (non-writable file system) sl@0: // sl@0: //************************************************************************ sl@0: if(CompDrv!='?') sl@0: { sl@0: pathName=_L("?:\\TEST\\"); sl@0: pathName[0]=(TText)CompDrv; sl@0: TheFs.SetSessionPath(pathName); sl@0: test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv); sl@0: sl@0: Test4(pathName); // Clamp tests for non-writable file system sl@0: } sl@0: else sl@0: test.Printf( _L("T_DENYCLAMP: Z drive not tested\n")); sl@0: sl@0: //************************************************************************ sl@0: // sl@0: // Test on LFFS (non-clampable file system) sl@0: // sl@0: //************************************************************************ sl@0: if(LffsDrv!='?') sl@0: { sl@0: TBuf<256> unsuppPath; sl@0: unsuppPath=_L("?:\\CLAMP-TST\\"); sl@0: unsuppPath[0]=(TText)LffsDrv; sl@0: r=TheFs.MkDirAll(unsuppPath); sl@0: test(r==KErrNone || r== KErrAlreadyExists); sl@0: TheFs.SetSessionPath(unsuppPath); sl@0: test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv); sl@0: sl@0: Test5(); // Clamp requests on non-clamping file systems sl@0: } sl@0: else sl@0: test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n")); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: #else sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Test does not run on UREL builds.")); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: #endif