1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/test/rtest/src/t_fmgrbursim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,164 @@
1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include "t_fmgrbursim.h"
1.26 +#include "t_fmgrburdefs.h"
1.27 +
1.28 +CFeatMgrBURSim* CFeatMgrBURSim::NewLC()
1.29 + {
1.30 + CFeatMgrBURSim* newInstance = new (ELeave) CFeatMgrBURSim();
1.31 + CleanupStack::PushL( newInstance );
1.32 + newInstance->ConstructL();
1.33 + return newInstance;
1.34 + }
1.35 +
1.36 +void CFeatMgrBURSim::ConstructL()
1.37 + {
1.38 + iBackupClient = CBaBackupSessionWrapper::NewL();
1.39 + }
1.40 +
1.41 +CFeatMgrBURSim::CFeatMgrBURSim()
1.42 + {
1.43 + }
1.44 +
1.45 +CFeatMgrBURSim::~CFeatMgrBURSim()
1.46 + {
1.47 + delete iBackupClient;
1.48 + }
1.49 +
1.50 +// BUR simulation functions
1.51 +
1.52 +/**
1.53 + * Use the babackup API to "start" a backup.
1.54 + * Ultimate effect is to cause the correct case statement inside
1.55 + * ChangeFileLockL to be called.
1.56 + */
1.57 +void CFeatMgrBURSim::Simulate_StartBackupL()
1.58 + {
1.59 + iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::EReleaseLockReadOnly );
1.60 +
1.61 + // Set BUR property to trigger
1.62 + TInt ret = RProperty::Set(KTestUid , conn::KUidBackupRestoreKey, conn::EBackupBase|conn::EBURBackupPartial);
1.63 + if (ret != KErrNone && ret != KErrNotFound)
1.64 + {
1.65 + User::Leave(ret);
1.66 + }
1.67 +
1.68 + // allow observers to be notified
1.69 + User::After(100000);
1.70 + }
1.71 +
1.72 +
1.73 +/**
1.74 + * Use the babackup API to "end" a backup.
1.75 + * Ultimate effect is to cause the correct case statement inside
1.76 + * ChangeFileLockL to be called.
1.77 + */
1.78 +void CFeatMgrBURSim::Simulate_EndBackupL( TBool /* aNormal */ )
1.79 + {
1.80 + iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::ETakeLock );
1.81 +
1.82 + // allow observers to be notified
1.83 + User::After(100000);
1.84 + }
1.85 +
1.86 +// Restore type
1.87 +
1.88 +/**
1.89 + * Use the babackup API to "start" a restore.
1.90 + * Ultimate effect is to cause the correct case statement inside
1.91 + * ChangeFileLockL to be called.
1.92 + */
1.93 +void CFeatMgrBURSim::Simulate_StartRestoreL()
1.94 + {
1.95 + iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::EReleaseLockNoAccess );
1.96 +
1.97 + // Set BUR property to trigger
1.98 + TInt ret = RProperty::Set(KTestUid , conn::KUidBackupRestoreKey, conn::EBackupBase|conn::EBURRestorePartial);
1.99 + if (ret != KErrNone && ret != KErrNotFound)
1.100 + {
1.101 + User::Leave(ret);
1.102 + }
1.103 +
1.104 + // allow observers to be notified
1.105 + User::After(100000);
1.106 + }
1.107 +
1.108 +
1.109 +/**
1.110 + * Use the babackup API to "end" a restore.
1.111 + * Ultimate effect is to cause the correct case statement inside
1.112 + * ChangeFileLockL to be called.
1.113 + */
1.114 +void CFeatMgrBURSim::Simulate_EndRestoreL( TBool /* aNormal */ )
1.115 + {
1.116 + iBackupClient->CloseFileL( KEfmBackupFileName, MBackupObserver::ETakeLock );
1.117 +
1.118 + // allow observers to be notified
1.119 + User::After(100000);
1.120 + }
1.121 +
1.122 +
1.123 +// Undefined type
1.124 +
1.125 +
1.126 +// Edge cases
1.127 +
1.128 +void CFeatMgrBURSim::Simulate_StartUndefinedL()
1.129 + {
1.130 + // Use the babackup API to "start" (neither a backup or restore explicitly).
1.131 + // Ultimate effect is to cause the correct case statement inside
1.132 + // CFeatMgrFeatureRegistry::HandleBackupOperationEventL
1.133 + // to be called.
1.134 + User::Leave( KErrNotSupported );
1.135 + }
1.136 +
1.137 +
1.138 +void CFeatMgrBURSim::Simulate_EndUndefinedL( TBool /* aNormal */ )
1.139 + {
1.140 + // Use the babackup API to "end" (neither a backup or restore explicitly).
1.141 + // Ultimate effect is to cause the correct case statement inside
1.142 + // CFeatMgrFeatureRegistry::HandleBackupOperationEventL
1.143 + // to be called.
1.144 + User::Leave( KErrNotSupported );
1.145 + }
1.146 +
1.147 +/**
1.148 + * CheckRegFileL
1.149 + * Open the babackup file to confirm that the file is present
1.150 + * this leaves if the KErrNotFound is returned
1.151 + */
1.152 +void CFeatMgrBURSim::Simulate_CheckRegFileL()
1.153 + {
1.154 + RFs fs;
1.155 + User::LeaveIfError(fs.Connect());
1.156 + CleanupClosePushL(fs);
1.157 + RFile file;
1.158 + TInt err = file.Open(fs, KRegistrationFile, EFileRead);
1.159 +
1.160 + if( err != KErrNone )
1.161 + {
1.162 + User::Leave(err);
1.163 + }
1.164 +
1.165 + file.Close();
1.166 + CleanupStack::PopAndDestroy(&fs);
1.167 + }