sl@0: // Copyright (c) 1995-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\server\t_chkuid.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: #if defined(__WINS__) sl@0: #define WIN32_LEAN_AND_MEAN sl@0: #pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union sl@0: #pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union sl@0: #endif sl@0: sl@0: GLDEF_D RTest test(_L("T_CHKUID")); sl@0: sl@0: sl@0: LOCAL_C void CreateUidTestFiles() sl@0: // sl@0: // Create files with uids for testing sl@0: // sl@0: { sl@0: // Create \\gSessionPath\\UIDCHKNO.SHT - no uid, zero length sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,_L("UIDCHKNO.SHT"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Create \\gSessionPath\\UIDCHKNO.LNG - no uid, long length sl@0: r=file.Replace(TheFs,_L("UIDCHKNO.LNG"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=file.Write(_L8("Hello World needs to be over 16 bytes")); sl@0: file.Close(); sl@0: sl@0: // Create \\gSessionPath\\UIDCHK.BLG - with uid no data sl@0: r=file.Replace(TheFs,_L("UIDCHK.BLG"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D')); sl@0: TCheckedUid checkedUid(uidType); sl@0: TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid)); sl@0: r=file.Write(buf); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Create \\gSessionPath\\UIDCHK.MSG - with uid and data sl@0: r=file.Replace(TheFs,_L("UIDCHK.MSG"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z')); sl@0: checkedUid.Set(uidType2); sl@0: buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid)); sl@0: r=file.Write(buf); sl@0: test(r==KErrNone); sl@0: r=file.Write(_L8("More file data")); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file sl@0: r=file.Replace(TheFs,_L("UIDCHK.DAT"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T')); sl@0: checkedUid.Set(uidType3); sl@0: buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid)); sl@0: r=file.Write(buf); sl@0: test(r==KErrNone); sl@0: r=file.Write(_L8("More file data")); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // Create \\gSessionPath\\UIDCHK.PE - uid stored in WINS PE file header sl@0: r=file.Replace(TheFs,_L("UIDWINS.PE"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: #if defined(__WINS__) sl@0: if (!IsTestingLFFS()) sl@0: { sl@0: RFile fileSource; sl@0: r=fileSource.Open(TheFs,_L("Z:\\TEST\\T_CHKUID.EXE"),EFileShareReadersOnly|EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf8<0x100> buffer; sl@0: do sl@0: { sl@0: r=fileSource.Read(buffer); sl@0: test(r==KErrNone); sl@0: r=file.Write(buffer); sl@0: test(r==KErrNone); sl@0: } sl@0: while (buffer.Length()==buffer.MaxLength()); sl@0: sl@0: fileSource.Close(); sl@0: } sl@0: else sl@0: { sl@0: r=file.Write(_L8("Some zany stuff here!")); sl@0: test(r==KErrNone); sl@0: } sl@0: #else sl@0: r=file.Write(_L8("Some zany stuff here!")); sl@0: test(r==KErrNone); sl@0: #endif sl@0: file.Close(); sl@0: } sl@0: sl@0: LOCAL_C void Test1() sl@0: // sl@0: // Test GetDir sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Use GetDir to check files")); sl@0: CDir* dum=NULL; sl@0: TInt r=TheFs.GetDir(_L("UID*"),KEntryAttAllowUid,ESortByName,dum); sl@0: CDir& dir=*dum; sl@0: test(r==KErrNone); sl@0: TInt count=dir.Count(); sl@0: test(count==6); sl@0: sl@0: TEntry entry=dir[0]; sl@0: test(entry.iName==_L("UIDCHK.BLG")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D')); sl@0: sl@0: entry=dir[1]; sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: sl@0: entry=dir[2]; sl@0: test(entry.iName==_L("UIDCHK.MSG")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z')); sl@0: sl@0: entry=dir[3]; sl@0: test(entry.iName==_L("UIDCHKNO.LNG")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: entry=dir[4]; sl@0: test(entry.iName==_L("UIDCHKNO.SHT")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: entry=dir[5]; sl@0: test(entry.iName==_L("UIDWINS.PE")); sl@0: #if defined(__WINS__) sl@0: TFileName sessionPath; sl@0: TheFs.SessionPath(sessionPath); sl@0: if (sessionPath[0]!='C') sl@0: test(entry.IsTypeValid()==EFalse); sl@0: else sl@0: { sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3)); sl@0: } sl@0: #else sl@0: test(entry.IsTypeValid()==EFalse); sl@0: #endif sl@0: delete dum; sl@0: } sl@0: sl@0: LOCAL_C void Test2() sl@0: // sl@0: // Test GetDir sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test KEntryAttAllowUid allows uids")); sl@0: CDir* dum=NULL; sl@0: TInt r=TheFs.GetDir(_L("UID*"),0,ESortByName,dum); sl@0: CDir& dir=*dum; sl@0: test(r==KErrNone); sl@0: TInt count=dir.Count(); sl@0: test(count==6); sl@0: sl@0: TEntry entry=dir[0]; sl@0: test(entry.iName==_L("UIDCHK.BLG")); sl@0: test(!entry.IsTypeValid()); sl@0: sl@0: entry=dir[1]; sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(!entry.IsTypeValid()); sl@0: sl@0: entry=dir[2]; sl@0: test(entry.iName==_L("UIDCHK.MSG")); sl@0: test(!entry.IsTypeValid()); sl@0: sl@0: entry=dir[3]; sl@0: test(entry.iName==_L("UIDCHKNO.LNG")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: entry=dir[4]; sl@0: test(entry.iName==_L("UIDCHKNO.SHT")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: entry=dir[5]; sl@0: test(entry.iName==_L("UIDWINS.PE")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: delete dum; sl@0: } sl@0: sl@0: LOCAL_C void Test3() sl@0: // sl@0: // Test RFs::Entry() sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Use RFs::EntryL() to check files")); sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(_L("UIDCHKNO.SHT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHKNO.SHT")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: r=TheFs.Entry(_L("UIDCHKNO.LNG"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHKNO.LNG")); sl@0: test(entry.IsTypeValid()==EFalse); sl@0: sl@0: r=TheFs.Entry(_L("UIDCHK.MSG"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.MSG")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z')); sl@0: sl@0: r=TheFs.Entry(_L("UIDCHK.BLG"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.BLG")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D')); sl@0: sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: sl@0: r=TheFs.Entry(_L("UIDWINS.PE"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDWINS.PE")); sl@0: #if defined(__WINS__) sl@0: TFileName sessionPath; sl@0: TheFs.SessionPath(sessionPath); sl@0: if (sessionPath[0]!='C') sl@0: test(entry.IsTypeValid()==EFalse); sl@0: else sl@0: { sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3)); sl@0: } sl@0: #else sl@0: test(entry.IsTypeValid()==EFalse); sl@0: #endif sl@0: } sl@0: sl@0: LOCAL_C void Test4() sl@0: // sl@0: // Test uid's can be read when the file is open sl@0: // sl@0: // EFileShareExclusive,EFileShareReadersOnly,EFileShareAny, sl@0: // EFileStream=0,EFileStreamText=0x100, sl@0: // EFileRead=0,EFileWrite=0x200 sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Uids can be read if the file is open")); sl@0: RFile f; sl@0: TEntry entry; sl@0: TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: f.Close(); sl@0: sl@0: r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: sl@0: r=f.SetSize(256); sl@0: test(r==KErrNone); sl@0: TBuf8<16> des; sl@0: r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16); sl@0: test(r==KErrNone); sl@0: sl@0: f.Close(); sl@0: sl@0: r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: f.Close(); sl@0: sl@0: // EFileShareReadersOnly|EFileWrite is illegal sl@0: sl@0: r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: f.Close(); sl@0: sl@0: r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: RFile secondFile; sl@0: r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: RFile thirdFile; sl@0: r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(_L("UIDCHK.DAT"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDCHK.DAT")); sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); sl@0: f.Close(); sl@0: secondFile.Close(); sl@0: thirdFile.Close(); sl@0: sl@0: r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(_L("UIDWINS.PE"),entry); sl@0: test(r==KErrNone); sl@0: test(entry.iName==_L("UIDWINS.PE")); sl@0: #if defined(__WINS__) sl@0: TFileName sessionPath; sl@0: TheFs.SessionPath(sessionPath); sl@0: if (sessionPath[0]!='C') sl@0: test(entry.IsTypeValid()==EFalse); sl@0: else sl@0: { sl@0: test(entry.IsTypeValid()); sl@0: test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3)); sl@0: } sl@0: #else sl@0: test(entry.IsTypeValid()==EFalse); sl@0: #endif sl@0: f.Close(); sl@0: } sl@0: sl@0: LOCAL_C void TestZ() sl@0: // sl@0: // Test Rom filesystem sl@0: // sl@0: { sl@0: sl@0: CDir* dum=NULL; sl@0: sl@0: TInt r=TheFs.GetDir(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\*"):_L("Z:\\System\\Bin\\*"),KEntryAttAllowUid,0,dum); sl@0: sl@0: if (r==KErrNotReady) sl@0: { sl@0: test.Printf(_L("Error: Unable to open Z:\n")); sl@0: return; sl@0: } sl@0: test(r==KErrNone); sl@0: CDir& dir=*dum; sl@0: TInt count=dir.Count(); sl@0: if (count==0) sl@0: test.Printf(_L("No files present on Z:\\*\n")); sl@0: while (count--) sl@0: { sl@0: TBuf<32> UID; sl@0: if (dir[count].IsTypeValid()==EFalse) sl@0: UID=_L("INVALID"); sl@0: else sl@0: { sl@0: UID=dir[count].iType[0].Name(); sl@0: UID.Append(dir[count].iType[1].Name()); sl@0: UID.Append(dir[count].iType[2].Name()); sl@0: } sl@0: test.Printf(_L("FILE: %S UID %S\n"),&dir[count].iName,&UID); sl@0: } sl@0: delete &dir; sl@0: TEntry entry; sl@0: r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\ELOCAL.FSY"):_L("Z:\\System\\Bin\\ELOCAL.FSY"),entry); sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL(void) sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: sl@0: TBuf<64> b; sl@0: sl@0: TFileName sessionPath; sl@0: sl@0: TInt r=TheFs.SessionPath(sessionPath); sl@0: test(r==KErrNone); sl@0: TChar driveLetter=sessionPath[0]; sl@0: b.Format(_L("Testing filesystem on %c:"),(TText)driveLetter); sl@0: test.Next(b); sl@0: sl@0: CreateUidTestFiles(); sl@0: Test1(); sl@0: Test2(); sl@0: Test3(); sl@0: Test4(); sl@0: sl@0: test.Next(_L("Testing filesystem on Z:")); sl@0: TRAP(r,TestZ()); sl@0: if (r!=KErrNone) sl@0: test.Printf(_L("Error: %d\n"),r); sl@0: }