First public contribution.
1 // Copyright (c) 2004-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 // Unit tests for the CMassStorageFileSystem class
26 #include <e32std_private.h>
29 #include "t_ms_main.h"
30 #include "t_ms_common.h"
31 #include "cmassstoragefilesystem.h"
32 #include "cmassstoragemountcb.h"
34 // a: Acutally error code; e: Expected error code
35 #define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("%d\n\r"), a); test(EFalse);}}
37 _LIT(KMsFsyName, "MassStorageFileSystem");
38 LOCAL_D TChar driveLetter;
40 LOCAL_D TBusLocalDrive* localDrive=NULL;
42 LOCAL_C void ParseCommandArguments()
44 // Parses the command line arguments
48 User::CommandLine(cmd);
52 token.Set(lex.NextToken());
53 if (token.Length() != 0)
55 driveLetter = token[0];
56 driveLetter.UpperCase();
57 test.Printf(_L("CmdLine Param=%S"),&token);
61 test.Printf(_L("Not enough command line arguments"));
66 LOCAL_C void doMsFsUnitTest()
69 ParseCommandArguments();
75 err = fs.CharToDrive(driveLetter, driveNumber);
76 test(KErrNone == err);
79 test.Printf(_L("Checking if drive %d is removable\n\r"), driveNumber);
80 TBool removable = isDriveRemovable(driveNumber);
83 test.Printf(_L("This test is not supported on the specified drive\n\t"));
87 CMassStorageFileSystem* msfs = CMassStorageFileSystem::NewL();
89 test.Printf(_L("Calling Install\n\r"));
90 err = msfs->Install();
91 test(err == KErrNone);
93 test.Printf(_L("Comparing name\n\r"));
94 TName name = msfs->Name();
95 test.Printf(_L("Name is %S\n\r"), &name);
96 test(name == KMsFsyName);
98 test.Printf(_L("Checking version\n\r"));
99 TVersion ver(1, 0, 0);
100 test(msfs->QueryVersionSupported(ver));
102 test.Printf(_L("Checking IsExtensionSupported\n\r"));
103 test(msfs->IsExtensionSupported());
105 test.Printf(_L("Checking NewMountL\n\r"));
106 //In this case new mount should leave because the controller thread is not started
107 TRAP(err, msfs->NewMountL());
108 LOG_AND_TEST(err, KErrNotReady);
110 test.Printf(_L("Calling unsupported functions\n\r"));
111 TRAP(err, msfs->NewFileL());
112 test(err == KErrNotReady);
114 TRAP(err, msfs->NewDirL());
115 test(err == KErrNotReady);
117 TRAP(err, msfs->NewFormatL());
118 test(err == KErrNotReady);
121 err = msfs->DefaultPath(buf);
122 test(err == KErrNotSupported);
125 err = msfs->DriveList(list);
126 test(err == KErrNotSupported);
128 test.Printf(_L("Deleting file system object\n\r"));
136 test.Printf(_L("MSFS unit test ===>PASS\n"));
140 GLDEF_C void t_ms_fsunit()
148 //=========================================================
150 EXPORT_C TInt CFsObject::SetName(const TDesC *aName)
157 iName=aName->Alloc();
159 return(KErrNoMemory);
164 EXPORT_C TName CFsObject::Name() const
171 EXPORT_C CFsObject::CFsObject()
177 EXPORT_C CFsObject::~CFsObject()
184 EXPORT_C TBool CFsObject::IsCorrectThread()
189 EXPORT_C void CFsObject::Close()
196 EXPORT_C TInt CFsObject::Open()
200 //------------------------------------
201 CFileSystem::CFileSystem(void)
204 CFileSystem::~CFileSystem(void)
209 TInt CFileSystem::DefaultPath(TDes& /*aPath*/) const
214 EXPORT_C void CFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const
218 EXPORT_C TBool CFileSystem::IsExtensionSupported() const
223 EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const
226 return(User::QueryVersionSupported(iVersion,aVer));
229 EXPORT_C TInt CFileSystem::Remove()
235 //--------------------------------------------------
236 EXPORT_C TBool IsValidLocalDriveMapping(TInt /*aDrive*/)
238 // Is the drive number to local drive mapping valid?
247 EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aLocalDrive)
250 TBusLocalDrive* dd=new(ELeave) TBusLocalDrive;
253 dd->Connect(aLocalDrive, mediaCh);
260 EXPORT_C TBool DriveNumberToLocalDriveNumber(TInt aDrive)
265 //---------------------------------------------
266 EXPORT_C CLocDrvMountCB::CLocDrvMountCB() {}
268 EXPORT_C CLocDrvMountCB::~CLocDrvMountCB()
271 __PRINT1(_L("CLocDrvMountCB::~CLocDrvMountCB() 0x%x"),this);
276 //-----------------------------------
277 EXPORT_C CMountCB::CMountCB()
278 : iMountQ(_FOFF(CFileCB,iMountLink))
286 Frees resources before destroying the object.
288 EXPORT_C CMountCB::~CMountCB()
293 //-------------------------------------
294 CFsDispatchObject::CFsDispatchObject()
299 CFsDispatchObject::~CFsDispatchObject()
302 int CFsDispatchObject::IsCorrectThread(void)
307 EXPORT_C void CFsDispatchObject::Close()
311 EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart)
316 int CLocDrvMountCB::CreateLocalDrive(class TBusLocalDrive &)
321 void CLocDrvMountCB::DismountedLocalDrive(void)
325 EXPORT_C void WriteToDisk(const TDesC& /*aFileName*/, const TDesC8& /*aBuf*/)
329 // Implement the GetInterface methods here as these are usually
330 // exported by EFILE, but these unit tests don't link to it.
332 TInt CMountCB::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
334 return KErrNotSupported;
337 TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
339 return KErrNotSupported;