featuremgmt/featuremgr/test/rtest/src/t_fmgrbursim.cpp
branchRCL_3
changeset 6 5ffdb8f2067f
equal deleted inserted replaced
2:6862383cf555 6:5ffdb8f2067f
       
     1 // Copyright (c) 2010 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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #include "t_fmgrbursim.h"
       
    23 #include "t_fmgrburdefs.h"
       
    24 
       
    25 CFeatMgrBURSim* CFeatMgrBURSim::NewLC()
       
    26 	{
       
    27 	CFeatMgrBURSim* newInstance = new (ELeave) CFeatMgrBURSim();
       
    28 	CleanupStack::PushL( newInstance );
       
    29 	newInstance->ConstructL();
       
    30 	return newInstance;	
       
    31 	}
       
    32 
       
    33 void CFeatMgrBURSim::ConstructL()
       
    34 	{
       
    35 	iBackupClient = CBaBackupSessionWrapper::NewL();
       
    36 	}
       
    37 
       
    38 CFeatMgrBURSim::CFeatMgrBURSim()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CFeatMgrBURSim::~CFeatMgrBURSim()
       
    43 	{
       
    44 	delete iBackupClient;	
       
    45 	}
       
    46 
       
    47 // BUR simulation functions
       
    48 
       
    49 /** 
       
    50  * Use the babackup API to "start" a backup.  
       
    51  * Ultimate effect is to cause the correct case statement inside 
       
    52  * ChangeFileLockL to be called.
       
    53  */
       
    54 void CFeatMgrBURSim::Simulate_StartBackupL()
       
    55 	{
       
    56 	iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::EReleaseLockReadOnly );		
       
    57 
       
    58 	// Set BUR property to trigger 
       
    59 	TInt ret = RProperty::Set(KTestUid , conn::KUidBackupRestoreKey, conn::EBackupBase|conn::EBURBackupPartial);
       
    60 	if (ret != KErrNone && ret != KErrNotFound)
       
    61 		{
       
    62 		User::Leave(ret);
       
    63 		}
       
    64 	
       
    65 	// allow observers to be notified
       
    66 	User::After(100000);
       
    67 	}
       
    68 
       
    69 
       
    70 /** 
       
    71  * Use the babackup API to "end" a backup.  
       
    72  * Ultimate effect is to cause the correct case statement inside 
       
    73  * ChangeFileLockL to be called. 
       
    74  */
       
    75 void CFeatMgrBURSim::Simulate_EndBackupL( TBool /* aNormal */ )
       
    76 	{
       
    77 	iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::ETakeLock );
       
    78 
       
    79 	// allow observers to be notified
       
    80 	User::After(100000);
       
    81 	}
       
    82 
       
    83 // Restore type
       
    84 
       
    85 /** 
       
    86  * Use the babackup API to "start" a restore.  
       
    87  * Ultimate effect is to cause the correct case statement inside 
       
    88  * ChangeFileLockL to be called.
       
    89  */
       
    90 void CFeatMgrBURSim::Simulate_StartRestoreL()
       
    91 	{
       
    92 	iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::EReleaseLockNoAccess );
       
    93 
       
    94 	// Set BUR property to trigger 
       
    95 	TInt ret = RProperty::Set(KTestUid , conn::KUidBackupRestoreKey, conn::EBackupBase|conn::EBURRestorePartial);
       
    96 	if (ret != KErrNone && ret != KErrNotFound)
       
    97 		{
       
    98 		User::Leave(ret);
       
    99 		}
       
   100 
       
   101 	// allow observers to be notified
       
   102 	User::After(100000);
       
   103 	}
       
   104 
       
   105 
       
   106 /** 
       
   107  * Use the babackup API to "end" a restore.  
       
   108  * Ultimate effect is to cause the correct case statement inside 
       
   109  * ChangeFileLockL to be called.
       
   110  */
       
   111 void CFeatMgrBURSim::Simulate_EndRestoreL( TBool /* aNormal */ )
       
   112 	{
       
   113 	iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::ETakeLock );		
       
   114 	
       
   115 	// allow observers to be notified
       
   116 	User::After(100000);
       
   117 	}
       
   118 
       
   119 
       
   120 // Undefined type
       
   121 
       
   122 
       
   123 // Edge cases
       
   124 
       
   125 void CFeatMgrBURSim::Simulate_StartUndefinedL()
       
   126 	{
       
   127 	// Use the babackup API to "start" (neither a backup or restore explicitly).  
       
   128 	// Ultimate effect is to cause the correct case statement inside 
       
   129 	// CFeatMgrFeatureRegistry::HandleBackupOperationEventL
       
   130 	// to be called.
       
   131 	User::Leave( KErrNotSupported );
       
   132 	}
       
   133 
       
   134 
       
   135 void CFeatMgrBURSim::Simulate_EndUndefinedL( TBool /* aNormal */ )
       
   136 	{
       
   137 	// Use the babackup API to "end" (neither a backup or restore explicitly).  
       
   138 	// Ultimate effect is to cause the correct case statement inside 
       
   139 	// CFeatMgrFeatureRegistry::HandleBackupOperationEventL
       
   140 	// to be called.
       
   141 	User::Leave( KErrNotSupported );
       
   142 	}
       
   143 
       
   144 /** 
       
   145  * CheckRegFileL
       
   146  * Open the babackup file to confirm that the file is present
       
   147  * this leaves if the KErrNotFound is returned
       
   148  */
       
   149 void CFeatMgrBURSim::Simulate_CheckRegFileL()
       
   150 	{
       
   151 	RFs fs;
       
   152 	User::LeaveIfError(fs.Connect());
       
   153 	CleanupClosePushL(fs);
       
   154 	RFile file;
       
   155 	TInt err = file.Open(fs, KRegistrationFile, EFileRead);
       
   156 	
       
   157 	if( err != KErrNone )
       
   158 		{
       
   159 		User::Leave(err);
       
   160 		}
       
   161 
       
   162 	file.Close();
       
   163 	CleanupStack::PopAndDestroy(&fs);
       
   164 	}