os/kernelhwsrv/kerneltest/f32test/smassstorage/src/t_ms_fsunit.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     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 EXPORT_C void CFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const
   215 	{
   216 	}
   217 
   218 EXPORT_C TBool CFileSystem::IsExtensionSupported() const
   219 	{
   220 	return(EFalse);
   221 	}
   222 
   223 EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const
   224 	{
   225 
   226 	return(User::QueryVersionSupported(iVersion,aVer));
   227 	}
   228 	
   229 EXPORT_C TInt CFileSystem::Remove()
   230 	{
   231 
   232 	return(KErrNone);
   233 	}	
   234 
   235 //--------------------------------------------------
   236 EXPORT_C TBool IsValidLocalDriveMapping(TInt /*aDrive*/)
   237 //
   238 // Is the drive number to local drive mapping valid?
   239 //
   240 	{
   241 
   242 	return(ETrue);
   243 	}
   244 
   245 
   246 
   247 EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aLocalDrive)
   248 	{
   249 	
   250 	TBusLocalDrive* dd=new(ELeave) TBusLocalDrive;
   251 	TBool mediaCh;
   252 	
   253 	dd->Connect(aLocalDrive, mediaCh);
   254 	localDrive = dd;
   255 	return *dd;
   256 
   257 	
   258 	}
   259 	
   260 EXPORT_C TBool DriveNumberToLocalDriveNumber(TInt aDrive)
   261 	{
   262 	return aDrive;
   263 	}
   264 
   265 //---------------------------------------------
   266 EXPORT_C CLocDrvMountCB::CLocDrvMountCB() {}
   267 
   268 EXPORT_C CLocDrvMountCB::~CLocDrvMountCB()
   269 
   270 	{
   271 	__PRINT1(_L("CLocDrvMountCB::~CLocDrvMountCB() 0x%x"),this);
   272 	if(iProxyDrive)
   273 		delete(iProxyDrive);
   274 	}
   275 	
   276 //-----------------------------------
   277 EXPORT_C CMountCB::CMountCB()
   278 	: iMountQ(_FOFF(CFileCB,iMountLink))
   279 	{
   280 
   281 	}
   282 
   283 /**
   284 Destructor.
   285 
   286 Frees resources before destroying the object.
   287 */
   288 EXPORT_C CMountCB::~CMountCB()
   289 	{
   290 	delete iVolumeName;
   291 	}	
   292 
   293 //-------------------------------------
   294 CFsDispatchObject::CFsDispatchObject()
   295 
   296 :iDriveNumber(-1) 
   297 {}
   298 
   299 CFsDispatchObject::~CFsDispatchObject()
   300 	{
   301 	}
   302 int CFsDispatchObject::IsCorrectThread(void)
   303 	{
   304 	return ETrue;
   305 	}
   306 
   307 EXPORT_C void CFsDispatchObject::Close()
   308 	{
   309 	}	
   310 
   311 EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart)
   312 	{
   313 	aFileStart=NULL;
   314 	}
   315 
   316 int CLocDrvMountCB::CreateLocalDrive(class TBusLocalDrive &) 
   317 
   318 	{
   319 	return KErrNone;
   320 	}
   321 void CLocDrvMountCB::DismountedLocalDrive(void) 
   322 	{
   323 	}
   324 	
   325 EXPORT_C void WriteToDisk(const TDesC& /*aFileName*/, const TDesC8& /*aBuf*/)
   326 	{
   327 	}
   328 
   329 // Implement the GetInterface methods here as these are usually 
   330 // exported by EFILE, but these unit tests don't link to it.
   331 
   332 TInt CMountCB::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
   333 	{
   334 	return KErrNotSupported;
   335 	}
   336 
   337 TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/, TAny*& /*aInterface*/, TAny* /*aInput*/)
   338 	{
   339 	return KErrNotSupported;
   340 	}
   341