kerneltest/f32test/smassstorage/src/t_ms_fsunit.cpp
changeset 0 a41df078684a
child 33 0173bcd7697c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Unit tests for the CMassStorageFileSystem class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #include <f32file.h>
       
    24 #include <e32test.h>
       
    25 #include <e32std.h>
       
    26 #include <e32std_private.h>
       
    27 #include <e32svr.h>
       
    28 #include <hal.h>
       
    29 #include "t_ms_main.h"
       
    30 #include "t_ms_common.h"
       
    31 #include "cmassstoragefilesystem.h"
       
    32 #include "cmassstoragemountcb.h"
       
    33 
       
    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);}}
       
    36 
       
    37 _LIT(KMsFsyName, "MassStorageFileSystem");
       
    38 LOCAL_D TChar driveLetter;
       
    39 
       
    40 LOCAL_D TBusLocalDrive* localDrive=NULL;
       
    41 
       
    42 LOCAL_C void ParseCommandArguments()
       
    43 //
       
    44 // Parses the command line arguments
       
    45 //
       
    46 	{
       
    47 	TBuf<0x100> cmd;
       
    48 	User::CommandLine(cmd);
       
    49 	TLex lex(cmd);
       
    50 	
       
    51 	TPtrC token;
       
    52 	token.Set(lex.NextToken());
       
    53 	if (token.Length() != 0)
       
    54 		{
       
    55 		driveLetter = token[0];
       
    56 		driveLetter.UpperCase();
       
    57 		test.Printf(_L("CmdLine Param=%S"),&token);
       
    58 		}
       
    59 	else
       
    60 		{
       
    61 		test.Printf(_L("Not enough command line arguments"));
       
    62 		test(EFalse);
       
    63 		}
       
    64 	}
       
    65 	
       
    66 LOCAL_C void doMsFsUnitTest()
       
    67 	{
       
    68 	__UHEAP_MARK;
       
    69 	ParseCommandArguments();
       
    70 
       
    71 	RFs fs;
       
    72 	
       
    73 	TInt err;
       
    74 	TInt driveNumber;
       
    75 	err = fs.CharToDrive(driveLetter, driveNumber);
       
    76 	test(KErrNone == err);
       
    77 	fs.Close();
       
    78 	
       
    79 	test.Printf(_L("Checking if drive %d is removable\n\r"), driveNumber);
       
    80 	TBool removable = isDriveRemovable(driveNumber);
       
    81 	if (!removable)
       
    82 		{
       
    83 		test.Printf(_L("This test is not supported on the specified drive\n\t"));
       
    84 		return;
       
    85 		}
       
    86 	
       
    87 	CMassStorageFileSystem* msfs = CMassStorageFileSystem::NewL();
       
    88 
       
    89 	test.Printf(_L("Calling Install\n\r"));
       
    90 	err = msfs->Install();
       
    91 	test(err == KErrNone);
       
    92 	
       
    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);
       
    97 
       
    98 	test.Printf(_L("Checking version\n\r"));
       
    99 	TVersion ver(1, 0, 0);
       
   100 	test(msfs->QueryVersionSupported(ver));
       
   101 	
       
   102 	test.Printf(_L("Checking IsExtensionSupported\n\r"));
       
   103 	test(msfs->IsExtensionSupported());
       
   104 	
       
   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);
       
   109 			
       
   110 	test.Printf(_L("Calling unsupported functions\n\r"));
       
   111 	TRAP(err, msfs->NewFileL());
       
   112 	test(err == KErrNotReady);
       
   113 
       
   114 	TRAP(err, msfs->NewDirL());
       
   115 	test(err == KErrNotReady);
       
   116 
       
   117 	TRAP(err, msfs->NewFormatL());
       
   118 	test(err == KErrNotReady);
       
   119 
       
   120 	TBuf<1> buf;
       
   121 	err = msfs->DefaultPath(buf);
       
   122 	test(err == KErrNotSupported);
       
   123 
       
   124 	TDriveList list;
       
   125 	err = msfs->DriveList(list);
       
   126 	test(err == KErrNotSupported);
       
   127 	
       
   128 	test.Printf(_L("Deleting file system object\n\r"));
       
   129 	msfs->Close();
       
   130 
       
   131 	delete msfs;
       
   132 	delete localDrive;	
       
   133 	
       
   134 	__UHEAP_MARKEND;
       
   135 
       
   136     test.Printf(_L("MSFS unit test ===>PASS\n"));
       
   137 	}
       
   138 	
       
   139 
       
   140 GLDEF_C void t_ms_fsunit()
       
   141 //
       
   142 // Do all tests
       
   143 //
       
   144 	{
       
   145     doMsFsUnitTest();
       
   146     }
       
   147 
       
   148 //=========================================================
       
   149 
       
   150 EXPORT_C TInt CFsObject::SetName(const TDesC *aName)
       
   151 
       
   152 	{
       
   153 	User::Free(iName);
       
   154 	iName=NULL;
       
   155 	if (aName!=NULL)
       
   156 		{
       
   157 		iName=aName->Alloc();
       
   158 		if (iName==NULL)
       
   159 			return(KErrNoMemory);
       
   160 		}
       
   161 	return(KErrNone);
       
   162 	}
       
   163 
       
   164 EXPORT_C TName CFsObject::Name() const
       
   165 
       
   166 	{
       
   167 	if (iName)
       
   168 		return(*iName);
       
   169 	return(NULL);
       
   170 	}
       
   171 EXPORT_C CFsObject::CFsObject()
       
   172 
       
   173 	{
       
   174 	iAccessCount=1;
       
   175 	}
       
   176 
       
   177 EXPORT_C  CFsObject::~CFsObject()
       
   178 	{
       
   179 	if(iName)
       
   180 		User::Free(iName);
       
   181 	iName=NULL;
       
   182 	}	
       
   183 
       
   184 EXPORT_C TBool CFsObject::IsCorrectThread()
       
   185 	{
       
   186 	return(ETrue);
       
   187 	}
       
   188 
       
   189 EXPORT_C void CFsObject::Close()	
       
   190 	{
       
   191 	if(iName)
       
   192 		User::Free(iName);
       
   193 	iName = NULL;
       
   194 	}
       
   195 	
       
   196 EXPORT_C TInt CFsObject::Open()
       
   197 	{
       
   198 	return KErrNone;
       
   199 	}
       
   200 //------------------------------------	
       
   201 CFileSystem::CFileSystem(void)
       
   202 	{
       
   203 	}
       
   204 CFileSystem::~CFileSystem(void)
       
   205 	{
       
   206 	}
       
   207 	
       
   208 
       
   209 TInt CFileSystem::DefaultPath(TDes& /*aPath*/) const 
       
   210 	{
       
   211 	return KErrNone;
       
   212 	}
       
   213 
       
   214 
       
   215 EXPORT_C TBool CFileSystem::IsExtensionSupported() const
       
   216 	{
       
   217 	return(EFalse);
       
   218 	}
       
   219 
       
   220 EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const
       
   221 	{
       
   222 
       
   223 	return(User::QueryVersionSupported(iVersion,aVer));
       
   224 	}
       
   225 	
       
   226 EXPORT_C TInt CFileSystem::Remove()
       
   227 	{
       
   228 
       
   229 	return(KErrNone);
       
   230 	}	
       
   231 
       
   232 //--------------------------------------------------
       
   233 EXPORT_C TBool IsValidLocalDriveMapping(TInt /*aDrive*/)
       
   234 //
       
   235 // Is the drive number to local drive mapping valid?
       
   236 //
       
   237 	{
       
   238 
       
   239 	return(ETrue);
       
   240 	}
       
   241 
       
   242 
       
   243 
       
   244 EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aLocalDrive)
       
   245 	{
       
   246 	
       
   247 	TBusLocalDrive* dd=new(ELeave) TBusLocalDrive;
       
   248 	TBool mediaCh;
       
   249 	
       
   250 	dd->Connect(aLocalDrive, mediaCh);
       
   251 	localDrive = dd;
       
   252 	return *dd;
       
   253 
       
   254 	
       
   255 	}
       
   256 	
       
   257 EXPORT_C TBool DriveNumberToLocalDriveNumber(TInt aDrive)
       
   258 	{
       
   259 	return aDrive;
       
   260 	}
       
   261 
       
   262 //---------------------------------------------
       
   263 EXPORT_C CLocDrvMountCB::CLocDrvMountCB() {}
       
   264 
       
   265 EXPORT_C CLocDrvMountCB::~CLocDrvMountCB()
       
   266 
       
   267 	{
       
   268 	__PRINT1(_L("CLocDrvMountCB::~CLocDrvMountCB() 0x%x"),this);
       
   269 	if(iProxyDrive)
       
   270 		delete(iProxyDrive);
       
   271 	}
       
   272 	
       
   273 //-----------------------------------
       
   274 EXPORT_C CMountCB::CMountCB()
       
   275 	: iMountQ(_FOFF(CFileCB,iMountLink))
       
   276 	{
       
   277 
       
   278 	}
       
   279 
       
   280 /**
       
   281 Destructor.
       
   282 
       
   283 Frees resources before destroying the object.
       
   284 */
       
   285 EXPORT_C CMountCB::~CMountCB()
       
   286 	{
       
   287 	delete iVolumeName;
       
   288 	}	
       
   289 
       
   290 //-------------------------------------
       
   291 CFsDispatchObject::CFsDispatchObject()
       
   292 
       
   293 :iDriveNumber(-1) 
       
   294 {}
       
   295 
       
   296 CFsDispatchObject::~CFsDispatchObject()
       
   297 	{
       
   298 	}
       
   299 int CFsDispatchObject::IsCorrectThread(void)
       
   300 	{
       
   301 	return ETrue;
       
   302 	}
       
   303 
       
   304 EXPORT_C void CFsDispatchObject::Close()
       
   305 	{
       
   306 	}	
       
   307 
       
   308 EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart)
       
   309 	{
       
   310 	aFileStart=NULL;
       
   311 	}
       
   312 
       
   313 int CLocDrvMountCB::CreateLocalDrive(class TBusLocalDrive &) 
       
   314 
       
   315 	{
       
   316 	return KErrNone;
       
   317 	}
       
   318 void CLocDrvMountCB::DismountedLocalDrive(void) 
       
   319 	{
       
   320 	}
       
   321 	
       
   322 EXPORT_C void WriteToDisk(const TDesC& /*aFileName*/, const TDesC8& /*aBuf*/)
       
   323 	{
       
   324 	}
       
   325 
       
   326 // Implement the GetInterface methods here as these are usually 
       
   327 // exported by EFILE, but these unit tests don't link to it.
       
   328 
       
   329 TInt CMountCB::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
       
   330 	{
       
   331 	return KErrNotSupported;
       
   332 	}
       
   333 
       
   334 TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
       
   335 	{
       
   336 	return KErrNotSupported;
       
   337 	}
       
   338