sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "t_backupsrvdefects.h" sl@0: sl@0: sl@0: RTest TheTest (_L("t_backupsrvdefects")); sl@0: #define TEST(arg) TheTest((arg), __LINE__) sl@0: sl@0: _LIT(KFileName1, "FileName1"); sl@0: sl@0: sl@0: CBUDefectTestMachine* CBUDefectTestMachine::NewL() sl@0: { sl@0: CBUDefectTestMachine* self = new (ELeave) CBUDefectTestMachine(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CBUDefectTestMachine::CBUDefectTestMachine() sl@0: :CActive(0) sl@0: {} sl@0: sl@0: CBUDefectTestMachine::~CBUDefectTestMachine() sl@0: { sl@0: delete iWrapper; sl@0: sl@0: // Cancel this if it's active sl@0: if (IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CBUDefectTestMachine::ConstructL() sl@0: { sl@0: iWrapper = CBaBackupSessionWrapper::NewL(); sl@0: sl@0: iNextState = EMachineStart; sl@0: sl@0: // Add this to the Active Scheduler and set us active sl@0: CActiveScheduler::Add(this); sl@0: SetActive(); sl@0: } sl@0: sl@0: // Called when CloseAll request is completed or the active object is scheduled. sl@0: void CBUDefectTestMachine::RunL() sl@0: { sl@0: switch(iNextState) sl@0: { sl@0: case EMachineStart: sl@0: // Send 2 requests of CloseAll with different file lock states. sl@0: // The second request will be ignored. The first one will be completed. sl@0: iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); sl@0: iWrapper->CloseAll(MBackupObserver::EReleaseLockNoAccess, iStatus); sl@0: sl@0: iNextState = EMachineCloseAllsEndSameClient; sl@0: SetActive(); sl@0: break; sl@0: case EMachineCloseAllsEndSameClient: sl@0: // The first CloseAll request is completed. sl@0: TEST(iStatus == KErrNone); sl@0: sl@0: // Send 2 requests of CloseAll from different client. sl@0: // The second client should be completed with KErrServerBusy before sl@0: // the first client is completed with KErrNone sl@0: iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); sl@0: iBackupFileObserver->CloseAll(MBackupObserver::EReleaseLockReadOnly); sl@0: sl@0: iNextState = EMachineCloseAllsEndOtherClient; sl@0: SetActive(); sl@0: break; sl@0: case EMachineCloseAllsEndOtherClient: sl@0: // The first CloseAll client is completed successfully sl@0: TEST(iStatus == KErrNone); sl@0: sl@0: // Tests under CloseAll operation, CloseFileL requested by the other client will leave; sl@0: // CloseFileL requested by the same client will be successful and not affect the CloseAll sl@0: // process. sl@0: iWrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, iStatus); sl@0: sl@0: TRAPD(err, iBackupFileObserver->CloseFileL(KFileName1,MBackupObserver::EReleaseLockNoAccess)); sl@0: TEST(err == KErrServerBusy); sl@0: sl@0: iWrapper->CloseFileL(KFileName1,MBackupObserver::EReleaseLockReadOnly); sl@0: sl@0: iNextState = EMachineCloseAllsEndCloseFile; sl@0: SetActive(); sl@0: sl@0: break; sl@0: sl@0: case EMachineCloseAllsEndCloseFile: sl@0: // The CloseAll is completed successfully sl@0: TEST(iStatus == KErrNone); sl@0: sl@0: CActiveScheduler::Stop(); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CBUDefectTestMachine::DoCancel() sl@0: { sl@0: Complete(); sl@0: } sl@0: sl@0: void CBUDefectTestMachine::Complete() sl@0: { sl@0: TRequestStatus* tempStatus=&iStatus; sl@0: User::RequestComplete(tempStatus, KErrNone); sl@0: } sl@0: sl@0: /* sl@0: Sets the other client of the backup server sl@0: */ sl@0: void CBUDefectTestMachine::SetFileObserver(CBackupFileObserver* aBackupFileObserver) sl@0: { sl@0: iBackupFileObserver = aBackupFileObserver; sl@0: } sl@0: sl@0: sl@0: sl@0: //CBackupFileObserver sl@0: CBackupFileObserver* CBackupFileObserver::NewL(CBUDefectTestMachine& aDefectMachine, const TDesC& aLockedFileName) sl@0: { sl@0: CBackupFileObserver* self = new (ELeave) CBackupFileObserver(aDefectMachine, aLockedFileName); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CBackupFileObserver::CBackupFileObserver(CBUDefectTestMachine& aTestMachine, const TDesC& aLockedFileName) sl@0: :CActive(0), iTestMachine(aTestMachine), iLockedFileName(aLockedFileName) sl@0: {} sl@0: sl@0: void CBackupFileObserver::ConstructL() sl@0: { sl@0: iWrapper = CBaBackupSessionWrapper::NewL(); sl@0: sl@0: iWrapper->RegisterFileL(iLockedFileName, *this); sl@0: iTestMachine.SetFileObserver(this); sl@0: sl@0: // Add this to the Active Scheduler and set us active sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: CBackupFileObserver::~CBackupFileObserver() sl@0: { sl@0: delete iWrapper; sl@0: sl@0: // Cancel this if it's active sl@0: if (IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CBackupFileObserver::CloseAll(MBackupObserver::TFileLockFlags aFlags) sl@0: { sl@0: iWrapper->CloseAll(aFlags, iStatus); sl@0: if(! IsActive()) sl@0: { sl@0: SetActive(); sl@0: } sl@0: } sl@0: sl@0: void CBackupFileObserver::CloseFileL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags) sl@0: { sl@0: iWrapper->CloseFileL(aFileName,aFlags); sl@0: } sl@0: sl@0: sl@0: void CBackupFileObserver::ChangeFileLockL(const TDesC& aFileName,TFileLockFlags aFlags) sl@0: { sl@0: TEST(aFileName == KFileName1); sl@0: TEST(aFlags == MBackupObserver::EReleaseLockReadOnly); sl@0: } sl@0: sl@0: /** sl@0: Called when CloseAll request is completed. sl@0: */ sl@0: void CBackupFileObserver::RunL() sl@0: { sl@0: if(iTestMachine.iNextState == EMachineCloseAllsEndOtherClient) sl@0: { sl@0: // As the second CloseAll client, Tests the CloseAll request is completed with KErrServerBusy sl@0: // while the first one is still pending sl@0: TEST(iStatus == KErrServerBusy); sl@0: TEST(iTestMachine.iStatus == KRequestPending); sl@0: } sl@0: } sl@0: sl@0: void CBackupFileObserver::DoCancel() sl@0: { sl@0: TRequestStatus* tempStatus=&iStatus; sl@0: User::RequestComplete(tempStatus, KErrNone); sl@0: } sl@0: sl@0: /** sl@0: Tests CBaBackupSessionWrapper::RegisterFileL leaves with KErrServerBusy while the sever is under sl@0: CloseAll operation. And the CloseAll request is complete successfully. sl@0: */ sl@0: void TestRegisterFileL() sl@0: { sl@0: class TSimpleObserver : public MBackupObserver sl@0: { sl@0: void ChangeFileLockL(const TDesC& /*aFileName*/,TFileLockFlags /*aFlags*/) {;} sl@0: } simpleObserver; sl@0: sl@0: CBaBackupSessionWrapper* wrapper = CBaBackupSessionWrapper::NewL(); sl@0: CleanupStack::PushL(wrapper); sl@0: TRequestStatus status; sl@0: wrapper->CloseAll(MBackupObserver::EReleaseLockReadOnly, status); sl@0: TRAPD(err,wrapper->RegisterFileL(KFileName1, simpleObserver)); sl@0: TEST(err == KErrServerBusy); sl@0: User::WaitForRequest(status); sl@0: TEST(status == KErrNone); sl@0: CleanupStack::PopAndDestroy(wrapper); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-BAFL-CT-4053 sl@0: @SYMTestCaseDesc Tests the updated functions work as expectation sl@0: @SYMTestPriority High sl@0: @SYMTestActions Calls the updated functions under the specified circumstance (sever under sl@0: CloseAll operation). They run as expectation: sl@0: 1. Call CBaBackupSessionWrapper::RegisterFileL while the sever is under sl@0: CloseAll operation. It leaves with KErrServerBusy. The CloseAll sl@0: request is complete successfully. sl@0: 2. Call CBaBackupSessionWrapper::CloseAll() 2 times from the same client. sl@0: The second request will be ignored. The first one will be completed sl@0: successfully. sl@0: 3. Call CBaBackupSessionWrapper::CloseAll() 2 times from the different clients. sl@0: The second request will be completed immediately with KErrServerBusy. The sl@0: first one will be completed successfully. sl@0: 4. Call CBaBackupSessionWrapper::CloseFileL() while the sever is under CloseAll sl@0: operation requested by the other client. It leaves with KErrServerBusy. The sl@0: CloseAll request is complete successfully. sl@0: 5. Call CBaBackupSessionWrapper::CloseFileL() while the sever is sl@0: under CloseAll operation requested by the same client. It is ignored and sl@0: the CloseAll request is complete successfully. sl@0: sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF PDEF121575 sl@0: */ sl@0: void PDEF121575L() sl@0: { sl@0: sl@0: TestRegisterFileL(); sl@0: CBUDefectTestMachine* bUSrvDefectMachine = CBUDefectTestMachine::NewL(); sl@0: CleanupStack::PushL(bUSrvDefectMachine); sl@0: sl@0: CBackupFileObserver* fileObserver = CBackupFileObserver::NewL(*bUSrvDefectMachine, KFileName1); sl@0: sl@0: CleanupStack::Pop(bUSrvDefectMachine); sl@0: sl@0: // start the machine sl@0: bUSrvDefectMachine->Complete(); sl@0: sl@0: CActiveScheduler::Start(); sl@0: sl@0: delete bUSrvDefectMachine ; sl@0: delete fileObserver ; sl@0: sl@0: return; sl@0: sl@0: } sl@0: sl@0: void StartTestsL() sl@0: { sl@0: TheTest.Start (_L("PDEF121575: BAFL Backup System Multiple Simultaneous Call Problema\n")); sl@0: PDEF121575L(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title (); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: sl@0: CTrapCleanup* theTrapCleanup=CTrapCleanup::New(); sl@0: CActiveScheduler *activeScheduler=new CActiveScheduler; sl@0: CActiveScheduler::Install(activeScheduler); sl@0: sl@0: TRAPD(error, StartTestsL()); sl@0: TEST(error == KErrNone); sl@0: sl@0: delete activeScheduler; sl@0: delete theTrapCleanup; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: