os/ossrv/lowlevellibsandfws/apputils/tsrc/t_backupsrvdefects.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) 2008-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 "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 <e32test.h>
sl@0
    17
#include "t_backupsrvdefects.h"
sl@0
    18
sl@0
    19
sl@0
    20
RTest TheTest (_L("t_backupsrvdefects"));
sl@0
    21
#define TEST(arg)  TheTest((arg), __LINE__)
sl@0
    22
sl@0
    23
_LIT(KFileName1, "FileName1");
sl@0
    24
sl@0
    25
sl@0
    26
CBUDefectTestMachine* CBUDefectTestMachine::NewL()
sl@0
    27
	{
sl@0
    28
	CBUDefectTestMachine* self = new (ELeave) CBUDefectTestMachine();
sl@0
    29
	CleanupStack::PushL(self);
sl@0
    30
	self->ConstructL();
sl@0
    31
	CleanupStack::Pop();
sl@0
    32
	return self;
sl@0
    33
	}
sl@0
    34
sl@0
    35
CBUDefectTestMachine::CBUDefectTestMachine()
sl@0
    36
	:CActive(0)
sl@0
    37
	{}
sl@0
    38
sl@0
    39
CBUDefectTestMachine::~CBUDefectTestMachine()
sl@0
    40
	{
sl@0
    41
	delete iWrapper;
sl@0
    42
sl@0
    43
	// Cancel this if it's active
sl@0
    44
	if (IsActive())
sl@0
    45
		{
sl@0
    46
		Cancel();
sl@0
    47
		}
sl@0
    48
	}	
sl@0
    49
	
sl@0
    50
void CBUDefectTestMachine::ConstructL()
sl@0
    51
	{
sl@0
    52
	iWrapper = CBaBackupSessionWrapper::NewL();
sl@0
    53
		
sl@0
    54
	iNextState = EMachineStart;
sl@0
    55
sl@0
    56
	// Add this to the Active Scheduler and set us active
sl@0
    57
	CActiveScheduler::Add(this);
sl@0
    58
	SetActive();	
sl@0
    59
	}
sl@0
    60
sl@0
    61
// Called when CloseAll request is completed or the active object is scheduled.	
sl@0
    62
void CBUDefectTestMachine::RunL()	
sl@0
    63
	{
sl@0
    64
	switch(iNextState)
sl@0
    65
		{
sl@0
    66
		case EMachineStart:
sl@0
    67
			// Send 2 requests of CloseAll with different file lock states.
sl@0
    68
			// The second request will be ignored. The first one will be completed.		
sl@0
    69
			iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus);
sl@0
    70
			iWrapper->CloseAll(MBackupObserver::EReleaseLockNoAccess, iStatus);
sl@0
    71
sl@0
    72
			iNextState = EMachineCloseAllsEndSameClient;
sl@0
    73
			SetActive();
sl@0
    74
			break;
sl@0
    75
		case EMachineCloseAllsEndSameClient:
sl@0
    76
			// The first CloseAll request is completed.		
sl@0
    77
			TEST(iStatus == KErrNone);
sl@0
    78
sl@0
    79
			// Send 2 requests of CloseAll from different client.
sl@0
    80
			// The second client should be completed with KErrServerBusy before 
sl@0
    81
			// the first client is completed with KErrNone
sl@0
    82
			iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus);
sl@0
    83
			iBackupFileObserver->CloseAll(MBackupObserver::EReleaseLockReadOnly);
sl@0
    84
sl@0
    85
			iNextState = EMachineCloseAllsEndOtherClient;
sl@0
    86
			SetActive();
sl@0
    87
			break;
sl@0
    88
		case EMachineCloseAllsEndOtherClient:
sl@0
    89
			// The first CloseAll client is completed successfully
sl@0
    90
			TEST(iStatus == KErrNone);
sl@0
    91
sl@0
    92
			// Tests under CloseAll operation, CloseFileL requested by the other client will leave;
sl@0
    93
			// CloseFileL requested by the same client will be successful and not affect the CloseAll
sl@0
    94
			// process.
sl@0
    95
			iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus);
sl@0
    96
			
sl@0
    97
			TRAPD(err, iBackupFileObserver->CloseFileL(KFileName1,MBackupObserver::EReleaseLockNoAccess));
sl@0
    98
			TEST(err == KErrServerBusy);
sl@0
    99
			
sl@0
   100
			iWrapper->CloseFileL(KFileName1,MBackupObserver::EReleaseLockReadOnly);
sl@0
   101
sl@0
   102
			iNextState = EMachineCloseAllsEndCloseFile;
sl@0
   103
			SetActive();
sl@0
   104
			
sl@0
   105
			break;
sl@0
   106
			
sl@0
   107
		case EMachineCloseAllsEndCloseFile:
sl@0
   108
			// The CloseAll is completed successfully
sl@0
   109
			TEST(iStatus == KErrNone);
sl@0
   110
			
sl@0
   111
			CActiveScheduler::Stop();	
sl@0
   112
			break;
sl@0
   113
		
sl@0
   114
		default:
sl@0
   115
			break;
sl@0
   116
		}
sl@0
   117
	}
sl@0
   118
	
sl@0
   119
void CBUDefectTestMachine::DoCancel()
sl@0
   120
	{ 
sl@0
   121
	Complete();
sl@0
   122
	}
sl@0
   123
sl@0
   124
void CBUDefectTestMachine::Complete()
sl@0
   125
	{
sl@0
   126
	TRequestStatus* tempStatus=&iStatus;
sl@0
   127
	User::RequestComplete(tempStatus, KErrNone);
sl@0
   128
	}
sl@0
   129
sl@0
   130
/*
sl@0
   131
Sets the other client of the backup server
sl@0
   132
*/
sl@0
   133
void CBUDefectTestMachine::SetFileObserver(CBackupFileObserver* aBackupFileObserver)
sl@0
   134
	{
sl@0
   135
	iBackupFileObserver = aBackupFileObserver;
sl@0
   136
	}
sl@0
   137
	
sl@0
   138
sl@0
   139
sl@0
   140
//CBackupFileObserver
sl@0
   141
CBackupFileObserver* CBackupFileObserver::NewL(CBUDefectTestMachine& aDefectMachine, const TDesC& aLockedFileName)
sl@0
   142
	{
sl@0
   143
	CBackupFileObserver* self = new (ELeave) CBackupFileObserver(aDefectMachine, aLockedFileName);
sl@0
   144
	CleanupStack::PushL(self);
sl@0
   145
	self->ConstructL();
sl@0
   146
	CleanupStack::Pop();
sl@0
   147
	return self;
sl@0
   148
	}
sl@0
   149
sl@0
   150
CBackupFileObserver::CBackupFileObserver(CBUDefectTestMachine& aTestMachine, const TDesC& aLockedFileName)
sl@0
   151
:CActive(0), iTestMachine(aTestMachine), iLockedFileName(aLockedFileName)
sl@0
   152
	{}
sl@0
   153
	
sl@0
   154
void CBackupFileObserver::ConstructL()
sl@0
   155
	{
sl@0
   156
	iWrapper = CBaBackupSessionWrapper::NewL();
sl@0
   157
sl@0
   158
	iWrapper->RegisterFileL(iLockedFileName, *this);
sl@0
   159
	iTestMachine.SetFileObserver(this);
sl@0
   160
	
sl@0
   161
	// Add this to the Active Scheduler and set us active
sl@0
   162
	CActiveScheduler::Add(this);
sl@0
   163
	}
sl@0
   164
	
sl@0
   165
CBackupFileObserver::~CBackupFileObserver()
sl@0
   166
	{
sl@0
   167
	delete iWrapper;
sl@0
   168
	
sl@0
   169
	// Cancel this if it's active
sl@0
   170
	if (IsActive())
sl@0
   171
		{
sl@0
   172
		Cancel();
sl@0
   173
		}	
sl@0
   174
	}
sl@0
   175
sl@0
   176
void CBackupFileObserver::CloseAll(MBackupObserver::TFileLockFlags aFlags)
sl@0
   177
	{
sl@0
   178
	iWrapper->CloseAll(aFlags, iStatus);
sl@0
   179
	if(! IsActive())
sl@0
   180
		{
sl@0
   181
		SetActive();
sl@0
   182
		}
sl@0
   183
	}
sl@0
   184
	
sl@0
   185
void CBackupFileObserver::CloseFileL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags)
sl@0
   186
	{
sl@0
   187
	iWrapper->CloseFileL(aFileName,aFlags);
sl@0
   188
	}
sl@0
   189
sl@0
   190
	
sl@0
   191
void CBackupFileObserver::ChangeFileLockL(const TDesC& aFileName,TFileLockFlags aFlags)
sl@0
   192
	{
sl@0
   193
	TEST(aFileName == KFileName1);
sl@0
   194
	TEST(aFlags == MBackupObserver::EReleaseLockReadOnly);
sl@0
   195
	}
sl@0
   196
sl@0
   197
/**
sl@0
   198
Called when CloseAll request is completed.
sl@0
   199
*/
sl@0
   200
void CBackupFileObserver::RunL()	
sl@0
   201
	{
sl@0
   202
	if(iTestMachine.iNextState == EMachineCloseAllsEndOtherClient)
sl@0
   203
		{
sl@0
   204
		// As the second CloseAll client, Tests the CloseAll request is completed with KErrServerBusy 
sl@0
   205
		// while the first one is still pending
sl@0
   206
		TEST(iStatus == KErrServerBusy); 
sl@0
   207
		TEST(iTestMachine.iStatus == KRequestPending);	
sl@0
   208
		}
sl@0
   209
	}
sl@0
   210
sl@0
   211
void CBackupFileObserver::DoCancel()
sl@0
   212
	{ 
sl@0
   213
	TRequestStatus* tempStatus=&iStatus;
sl@0
   214
	User::RequestComplete(tempStatus, KErrNone);
sl@0
   215
	}
sl@0
   216
sl@0
   217
/**
sl@0
   218
Tests CBaBackupSessionWrapper::RegisterFileL leaves with KErrServerBusy while the sever is under 
sl@0
   219
CloseAll operation. And the CloseAll request is complete successfully.
sl@0
   220
*/	
sl@0
   221
void TestRegisterFileL()
sl@0
   222
	{
sl@0
   223
	class TSimpleObserver : public MBackupObserver
sl@0
   224
	{
sl@0
   225
	void ChangeFileLockL(const TDesC& /*aFileName*/,TFileLockFlags /*aFlags*/) {;}
sl@0
   226
	} simpleObserver;
sl@0
   227
	
sl@0
   228
	CBaBackupSessionWrapper* wrapper = CBaBackupSessionWrapper::NewL();
sl@0
   229
	CleanupStack::PushL(wrapper);
sl@0
   230
	TRequestStatus status;
sl@0
   231
	wrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, status);
sl@0
   232
	TRAPD(err,wrapper->RegisterFileL(KFileName1, simpleObserver));
sl@0
   233
	TEST(err == KErrServerBusy);
sl@0
   234
	User::WaitForRequest(status);
sl@0
   235
	TEST(status == KErrNone);
sl@0
   236
	CleanupStack::PopAndDestroy(wrapper);
sl@0
   237
	}
sl@0
   238
sl@0
   239
/**
sl@0
   240
@SYMTestCaseID          SYSLIB-BAFL-CT-4053
sl@0
   241
@SYMTestCaseDesc        Tests the updated functions work as expectation
sl@0
   242
@SYMTestPriority        High
sl@0
   243
@SYMTestActions         Calls the updated functions under the specified circumstance (sever under 
sl@0
   244
						CloseAll operation). They run as expectation:
sl@0
   245
                        1. Call CBaBackupSessionWrapper::RegisterFileL while the sever is under 
sl@0
   246
                           CloseAll operation. It leaves with KErrServerBusy. The CloseAll 
sl@0
   247
                           request is complete successfully.
sl@0
   248
                        2. Call CBaBackupSessionWrapper::CloseAll() 2 times from the same client. 
sl@0
   249
                           The second request will be ignored. The first one will be completed 
sl@0
   250
                           successfully.	
sl@0
   251
                        3. Call CBaBackupSessionWrapper::CloseAll() 2 times from the different clients. 
sl@0
   252
                           The second request will be completed immediately with KErrServerBusy. The 
sl@0
   253
                           first one will be completed successfully.	
sl@0
   254
                        4. Call CBaBackupSessionWrapper::CloseFileL() while the sever is under CloseAll 
sl@0
   255
                           operation requested by the other client. It leaves with KErrServerBusy. The 
sl@0
   256
                           CloseAll request is complete successfully.
sl@0
   257
                        5. Call CBaBackupSessionWrapper::CloseFileL() while the sever is 
sl@0
   258
                           under CloseAll operation requested by the same client. It is ignored and 
sl@0
   259
                           the CloseAll request is complete successfully.
sl@0
   260
                    
sl@0
   261
@SYMTestExpectedResults Test must not fail
sl@0
   262
@SYMDEF                 PDEF121575
sl@0
   263
*/	
sl@0
   264
void PDEF121575L()
sl@0
   265
	{
sl@0
   266
	
sl@0
   267
	TestRegisterFileL();
sl@0
   268
	CBUDefectTestMachine* bUSrvDefectMachine = CBUDefectTestMachine::NewL();
sl@0
   269
	CleanupStack::PushL(bUSrvDefectMachine);
sl@0
   270
	
sl@0
   271
	CBackupFileObserver* fileObserver = CBackupFileObserver::NewL(*bUSrvDefectMachine, KFileName1);
sl@0
   272
	
sl@0
   273
	CleanupStack::Pop(bUSrvDefectMachine);
sl@0
   274
	
sl@0
   275
	// start the machine
sl@0
   276
	bUSrvDefectMachine->Complete();
sl@0
   277
	
sl@0
   278
	CActiveScheduler::Start();
sl@0
   279
	
sl@0
   280
	delete bUSrvDefectMachine ;
sl@0
   281
	delete fileObserver ;
sl@0
   282
	
sl@0
   283
	return;	
sl@0
   284
	
sl@0
   285
	}
sl@0
   286
	
sl@0
   287
void StartTestsL()
sl@0
   288
	{
sl@0
   289
	TheTest.Start (_L("PDEF121575: BAFL Backup System Multiple Simultaneous Call Problema\n"));
sl@0
   290
	PDEF121575L();
sl@0
   291
	}
sl@0
   292
sl@0
   293
TInt E32Main()
sl@0
   294
	{
sl@0
   295
	TheTest.Title ();
sl@0
   296
	
sl@0
   297
	__UHEAP_MARK;
sl@0
   298
sl@0
   299
sl@0
   300
	CTrapCleanup* theTrapCleanup=CTrapCleanup::New();
sl@0
   301
	CActiveScheduler *activeScheduler=new CActiveScheduler;
sl@0
   302
	CActiveScheduler::Install(activeScheduler);
sl@0
   303
sl@0
   304
	TRAPD(error, StartTestsL());
sl@0
   305
	TEST(error == KErrNone);
sl@0
   306
	
sl@0
   307
	delete activeScheduler;
sl@0
   308
	delete theTrapCleanup;
sl@0
   309
	
sl@0
   310
	__UHEAP_MARKEND; 
sl@0
   311
	
sl@0
   312
	TheTest.End();	
sl@0
   313
	
sl@0
   314
	return(KErrNone);
sl@0
   315
	}
sl@0
   316