|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @publishedAll |
|
19 @released |
|
20 */ |
|
21 #include "TimeoutBaseStep.h" |
|
22 #include "PerformanceFunctionalityDefs.h" |
|
23 |
|
24 CTimeoutBaseStep::CTimeoutBaseStep(const TInt aContacts, const TInt aDeviation) |
|
25 : CPerformanceFunctionalityBase( aContacts ), |
|
26 iTimeOut(KStartTime), |
|
27 iDeviation(aDeviation) |
|
28 { |
|
29 } |
|
30 /** |
|
31 Checks that the relevant function call waits for the expected amount of time |
|
32 also checks that the timeout error matches the expected error |
|
33 */ |
|
34 TBool CTimeoutBaseStep::CheckTimeOutL( TInt (CTimeoutBaseStep::*aFunc)(CContactDatabase *, const TContactItemId), |
|
35 CContactDatabase *aContactsDatabase, |
|
36 const TContactItemId aCid, |
|
37 const TInt aLockErr, |
|
38 const TInt aTimeout, |
|
39 const TBool aSetTime) |
|
40 { |
|
41 TBool SingleCheck = EFalse; |
|
42 TBool OverallResult = EFalse; |
|
43 TInt deviation = 0; |
|
44 if( aSetTime ) |
|
45 { |
|
46 SetTimeOutL( aContactsDatabase ); |
|
47 } |
|
48 iStart.UniversalTime(); |
|
49 TInt err = (this->*aFunc)(aContactsDatabase, aCid); |
|
50 iEnd.UniversalTime(); |
|
51 deviation = static_cast<TInt>( iEnd.MicroSecondsFrom( iStart ).Int64() - aTimeout ); |
|
52 TESTPRINT( SingleCheck = (aLockErr == err) ); |
|
53 OverallResult = SingleCheck; |
|
54 TESTPRINT( SingleCheck = ( Abs( deviation ) <= iDeviation ) ); |
|
55 OverallResult = OverallResult && SingleCheck; |
|
56 if(!OverallResult) |
|
57 { |
|
58 _LIT(KTimeoutError,"Timeout check failed with following deviance %d <= %d and err %d == %d"); |
|
59 ERR_PRINTF5(KTimeoutError, Abs(deviation), iDeviation, aLockErr, err); |
|
60 } |
|
61 return OverallResult; |
|
62 } |
|
63 |
|
64 //set the timeout for this session |
|
65 void CTimeoutBaseStep::SetTimeOutL(CContactDatabase *aContactsDatabase) |
|
66 { |
|
67 if( aContactsDatabase == NULL ) |
|
68 { |
|
69 aContactsDatabase = iContactsDatabase; |
|
70 } |
|
71 aContactsDatabase->SetOperationTimeOutL( iTimeOut ); |
|
72 } |
|
73 //the following methods attemp to call a specific contact api and return any errors generated. |
|
74 TInt CTimeoutBaseStep::CheckOpenL(CContactDatabase *aContactsDatabase, const TContactItemId aCid) |
|
75 { |
|
76 CContactItem *contactItem = NULL; |
|
77 TRAPD(err, contactItem = aContactsDatabase->OpenContactL( aCid, *iViewAll )); |
|
78 if( KErrNone == err ) |
|
79 { |
|
80 iContactsDatabase->CloseContactL(contactItem->Id()); // this method *CANNOT* leave, depsite the trailing 'L' |
|
81 CLEAR( contactItem ); |
|
82 } |
|
83 return err; |
|
84 } |
|
85 |
|
86 TInt CTimeoutBaseStep::CheckUpdateL(CContactDatabase *aContactsDatabase, const TContactItemId aCid) |
|
87 { |
|
88 CContactItem *contactItemR = iContactsDatabase->ReadContactLC( aCid, *iViewAll ); |
|
89 TRAPD(err, |
|
90 CContactItem *contactItem = aContactsDatabase->UpdateContactLC( aCid, contactItemR ); |
|
91 CleanupStack::PopAndDestroy( contactItem ); |
|
92 ); |
|
93 CleanupStack::PopAndDestroy( contactItemR ); |
|
94 contactItemR = NULL; |
|
95 return err; |
|
96 } |
|
97 |
|
98 TInt CTimeoutBaseStep::CheckRead(CContactDatabase *aContactsDatabase, const TContactItemId aCid) |
|
99 { |
|
100 TRAPD(err, |
|
101 CContactItem *contactItem = aContactsDatabase->ReadContactL( aCid, *iViewAll ); |
|
102 CLEAR( contactItem ); |
|
103 ); |
|
104 return err; |
|
105 } |
|
106 |
|
107 TInt CTimeoutBaseStep::CheckAddL(CContactDatabase *aContactsDatabase, const TContactItemId /*aCid*/) |
|
108 { |
|
109 CContactCard* contact = CContactCard::NewLC(iTemplate); |
|
110 TContactItemId cid = 0; |
|
111 TRAPD(err, |
|
112 cid = aContactsDatabase->doAddNewContactL(*contact, EFalse, iTransaction); |
|
113 iIterate->AddL( cid ); |
|
114 ); |
|
115 CleanupStack::PopAndDestroy(contact); |
|
116 return err; |
|
117 } |
|
118 |
|
119 TInt CTimeoutBaseStep::CheckDelete(CContactDatabase *aContactsDatabase, const TContactItemId aCid) |
|
120 { |
|
121 TRAPD(err, |
|
122 aContactsDatabase->doDeleteContactL( aCid, ETrue, iTransaction ); |
|
123 iIterate->RemoveL(aCid); |
|
124 ); |
|
125 return err; |
|
126 } |
|
127 |