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