os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/combinational_plugin.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.
sl@0
     1
// Copyright (c) 2007-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
//
sl@0
    15
sl@0
    16
#include "combinational_plugin.h"
sl@0
    17
#include "plugincommon.h"
sl@0
    18
#include <f32pluginutils.h>
sl@0
    19
sl@0
    20
/**
sl@0
    21
Leaving New function for the plugin
sl@0
    22
@internalComponent
sl@0
    23
*/
sl@0
    24
CCombinationalPlugin* CCombinationalPlugin::NewL()
sl@0
    25
	{
sl@0
    26
	CCombinationalPlugin* self = new(ELeave) CCombinationalPlugin;
sl@0
    27
    CleanupStack::PushL(self);
sl@0
    28
    self->ConstructL();
sl@0
    29
    CleanupStack::Pop();
sl@0
    30
	return self;
sl@0
    31
	}
sl@0
    32
sl@0
    33
sl@0
    34
/**
sl@0
    35
Constructor for the plugin
sl@0
    36
@internalComponent
sl@0
    37
*/
sl@0
    38
CCombinationalPlugin::CCombinationalPlugin() : iInterceptsEnabled(EFalse),
sl@0
    39
									 iLogging(ETrue)
sl@0
    40
	{
sl@0
    41
	}
sl@0
    42
sl@0
    43
sl@0
    44
void CCombinationalPlugin::ConstructL()
sl@0
    45
	{
sl@0
    46
	//iFile = RFilePlugin::Open();
sl@0
    47
	}
sl@0
    48
sl@0
    49
/**
sl@0
    50
The destructor for the plugin
sl@0
    51
@internalComponent
sl@0
    52
*/
sl@0
    53
CCombinationalPlugin::~CCombinationalPlugin()
sl@0
    54
	{
sl@0
    55
	}
sl@0
    56
sl@0
    57
/**
sl@0
    58
Initialise the plugin.
sl@0
    59
@internalComponent
sl@0
    60
*/
sl@0
    61
void CCombinationalPlugin::InitialiseL()
sl@0
    62
	{
sl@0
    63
	_LOG(_L("CCombinationalPlugin InitialiseL"));
sl@0
    64
	EnableInterceptsL();
sl@0
    65
	}
sl@0
    66
sl@0
    67
/**
sl@0
    68
Enable the plugin's intercepts.
sl@0
    69
@internalComponent
sl@0
    70
*/
sl@0
    71
void CCombinationalPlugin::EnableInterceptsL()
sl@0
    72
	{
sl@0
    73
	if (iInterceptsEnabled) return;
sl@0
    74
	
sl@0
    75
	User::LeaveIfError(RegisterIntercept(EFsFileRead,			EPrePostIntercept));
sl@0
    76
	User::LeaveIfError(RegisterIntercept(EFsFileWrite,			EPrePostIntercept));
sl@0
    77
	User::LeaveIfError(RegisterIntercept(EFsDirOpen,			EPrePostIntercept));
sl@0
    78
	User::LeaveIfError(RegisterIntercept(EFsFileLock,			EPrePostIntercept));
sl@0
    79
	User::LeaveIfError(RegisterIntercept(EFsFileUnLock,			EPrePostIntercept));
sl@0
    80
	User::LeaveIfError(RegisterIntercept(EFsFileSeek,			EPrePostIntercept));
sl@0
    81
	User::LeaveIfError(RegisterIntercept(EFsFileSize,			EPrePostIntercept));
sl@0
    82
	User::LeaveIfError(RegisterIntercept(EFsFileSetSize,		EPrePostIntercept));
sl@0
    83
	User::LeaveIfError(RegisterIntercept(EFsDirReadOne,			EPrePostIntercept));
sl@0
    84
	User::LeaveIfError(RegisterIntercept(EFsDirReadPacked,		EPrePostIntercept));
sl@0
    85
	User::LeaveIfError(RegisterIntercept(EFsFileOpen,			EPrePostIntercept));
sl@0
    86
	User::LeaveIfError(RegisterIntercept(EFsFileCreate,			EPrePostIntercept));
sl@0
    87
	User::LeaveIfError(RegisterIntercept(EFsFileReplace,		EPrePostIntercept));
sl@0
    88
	User::LeaveIfError(RegisterIntercept(EFsFileRename,			EPrePostIntercept));
sl@0
    89
   	User::LeaveIfError(RegisterIntercept(EFsReadFileSection,	EPrePostIntercept));
sl@0
    90
	User::LeaveIfError(RegisterIntercept(EFsFileSubClose,       EPrePostIntercept));
sl@0
    91
	User::LeaveIfError(RegisterIntercept(EFsEntry,        		EPrePostIntercept));
sl@0
    92
	User::LeaveIfError(RegisterIntercept(EFsSetEntry,      		EPrePostIntercept));
sl@0
    93
sl@0
    94
	_LOG(_L("Combinational Plugin: Enabled intercepts."));
sl@0
    95
    
sl@0
    96
	iInterceptsEnabled = ETrue;
sl@0
    97
	}
sl@0
    98
sl@0
    99
/**
sl@0
   100
Disable the plugin's intercepts.
sl@0
   101
@internalComponent
sl@0
   102
*/
sl@0
   103
void CCombinationalPlugin::DisableInterceptsL()
sl@0
   104
	{
sl@0
   105
	if (!iInterceptsEnabled) return;
sl@0
   106
	
sl@0
   107
	User::LeaveIfError(UnregisterIntercept(EFsFileRead,			EPrePostIntercept));
sl@0
   108
	User::LeaveIfError(UnregisterIntercept(EFsFileRename,		EPrePostIntercept));
sl@0
   109
	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,		EPrePostIntercept));
sl@0
   110
	User::LeaveIfError(UnregisterIntercept(EFsDirOpen,			EPrePostIntercept));
sl@0
   111
	User::LeaveIfError(UnregisterIntercept(EFsFileLock,			EPrePostIntercept));
sl@0
   112
	User::LeaveIfError(UnregisterIntercept(EFsFileUnLock,		EPrePostIntercept));
sl@0
   113
	User::LeaveIfError(UnregisterIntercept(EFsFileSeek,			EPrePostIntercept));
sl@0
   114
	User::LeaveIfError(UnregisterIntercept(EFsFileSize,			EPrePostIntercept));
sl@0
   115
	User::LeaveIfError(UnregisterIntercept(EFsFileSetSize,		EPrePostIntercept));
sl@0
   116
	User::LeaveIfError(UnregisterIntercept(EFsFileCreate,		EPrePostIntercept));
sl@0
   117
	User::LeaveIfError(UnregisterIntercept(EFsFileOpen, 		EPrePostIntercept));
sl@0
   118
	User::LeaveIfError(UnregisterIntercept(EFsFileReplace, 		EPrePostIntercept));
sl@0
   119
	User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, 	EPrePostIntercept));
sl@0
   120
	User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,	EPrePostIntercept));
sl@0
   121
	User::LeaveIfError(UnregisterIntercept(EFsDirReadOne,		EPrePostIntercept));
sl@0
   122
	User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,	EPrePostIntercept));
sl@0
   123
	User::LeaveIfError(UnregisterIntercept(EFsEntry,        	EPrePostIntercept));
sl@0
   124
	User::LeaveIfError(UnregisterIntercept(EFsSetEntry,      	EPrePostIntercept));
sl@0
   125
sl@0
   126
	_LOG(_L("Combinational Plugin: Disabled intercepts."));
sl@0
   127
    
sl@0
   128
	iInterceptsEnabled = EFalse;
sl@0
   129
	}
sl@0
   130
sl@0
   131
/**
sl@0
   132
Handle requests
sl@0
   133
@internalComponent
sl@0
   134
*/
sl@0
   135
TInt CCombinationalPlugin::DoRequestL(TFsPluginRequest& aRequest)
sl@0
   136
	{
sl@0
   137
	TInt r = KErrNone;
sl@0
   138
	TInt function = aRequest.Function();
sl@0
   139
	
sl@0
   140
	if (aRequest.IsPostOperation())
sl@0
   141
		{
sl@0
   142
		_LOG2(_L("CCombinationalPlugin post intercept for function %d"), function);
sl@0
   143
		}
sl@0
   144
	else
sl@0
   145
		{
sl@0
   146
		_LOG2(_L("CCombinationalPlugin pre intercept for function %d"), function);
sl@0
   147
		}
sl@0
   148
sl@0
   149
	switch (function)
sl@0
   150
		{
sl@0
   151
		case EFsFileOpen:
sl@0
   152
			r= DoFileOpen(aRequest);
sl@0
   153
			break;
sl@0
   154
		case EFsFileSubClose:
sl@0
   155
			r = DoFileSubClose(aRequest);
sl@0
   156
			break;
sl@0
   157
		case EFsFileReplace:
sl@0
   158
			r = DoFileReplace(aRequest);
sl@0
   159
			break;
sl@0
   160
		case EFsEntry:
sl@0
   161
			r = DoEntry(aRequest);
sl@0
   162
			break;
sl@0
   163
		case EFsDirReadPacked:
sl@0
   164
			r = DoDirReadPacked(aRequest);
sl@0
   165
			break;
sl@0
   166
		case EFsDirOpen:
sl@0
   167
			aRequest.Src();
sl@0
   168
			break;
sl@0
   169
		default:
sl@0
   170
			break;
sl@0
   171
		}
sl@0
   172
	return r;
sl@0
   173
	}
sl@0
   174
sl@0
   175
sl@0
   176
sl@0
   177
sl@0
   178
TInt CCombinationalPlugin::DoFileRead(TFsPluginRequest& /*aRequest*/)
sl@0
   179
	{
sl@0
   180
	iLastError = KErrNotSupported;
sl@0
   181
	iLineNumber = __LINE__;
sl@0
   182
	return KErrNotSupported;
sl@0
   183
	}
sl@0
   184
TInt CCombinationalPlugin::DoFileWrite(TFsPluginRequest& /*aRequest*/)
sl@0
   185
	{
sl@0
   186
	iLastError = KErrNotSupported;
sl@0
   187
	iLineNumber = __LINE__;
sl@0
   188
	return KErrNotSupported;
sl@0
   189
	}
sl@0
   190
sl@0
   191
/*
sl@0
   192
Test - 	Perform an Open here,
sl@0
   193
 		then make sure we get the right details in the second plugin.
sl@0
   194
*/
sl@0
   195
TInt CCombinationalPlugin::DoEntry(TFsPluginRequest& aRequest)
sl@0
   196
	{
sl@0
   197
	TInt err = KErrNone;
sl@0
   198
	TFileName name;
sl@0
   199
	
sl@0
   200
	TBuf<256> testfilename1;
sl@0
   201
sl@0
   202
	//setting up test files
sl@0
   203
	testfilename1.Append(iDriveToTest);
sl@0
   204
	testfilename1.Append(_L(":\\data\\test.entry.combi"));
sl@0
   205
sl@0
   206
	name = aRequest.Src().FullName();
sl@0
   207
	
sl@0
   208
	if(!aRequest.IsPostOperation()) //pre
sl@0
   209
		{
sl@0
   210
		err = KErrNone;
sl@0
   211
		
sl@0
   212
		TBuf<256> clientfilename;
sl@0
   213
		clientfilename.Append(iDriveToTest);
sl@0
   214
		clientfilename.Append(_L(":\\combi.txt"));
sl@0
   215
		
sl@0
   216
		if(name.Compare(clientfilename) == 0)
sl@0
   217
			{
sl@0
   218
			RFilePlugin file(aRequest);
sl@0
   219
			err = file.Replace(testfilename1, EFileWrite);//open
sl@0
   220
			iLastError = err;
sl@0
   221
			iLineNumber = __LINE__;
sl@0
   222
			if(err!=KErrNone)
sl@0
   223
				return err;
sl@0
   224
			
sl@0
   225
			file.Close();
sl@0
   226
			}
sl@0
   227
		
sl@0
   228
		}
sl@0
   229
	else //post
sl@0
   230
		{
sl@0
   231
		TEntry entry;
sl@0
   232
		TPckg<TEntry> entryPckg(entry);
sl@0
   233
		err = aRequest.Read(TFsPluginRequest::EEntry, entryPckg);
sl@0
   234
		iLastError = err;
sl@0
   235
		iLineNumber = __LINE__;
sl@0
   236
		if(err!=KErrNone)
sl@0
   237
			return err;
sl@0
   238
		}
sl@0
   239
sl@0
   240
	return err;
sl@0
   241
	}
sl@0
   242
sl@0
   243
TInt CCombinationalPlugin::DoDirReadPacked(TFsPluginRequest& aRequest)
sl@0
   244
	{
sl@0
   245
	TInt err = KErrNone;
sl@0
   246
	
sl@0
   247
	TBuf<16> compareName;
sl@0
   248
	compareName.Append(iDriveToTest);
sl@0
   249
	compareName.Append(_L(":\\dir3\\"));
sl@0
   250
	if(iDirFullName.Compare(compareName) == 0)
sl@0
   251
		{
sl@0
   252
		return KErrNone;
sl@0
   253
		}
sl@0
   254
	
sl@0
   255
	if (aRequest.IsPostOperation()) //Post
sl@0
   256
		{
sl@0
   257
		// NOP
sl@0
   258
		}
sl@0
   259
	else							//Pre 
sl@0
   260
		{
sl@0
   261
		RDirPlugin dir1(aRequest);
sl@0
   262
		err = dir1.Open(iDirFullName, KEntryAttMatchMask); 
sl@0
   263
		iLastError = err;
sl@0
   264
		iLineNumber = __LINE__;
sl@0
   265
		if(err!=KErrNone)
sl@0
   266
			return err;
sl@0
   267
sl@0
   268
		TBuf<16> dirname2;
sl@0
   269
		dirname2.Append(iDriveToTest);
sl@0
   270
		dirname2.Append(_L(":\\dir2\\"));
sl@0
   271
		
sl@0
   272
		TEntryArray entryarray1;
sl@0
   273
		err = dir1.Read(entryarray1); //we can complete
sl@0
   274
		iLastError = err;
sl@0
   275
		iLineNumber = __LINE__;
sl@0
   276
		if(err!=KErrNone && err!=KErrEof)
sl@0
   277
			return err;
sl@0
   278
sl@0
   279
		TUidType uid(TUid::Null(),TUid::Null(),TUid::Null());
sl@0
   280
	
sl@0
   281
		RDirPlugin dir2(aRequest);
sl@0
   282
		err = dir2.Open(dirname2,uid);
sl@0
   283
		iLastError = err;
sl@0
   284
		iLineNumber = __LINE__;
sl@0
   285
		if(err!=KErrNone)
sl@0
   286
			return err;
sl@0
   287
		
sl@0
   288
		TEntryArray entryarray2;
sl@0
   289
		err = dir2.Read(entryarray2);
sl@0
   290
		iLastError = err;
sl@0
   291
		iLineNumber = __LINE__;
sl@0
   292
		if(err!=KErrNone && err!=KErrEof)
sl@0
   293
			return err;
sl@0
   294
		
sl@0
   295
		if(entryarray1.Count() >= 1 && entryarray2.Count() >= 1)
sl@0
   296
			{
sl@0
   297
			TEntry e1 = entryarray1[0];
sl@0
   298
			
sl@0
   299
			TBuf<16> dir1file;
sl@0
   300
			dir1file.Append(_L("dir1.file"));
sl@0
   301
			if(e1.iName.Compare(dir1file) != 0)
sl@0
   302
				{
sl@0
   303
				iLastError = err;
sl@0
   304
				iLineNumber = __LINE__;
sl@0
   305
				if(err!=KErrNone)
sl@0
   306
					return err;
sl@0
   307
				}
sl@0
   308
			}
sl@0
   309
		else 
sl@0
   310
			{
sl@0
   311
			iLastError = err;
sl@0
   312
			iLineNumber = __LINE__;
sl@0
   313
			if(err!=KErrNone)
sl@0
   314
				return err;
sl@0
   315
			}
sl@0
   316
		
sl@0
   317
		TBuf<16> dirname3;
sl@0
   318
		dirname3.Append(iDriveToTest);
sl@0
   319
		dirname3.Append(_L(":\\dir3\\"));
sl@0
   320
sl@0
   321
		TRawEntryArray entryarray3;
sl@0
   322
		RDirPlugin dir3(aRequest);
sl@0
   323
		TUidType uid3(TUid::Null(), TUid::Null(), TUid::Null());
sl@0
   324
		err = dir3.Open(dirname3,uid3);
sl@0
   325
		iLastError = err;
sl@0
   326
		iLineNumber = __LINE__;
sl@0
   327
		if(err!=KErrNone)
sl@0
   328
			return err;
sl@0
   329
		
sl@0
   330
		err = dir3.Read(entryarray3);
sl@0
   331
		iLastError = err;
sl@0
   332
		iLineNumber = __LINE__;
sl@0
   333
		if(err!=KErrNone && err!=KErrEof)
sl@0
   334
			return err;
sl@0
   335
		
sl@0
   336
		err = aRequest.Write(TFsPluginRequest::EEntryArray,entryarray3.Buf());
sl@0
   337
		iLastError = err;
sl@0
   338
		iLineNumber = __LINE__;
sl@0
   339
		if(err!=KErrNone)
sl@0
   340
			return err;
sl@0
   341
sl@0
   342
		dir1.Close();
sl@0
   343
		dir2.Close();
sl@0
   344
		dir3.Close();
sl@0
   345
		
sl@0
   346
		return KErrCompletion;
sl@0
   347
		}
sl@0
   348
		
sl@0
   349
	return err;
sl@0
   350
	}
sl@0
   351
sl@0
   352
sl@0
   353
/*
sl@0
   354
sl@0
   355
Test 1 - This test opens 3 files and reads their contents (which was written in the test harness)
sl@0
   356
sl@0
   357
Test 2 - 
sl@0
   358
sl@0
   359
*/
sl@0
   360
TInt CCombinationalPlugin::DoFileOpen(TFsPluginRequest& aRequest)
sl@0
   361
	{
sl@0
   362
	//intercept open
sl@0
   363
	TInt err = KErrNone;
sl@0
   364
sl@0
   365
	if (aRequest.IsPostOperation()) //Post
sl@0
   366
		{
sl@0
   367
		//Start of test
sl@0
   368
		RFilePlugin file(aRequest);
sl@0
   369
		err = file.AdoptFromClient();
sl@0
   370
		iLastError = err;
sl@0
   371
		iLineNumber = __LINE__;
sl@0
   372
		if(err!=KErrNone)
sl@0
   373
			return err;
sl@0
   374
		
sl@0
   375
		TFileName filename;
sl@0
   376
		filename.FillZ();
sl@0
   377
sl@0
   378
		//TODO: get rid of this?
sl@0
   379
		#ifdef __WINS__ 
sl@0
   380
			_LIT(KSecondFile,"X:\\combi1.txt");
sl@0
   381
		#else
sl@0
   382
			_LIT(KSecondFile,"D:\\combi1.txt");
sl@0
   383
		#endif
sl@0
   384
sl@0
   385
		filename.SetLength(KSecondFile().Length());
sl@0
   386
		filename.Replace(0,KSecondFile().Length(),KSecondFile());
sl@0
   387
		
sl@0
   388
		TUint mode;
sl@0
   389
		err = aRequest.Read(TFsPluginRequest::EMode, mode);
sl@0
   390
		iLastError = err;
sl@0
   391
		iLineNumber = __LINE__;
sl@0
   392
		if(err!=KErrNone)
sl@0
   393
			return err;
sl@0
   394
sl@0
   395
		//try to open a second file.			
sl@0
   396
		err = file.Open(filename, mode);
sl@0
   397
		
sl@0
   398
		//NEGATIVE TESTING: 
sl@0
   399
		if(err!=KErrBadHandle)
sl@0
   400
			{
sl@0
   401
			iLastError = err;
sl@0
   402
			iLineNumber = __LINE__;
sl@0
   403
			if(err!=KErrNone)
sl@0
   404
				return err;
sl@0
   405
			}
sl@0
   406
		
sl@0
   407
		RFilePlugin file2(aRequest);
sl@0
   408
		err = file2.Open(filename, mode);
sl@0
   409
		iLastError = err;
sl@0
   410
		iLineNumber = __LINE__;
sl@0
   411
		if(err!=KErrNone)
sl@0
   412
			return err;
sl@0
   413
		
sl@0
   414
		//Lets write something
sl@0
   415
		TBuf8<64> combi1Buf;
sl@0
   416
		combi1Buf.SetLength(10);
sl@0
   417
		err = file2.Read(0,combi1Buf,6);
sl@0
   418
		iLastError = err;
sl@0
   419
		iLineNumber = __LINE__;
sl@0
   420
		if(err!=KErrNone)
sl@0
   421
			return err;
sl@0
   422
		
sl@0
   423
		// second file is open.
sl@0
   424
		// lets be wild and open a third!
sl@0
   425
		filename.FillZ();
sl@0
   426
		
sl@0
   427
		//TODO: Get rid of this?
sl@0
   428
		#ifdef __WINS__ 
sl@0
   429
			_LIT(KThirdFile,"X:\\combi2.txt");
sl@0
   430
		#else
sl@0
   431
			_LIT(KThirdFile,"D:\\combi2.txt");
sl@0
   432
		#endif
sl@0
   433
sl@0
   434
		filename.SetLength(KThirdFile().Length());
sl@0
   435
		filename.Replace(0,KThirdFile().Length(),KThirdFile());
sl@0
   436
		
sl@0
   437
		RFilePlugin file3(aRequest);
sl@0
   438
		err = file3.Open(filename, mode);
sl@0
   439
		User::LeaveIfError(err);
sl@0
   440
		
sl@0
   441
		TBuf8<64> combi2Buf;
sl@0
   442
		combi2Buf.SetLength(20);
sl@0
   443
		err = file3.Read(0, combi2Buf, 18);
sl@0
   444
		User::LeaveIfError(err);
sl@0
   445
		
sl@0
   446
		_LOG2(_L("combi1Buf := %S"),&combi1Buf);
sl@0
   447
		_LOG2(_L("combi2Buf := %S"),&combi2Buf);
sl@0
   448
		
sl@0
   449
		err = combi1Buf.Compare(combi2Buf);
sl@0
   450
		if(err != 0) // is equal
sl@0
   451
		    {
sl@0
   452
			iLastError = err;
sl@0
   453
			iLineNumber = __LINE__;
sl@0
   454
			return err;
sl@0
   455
		    }
sl@0
   456
		
sl@0
   457
		// Right, best close these then eh?
sl@0
   458
		
sl@0
   459
		//close in different order - should be fine.
sl@0
   460
		file2.Close();
sl@0
   461
		file.Close();
sl@0
   462
		file3.Close();
sl@0
   463
		
sl@0
   464
		return KErrNone;
sl@0
   465
		} 
sl@0
   466
	else // PRE
sl@0
   467
		{
sl@0
   468
		RFilePlugin file(aRequest);
sl@0
   469
		
sl@0
   470
		TFileName filename;
sl@0
   471
sl@0
   472
sl@0
   473
		filename = aRequest.Src().FullName();
sl@0
   474
sl@0
   475
		TUint mode;
sl@0
   476
		err = aRequest.Read(TFsPluginRequest::EMode, mode);
sl@0
   477
		iLastError = err;
sl@0
   478
		iLineNumber = __LINE__;
sl@0
   479
		if(err!=KErrNone)
sl@0
   480
			return err;
sl@0
   481
sl@0
   482
		// Combinational test 1) Try to perform an RfilePlugin:Open on the same file.
sl@0
   483
		err = file.Open(filename, mode);
sl@0
   484
		iLastError = err;
sl@0
   485
		iLineNumber = __LINE__;
sl@0
   486
		if(err!=KErrNone)
sl@0
   487
			return err;
sl@0
   488
sl@0
   489
		err = file.TransferToClient();
sl@0
   490
		iLastError = err;
sl@0
   491
		iLineNumber = __LINE__;
sl@0
   492
		if(err!=KErrNone)
sl@0
   493
			return err;
sl@0
   494
sl@0
   495
		file.Close();
sl@0
   496
sl@0
   497
		return KErrCompletion;
sl@0
   498
		}
sl@0
   499
	}
sl@0
   500
sl@0
   501
TInt CCombinationalPlugin::DoFileSubClose(TFsPluginRequest& aRequest)
sl@0
   502
	{
sl@0
   503
	TInt err = KErrNone;
sl@0
   504
	if (aRequest.IsPostOperation())
sl@0
   505
		{
sl@0
   506
		} 
sl@0
   507
	else 
sl@0
   508
		{ //PRE
sl@0
   509
		RFilePlugin file(aRequest);
sl@0
   510
		err = file.AdoptFromClient(); //This is weird but it follows the open/close pattern;
sl@0
   511
		iLastError = err;
sl@0
   512
		iLineNumber = __LINE__;
sl@0
   513
		if(err!=KErrNone)
sl@0
   514
			return err;
sl@0
   515
		file.Close(); 
sl@0
   516
		}
sl@0
   517
	return err;
sl@0
   518
	}
sl@0
   519
sl@0
   520
/*
sl@0
   521
 * This test is testing the following scenario : 
sl@0
   522
 * 
sl@0
   523
Intercept Replace:
sl@0
   524
	plugin: replace file1, write to file1,replace file2, write to file2, rfsplugin.delete file3, create file3, write3, read, compare, close, read, compare 2, close, read, compare 1, close.
sl@0
   525
	(basically, open/replace/create 3 files, write to them and read back from them and check the contents)  
sl@0
   526
 */
sl@0
   527
TInt CCombinationalPlugin::DoFileReplace(TFsPluginRequest& aRequest)
sl@0
   528
	{
sl@0
   529
	TInt err = KErrNone;
sl@0
   530
sl@0
   531
	TBuf<256> testfilename1;
sl@0
   532
	TBuf<256> testfilename2;
sl@0
   533
sl@0
   534
	//setting up test files
sl@0
   535
	testfilename1.Append(iDriveToTest);
sl@0
   536
	testfilename1.Append(_L(":\\combiReplace2.txt"));
sl@0
   537
sl@0
   538
	testfilename2.Append(iDriveToTest);
sl@0
   539
	testfilename2.Append(_L(":\\combiReplace3.txt"));
sl@0
   540
sl@0
   541
	if (aRequest.IsPostOperation()) //POST
sl@0
   542
		{
sl@0
   543
		}
sl@0
   544
	else //PRE
sl@0
   545
		{
sl@0
   546
		TFileName filename;
sl@0
   547
		filename = aRequest.Src().FullName();
sl@0
   548
		
sl@0
   549
		RFsPlugin rfs(aRequest);
sl@0
   550
		err = rfs.Connect();
sl@0
   551
		iLastError = err;
sl@0
   552
		iLineNumber = __LINE__;
sl@0
   553
		if(err!=KErrNone)
sl@0
   554
			return err;
sl@0
   555
sl@0
   556
		//rfs.Delete(aRequest,filename);
sl@0
   557
		
sl@0
   558
		RFilePlugin file(aRequest);
sl@0
   559
sl@0
   560
		TUint mode = 0;
sl@0
   561
		err = aRequest.Read(TFsPluginRequest::EMode, mode);
sl@0
   562
		iLastError = err;
sl@0
   563
		iLineNumber = __LINE__;
sl@0
   564
		if(err!=KErrNone)
sl@0
   565
			return err;
sl@0
   566
sl@0
   567
		err = file.Replace(filename, mode);
sl@0
   568
		iLastError = err;
sl@0
   569
		iLineNumber = __LINE__;
sl@0
   570
		if(err!=KErrNone)
sl@0
   571
			return err;
sl@0
   572
		
sl@0
   573
		//we have replace/opened our file, now lets write to it.
sl@0
   574
		
sl@0
   575
		TBuf8<64> writeData;
sl@0
   576
		writeData.FillZ(64);
sl@0
   577
		writeData.Copy(_L8("0123456789"));
sl@0
   578
		err = file.Write(0, writeData, 10);
sl@0
   579
		iLastError = err;
sl@0
   580
		iLineNumber = __LINE__;
sl@0
   581
		if(err!=KErrNone)
sl@0
   582
			return err;
sl@0
   583
		
sl@0
   584
		//Now lets EFsFileReplace another file
sl@0
   585
		TFileName secondName;
sl@0
   586
		secondName.Append(testfilename1);
sl@0
   587
		RFilePlugin file2(aRequest);
sl@0
   588
		err = file2.Replace(secondName, mode);
sl@0
   589
		iLastError = err;
sl@0
   590
		iLineNumber = __LINE__;
sl@0
   591
		if(err!=KErrNone)
sl@0
   592
			return err;
sl@0
   593
		
sl@0
   594
		//Now lets write to it.
sl@0
   595
		TBuf8<64> writeData2;
sl@0
   596
		writeData2.FillZ(64);
sl@0
   597
		writeData2.Copy(_L8("9876543210"));
sl@0
   598
		err = file2.Write(0,writeData2,10);
sl@0
   599
		iLastError = err;
sl@0
   600
		iLineNumber = __LINE__;
sl@0
   601
		if(err!=KErrNone)
sl@0
   602
			return err;
sl@0
   603
		
sl@0
   604
		//Now lets open another file.
sl@0
   605
		TFileName thirdFile;
sl@0
   606
		thirdFile.Append(testfilename2);
sl@0
   607
		err = rfs.Delete(thirdFile);
sl@0
   608
		if(err == KErrNotFound)
sl@0
   609
			err = KErrNone;
sl@0
   610
		iLastError = err;
sl@0
   611
		iLineNumber = __LINE__;
sl@0
   612
		if(err!=KErrNone)
sl@0
   613
			return err;
sl@0
   614
sl@0
   615
		RFilePlugin file3(aRequest);
sl@0
   616
		err = file3.Create(thirdFile, EFileWrite);
sl@0
   617
		iLastError = err;
sl@0
   618
		iLineNumber = __LINE__;
sl@0
   619
		if(err!=KErrNone)
sl@0
   620
			return err;
sl@0
   621
		
sl@0
   622
		//Now lets write to it.
sl@0
   623
		TBuf8<64> writeData3;
sl@0
   624
		writeData3.FillZ(64);
sl@0
   625
		writeData3.Copy(_L8("3333333333"));
sl@0
   626
		err = file3.Write(0,writeData3,10);
sl@0
   627
		iLastError = err;
sl@0
   628
		iLineNumber = __LINE__;
sl@0
   629
		if(err!=KErrNone)
sl@0
   630
			return err;
sl@0
   631
		
sl@0
   632
		// Now we need to read the data and make sure that the correct data is in the correct files,
sl@0
   633
		// this check probably needs to be checked from RFile/test_harness as well.
sl@0
   634
		TBuf8<64> readData3;
sl@0
   635
		readData3.SetLength(10);
sl@0
   636
		err = file3.Read(0, readData3, 10);
sl@0
   637
		iLastError = err;
sl@0
   638
		iLineNumber = __LINE__;
sl@0
   639
		if(err!=KErrNone)
sl@0
   640
			return err;
sl@0
   641
			
sl@0
   642
		err = readData3.Compare(writeData3);
sl@0
   643
		if(err != KErrNone)
sl@0
   644
			{
sl@0
   645
			iLastError = err;
sl@0
   646
			iLineNumber = __LINE__;
sl@0
   647
			return err;
sl@0
   648
			}
sl@0
   649
		
sl@0
   650
		//close file 3
sl@0
   651
		file3.Close();
sl@0
   652
		
sl@0
   653
		// read from file2
sl@0
   654
		TBuf8<64> readData2;
sl@0
   655
		readData2.SetLength(10);
sl@0
   656
		err = file2.Read(0, readData2, 10);
sl@0
   657
		iLastError = err;
sl@0
   658
		iLineNumber = __LINE__;
sl@0
   659
		if(err!=KErrNone)
sl@0
   660
			return err;
sl@0
   661
		
sl@0
   662
		err = readData2.Compare(writeData2);
sl@0
   663
		if(err != KErrNone)
sl@0
   664
			{
sl@0
   665
			iLastError = err;
sl@0
   666
			iLineNumber = __LINE__;
sl@0
   667
			return err;
sl@0
   668
			}
sl@0
   669
		
sl@0
   670
		//close file 2
sl@0
   671
		file2.Close();
sl@0
   672
		
sl@0
   673
		// read from file1
sl@0
   674
		TBuf8<64> readData1;
sl@0
   675
		readData1.SetLength(10);
sl@0
   676
		err = file.Read(0, readData1, 10);
sl@0
   677
		iLastError = err;
sl@0
   678
		iLineNumber = __LINE__;
sl@0
   679
		if(err!=KErrNone)
sl@0
   680
			return err;
sl@0
   681
		
sl@0
   682
		err = readData1.Compare(writeData);
sl@0
   683
		if(err != KErrNone)
sl@0
   684
			{
sl@0
   685
			iLastError = err;
sl@0
   686
			iLineNumber = __LINE__;
sl@0
   687
			return err;
sl@0
   688
			}
sl@0
   689
sl@0
   690
		file.TransferToClient();
sl@0
   691
sl@0
   692
		rfs.Close();
sl@0
   693
		
sl@0
   694
		return KErrCompletion;
sl@0
   695
	
sl@0
   696
		}
sl@0
   697
	return err;
sl@0
   698
	}
sl@0
   699
sl@0
   700
sl@0
   701
CFsPluginConn* CCombinationalPlugin::NewPluginConnL()
sl@0
   702
	{
sl@0
   703
	return new(ELeave) CCombinationalPluginConn();
sl@0
   704
	}
sl@0
   705
sl@0
   706
sl@0
   707
//Synchronous RPlugin::DoControl
sl@0
   708
TInt CCombinationalPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
sl@0
   709
	{	
sl@0
   710
	TInt err = KErrNone;
sl@0
   711
sl@0
   712
	//We can use this to set the drive
sl@0
   713
	//We can store this as a member of this class.
sl@0
   714
	TInt function = aRequest.Function();
sl@0
   715
	TPckg<TChar> drive(iDriveToTest);
sl@0
   716
	typedef TBuf<256> TDirName;
sl@0
   717
	TPckg<TDirName> dirnamePckg(iDirFullName);
sl@0
   718
	TPckg<TInt> errCodeDes(iLastError);
sl@0
   719
	TPckg<TInt> lineNumberDes(iLineNumber);
sl@0
   720
	
sl@0
   721
	switch(function)
sl@0
   722
		{
sl@0
   723
		case KPluginSetDrive:
sl@0
   724
			{
sl@0
   725
			TRAP(err,aRequest.ReadParam1L(drive));
sl@0
   726
			break;
sl@0
   727
			}
sl@0
   728
		case KPluginSetDirFullName:
sl@0
   729
			{
sl@0
   730
			//This is necessary as at present we have nwo way of getting the name of
sl@0
   731
			//a directory!
sl@0
   732
			TRAP(err,aRequest.ReadParam1L(dirnamePckg));
sl@0
   733
			break;
sl@0
   734
			}
sl@0
   735
		case KPluginGetError:
sl@0
   736
			{
sl@0
   737
			TRAP(err,aRequest.WriteParam1L(errCodeDes));
sl@0
   738
			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
sl@0
   739
			break;
sl@0
   740
			}
sl@0
   741
		default:
sl@0
   742
			break;
sl@0
   743
		}
sl@0
   744
sl@0
   745
	return err;
sl@0
   746
	}
sl@0
   747
sl@0
   748
sl@0
   749
TInt CCombinationalPluginConn::DoControl(CFsPluginConnRequest& aRequest)
sl@0
   750
	{
sl@0
   751
	return ((CCombinationalPlugin*)Plugin())->FsPluginDoControlL(aRequest);
sl@0
   752
	}
sl@0
   753
sl@0
   754
void CCombinationalPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
sl@0
   755
	{
sl@0
   756
	DoControl(aRequest);
sl@0
   757
	}
sl@0
   758
sl@0
   759
void CCombinationalPluginConn::DoCancel(TInt /*aReqMask*/)
sl@0
   760
	{
sl@0
   761
	}
sl@0
   762
sl@0
   763
sl@0
   764
sl@0
   765
//factory functions
sl@0
   766
sl@0
   767
class CCombinationalPluginFactory : public CFsPluginFactory
sl@0
   768
	{
sl@0
   769
public:
sl@0
   770
	CCombinationalPluginFactory();
sl@0
   771
	virtual TInt Install();			
sl@0
   772
	virtual CFsPlugin* NewPluginL();
sl@0
   773
	virtual CFsPlugin* NewPluginConnL();
sl@0
   774
	virtual TInt UniquePosition();
sl@0
   775
	};
sl@0
   776
sl@0
   777
/**
sl@0
   778
Constructor for the plugin factory
sl@0
   779
@internalComponent
sl@0
   780
*/
sl@0
   781
CCombinationalPluginFactory::CCombinationalPluginFactory()
sl@0
   782
	{
sl@0
   783
	}
sl@0
   784
sl@0
   785
/**
sl@0
   786
Install function for the plugin factory
sl@0
   787
@internalComponent
sl@0
   788
*/
sl@0
   789
TInt CCombinationalPluginFactory::Install()
sl@0
   790
	{
sl@0
   791
	SetSupportedDrives(KPluginSupportAllDrives);
sl@0
   792
	return(SetName(&KCombinationalPluginName));
sl@0
   793
	}
sl@0
   794
sl@0
   795
/**
sl@0
   796
@internalComponent
sl@0
   797
*/
sl@0
   798
TInt CCombinationalPluginFactory::UniquePosition()
sl@0
   799
	{
sl@0
   800
	return(KCombinationalPos);
sl@0
   801
	}
sl@0
   802
sl@0
   803
/**
sl@0
   804
Plugin factory function
sl@0
   805
@internalComponent
sl@0
   806
*/
sl@0
   807
CFsPlugin* CCombinationalPluginFactory::NewPluginL()
sl@0
   808
sl@0
   809
	{
sl@0
   810
	return CCombinationalPlugin::NewL();
sl@0
   811
	}
sl@0
   812
sl@0
   813
/**
sl@0
   814
Plugin factory function
sl@0
   815
@internalComponent
sl@0
   816
*/
sl@0
   817
CFsPlugin* CCombinationalPluginFactory::NewPluginConnL()
sl@0
   818
sl@0
   819
	{
sl@0
   820
	return CCombinationalPlugin::NewL();
sl@0
   821
	}
sl@0
   822
sl@0
   823
/**
sl@0
   824
Create a new Plugin
sl@0
   825
@internalComponent
sl@0
   826
*/
sl@0
   827
extern "C" {
sl@0
   828
sl@0
   829
EXPORT_C CFsPluginFactory* CreateFileSystem()
sl@0
   830
	{
sl@0
   831
	return(new CCombinationalPluginFactory());
sl@0
   832
	}
sl@0
   833
}
sl@0
   834