sl@0: // Copyright (c) 2004-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: // Unit tests for the CMassStorageFileSystem class sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_ms_main.h" sl@0: #include "t_ms_common.h" sl@0: #include "cmassstoragefilesystem.h" sl@0: #include "cmassstoragemountcb.h" sl@0: sl@0: // a: Acutally error code; e: Expected error code sl@0: #define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("%d\n\r"), a); test(EFalse);}} sl@0: sl@0: _LIT(KMsFsyName, "MassStorageFileSystem"); sl@0: LOCAL_D TChar driveLetter; sl@0: sl@0: LOCAL_D TBusLocalDrive* localDrive=NULL; sl@0: sl@0: LOCAL_C void ParseCommandArguments() sl@0: // sl@0: // Parses the command line arguments sl@0: // sl@0: { sl@0: TBuf<0x100> cmd; sl@0: User::CommandLine(cmd); sl@0: TLex lex(cmd); sl@0: sl@0: TPtrC token; sl@0: token.Set(lex.NextToken()); sl@0: if (token.Length() != 0) sl@0: { sl@0: driveLetter = token[0]; sl@0: driveLetter.UpperCase(); sl@0: test.Printf(_L("CmdLine Param=%S"),&token); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Not enough command line arguments")); sl@0: test(EFalse); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void doMsFsUnitTest() sl@0: { sl@0: __UHEAP_MARK; sl@0: ParseCommandArguments(); sl@0: sl@0: RFs fs; sl@0: sl@0: TInt err; sl@0: TInt driveNumber; sl@0: err = fs.CharToDrive(driveLetter, driveNumber); sl@0: test(KErrNone == err); sl@0: fs.Close(); sl@0: sl@0: test.Printf(_L("Checking if drive %d is removable\n\r"), driveNumber); sl@0: TBool removable = isDriveRemovable(driveNumber); sl@0: if (!removable) sl@0: { sl@0: test.Printf(_L("This test is not supported on the specified drive\n\t")); sl@0: return; sl@0: } sl@0: sl@0: CMassStorageFileSystem* msfs = CMassStorageFileSystem::NewL(); sl@0: sl@0: test.Printf(_L("Calling Install\n\r")); sl@0: err = msfs->Install(); sl@0: test(err == KErrNone); sl@0: sl@0: test.Printf(_L("Comparing name\n\r")); sl@0: TName name = msfs->Name(); sl@0: test.Printf(_L("Name is %S\n\r"), &name); sl@0: test(name == KMsFsyName); sl@0: sl@0: test.Printf(_L("Checking version\n\r")); sl@0: TVersion ver(1, 0, 0); sl@0: test(msfs->QueryVersionSupported(ver)); sl@0: sl@0: test.Printf(_L("Checking IsExtensionSupported\n\r")); sl@0: test(msfs->IsExtensionSupported()); sl@0: sl@0: test.Printf(_L("Checking NewMountL\n\r")); sl@0: //In this case new mount should leave because the controller thread is not started sl@0: TRAP(err, msfs->NewMountL()); sl@0: LOG_AND_TEST(err, KErrNotReady); sl@0: sl@0: test.Printf(_L("Calling unsupported functions\n\r")); sl@0: TRAP(err, msfs->NewFileL()); sl@0: test(err == KErrNotReady); sl@0: sl@0: TRAP(err, msfs->NewDirL()); sl@0: test(err == KErrNotReady); sl@0: sl@0: TRAP(err, msfs->NewFormatL()); sl@0: test(err == KErrNotReady); sl@0: sl@0: TBuf<1> buf; sl@0: err = msfs->DefaultPath(buf); sl@0: test(err == KErrNotSupported); sl@0: sl@0: TDriveList list; sl@0: err = msfs->DriveList(list); sl@0: test(err == KErrNotSupported); sl@0: sl@0: test.Printf(_L("Deleting file system object\n\r")); sl@0: msfs->Close(); sl@0: sl@0: delete msfs; sl@0: delete localDrive; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: test.Printf(_L("MSFS unit test ===>PASS\n")); sl@0: } sl@0: sl@0: sl@0: GLDEF_C void t_ms_fsunit() sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: doMsFsUnitTest(); sl@0: } sl@0: sl@0: //========================================================= sl@0: sl@0: EXPORT_C TInt CFsObject::SetName(const TDesC *aName) sl@0: sl@0: { sl@0: User::Free(iName); sl@0: iName=NULL; sl@0: if (aName!=NULL) sl@0: { sl@0: iName=aName->Alloc(); sl@0: if (iName==NULL) sl@0: return(KErrNoMemory); sl@0: } sl@0: return(KErrNone); sl@0: } sl@0: sl@0: EXPORT_C TName CFsObject::Name() const sl@0: sl@0: { sl@0: if (iName) sl@0: return(*iName); sl@0: return(NULL); sl@0: } sl@0: EXPORT_C CFsObject::CFsObject() sl@0: sl@0: { sl@0: iAccessCount=1; sl@0: } sl@0: sl@0: EXPORT_C CFsObject::~CFsObject() sl@0: { sl@0: if(iName) sl@0: User::Free(iName); sl@0: iName=NULL; sl@0: } sl@0: sl@0: EXPORT_C TBool CFsObject::IsCorrectThread() sl@0: { sl@0: return(ETrue); sl@0: } sl@0: sl@0: EXPORT_C void CFsObject::Close() sl@0: { sl@0: if(iName) sl@0: User::Free(iName); sl@0: iName = NULL; sl@0: } sl@0: sl@0: EXPORT_C TInt CFsObject::Open() sl@0: { sl@0: return KErrNone; sl@0: } sl@0: //------------------------------------ sl@0: CFileSystem::CFileSystem(void) sl@0: { sl@0: } sl@0: CFileSystem::~CFileSystem(void) sl@0: { sl@0: } sl@0: sl@0: sl@0: TInt CFileSystem::DefaultPath(TDes& /*aPath*/) const sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C void CFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TBool CFileSystem::IsExtensionSupported() const sl@0: { sl@0: return(EFalse); sl@0: } sl@0: sl@0: EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const sl@0: { sl@0: sl@0: return(User::QueryVersionSupported(iVersion,aVer)); sl@0: } sl@0: sl@0: EXPORT_C TInt CFileSystem::Remove() sl@0: { sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: //-------------------------------------------------- sl@0: EXPORT_C TBool IsValidLocalDriveMapping(TInt /*aDrive*/) sl@0: // sl@0: // Is the drive number to local drive mapping valid? sl@0: // sl@0: { sl@0: sl@0: return(ETrue); sl@0: } sl@0: sl@0: sl@0: sl@0: EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aLocalDrive) sl@0: { sl@0: sl@0: TBusLocalDrive* dd=new(ELeave) TBusLocalDrive; sl@0: TBool mediaCh; sl@0: sl@0: dd->Connect(aLocalDrive, mediaCh); sl@0: localDrive = dd; sl@0: return *dd; sl@0: sl@0: sl@0: } sl@0: sl@0: EXPORT_C TBool DriveNumberToLocalDriveNumber(TInt aDrive) sl@0: { sl@0: return aDrive; sl@0: } sl@0: sl@0: //--------------------------------------------- sl@0: EXPORT_C CLocDrvMountCB::CLocDrvMountCB() {} sl@0: sl@0: EXPORT_C CLocDrvMountCB::~CLocDrvMountCB() sl@0: sl@0: { sl@0: __PRINT1(_L("CLocDrvMountCB::~CLocDrvMountCB() 0x%x"),this); sl@0: if(iProxyDrive) sl@0: delete(iProxyDrive); sl@0: } sl@0: sl@0: //----------------------------------- sl@0: EXPORT_C CMountCB::CMountCB() sl@0: : iMountQ(_FOFF(CFileCB,iMountLink)) sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: Frees resources before destroying the object. sl@0: */ sl@0: EXPORT_C CMountCB::~CMountCB() sl@0: { sl@0: delete iVolumeName; sl@0: } sl@0: sl@0: //------------------------------------- sl@0: CFsDispatchObject::CFsDispatchObject() sl@0: sl@0: :iDriveNumber(-1) sl@0: {} sl@0: sl@0: CFsDispatchObject::~CFsDispatchObject() sl@0: { sl@0: } sl@0: int CFsDispatchObject::IsCorrectThread(void) sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: EXPORT_C void CFsDispatchObject::Close() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart) sl@0: { sl@0: aFileStart=NULL; sl@0: } sl@0: sl@0: int CLocDrvMountCB::CreateLocalDrive(class TBusLocalDrive &) sl@0: sl@0: { sl@0: return KErrNone; sl@0: } sl@0: void CLocDrvMountCB::DismountedLocalDrive(void) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void WriteToDisk(const TDesC& /*aFileName*/, const TDesC8& /*aBuf*/) sl@0: { sl@0: } sl@0: sl@0: // Implement the GetInterface methods here as these are usually sl@0: // exported by EFILE, but these unit tests don't link to it. sl@0: sl@0: TInt CMountCB::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: