commonuisupport/uikon/test/teiksrv/tbackup/tbackup.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-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 "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 // Tests CBaBackupSessionWrapper APIs and observers for backup server.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 #include <eikenv.h>
       
    24 #include <coecntrl.h>
       
    25 #include <basched.h>
       
    26 #include <babackup.h>
       
    27 #include <eikappui.h>
       
    28 #include <eikdef.h>
       
    29 #include <eikapp.h>
       
    30 #include <eikdoc.h>
       
    31 #include <techview/eikon.hrh>
       
    32 #include <techview/eiktxlbx.h>
       
    33 #include <techview/eiktxlbm.h>
       
    34 #include <techview/eikchlst.h>
       
    35 #include <techview/eikclb.h>
       
    36 #include <techview/eikclbd.h>
       
    37 #include <techview/eikdialg.h>
       
    38 #include <techview/eikcapc.h>
       
    39 #include <apgwgnam.h>
       
    40 #include <apgtask.h>
       
    41 #include <apgcli.h>
       
    42 #include <eikcoctl.rsg>
       
    43 #include <techview/eikchkbx.h>
       
    44 #include <eikmsg.h>
       
    45 #include <techview/eikhopbt.h>
       
    46 #include <uiklafgt/eikcore.rsg>
       
    47 #include <ecom/ecom.h>
       
    48 
       
    49 
       
    50 #include "tbackup.hrh"
       
    51 #include <tbackup.rsg>
       
    52 
       
    53 
       
    54 #include "tbackup.h"
       
    55 
       
    56 _LIT(KBackupFile1,"foo1");
       
    57 _LIT(KBackupFile2,"foo2");
       
    58 _LIT(KBackupFile3,"foo3");
       
    59 _LIT(KObserverStr, "Observer %d:");
       
    60 _LIT(KBackupOpMsg, "Backup Operation running");
       
    61 _LIT(KRegistrationDlgTitle, "Register and DeRegister Observers");
       
    62 
       
    63 _LIT(KTBackupResourceFilePath, "z:\\system\\test\\tbackup\\tbackup.rsc");
       
    64 
       
    65 
       
    66 
       
    67 /**********************************************
       
    68  
       
    69  
       
    70  
       
    71  	CBackupDialogBase
       
    72  
       
    73  
       
    74  
       
    75 ************************************************/
       
    76 CBackupDialogBase::CBackupDialogBase(CDesCArray& aFiles,TOperationGranularity& aGranularity,TDes& aFileName)
       
    77 	: iFiles(aFiles), iGranularity(aGranularity), iFileName(aFileName)
       
    78 /**
       
    79    Constructor
       
    80  */
       
    81 	{}
       
    82 
       
    83 
       
    84 /**
       
    85    Auxiliary Function for all Test Cases
       
    86   
       
    87    This method is an override from CEikDialog.It performs pre-layout dialog
       
    88    initialisation.
       
    89   
       
    90  */
       
    91 void CBackupDialogBase::PreLayoutDynInitL()
       
    92 	{
       
    93 	SetHorOptionButListCurrentSet(EDlgBackupCloseOpButList,EDlgBackupCloseAll);
       
    94 	CEikChoiceList* list=static_cast<CEikChoiceList*>(Control(EDlgBackupFileList));
       
    95 	list->SetArrayExternalOwnership(ETrue);
       
    96 	list->SetArrayL(&iFiles);
       
    97 	UpdateFileListDimmedState();
       
    98 	}
       
    99 
       
   100 
       
   101 /**
       
   102    Auxiliary Function for all Test Cases
       
   103   
       
   104    This method is an override from CEikDialog. Handles dialog button press 'All'
       
   105    and 'File' to select a single file or all files to be closed by the dialog.
       
   106   
       
   107  */
       
   108 TBool CBackupDialogBase::OkToExitL(TInt /*aButtonId*/)
       
   109 	{
       
   110 	if (HorOptionButListCurrentSet(EDlgBackupCloseOpButList)==EDlgBackupCloseAll)
       
   111 		{
       
   112 		iGranularity=EAll;
       
   113 		}
       
   114 	else
       
   115 		{
       
   116 		iGranularity=ESingleFile;
       
   117 		const CEikChoiceList* list=static_cast<CEikChoiceList*>(Control(EDlgBackupFileList));
       
   118 		iFileName=iFiles[list->CurrentItem()];
       
   119 		}
       
   120 	return ETrue;
       
   121 	}
       
   122 
       
   123 /**
       
   124    Auxiliary Function for all Test Cases
       
   125   
       
   126    This method is an override from CEikDialog. This function is called when a
       
   127    control event of type EEventStateChanged is received by the dialog from one
       
   128    of its component controls. 
       
   129   
       
   130  */
       
   131 void CBackupDialogBase::HandleControlStateChangeL(TInt aControlId)
       
   132 	{
       
   133 	if (aControlId==EDlgBackupCloseOpButList)
       
   134 		{
       
   135 		UpdateFileListDimmedState();
       
   136 		}
       
   137 	}
       
   138 
       
   139 /**
       
   140    Auxiliary Function for all Test Cases
       
   141   
       
   142    This method is an override from CEikDialog. This method dims and deactivates
       
   143    the file choice list on the dialog.
       
   144   
       
   145  */
       
   146 void CBackupDialogBase::UpdateFileListDimmedState()
       
   147 	{
       
   148 	const TBool dimFileList=(HorOptionButListCurrentSet(EDlgBackupCloseOpButList)==EDlgBackupCloseAll);
       
   149 	const CEikChoiceList* list=static_cast<CEikChoiceList*>(Control(EDlgBackupFileList));
       
   150 	const TBool fileListDimmed=list->IsDimmed();
       
   151 	if (dimFileList!=fileListDimmed)
       
   152 		{
       
   153 		SetLineDimmedNow(EDlgBackupFileList,dimFileList);
       
   154 		}
       
   155 	}
       
   156 
       
   157 
       
   158 /**********************************************
       
   159  
       
   160  
       
   161  
       
   162  	CBackupCloseDialog
       
   163  
       
   164  
       
   165  
       
   166 ************************************************/
       
   167 
       
   168 /**
       
   169   Auxiliary function for TestCaseID tbackup-CmdCloseL
       
   170   
       
   171   This method initialises and launches the backup close dialog.
       
   172   
       
   173  */
       
   174 TBool CBackupCloseDialog::RunDlgLD(CDesCArray& aFiles,CBackupDialogBase::TOperationGranularity& aGranularity,
       
   175 										TDes& aFileName,MBackupObserver::TFileLockFlags& aFlag)
       
   176 	{ // static
       
   177 	CBackupCloseDialog* dlg=new(ELeave) CBackupCloseDialog(aFiles,aGranularity,aFileName,aFlag);
       
   178 	return dlg->ExecuteLD(R_TBACKUP_FILE_OPTIONS);
       
   179 	}
       
   180 
       
   181 CBackupCloseDialog::CBackupCloseDialog(CDesCArray& aFiles,CBackupDialogBase::TOperationGranularity& aGranularity,
       
   182 										TDes& aFileName,MBackupObserver::TFileLockFlags& aFlag)
       
   183 	: CBackupDialogBase(aFiles,aGranularity,aFileName), iFileFlag(aFlag)
       
   184 /**
       
   185    Constructor
       
   186  */
       
   187 	{
       
   188 	}
       
   189 /**
       
   190    Auxiliary function for TestCaseID tbackup-CmdCloseL
       
   191   
       
   192    This method is an override from CEikDialog.It performs pre-layout dialog
       
   193    initialisation.
       
   194   
       
   195  */
       
   196 void CBackupCloseDialog::PreLayoutDynInitL()
       
   197 	{
       
   198 	SetHorOptionButListCurrentSet(EDlgBackupFlagOpButList,EDlgBackupReadOnly);
       
   199 	CBackupDialogBase::PreLayoutDynInitL();
       
   200 	}
       
   201 
       
   202 /**
       
   203    Auxiliary function for TestCaseID tbackup-CmdCloseL
       
   204   
       
   205    This method is an override from CEikDialog. It is used to specify 'Read only' or
       
   206    'No access' file locks while CloseAll() & CloseFileL() APIs are invoked.
       
   207   
       
   208  */
       
   209 TBool CBackupCloseDialog::OkToExitL(TInt aButtonId)
       
   210 	{
       
   211 	if (HorOptionButListCurrentSet(EDlgBackupFlagOpButList)==EDlgBackupReadOnly)
       
   212 		{
       
   213 		iFileFlag=MBackupObserver::EReleaseLockReadOnly;
       
   214 		}
       
   215 	else
       
   216 		{
       
   217 		iFileFlag=MBackupObserver::EReleaseLockNoAccess;
       
   218 		}
       
   219 	return CBackupDialogBase::OkToExitL(aButtonId);
       
   220 	}
       
   221 
       
   222 
       
   223 /**********************************************
       
   224 
       
   225  
       
   226  
       
   227  	CBackupRestartDialog
       
   228  
       
   229  
       
   230  
       
   231 ************************************************/
       
   232 
       
   233 /**
       
   234    Auxiliary function for TestCaseID tbackup-CmdRestartL
       
   235   
       
   236    This method initialises and launches the backup restart dialog.
       
   237   
       
   238  */
       
   239 TBool CBackupRestartDialog::RunDlgLD(CDesCArray& aFiles,CBackupDialogBase::TOperationGranularity& aGranularity,
       
   240 										TDes& aFileName)
       
   241 	{ // static
       
   242 	CBackupRestartDialog* dlg=new(ELeave) CBackupRestartDialog(aFiles,aGranularity,aFileName);
       
   243 	return dlg->ExecuteLD(R_TBACKUP_FILE_OPTIONS);
       
   244 	}
       
   245 
       
   246 CBackupRestartDialog::CBackupRestartDialog(CDesCArray& aFiles,CBackupDialogBase::TOperationGranularity& aGranularity,
       
   247 											TDes& aFileName)
       
   248 	: CBackupDialogBase(aFiles,aGranularity,aFileName)
       
   249 /**
       
   250    Constructor
       
   251  */
       
   252 	{}
       
   253 
       
   254 /**
       
   255    Auxiliary function for TestCaseID tbackup-CmdRestartL
       
   256   
       
   257    This method is an override from CEikDialog.It performs pre-layout dialog
       
   258    initialisation.
       
   259   
       
   260  */
       
   261 void CBackupRestartDialog::PreLayoutDynInitL()
       
   262 	{
       
   263 	SetTitleL(R_TBACKUP_RESTART_DLG_TITLE);
       
   264 	TBuf<20> text;
       
   265 	iCoeEnv->ReadResource(text,R_TBACKUP_RESTART_OPTION_TITLE);
       
   266 	CEikLabel* caption=Line(EDlgBackupCloseOpButList)->iCaption;
       
   267 	caption->SetTextL(text);
       
   268 	DeleteLine(EDlgBackupFlagOpButList);
       
   269 	CBackupDialogBase::PreLayoutDynInitL();
       
   270 	}
       
   271 
       
   272 
       
   273 
       
   274 /**********************************************
       
   275  
       
   276  
       
   277  
       
   278  	CBackupFileObserver
       
   279  
       
   280  
       
   281  
       
   282 ************************************************/
       
   283 CBackupFileObserver::TBackupFile::TBackupFile(const TDesC& aFileName,TFileLock aLockState)
       
   284 	: iFileName(aFileName), iLockState(aLockState)
       
   285 /**
       
   286    Constructor
       
   287  */
       
   288 	{}
       
   289 
       
   290 /**
       
   291    Auxiliary function for all test cases
       
   292   
       
   293    This method is part of two-phase construction of CBackupFileObserver.The
       
   294    method is called by CTBackupAppUi::CreateFileObserversL() to construct new
       
   295    client to backup server.
       
   296   
       
   297  */
       
   298 CBackupFileObserver* CBackupFileObserver::NewLC()
       
   299 	{ // static
       
   300 	CBackupFileObserver* self=new(ELeave) CBackupFileObserver();
       
   301 	CleanupStack::PushL(self);
       
   302 	self->ConstructL();
       
   303 	return self;
       
   304 	}
       
   305 
       
   306 CBackupFileObserver::~CBackupFileObserver()
       
   307 /**
       
   308    Destructor
       
   309  */
       
   310 	{
       
   311 	const TInt count=iBackupArray.Count();
       
   312 	for (TInt ii=count-1;ii>=0;ii--)
       
   313 		{
       
   314 		const TBackupFile& backup=iBackupArray[ii];
       
   315 		RemoveFile(backup.iFileName);
       
   316 		}
       
   317 	iBackupArray.Close();
       
   318 	delete iBackupSession;
       
   319 	}
       
   320 
       
   321 struct SFileAddCleanup
       
   322 	{
       
   323 	CBackupFileObserver* iFileObserver;
       
   324 	TFileName iFileName;
       
   325 	};
       
   326 
       
   327 /**
       
   328    Auxiliary function for all Test Cases
       
   329    
       
   330    This method is cleanup operation invoked by the pop and destroy action
       
   331    resulting from a subsequent call to CleanupStack::PopAndDestroy() to
       
   332    perform clean up of SFileAddCleanup object.
       
   333    
       
   334  */
       
   335 LOCAL_C void CleanupAddFile(TAny* aPtr)
       
   336 	{
       
   337 	SFileAddCleanup* cleanup=REINTERPRET_CAST(SFileAddCleanup*,aPtr);
       
   338 	cleanup->iFileObserver->RemoveFile(cleanup->iFileName);
       
   339 	}
       
   340 
       
   341 /**
       
   342    Auxiliary function for all Test Cases
       
   343    
       
   344    This method registers a file with the backup server.
       
   345    
       
   346  */
       
   347 void CBackupFileObserver::AddFileL(const TDesC& aFileName)
       
   348 	{
       
   349 	TBackupFile backup(aFileName,ELocked);
       
   350 	User::LeaveIfError(iBackupArray.Append(backup));
       
   351 	SFileAddCleanup cleanup;
       
   352 	cleanup.iFileObserver=this;
       
   353 	cleanup.iFileName=aFileName;
       
   354 	CleanupStack::PushL(TCleanupItem(CleanupAddFile,&cleanup));
       
   355 	iBackupSession->RegisterFileL(aFileName,*this);
       
   356 	CleanupStack::Pop(); // CleanupAddFile
       
   357 	}
       
   358 
       
   359 /**
       
   360    Auxiliary function for all Test Cases
       
   361    
       
   362    This method is invoked by cleanup method CleanupAddFile() to remove the
       
   363    registration of a file with the backup server.
       
   364    
       
   365  */
       
   366 void CBackupFileObserver::RemoveFile(const TDesC& aFileName)
       
   367 	{
       
   368 	const TInt index=Find(aFileName);
       
   369 	if (index!=KErrNotFound)
       
   370 		{
       
   371 		iBackupSession->DeregisterFile(aFileName);
       
   372 		iBackupArray.Remove(index);
       
   373 		iBackupArray.Compress();
       
   374 		}
       
   375 	}
       
   376 
       
   377 /**
       
   378    Auxiliary function for all Test Cases
       
   379    
       
   380    This method returns the array iBackupArray which holds the list of files
       
   381    registered with the observer.
       
   382    
       
   383  */
       
   384 const RArray<CBackupFileObserver::TBackupFile>& CBackupFileObserver::BackupArray() const
       
   385 	{
       
   386 	return iBackupArray;
       
   387 	}
       
   388 
       
   389 CBackupFileObserver::CBackupFileObserver()
       
   390 /**
       
   391    Constructor
       
   392  */
       
   393 	{}
       
   394 
       
   395 /**
       
   396    Auxiliary function for all test cases
       
   397   
       
   398    This method is part of Two-phase construction of CBackupFileObserver.The
       
   399    method constructs a new client to the backup server .
       
   400   
       
   401  */
       
   402 void CBackupFileObserver::ConstructL()
       
   403 	{
       
   404 	iBackupSession=CBaBackupSessionWrapper::NewL();
       
   405 	}
       
   406 
       
   407 /**
       
   408    Auxiliary function for all Test Cases
       
   409    
       
   410    This method attempts to find the file specifed within the iBackupArray
       
   411    and returns its index within the array if found. Otherwise KErrNotFound is
       
   412    returned.
       
   413    
       
   414  */
       
   415 TInt CBackupFileObserver::Find(const TDesC& aFileName) const
       
   416 	{
       
   417 	TInt index=KErrNotFound;
       
   418 	const TInt count=iBackupArray.Count();
       
   419 	for (TInt ii=0;ii<count;ii++)
       
   420 		{
       
   421 		const TBackupFile& backup=iBackupArray[ii];
       
   422 		if (backup.iFileName==aFileName)
       
   423 			{
       
   424 			index=ii;
       
   425 			break;
       
   426 			}
       
   427 		}
       
   428 	return index;
       
   429 	}
       
   430 
       
   431 /**
       
   432    Auxiliary function for all Test Cases
       
   433    
       
   434    This method finds the file specifed within the iBackupArray and changes its
       
   435    file lock as specified by aFlag parameter.
       
   436    
       
   437  */
       
   438 void CBackupFileObserver::ChangeFileLockL(const TDesC& aFileName,TFileLockFlags aFlags)
       
   439 	{
       
   440 	const TInt index=Find(aFileName);
       
   441 	if (index==KErrNotFound)
       
   442 		{
       
   443 		User::Invariant();
       
   444 		}
       
   445 	iBackupArray[index].iLockState=(CBackupFileObserver::TFileLock)aFlags;
       
   446 	}
       
   447 
       
   448 
       
   449 /**********************************************
       
   450  
       
   451  
       
   452   	CBackupOpeartionObserver
       
   453  
       
   454  
       
   455 ************************************************/
       
   456 
       
   457 /**
       
   458    Auxiliary function for all Test cases
       
   459    
       
   460    This method returns ETrue if the observer is registered with the backup
       
   461    server.
       
   462   
       
   463  */
       
   464 inline TBool CBackupOpeartionObserver::IsRegistered() const
       
   465 	{
       
   466 	return iRegistered;
       
   467 	}
       
   468 
       
   469 /**
       
   470    Auxiliary function for TestCaseID tbackup-AutoUpdateBackupObserverRegistrationL
       
   471   
       
   472    The method sets the observer as registered with the back up server.
       
   473   
       
   474  */
       
   475 inline void CBackupOpeartionObserver::SetRegistered(TBool aIsRegistered)
       
   476 	{
       
   477 	iRegistered = aIsRegistered;
       
   478 	}
       
   479 
       
   480 /**
       
   481    Auxiliary function for all Test cases
       
   482    
       
   483    This method creates an observer for backup operation.
       
   484   
       
   485  */
       
   486 CBackupOpeartionObserver* CBackupOpeartionObserver::NewL()
       
   487 	{
       
   488 	CBackupOpeartionObserver* self=new(ELeave) CBackupOpeartionObserver();
       
   489 	return self;
       
   490 	}
       
   491 
       
   492 CBackupOpeartionObserver::CBackupOpeartionObserver()
       
   493 /**
       
   494    Constructor
       
   495  */
       
   496 	{
       
   497 	}
       
   498 
       
   499 /**
       
   500    Auxiliary function for TestCaseID tbackup-AutoUpdateBackupOperationStateL
       
   501   
       
   502    This method is an override from MBackupOperationObserver and is invoked when a
       
   503    backup or restore operation either starts or ends.
       
   504   
       
   505  */
       
   506 void CBackupOpeartionObserver::HandleBackupOperationEventL(const TBackupOperationAttributes& aBackupOperationAttributes)
       
   507 	{
       
   508 	MBackupOperationObserver::TOperationType operation = aBackupOperationAttributes.iOperation;
       
   509 	switch (operation)
       
   510 		{
       
   511 		case MBackupOperationObserver::EStart:
       
   512 			User::InfoPrint(_L("Backup Operation Start"));
       
   513 			break;
       
   514 		case MBackupOperationObserver::EEnd:
       
   515 			User::InfoPrint(_L("Backup Operation End"));
       
   516 			break;
       
   517 		case MBackupOperationObserver::EAbort:
       
   518 			User::InfoPrint(_L("Backup Operation Abort"));
       
   519 			break;
       
   520 		case MBackupOperationObserver::ENone:
       
   521 		default:
       
   522 			break;
       
   523 		}
       
   524 	iBackupOperationAttributes = aBackupOperationAttributes;
       
   525 	}
       
   526 
       
   527 
       
   528 
       
   529 /**********************************************
       
   530  
       
   531  
       
   532  
       
   533  	CBackupOpeartionObserversWrapper
       
   534  
       
   535  
       
   536  
       
   537 ************************************************/
       
   538 
       
   539 
       
   540 /**
       
   541    Auxiliary function for TestCaseID tbackup-AutoUpdateBackupObserverRegistrationL
       
   542   
       
   543    This method returns the number of backup observer object pointers stored in
       
   544    the pointer array iBackupOpeartionObserver.
       
   545   
       
   546  */
       
   547 inline TInt CBackupOpeartionObserversWrapper::CountObservers() const
       
   548 	{
       
   549 	return iBackupOpeartionObserver.Count();
       
   550 	}
       
   551 
       
   552 
       
   553 /**
       
   554    Auxiliary function for TestCaseID tbackup-AutoUpdateBackupObserverRegistrationL
       
   555   
       
   556    This method returns the backup operation observer handle specified by
       
   557    aIndex from pointer array iBackupOpeartionObserver.
       
   558   
       
   559  */
       
   560 inline CBackupOpeartionObserver* CBackupOpeartionObserversWrapper::Observer(TInt aIndex)
       
   561 	{
       
   562 	return iBackupOpeartionObserver[aIndex];
       
   563 	}
       
   564 
       
   565 
       
   566 /**
       
   567    Auxiliary function for all Test Cases
       
   568   
       
   569    This method creates a wrapper for backup operation observers. The wrapper
       
   570    would contains number of observers as indicated by parameter
       
   571    aNumberOfObservers.
       
   572   
       
   573  */
       
   574 CBackupOpeartionObserversWrapper* CBackupOpeartionObserversWrapper::NewL(TInt aNumberOfObservers)
       
   575 	{
       
   576 	CBackupOpeartionObserversWrapper* self=new(ELeave) CBackupOpeartionObserversWrapper();
       
   577 	CleanupStack::PushL(self);
       
   578 	self->ConstructL(aNumberOfObservers);
       
   579 	CleanupStack::Pop(self);
       
   580 	return self;
       
   581 	}
       
   582 
       
   583 CBackupOpeartionObserversWrapper::~CBackupOpeartionObserversWrapper()
       
   584 /**
       
   585    Destructor
       
   586  */
       
   587 	{
       
   588 	ResetAndDestroy();
       
   589 	iBackupOpeartionObserver.Close();
       
   590 	delete iBackupSession;
       
   591 	}
       
   592 
       
   593 CBackupOpeartionObserversWrapper::CBackupOpeartionObserversWrapper()
       
   594 /**
       
   595    Constructor
       
   596  */
       
   597 	{
       
   598 	}
       
   599 
       
   600 /**
       
   601    Auxiliary function for all Test Cases
       
   602   
       
   603    This method creates 'aNumberOfObservers' of backup operation observers for
       
   604    the wrapper.
       
   605   
       
   606  */
       
   607 void CBackupOpeartionObserversWrapper::ConstructL(TInt aNumberOfObservers)
       
   608 	{
       
   609 	iBackupSession=CBaBackupSessionWrapper::NewL();
       
   610 	for (TInt counter=0; counter<aNumberOfObservers; ++counter)
       
   611 		{
       
   612 		User::LeaveIfError(iBackupOpeartionObserver.Append(CBackupOpeartionObserver::NewL()));
       
   613 		}
       
   614 	}
       
   615 
       
   616 /**
       
   617    Auxiliary function for TestCaseID tbackup-AutoUpdateBackupObserverRegistrationL
       
   618   
       
   619    The method registers the specified observer for notifications when a backup
       
   620    operation starts or ends and sets the observer as registered by calling
       
   621    CBackupOpeartionObserver::SetRegistered().
       
   622   
       
   623  */
       
   624 void CBackupOpeartionObserversWrapper::RegisterBackupOperationObserverL(CBackupOpeartionObserver& aBackupOpeartionObserver)
       
   625 	{
       
   626 	iBackupSession->RegisterBackupOperationObserverL(aBackupOpeartionObserver);
       
   627 	aBackupOpeartionObserver.SetRegistered(ETrue);
       
   628 	}
       
   629 
       
   630 /**
       
   631    Auxiliary function for all Test Cases
       
   632   
       
   633    The method de-registers the specified backup/restore observer and resets the
       
   634    iRegister flag of observer by calling
       
   635    CBackupOpeartionObserver::SetRegistered(). The method is invoked by
       
   636    CBackupOpeartionObserversWrapper::ResetAndDestroy() during destruction.
       
   637   
       
   638  */
       
   639 void CBackupOpeartionObserversWrapper::DeRegisterBackupOperationObserver(CBackupOpeartionObserver& aBackupOpeartionObserver)
       
   640 	{
       
   641 	iBackupSession->DeRegisterBackupOperationObserver(aBackupOpeartionObserver);
       
   642 	aBackupOpeartionObserver.SetRegistered(EFalse);
       
   643 	}
       
   644 
       
   645 /**
       
   646    Auxiliary function for all Test Cases
       
   647   
       
   648    This method is invoked by destructor to deregister all backup observers
       
   649    present in the wrapper. 
       
   650   
       
   651  */
       
   652 void CBackupOpeartionObserversWrapper::ResetAndDestroy()
       
   653 	{
       
   654 	const TInt count = iBackupOpeartionObserver.Count();
       
   655 	for (TInt index=0; index<count; ++index)
       
   656 		{
       
   657 		iBackupSession->DeRegisterBackupOperationObserver(*iBackupOpeartionObserver[index]);
       
   658 		}
       
   659 	iBackupOpeartionObserver.ResetAndDestroy();
       
   660 	iBackupOpeartionObserver.Close();
       
   661 	}
       
   662 
       
   663 /**********************************************
       
   664  
       
   665  
       
   666  
       
   667  	CBackupRegistrationDialog
       
   668  
       
   669  
       
   670  
       
   671 ************************************************/
       
   672 
       
   673 CBackupRegistrationDialog::CBackupRegistrationDialog(RPointerArray<CBackupOpeartionObserversWrapper>& aBackupOperationObserversWrapper)
       
   674 	: iBackupOperationObserversWrapper(aBackupOperationObserversWrapper)
       
   675 /**
       
   676    Constructor
       
   677  */
       
   678 	{
       
   679 	}
       
   680 
       
   681 /**
       
   682    Auxiliary Function tbackup-UpdateBackupObserverRegistrationL
       
   683   
       
   684    This method is an override from CEikDialog.It performs pre-layout dialog
       
   685    initialisation. The method finds whether all observers for each observer
       
   686    wrapper are registered and the state of each is displayed as a checkbox
       
   687    on the dialog.
       
   688   
       
   689  */
       
   690 void CBackupRegistrationDialog::PreLayoutDynInitL()
       
   691 	{
       
   692 	const TInt count = iBackupOperationObserversWrapper.Count();
       
   693 	CBackupOpeartionObserversWrapper* observerWrapper = NULL;
       
   694 	TInt previousCount = 0;
       
   695 	for (TInt index1=0; index1<count; ++index1)
       
   696 		{
       
   697 		observerWrapper = iBackupOperationObserversWrapper[index1];
       
   698 		const TInt count2 = observerWrapper->CountObservers();
       
   699 		for (TInt index2=0; index2<count2; ++index2)
       
   700 			{
       
   701 			CBackupOpeartionObserver* observer = observerWrapper->Observer(index2);
       
   702 			const TInt realIndex = previousCount+index2;
       
   703 			CEikCheckBox* checkBox = (CEikCheckBox*)Control(EObserversId+realIndex);
       
   704 			checkBox->SetState(observer->IsRegistered() ? CEikButtonBase::ESet : CEikButtonBase::EClear);
       
   705 			}
       
   706 		previousCount += count2;
       
   707 		}
       
   708 	}
       
   709 
       
   710 /**
       
   711    Auxiliary function for TestCaseID tbackup-UpdateBackupObserverRegistrationL
       
   712   
       
   713    This method is an override from CEikDialog. On click of OK button this
       
   714    method checks whether the check boxes that represent observers in each
       
   715    wrapper is set or reset and registers or deregisters the backup observer.
       
   716   
       
   717  */
       
   718 TBool CBackupRegistrationDialog::OkToExitL(TInt aButtonId)
       
   719 	{
       
   720 	if (aButtonId==EEikBidOk)
       
   721 		{
       
   722 		const TInt count = iBackupOperationObserversWrapper.Count();
       
   723 		CBackupOpeartionObserversWrapper* observerWrapper = NULL;
       
   724 		TInt previousCount = 0;
       
   725 		for (TInt index1=0; index1<count; ++index1)
       
   726 			{
       
   727 			observerWrapper = iBackupOperationObserversWrapper[index1];
       
   728 			const TInt count2 = observerWrapper->CountObservers();
       
   729 			for (TInt index2=0; index2<count2; ++index2)
       
   730 				{
       
   731 				CBackupOpeartionObserver* observer = observerWrapper->Observer(index2);
       
   732 				const TInt realIndex = previousCount+index2;
       
   733 				CEikCheckBox* checkBox = (CEikCheckBox*)Control(EObserversId+realIndex);
       
   734 				
       
   735 				const TBool stateSet = (checkBox->State()==CEikButtonBase::ESet);
       
   736 				const TBool previousState = observer->IsRegistered();
       
   737 				const TBool stateChanged = (!stateSet)!=(!previousState);
       
   738 				if (stateChanged)
       
   739 					{
       
   740 					if (stateSet)
       
   741 						{
       
   742 						observerWrapper->RegisterBackupOperationObserverL(*observer);
       
   743 						}
       
   744 					else
       
   745 						{
       
   746 						observerWrapper->DeRegisterBackupOperationObserver(*observer);
       
   747 						}
       
   748 					}
       
   749 				}
       
   750 			previousCount += count2;
       
   751 			}
       
   752 		}
       
   753 	return ETrue;
       
   754 	}
       
   755 
       
   756 
       
   757 /**********************************************
       
   758  
       
   759  
       
   760  
       
   761  	CBackupOperationDialog
       
   762  
       
   763  
       
   764  
       
   765 ************************************************/
       
   766 CBackupOperationDialog::CBackupOperationDialog(CBaBackupSessionWrapper& aBackupSession)
       
   767 	:iBackupSession(aBackupSession)
       
   768 /**
       
   769    Constructor
       
   770  */
       
   771 	{}
       
   772 
       
   773 /**
       
   774    Auxiliary function for TestCaseID tbackup-UpdateBackupOperationStateL
       
   775   
       
   776    This method is an override from CEikDialog.It performs pre-layout dialog
       
   777    initialisation. The method invokes 
       
   778    CBaBackupSessionWrapper::IsBackupOperationRunning() to find whether backup
       
   779    operation is in running and accordingly sets 'Start' & 'End' option buttons.
       
   780   
       
   781  */
       
   782 void CBackupOperationDialog::PreLayoutDynInitL()
       
   783 	{
       
   784 	CEikHorOptionButtonList* optionButtonList = (CEikHorOptionButtonList*)Control(EDlgBackupOperationSel);
       
   785 	const TBool isRunning = iBackupSession.IsBackupOperationRunning();
       
   786 	optionButtonList->SetButtonById(isRunning ? EDlgBackupOperationSel1 : EDlgBackupOperationSel2);
       
   787 	}
       
   788 
       
   789 /**
       
   790    Auxiliary function for TestCaseID tbackup-UpdateBackupOperationStateL
       
   791   
       
   792    This method is an override from CEikDialog. On click of OK button this
       
   793    method checks the state of option buttons labeled 'Start' & 'End'
       
   794    and accordingly starts / ends the backup operation by calling
       
   795    CBaBackupSessionWrapper::NotifyBackupOperationL().
       
   796   
       
   797  */
       
   798 TBool CBackupOperationDialog::OkToExitL(TInt aButtonId)
       
   799 	{
       
   800 	if (aButtonId==EEikBidOk)
       
   801 		{
       
   802 		CEikHorOptionButtonList* optionButtonList = (CEikHorOptionButtonList*)Control(EDlgBackupOperationSel);
       
   803 		const TInt labeledButtonId = optionButtonList->LabeledButtonId();
       
   804 		TBackupOperationAttributes backupOperationAttributes;
       
   805 		switch (labeledButtonId)
       
   806 			{
       
   807 		case EDlgBackupOperationSel1:
       
   808 			{
       
   809 			backupOperationAttributes.iFileFlag = MBackupObserver::EReleaseLockReadOnly;
       
   810 			backupOperationAttributes.iOperation = MBackupOperationObserver::EStart;
       
   811 			break;
       
   812 			}
       
   813 		case EDlgBackupOperationSel2:
       
   814 			{
       
   815 			backupOperationAttributes.iFileFlag = MBackupObserver::ETakeLock;
       
   816 			backupOperationAttributes.iOperation = MBackupOperationObserver::EEnd;
       
   817 			break;
       
   818 			}
       
   819 		default:
       
   820 			return EFalse;
       
   821 			}
       
   822 		iBackupSession.NotifyBackupOperationL(backupOperationAttributes);
       
   823 		}
       
   824 	return ETrue;
       
   825 	}
       
   826 
       
   827 
       
   828 /**********************************************
       
   829  
       
   830  
       
   831  
       
   832  	CBackdrop
       
   833  
       
   834  
       
   835  
       
   836 ************************************************/
       
   837 
       
   838 
       
   839 /**
       
   840    Auxiliary function for all Test Cases
       
   841   
       
   842    This method is part of Two - phase construction. It creates the background
       
   843    control.
       
   844   
       
   845  */
       
   846 CBackdrop* CBackdrop::NewL()
       
   847 	{ // static
       
   848 	CBackdrop* self=new(ELeave) CBackdrop();
       
   849 	CleanupStack::PushL(self);
       
   850 	self->CreateWindowL();
       
   851 	CleanupStack::Pop(); // self
       
   852 	return self;
       
   853 	}
       
   854 /**
       
   855    Auxiliary function for all Test Cases
       
   856   
       
   857    This method is an override from CCoeControl. It draws the background
       
   858    control.
       
   859   
       
   860  */
       
   861 void CBackdrop::Draw(const TRect& aRect) const
       
   862 	{
       
   863 	CWindowGc& gc=SystemGc();
       
   864 	gc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   865 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   866 	gc.SetPenColor(KRgbGreen);
       
   867 	gc.SetBrushColor(KRgbGreen);
       
   868 	gc.DrawRect(aRect);
       
   869 	}
       
   870 
       
   871 
       
   872 /**********************************************
       
   873  
       
   874  
       
   875  
       
   876  	COpenAppList
       
   877  
       
   878  
       
   879  
       
   880 ************************************************/
       
   881 
       
   882 /**
       
   883    Auxiliary function for TestCaseID tbackup-CmdListAppsL
       
   884   
       
   885    This method creates a client session with the windows server and retrieves
       
   886    the window group list currently available. The caption or the thread id for
       
   887    each of window groups from the list is obtained and added to the list box.
       
   888   
       
   889  */
       
   890 void COpenAppList::UpdateL()
       
   891 	{
       
   892 	RWsSession& wsSession=iEikonEnv->WsSession();
       
   893 	TInt count=wsSession.NumWindowGroups(0);
       
   894 	if (!count)
       
   895 		return;
       
   896 	CDesCArray* tasks=new(ELeave) CDesCArrayFlat(count);
       
   897 	CleanupStack::PushL(tasks);
       
   898 	CArrayFixFlat<TInt>* wgIds=new(ELeave) CArrayFixFlat<TInt>(count);
       
   899 	CleanupStack::PushL(wgIds);
       
   900 	CApaWindowGroupName* wgName=CApaWindowGroupName::NewLC(wsSession);
       
   901 	wsSession.WindowGroupList(0,wgIds);
       
   902 	TBuf<2*KMaxFileName+1> name;
       
   903 	const TInt wgCount=wgIds->Count();
       
   904 	for (TInt ii=0;ii<wgCount;ii++)
       
   905 		{ 
       
   906 		const TInt wgId=(*wgIds)[ii];
       
   907 		wgName->ConstructFromWgIdL(wgId);
       
   908 		TPtrC caption=wgName->Caption();
       
   909 		if(wgName->Hidden())
       
   910 			{
       
   911 			continue;
       
   912 			}
       
   913 		else if (caption.Length()==0) // not set yet - use thread name instead
       
   914 			{
       
   915 			TThreadId threadId;
       
   916 			TInt err=wsSession.GetWindowGroupClientThreadId(wgId,threadId);
       
   917 			if (err==KErrNone)
       
   918 				{
       
   919 				RThread thread;
       
   920 				err=thread.Open(threadId);
       
   921 				if (err==KErrNone)
       
   922 					{
       
   923 					name.Copy(thread.Name());
       
   924 					thread.Close();
       
   925 					}
       
   926 				}
       
   927 			if (err!=KErrNone)
       
   928 				name.Copy(_L("???"));
       
   929 			}
       
   930 		else
       
   931 			{
       
   932 			name=caption;
       
   933 			name.Append(' ');
       
   934 			TFileName docName=wgName->DocName();
       
   935 			name.Append(docName);
       
   936 			}
       
   937 		tasks->AppendL(name);
       
   938 		}
       
   939 	CleanupStack::PopAndDestroy(2); // wgIds, wgName
       
   940 	Model()->SetItemTextArray(tasks);
       
   941 	CleanupStack::Pop(); // tasks
       
   942 	HandleItemAdditionL();
       
   943 	}
       
   944 
       
   945 /**********************************************
       
   946  
       
   947   
       
   948  	COpenFileList
       
   949  
       
   950  
       
   951  
       
   952 ************************************************/
       
   953 
       
   954 COpenFileList::COpenFileList(CArrayPtr<CBackupFileObserver>& aFileObservers)
       
   955 	: iFileObservers(aFileObservers)
       
   956 /**
       
   957    Constructor
       
   958  */
       
   959 	{}
       
   960 
       
   961 COpenFileList::~COpenFileList()
       
   962 /**
       
   963    Destructor
       
   964  */
       
   965 	{
       
   966 	delete iList;
       
   967 	}
       
   968 
       
   969 /**
       
   970    Auxiliary function for all Test Cases
       
   971   
       
   972    The method creates a Column List Box and sets the width for all the
       
   973    columns in the list box.
       
   974   
       
   975  */
       
   976 void COpenFileList::ConstructL()
       
   977 	{
       
   978 	CreateWindowL();
       
   979 	iList=new(ELeave) CEikColumnListBox();
       
   980 	iList->ConstructL(this);
       
   981 	CColumnListBoxData* columnData=iList->ItemDrawer()->ColumnData();
       
   982 	// following assumes a know width for this control
       
   983 	// bad practise but not worth writing a scalable control in this test app
       
   984 	columnData->SetColumnWidthPixelL(0,20);
       
   985 	columnData->SetColumnWidthPixelL(1,180);
       
   986 	columnData->SetColumnWidthPixelL(2,100);
       
   987 	}
       
   988 
       
   989 /**
       
   990    Auxiliary function for TestCaseID tbackup_CmdListOpenFilesL
       
   991   
       
   992    This method lists filename and lock state of all files associated with the
       
   993    file observers.
       
   994   
       
   995  */
       
   996 void COpenFileList::UpdateL()
       
   997 	{
       
   998 	CDesCArray* textArray=new(ELeave) CDesCArrayFlat(2);
       
   999 	CleanupStack::PushL(textArray);
       
  1000 	TChar separator(KColumnListSeparator);
       
  1001 	const TInt obsCount=iFileObservers.Count();
       
  1002 	for (TInt ii=0;ii<obsCount;ii++)
       
  1003 		{
       
  1004 		TBuf<2> num;
       
  1005 		num.Num(ii);
       
  1006 		const RArray<CBackupFileObserver::TBackupFile>& backupArray=iFileObservers[ii]->BackupArray();
       
  1007 		const TInt fileCount=backupArray.Count();
       
  1008 		for (TInt jj=0;jj<fileCount;jj++)
       
  1009 			{
       
  1010 			TBuf<300> buf;
       
  1011 			buf.Append(num);
       
  1012 			const CBackupFileObserver::TBackupFile& backupFile=backupArray[jj];
       
  1013 			buf.Append(separator);
       
  1014 			buf.Append(backupFile.iFileName);
       
  1015 			buf.Append(separator);
       
  1016 			TBuf<20> lockState;
       
  1017 			if (backupFile.iLockState==CBackupFileObserver::ELocked)
       
  1018 				{
       
  1019 				iCoeEnv->ReadResource(lockState,R_TBACKUP_LOCKSTATE_LOCKED);
       
  1020 				}
       
  1021 			else if (backupFile.iLockState==CBackupFileObserver::EReadOnly)
       
  1022 				{
       
  1023 				iCoeEnv->ReadResource(lockState,R_TBACKUP_LOCKSTATE_READONLY);
       
  1024 				}
       
  1025 			else if(backupFile.iLockState==CBackupFileObserver::ENoAccess)
       
  1026 				{
       
  1027 				iCoeEnv->ReadResource(lockState,R_TBACKUP_LOCKSTATE_NOACCESS);
       
  1028 				}
       
  1029 			else
       
  1030 				{
       
  1031 				lockState=_L("???");
       
  1032 				}
       
  1033 			buf.Append(lockState);
       
  1034 			textArray->AppendL(buf);
       
  1035 			}
       
  1036 		}
       
  1037 	iList->Model()->SetItemTextArray(textArray);
       
  1038 	CleanupStack::Pop(); // textArray
       
  1039 	iList->HandleItemAdditionL();
       
  1040 	}
       
  1041 
       
  1042 /**
       
  1043    Auxiliary function for all Test Cases
       
  1044   
       
  1045    The method is an override from CCoeControl. It returns minimum required
       
  1046    size of column list box.
       
  1047   
       
  1048  */
       
  1049 TSize COpenFileList::MinimumSize()
       
  1050 	{
       
  1051 	return iList->MinimumSize();
       
  1052 	}
       
  1053 
       
  1054 /**
       
  1055    Auxiliary function for all Test Cases
       
  1056   
       
  1057    The method is an override from CCoeControl. It is invoked to set the size
       
  1058    and position of the content of list box control.
       
  1059   
       
  1060  */
       
  1061 void COpenFileList::SizeChanged()
       
  1062 	{
       
  1063 	const TRect rect(Rect());
       
  1064 	iList->SetRect(rect);
       
  1065 	}
       
  1066 
       
  1067 /**
       
  1068    Auxiliary function for all Test Cases
       
  1069   
       
  1070    The method is an override from CCoeControl. It returns the number of
       
  1071    controls contained in the compound control COpenFileList.
       
  1072   
       
  1073  */
       
  1074 TInt COpenFileList::CountComponentControls() const
       
  1075 	{
       
  1076 	return 1;
       
  1077 	}
       
  1078 
       
  1079 /**
       
  1080    Auxiliary function for all Test Cases
       
  1081   
       
  1082    The method is an override from CCoeControl. It returns the handle to list
       
  1083    box present on compound control COpenFileList.  
       
  1084   
       
  1085  */
       
  1086 CCoeControl* COpenFileList::ComponentControl(TInt aIndex) const
       
  1087 	{
       
  1088 	if (aIndex==0)
       
  1089 		{
       
  1090 		return iList;
       
  1091 		}
       
  1092 	return NULL;
       
  1093 	}
       
  1094 
       
  1095 
       
  1096 /**********************************************
       
  1097  
       
  1098  
       
  1099  
       
  1100  	CTBackupAppUi
       
  1101  
       
  1102  
       
  1103  
       
  1104 ************************************************/
       
  1105 
       
  1106 CTBackupAppUi::CTBackupAppUi(CTmsTestStep* aStep) :
       
  1107 	CTestAppUi(aStep, KTBackupResourceFilePath)//,		R_TBACKUP_HOTKEYS, R_TBACKUP_MENUBAR, R_TBACKUP_TOOLBAR)
       
  1108 /**
       
  1109    Constructor
       
  1110  */
       
  1111 	{
       
  1112 	}
       
  1113 /**
       
  1114    Auxiliary function for all Test Cases
       
  1115    
       
  1116    This method creates a client interface to the backup server and performs the
       
  1117    following:
       
  1118    (a) Creates a background control.
       
  1119    (b) Creates backup observers and adds files to the observer.
       
  1120    (c) Creates an Application List from window groups.
       
  1121    (d) Creates a list for files attached to the observers.
       
  1122    
       
  1123  */
       
  1124 void CTBackupAppUi::ConstructL()
       
  1125 	{
       
  1126 	CTestAppUi::ConstructL();
       
  1127 	iEikonEnv->SetSystem(ETrue);
       
  1128 	iBackupSession=CBaBackupSessionWrapper::NewL();
       
  1129 
       
  1130 	CreateBackgroundL();
       
  1131 	CreateFileObserversL();
       
  1132 	CreateAppListL();
       
  1133 	CreateFileListL();
       
  1134 	CreateObserversListL();
       
  1135 	iBusyMsg = new (ELeave) CEikBusyMsgWin(*iEikonEnv);
       
  1136 	iBusyMsg->ConstructL(iEikonEnv->RootWin());
       
  1137 	CTestAppUi::AutoTestManager().StartAutoTest();
       
  1138 	}
       
  1139 
       
  1140 CTBackupAppUi::~CTBackupAppUi()
       
  1141 /**
       
  1142    Destructor
       
  1143  */
       
  1144 	{
       
  1145 	delete iBackdrop;
       
  1146 	delete iAppList;
       
  1147 	delete iFileList;
       
  1148 	if (iFileObservers)
       
  1149 		{
       
  1150 		iFileObservers->ResetAndDestroy();
       
  1151 		delete iFileObservers;
       
  1152 		}
       
  1153 	iBackupOperationObserversWrapper.ResetAndDestroy();
       
  1154 	iBackupOperationObserversWrapper.Close();
       
  1155 	iBusyMsg->CancelDisplay();
       
  1156 	delete iBusyMsg;
       
  1157 	delete iBackupSession;
       
  1158 	}
       
  1159 
       
  1160 /**
       
  1161    Auxiliary function for all Test Cases
       
  1162   
       
  1163    The method is an override from CTestAppUi. The method initiates back up
       
  1164    tests.
       
  1165    
       
  1166  */
       
  1167 void CTBackupAppUi::RunTestStepL(TInt aNextStep)
       
  1168 	{
       
  1169 
       
  1170 	switch(aNextStep)
       
  1171 		{
       
  1172 	case 1:
       
  1173 		INFO_PRINTF1(_L("Test: List Apps."));
       
  1174 		SetTestStepID(_L("UIF-tbackup-CmdListAppsL"));
       
  1175 		HandleCommandL(EBackupCmdListApps);
       
  1176 		RecordTestResultL();
       
  1177 		INFO_PRINTF1(_L("List Apps Completed"));
       
  1178 		break;
       
  1179 	case 2:
       
  1180 		INFO_PRINTF1(_L("Test: List Open Files."));
       
  1181 		SetTestStepID(_L("UIF-tbackup-CmdListOpenFilesL"));
       
  1182 		HandleCommandL(EBackupCmdListOpenFiles);
       
  1183 		RecordTestResultL();
       
  1184 		INFO_PRINTF1(_L("List Open Files Completed"));
       
  1185 		break;
       
  1186 	case 3:
       
  1187 		INFO_PRINTF1(_L("Test: Close Files."));
       
  1188 		SetTestStepID(_L("UIF-tbackup-AutoCmdCloseL"));
       
  1189 		HandleCommandL(EBackupCmdClose);
       
  1190 		RecordTestResultL();
       
  1191 		INFO_PRINTF1(_L("Close Files Completed"));
       
  1192 		break;
       
  1193 	case 4:
       
  1194 		INFO_PRINTF1(_L("Test: Restart."));
       
  1195 		SetTestStepID(_L("UIF-tbackup-AutoCmdRestartL"));
       
  1196 		HandleCommandL(EBackupCmdRestart);
       
  1197 		RecordTestResultL();
       
  1198 		INFO_PRINTF1(_L("Restart Completed"));
       
  1199 		break;
       
  1200 	case 5:
       
  1201 		INFO_PRINTF1(_L("Test: CloseAllAndRestartAll."));
       
  1202 		SetTestStepID(_L("UIF-tbackup-AutoCmdCloseAllAndRestartAllL"));
       
  1203 		HandleCommandL(EBackupCmdCloseAllAndRestartAll);
       
  1204 		RecordTestResultL();
       
  1205 		INFO_PRINTF1(_L("CloseAllAndRestartAll Completed"));
       
  1206 		break;
       
  1207 	case 6:
       
  1208 		INFO_PRINTF1(_L("Test: Register Objects."));
       
  1209 		SetTestStepID(_L("UIF-tbackup-AutoUpdateBackupObserverRegistrationL"));
       
  1210 		HandleCommandL(EBackupCmdRegisterObs);
       
  1211 		RecordTestResultL();
       
  1212 		INFO_PRINTF1(_L("Register Objects Completed."));
       
  1213 
       
  1214 		INFO_PRINTF1(_L("Test: Backup Operation."));
       
  1215 		SetTestStepID(_L("UIF-tbackup-AutoUpdateBackupOperationStateL"));
       
  1216 		HandleCommandL(EBackupCmdBackupOperation);
       
  1217 		RecordTestResultL();
       
  1218 		CloseTMSGraphicsStep();
       
  1219 		INFO_PRINTF1(_L("Completed: Backup Operation running..."));
       
  1220 		User::After(TTimeIntervalMicroSeconds32(2000000));
       
  1221 		break;
       
  1222 	case 7:
       
  1223 		INFO_PRINTF1(_L("Test: Backup operation stop."));
       
  1224 		HandleCommandL(EBackupCmdDestroyBackupOperationClient);
       
  1225 		INFO_PRINTF1(_L("Backup operation stop completed"));
       
  1226 		break;
       
  1227 	case 8:
       
  1228 		INFO_PRINTF1(_L("Tests completed - End of Test."));
       
  1229 		CTestAppUi::AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
  1230 		break;
       
  1231 	default:
       
  1232 		break;
       
  1233 		}
       
  1234 	}
       
  1235 
       
  1236 /**
       
  1237    Auxiliary function for all Test Cases
       
  1238   
       
  1239    This method is called by CTBackupAppUi::RunTestStepL() to initiate the
       
  1240    tests.
       
  1241    
       
  1242  */
       
  1243 void CTBackupAppUi::HandleCommandL(TInt aCommand)
       
  1244 	{
       
  1245 	switch (aCommand)
       
  1246 		{
       
  1247 	case EEikCmdExit:
       
  1248 		Exit();
       
  1249 		break;
       
  1250 	case EBackupCmdListApps:
       
  1251 		CmdListAppsL();
       
  1252 		break;
       
  1253 	case EBackupCmdListOpenFiles:
       
  1254 		CmdListOpenFilesL();
       
  1255 		break;
       
  1256 	case EBackupCmdClose:
       
  1257 		AutoCmdCloseL();
       
  1258 		break;
       
  1259 	case EBackupCmdRestart:
       
  1260 		AutoCmdRestartL();
       
  1261 		break;
       
  1262 	case EBackupCmdCloseAllAndRestartAll:
       
  1263 		AutoCmdCloseAllAndRestartAllL();
       
  1264 		break;
       
  1265 	case EBackupCmdRegisterObs:
       
  1266 		AutoUpdateBackupObserverRegistrationL();
       
  1267 		break;
       
  1268 	case EBackupCmdBackupOperation:
       
  1269 		AutoUpdateBackupOperationStateL();
       
  1270 		break;
       
  1271 	case EBackupCmdDestroyBackupOperationClient:
       
  1272 		{
       
  1273 			const TBool backupOperationRunning = iBackupSession->IsBackupOperationRunning();
       
  1274 	
       
  1275 			if (backupOperationRunning)
       
  1276 			{
       
  1277 			iBusyMsg->CancelDisplay();
       
  1278 			}
       
  1279 
       
  1280 			delete iBackupSession;
       
  1281 			iBackupSession = NULL;
       
  1282 		}
       
  1283 		break;
       
  1284 	default:
       
  1285 		User::Leave(KErrNotSupported);
       
  1286 		break;
       
  1287 		}
       
  1288 	}
       
  1289 
       
  1290 /**
       
  1291    Auxiliary function for all Test Cases
       
  1292    
       
  1293    This method creates the background control.
       
  1294    
       
  1295  */
       
  1296 void CTBackupAppUi::CreateBackgroundL()
       
  1297 	{
       
  1298 	iBackdrop=CBackdrop::NewL();
       
  1299 	const TRect clientRect=ClientRect();
       
  1300 	iBackdrop->SetRect(clientRect);
       
  1301 	iBackdrop->ActivateL();
       
  1302 	}
       
  1303 
       
  1304 /**
       
  1305    Auxiliary function for all Test Cases
       
  1306    
       
  1307    This method creates a List Box and adds the list of applications currently
       
  1308    running.
       
  1309    
       
  1310  */
       
  1311 void CTBackupAppUi::CreateAppListL()
       
  1312 	{
       
  1313 	iAppList=new(ELeave) COpenAppList();
       
  1314 	iAppList->ConstructL(NULL,0);
       
  1315 	TRect rect=ClientRect();
       
  1316 	rect.Shrink(TSize(20,20));
       
  1317 	iAppList->SetExtent(rect.iTl,rect.Size());
       
  1318 	iAppList->UpdateL();
       
  1319 	iAppList->ActivateL();
       
  1320 	}
       
  1321 
       
  1322 /**
       
  1323    Auxiliary function for all Test Cases
       
  1324    
       
  1325    This method prepares a list of files associated with each of the observers
       
  1326    and adds them to a List Box.
       
  1327    
       
  1328  */
       
  1329 void CTBackupAppUi::CreateFileListL()
       
  1330 	{
       
  1331 	iFileList=new(ELeave) COpenFileList(*iFileObservers);
       
  1332 	iFileList->ConstructL();
       
  1333 	TRect rect=ClientRect();
       
  1334 	rect.Shrink(TSize(20,20));
       
  1335 	iFileList->SetExtent(rect.iTl,rect.Size());
       
  1336 	iFileList->UpdateL();
       
  1337 	iFileList->ActivateL();
       
  1338 	iFileList->MakeVisible(EFalse);
       
  1339 	}
       
  1340 
       
  1341 /**
       
  1342    Auxiliary function for all Test Cases
       
  1343    
       
  1344    This method creates 3 file observers to the backup server and associates
       
  1345    them with their respective files.
       
  1346    
       
  1347  */
       
  1348 void CTBackupAppUi::CreateFileObserversL()
       
  1349 	{
       
  1350 	iFileObservers=new(ELeave) CArrayPtrFlat<CBackupFileObserver>(3);
       
  1351 	for (TInt ii=0;ii<3;ii++)
       
  1352 		{
       
  1353 		iFileObservers->AppendL(CBackupFileObserver::NewLC());
       
  1354 		CleanupStack::Pop(); // CBackupFileObserver
       
  1355 		}
       
  1356 	CBackupFileObserver* backup=(*iFileObservers)[0];
       
  1357 	backup->AddFileL(KBackupFile1);
       
  1358 	backup->AddFileL(KBackupFile2);
       
  1359 	backup->AddFileL(KBackupFile3);
       
  1360 	backup=(*iFileObservers)[1];
       
  1361 	backup->AddFileL(KBackupFile1);
       
  1362 	backup->AddFileL(KBackupFile3);
       
  1363 	backup=(*iFileObservers)[2];
       
  1364 	backup->AddFileL(KBackupFile3);
       
  1365 	}
       
  1366 
       
  1367 /**
       
  1368    Auxiliary function for all Test Cases
       
  1369    
       
  1370    This method creates observers for the backup operation.
       
  1371    
       
  1372  */
       
  1373 void CTBackupAppUi::CreateObserversListL()
       
  1374 	{
       
  1375 	for (TInt ii=0; ii<KNumOfBackupOperationObservers; ++ii)
       
  1376 		{
       
  1377 		User::LeaveIfError(iBackupOperationObserversWrapper.Append(CBackupOpeartionObserversWrapper::NewL(ii+1)));
       
  1378 		}
       
  1379 	}
       
  1380 
       
  1381 /**
       
  1382    @SYMTestCaseID UIF-tbackup-CmdListAppsL
       
  1383   
       
  1384    @SYMPREQ
       
  1385   
       
  1386    @SYMTestCaseDesc Test retrieving the application list.
       
  1387   
       
  1388    @SYMTestPriority High
       
  1389   
       
  1390    @SYMTestStatus Implemented
       
  1391    
       
  1392    @SYMTestActions The method calls COpenAppList::UpdateL() to update the list of
       
  1393    applications currently running and makes the application list visible on the
       
  1394    background control.
       
  1395   
       
  1396    @SYMTestExpectedResults All currently running application should be listed.
       
  1397    
       
  1398  */
       
  1399 void CTBackupAppUi::CmdListAppsL()
       
  1400 	{
       
  1401 	iAppList->UpdateL();
       
  1402 	if (!iAppList->IsVisible())
       
  1403 		{
       
  1404 		iFileList->MakeVisible(EFalse);
       
  1405 		iAppList->MakeVisible(ETrue);
       
  1406 		}
       
  1407 	iAppList->DrawNow();
       
  1408 	}
       
  1409 
       
  1410 /**
       
  1411    @SYMTestCaseID UIF-tbackup-CmdListOpenFilesL
       
  1412   
       
  1413    @SYMPREQ
       
  1414   
       
  1415    @SYMTestCaseDesc Test retrieving the list of files associated with the file
       
  1416    observers.
       
  1417   
       
  1418    @SYMTestPriority High
       
  1419   
       
  1420    @SYMTestStatus Implemented
       
  1421    
       
  1422    @SYMTestActions The method calls COpenAppList::UpdateL() to update the list of
       
  1423    files associated with each file observer and makes the file list visible
       
  1424    on the background control. The access rights to these files are also displayed.
       
  1425   
       
  1426    @SYMTestExpectedResults All files associated with file observers should be listed.
       
  1427    
       
  1428  */
       
  1429 void CTBackupAppUi::CmdListOpenFilesL()
       
  1430 	{
       
  1431 	iFileList->UpdateL();
       
  1432 	if (!iFileList->IsVisible())
       
  1433 		{
       
  1434 		iAppList->MakeVisible(EFalse);
       
  1435 		iFileList->MakeVisible(ETrue);
       
  1436 		}
       
  1437 	iFileList->DrawNow();
       
  1438 	}
       
  1439 
       
  1440 /**
       
  1441    @SYMTestCaseID UIF-tbackup-CmdCloseL
       
  1442   
       
  1443    @SYMPREQ
       
  1444   
       
  1445    @SYMTestCaseDesc Test CloseFileL() & CloseAll() API's.
       
  1446   
       
  1447    @SYMTestPriority High
       
  1448   
       
  1449    @SYMTestStatus Implemented
       
  1450    
       
  1451    @SYMTestActions The method opens the close dialog.The user selection of 'All'
       
  1452    or 'Single File' is recognised and CBaBackupSessionWrapper::CloseAll() or
       
  1453    CBaBackupSessionWrapper::CloseFileL() is invoked to stop writing to a
       
  1454    specified file or all files respectively.
       
  1455   
       
  1456    @SYMTestExpectedResults The test checks whether the status of the asynchronous
       
  1457    request is KErrInUse.
       
  1458    
       
  1459  */
       
  1460 void CTBackupAppUi::CmdCloseL()
       
  1461 	{
       
  1462 	CDesCArray* files=new(ELeave) CDesCArrayFlat(3);
       
  1463 	CleanupStack::PushL(files);
       
  1464 	files->AppendL(KBackupFile1);
       
  1465 	files->AppendL(KBackupFile2);
       
  1466 	files->AppendL(KBackupFile3);
       
  1467 	CBackupDialogBase::TOperationGranularity granularity;
       
  1468 	TFileName fileName;
       
  1469 	MBackupObserver::TFileLockFlags fileFlag;
       
  1470 	
       
  1471 	if (CBackupCloseDialog::RunDlgLD(*files,granularity,fileName,fileFlag))
       
  1472 		{
       
  1473 		if (granularity==CBackupDialogBase::EAll)
       
  1474 			{
       
  1475 			TRequestStatus status=KRequestPending;
       
  1476 			iBackupSession->CloseAll(fileFlag,status);
       
  1477 			User::WaitForRequest(status);
       
  1478 			}
       
  1479 		else
       
  1480 			{
       
  1481 			iBackupSession->CloseFileL(fileName,fileFlag);
       
  1482 			}
       
  1483 		}
       
  1484 	CleanupStack::PopAndDestroy(); // files
       
  1485 	}
       
  1486 
       
  1487 /**
       
  1488    @SYMTestCaseID UIF-tbackup-AutoCmdCloseL
       
  1489   
       
  1490    @SYMPREQ
       
  1491   
       
  1492    @SYMTestCaseDesc Test CloseFileL() & CloseAll() API's.
       
  1493  
       
  1494    @SYMTestPriority High
       
  1495   
       
  1496    @SYMTestStatus Implemented
       
  1497    
       
  1498    @SYMTestActions The method tests informing observers to stop writing to a specified
       
  1499    file by calling CBaBackupSessionWrapper::CloseFileL(). It also tests whether
       
  1500    CBaBackupSessionWrapper::CloseAll() closes all non-system applications and
       
  1501    calls all observers to stop writing to the registered files.
       
  1502   
       
  1503    @SYMTestExpectedResults The test checks whether the status of the asynchronous
       
  1504    request is KErrInUse.
       
  1505    
       
  1506  */
       
  1507 void CTBackupAppUi::AutoCmdCloseL()
       
  1508 	{
       
  1509 	TFileName fileName;
       
  1510 	MBackupObserver::TFileLockFlags fileFlag;
       
  1511 	
       
  1512 	fileFlag=MBackupObserver::EReleaseLockReadOnly;
       
  1513 	fileName = KBackupFile1;
       
  1514 	iBackupSession->CloseFileL(fileName,fileFlag);
       
  1515 
       
  1516 	TRequestStatus status=KRequestPending;
       
  1517 
       
  1518 	fileFlag=MBackupObserver::EReleaseLockReadOnly;
       
  1519 	iBackupSession->CloseAll(fileFlag,status);
       
  1520 	User::WaitForRequest(status);
       
  1521 	
       
  1522 	iBackupSession->RestartAll();
       
  1523 	fileFlag=MBackupObserver::EReleaseLockNoAccess;
       
  1524 	iBackupSession->CloseAll(fileFlag,status);
       
  1525 	User::WaitForRequest(status);
       
  1526 	}
       
  1527 
       
  1528 /**
       
  1529    @SYMTestCaseID UIF-tbackup-CmdRestartL
       
  1530   
       
  1531    @SYMPREQ
       
  1532   
       
  1533    @SYMTestCaseDesc Test RestartFileL() & RestartAll() APIs.
       
  1534   
       
  1535    @SYMTestPriority High
       
  1536   
       
  1537    @SYMTestStatus Implemented
       
  1538    
       
  1539    @SYMTestActions The method opens the backup restart dialog.The user selection
       
  1540    of 'All' or 'Single File' is recognised and
       
  1541    CBaBackupSessionWrapper::RestartAll() or
       
  1542    CBaBackupSessionWrapper::RestartFileL() is invoked to take back all file
       
  1543    locks on a specified file or on all files respectively.
       
  1544   
       
  1545    @SYMTestExpectedResults The checks whether the API CBaBackupSessionWrapper::RestartAll()
       
  1546    reverses a CBaBackupSessionWrapper::CloseAll() call.
       
  1547    
       
  1548  */
       
  1549 void CTBackupAppUi::CmdRestartL()
       
  1550 	{
       
  1551 	CDesCArray* files=new(ELeave) CDesCArrayFlat(3);
       
  1552 	CleanupStack::PushL(files);
       
  1553 	files->AppendL(KBackupFile1);
       
  1554 	files->AppendL(KBackupFile2);
       
  1555 	files->AppendL(KBackupFile3);
       
  1556 	CBackupDialogBase::TOperationGranularity granularity;
       
  1557 	TFileName fileName;
       
  1558 	
       
  1559 	if (CBackupRestartDialog::RunDlgLD(*files,granularity,fileName))
       
  1560 		{
       
  1561 		if (granularity==CBackupDialogBase::EAll)
       
  1562 			{
       
  1563 			iBackupSession->RestartAll();
       
  1564 			}
       
  1565 		else
       
  1566 			{
       
  1567 			iBackupSession->RestartFile(fileName);
       
  1568 			}
       
  1569 		}
       
  1570 	CleanupStack::PopAndDestroy(); // files
       
  1571 	}
       
  1572 
       
  1573 /**
       
  1574    @SYMTestCaseID UIF-tbackup-AutoCmdRestartL
       
  1575   
       
  1576    @SYMPREQ
       
  1577   
       
  1578    @SYMTestCaseDesc Test RestartFileL() & RestartAll() APIs.
       
  1579   
       
  1580    @SYMTestPriority High
       
  1581   
       
  1582    @SYMTestStatus Implemented
       
  1583    
       
  1584    @SYMTestActions The method tests informing all observers to take back the file
       
  1585    lock for the specified file by calling CBaBackupSessionWrapper::RestartFile().
       
  1586    Similarly it also tests informing all observers to take back file locks for
       
  1587    the registered files by calling CBaBackupSessionWrapper::RestartAll()
       
  1588   
       
  1589    @SYMTestExpectedResults The method checks whether the API
       
  1590    CBaBackupSessionWrapper::RestartAll() reverses a
       
  1591    CBaBackupSessionWrapper::CloseAll() call.
       
  1592    
       
  1593  */
       
  1594 void CTBackupAppUi::AutoCmdRestartL()
       
  1595 	{
       
  1596 	CDesCArray* files=new(ELeave) CDesCArrayFlat(3);
       
  1597 	CleanupStack::PushL(files);
       
  1598 	files->AppendL(KBackupFile1);
       
  1599 	files->AppendL(KBackupFile2);
       
  1600 	files->AppendL(KBackupFile3);
       
  1601 	TFileName fileName;
       
  1602 	
       
  1603 	fileName = KBackupFile1;
       
  1604 	iBackupSession->RestartFile(fileName);
       
  1605 		
       
  1606 	iBackupSession->RestartAll();
       
  1607 
       
  1608 	CleanupStack::PopAndDestroy(); // files
       
  1609 	}
       
  1610 
       
  1611 /**
       
  1612    @SYMTestCaseID UIF-tbackup-AutoCmdCloseAllAndRestartAllL
       
  1613   
       
  1614    @SYMDEF DEF64721
       
  1615   
       
  1616    @SYMTestCaseDesc Test CloseAll() & RestartAll() APIs.
       
  1617   
       
  1618    @SYMTestPriority High
       
  1619   
       
  1620    @SYMTestStatus Implemented
       
  1621    
       
  1622    @SYMTestActions The method tests whether CBaBackupSessionWrapper::CloseAll() closes all 
       
  1623    non-system applications and calls all observers to stop writing to the registered files.
       
  1624    Similarly it also tests informing all observers to take back file locks for
       
  1625    the registered files by calling CBaBackupSessionWrapper::RestartAll()
       
  1626   
       
  1627    @SYMTestExpectedResults The method checks whether the API
       
  1628    CBaBackupSessionWrapper::RestartAll() reverses a
       
  1629    CBaBackupSessionWrapper::CloseAll() call.
       
  1630    
       
  1631  */
       
  1632 void CTBackupAppUi::AutoCmdCloseAllAndRestartAllL()
       
  1633 	{
       
  1634 	RApaLsSession apaLsSession;
       
  1635 	apaLsSession.Connect();
       
  1636 
       
  1637 	CApaCommandLine* cmdLn=CApaCommandLine::NewLC();
       
  1638 	
       
  1639 	_LIT(KLitExePath,"agenda.exe");
       
  1640 	cmdLn->SetExecutableNameL(KLitExePath);
       
  1641 	
       
  1642 	TThreadId tId;
       
  1643 	TRequestStatus appStatus= KRequestPending;
       
  1644 
       
  1645 	//Starting the application
       
  1646 	TInt ret = apaLsSession.StartApp(*cmdLn,tId,&appStatus); // explicit
       
  1647   	INFO_PRINTF2(_L("StartApp return code is %d"), ret);
       
  1648 	TEST(ret==KErrNone);
       
  1649 	User::WaitForRequest(appStatus);
       
  1650 
       
  1651 	CleanupStack::PopAndDestroy(cmdLn);
       
  1652 	
       
  1653 	//Check whether the application is Started
       
  1654 	TFullName repName; 
       
  1655 	_LIT(KAppName,"agenda*");
       
  1656 	{//(Scoped in order to reuse appThread)
       
  1657 		TFindThread appThread(KAppName);
       
  1658 		//TFindThread::Next gets the next thread that matches the pattern above
       
  1659 		TEST(appThread.Next(repName) == KErrNone);
       
  1660 	}
       
  1661 	
       
  1662 	RThread thread;
       
  1663 	thread.Open(tId);
       
  1664 
       
  1665 	MBackupObserver::TFileLockFlags fileFlag;
       
  1666 	fileFlag=MBackupObserver::EReleaseLockReadOnly;
       
  1667 	TRequestStatus closeallStatus = KRequestPending;
       
  1668 	
       
  1669 	//Closing all the non system applications
       
  1670 	iBackupSession->CloseAll(fileFlag,closeallStatus);
       
  1671 	//Wait till all the applications are closed
       
  1672 	User::WaitForRequest(closeallStatus);
       
  1673 	
       
  1674 	//Check whether the agenda application is closed in CloseAll
       
  1675 	TEST(thread.ExitType() != EExitPending);
       
  1676 		
       
  1677 	//Restarting All the nonsystem applications which are closed by previous CloseAll Call
       
  1678 	iBackupSession->RestartAll();
       
  1679 	
       
  1680 	//Check whether the application is Restarted
       
  1681 	TFindThread appThread(KAppName);
       
  1682 	TEST(appThread.Next(repName) == KErrNone);
       
  1683 
       
  1684 	apaLsSession.Close();
       
  1685 	}
       
  1686 		
       
  1687 /**
       
  1688    @SYMTestCaseID UIF-tbackup-UpdateBackupObserverRegistrationL
       
  1689   
       
  1690    @SYMPREQ
       
  1691   
       
  1692    @SYMTestCaseDesc Tests registering observers for back up operation.
       
  1693   
       
  1694    @SYMTestPriority High
       
  1695   
       
  1696    @SYMTestStatus Implemented 
       
  1697    
       
  1698    @SYMTestActions The method creates a backup registration dialog and adds check
       
  1699    boxes to represent all observers that are associated to each of the
       
  1700    wrappers. On click of OK button of the dialog all selected observers should
       
  1701    be registered with the backup server.
       
  1702   
       
  1703    @SYMTestExpectedResults The method should register all observers for backup
       
  1704    operation.
       
  1705    
       
  1706  */
       
  1707 void CTBackupAppUi::UpdateBackupObserverRegistrationL()
       
  1708 	{
       
  1709 	CBackupRegistrationDialog* dialog = new(ELeave) CBackupRegistrationDialog(iBackupOperationObserversWrapper);
       
  1710 	dialog->ConstructAutoDialogLC(EEikDialogFlagWait, R_EIK_BUTTONS_CANCEL_OK);
       
  1711 	dialog->SetTitleL(KRegistrationDlgTitle);
       
  1712 	const TInt count = iBackupOperationObserversWrapper.Count();
       
  1713 	TBuf<20> buf;
       
  1714 	CBackupOpeartionObserversWrapper* observerWrapper = NULL;
       
  1715 	TInt previousCount = 0;
       
  1716 	for (TInt index1=0; index1<count; ++index1)
       
  1717 		{
       
  1718 		observerWrapper = iBackupOperationObserversWrapper[index1];
       
  1719 		const TInt count2 = observerWrapper->CountObservers();
       
  1720 		for (TInt index2=0; index2<count2; ++index2)
       
  1721 			{
       
  1722 			const TInt realIndex = previousCount+index2;
       
  1723 			buf.Format(KObserverStr, realIndex+1);
       
  1724 			CEikCheckBox* checkBox=(CEikCheckBox*)dialog->CreateLineByTypeL(buf, EObserversId+realIndex, EEikCtCheckBox, NULL);
       
  1725 			checkBox->SetSize(checkBox->MinimumSize());
       
  1726 			}
       
  1727 		previousCount += count2;
       
  1728 		}
       
  1729 	dialog->RunLD();
       
  1730 	}
       
  1731 
       
  1732 /**
       
  1733    @SYMTestCaseID UIF-tbackup-AutoUpdateBackupObserverRegistrationL
       
  1734   
       
  1735    @SYMPREQ
       
  1736   
       
  1737    @SYMTestCaseDesc Tests registering observers for back up operation.
       
  1738   
       
  1739    @SYMTestPriority High
       
  1740   
       
  1741    @SYMTestStatus Implemented 
       
  1742    
       
  1743    @SYMTestActions The method finds the number of the observers that each interface
       
  1744    object CBackupOpeartionObserversWrapper has and registers each of its observers
       
  1745    to receive notification for backup operation by calling
       
  1746    CBackupOpeartionObserversWrapper::RegisterBackupOperationObserverL().
       
  1747   
       
  1748    @SYMTestExpectedResults The method should register all observers for backup
       
  1749    operation.
       
  1750    
       
  1751  */
       
  1752 void CTBackupAppUi::AutoUpdateBackupObserverRegistrationL()
       
  1753 	{
       
  1754 	//Following is copied from dialog->RunLD()....
       
  1755 	const TInt count1 = iBackupOperationObserversWrapper.Count();
       
  1756 	CBackupOpeartionObserversWrapper* observerWrapper = NULL;
       
  1757 	TInt previousCount = 0;
       
  1758 	for (TInt index3=0; index3<count1; ++index3)
       
  1759 		{
       
  1760 		observerWrapper = iBackupOperationObserversWrapper[index3];
       
  1761 		const TInt count2 = observerWrapper->CountObservers();
       
  1762 		for (TInt index4=0; index4<count2; ++index4)
       
  1763 			{
       
  1764 			CBackupOpeartionObserver* observer = observerWrapper->Observer(index4);
       
  1765 			observerWrapper->RegisterBackupOperationObserverL(*observer);
       
  1766 			}
       
  1767 			previousCount += count2;
       
  1768 		}
       
  1769 	}		
       
  1770 		
       
  1771 /**
       
  1772    @SYMTestCaseID UIF-tbackup-UpdateBackupOperationStateL
       
  1773   
       
  1774    @SYMPREQ
       
  1775   
       
  1776    @SYMTestCaseDesc Manual Test to start / end back up operation.
       
  1777   
       
  1778    @SYMTestPriority High
       
  1779   
       
  1780    @SYMTestStatus Implemented
       
  1781    
       
  1782    @SYMTestActions The method displays the backup operation dialog with option
       
  1783    buttons labelled 'Start' or 'End'. On click of OK button the state of
       
  1784    option buttons is verified and backup operation is started or ended.
       
  1785   
       
  1786    @SYMTestExpectedResults The method CBaBackupSessionWrapper::IsBackupOperationRunning()
       
  1787    is invoked to verify the start of backup operation.
       
  1788    
       
  1789  */
       
  1790 void CTBackupAppUi::UpdateBackupOperationStateL()
       
  1791 	{
       
  1792 	CEikDialog* dialog = new(ELeave) CBackupOperationDialog(*iBackupSession);
       
  1793 	dialog->ExecuteLD(R_TBACKUP_BACKUP_OPERATION);
       
  1794 	const TBool backupOperationRunning = iBackupSession->IsBackupOperationRunning();
       
  1795 	if (backupOperationRunning)
       
  1796 		{
       
  1797 		iBusyMsg->StartDisplay(KBackupOpMsg, TGulAlignment(EHLeftVTop));
       
  1798 		}
       
  1799 	else
       
  1800 		{
       
  1801 		iBusyMsg->CancelDisplay();
       
  1802 		}
       
  1803 	}
       
  1804 
       
  1805 /**
       
  1806    @SYMTestCaseID UIF-tbackup-AutoUpdateBackupOperationStateL
       
  1807   
       
  1808    @SYMPREQ
       
  1809   
       
  1810    @SYMTestCaseDesc Test starting of back up operation.
       
  1811   
       
  1812    @SYMTestPriority High
       
  1813   
       
  1814    @SYMTestStatus Implemented
       
  1815    
       
  1816    @SYMTestActions The method prepares the attributes to start the backup operation
       
  1817    and notifies the server to start a backup operation by calling
       
  1818    CBaBackupSessionWrapper::NotifyBackupOperationL(). The method then checks
       
  1819    whether the backup operation has started by calling
       
  1820    CBaBackupSessionWrapper::IsBackupOperationRunning(). Note that on start of
       
  1821    backup operation CBackupOpeartionObserver::HandleBackupOperationEventL() is
       
  1822    invoked by the server to notify client of backup start oiperation.
       
  1823   
       
  1824    @SYMTestExpectedResults The method CBaBackupSessionWrapper::IsBackupOperationRunning()
       
  1825    should return ETrue to indicate the start of backup operation.
       
  1826    
       
  1827  */
       
  1828 void CTBackupAppUi::AutoUpdateBackupOperationStateL()
       
  1829 	{
       
  1830 
       
  1831 	//From dialog OKToExit
       
  1832 
       
  1833 	const TInt labeledButtonId = EDlgBackupOperationSel1;
       
  1834 	
       
  1835 	//Another test case is required.
       
  1836 	//labeledButtonId = EDlgBackupOperationSel2;
       
  1837 
       
  1838 	TBackupOperationAttributes backupOperationAttributes;
       
  1839 	switch (labeledButtonId)
       
  1840 		{
       
  1841 		case EDlgBackupOperationSel1:
       
  1842 			{
       
  1843 			backupOperationAttributes.iFileFlag = MBackupObserver::EReleaseLockReadOnly;
       
  1844 			backupOperationAttributes.iOperation = MBackupOperationObserver::EStart;
       
  1845 			break;
       
  1846 			}
       
  1847 		case EDlgBackupOperationSel2:
       
  1848 			{
       
  1849 			backupOperationAttributes.iFileFlag = MBackupObserver::ETakeLock;
       
  1850 			backupOperationAttributes.iOperation = MBackupOperationObserver::EEnd;
       
  1851 			break;
       
  1852 			}
       
  1853 		default:
       
  1854 			//return EFalse;
       
  1855 			break;
       
  1856 		}
       
  1857 	
       
  1858 	iBackupSession->NotifyBackupOperationL(backupOperationAttributes);
       
  1859 
       
  1860 	// Run backup operation. This continues to run until the cancel backup command is
       
  1861 	// chosen.
       
  1862 	const TBool backupOperationRunning = iBackupSession->IsBackupOperationRunning();
       
  1863 	
       
  1864 	if (backupOperationRunning)
       
  1865 		{
       
  1866 		iBusyMsg->StartDisplay(KBackupOpMsg, TGulAlignment(EHLeftVTop));
       
  1867 		}
       
  1868 	else
       
  1869 		{
       
  1870 		iBusyMsg->CancelDisplay();
       
  1871 		}
       
  1872 	}
       
  1873 
       
  1874 /**********************************************
       
  1875  
       
  1876  
       
  1877  
       
  1878  	CTestBackupStep
       
  1879  
       
  1880  
       
  1881  
       
  1882 ************************************************/
       
  1883 CTestBackupStep::CTestBackupStep()
       
  1884 /**
       
  1885    Constructor
       
  1886  */
       
  1887 	{
       
  1888 	SetTestStepName(KTestBackupStep);
       
  1889 	}
       
  1890 
       
  1891 CTestBackupStep::~CTestBackupStep()
       
  1892 /**
       
  1893    Destructor
       
  1894  */
       
  1895 	{
       
  1896 	}
       
  1897 
       
  1898 /**
       
  1899    Auxiliary function for all Test Cases
       
  1900   
       
  1901    The method creates & sets the application's user interface object.
       
  1902    
       
  1903  */
       
  1904 void CTestBackupStep::ConstructAppL(CEikonEnv* aCoe)
       
  1905     { // runs inside a TRAP harness
       
  1906 	aCoe->ConstructL();
       
  1907 
       
  1908 	CTestAppUi* appUi= new (ELeave) CTBackupAppUi(this);
       
  1909     aCoe->SetAppUi(appUi);
       
  1910     appUi->ConstructL();
       
  1911     }
       
  1912 
       
  1913 /**
       
  1914    Auxiliary function for all Test Cases
       
  1915   
       
  1916    The method creates & sets the test step's user interface object and
       
  1917    launches the test step.
       
  1918    
       
  1919  */
       
  1920 TVerdict CTestBackupStep::doTestStepL() // main function called by E32
       
  1921 	{
       
  1922 	PreallocateHALBuffer();
       
  1923 	__UHEAP_MARK;
       
  1924 
       
  1925 	CEikonEnv* coe=new CEikonEnv;
       
  1926 	TRAPD(err,ConstructAppL(coe));
       
  1927 
       
  1928 	if (!err)
       
  1929 		coe->ExecuteD();
       
  1930 
       
  1931 	REComSession::FinalClose();	
       
  1932 	__UHEAP_MARKEND;
       
  1933 
       
  1934 	return TestStepResult();
       
  1935 	}
       
  1936 
       
  1937