|
1 // Copyright (c) 2004-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This CTestContactsBase |
|
15 // |
|
16 // |
|
17 |
|
18 // User include |
|
19 #include "TestContactsBase.h" |
|
20 |
|
21 // EPOC includes |
|
22 #include <e32base.h> |
|
23 #include <Uri16.h> |
|
24 #include <UriUtils.h> |
|
25 #include <TestExecuteLog.h> |
|
26 |
|
27 /*@{*/ |
|
28 /// Literal constants |
|
29 _LIT(KDef, "default"); |
|
30 _LIT(KFileName, "filenameSecure"); |
|
31 _LIT(KKey, "key"); |
|
32 /*@}*/ |
|
33 |
|
34 |
|
35 // constructor |
|
36 CTestContactsBase::CTestContactsBase() |
|
37 : iDatabase(NULL) |
|
38 , iFieldDef(NULL) |
|
39 , iSchedular(NULL) |
|
40 { |
|
41 } |
|
42 |
|
43 // destructor |
|
44 CTestContactsBase::~CTestContactsBase() |
|
45 { |
|
46 delete iFieldDef; |
|
47 iFieldDef=NULL; |
|
48 |
|
49 delete iSchedular; |
|
50 iSchedular=NULL; |
|
51 CActiveScheduler::Install(NULL); |
|
52 } |
|
53 |
|
54 enum TVerdict CTestContactsBase::doTestStepPreambleL() |
|
55 { |
|
56 iSchedular=new (ELeave)CActiveScheduler(); |
|
57 CActiveScheduler::Install(iSchedular); |
|
58 |
|
59 iFieldDef=new(ELeave) CContactItemFieldDef; |
|
60 iFieldDef->AppendL(KUidContactFieldFamilyName); |
|
61 iFieldDef->AppendL(KUidContactFieldGivenName); |
|
62 return CTestStep::doTestStepPreambleL(); |
|
63 } |
|
64 |
|
65 enum TVerdict CTestContactsBase::doTestStepPostambleL() |
|
66 { |
|
67 delete iFieldDef; |
|
68 iFieldDef=NULL; |
|
69 |
|
70 delete iSchedular; |
|
71 iSchedular=NULL; |
|
72 CActiveScheduler::Install(NULL); |
|
73 |
|
74 return CTestStep::doTestStepPostambleL(); |
|
75 } |
|
76 |
|
77 // Create a new database |
|
78 void CTestContactsBase::CreateDatabase() |
|
79 { |
|
80 TPtrC ptrFileName; |
|
81 TBool returnValue =GetStringFromConfig(ConfigSection(), KFileName(), ptrFileName); |
|
82 if (!returnValue) |
|
83 returnValue=GetStringFromConfig(KDef(), KFileName(), ptrFileName); |
|
84 |
|
85 // Create database |
|
86 if (returnValue) |
|
87 { |
|
88 INFO_PRINTF2(_L("filename = %S"), &ptrFileName); |
|
89 TRAPD(r, iDatabase=CContactDatabase::ReplaceL(ptrFileName)) |
|
90 if (r!=KErrNone) |
|
91 { |
|
92 ERR_PRINTF2(_L("Creating Contacts file failed. Error %d"), r); |
|
93 SetTestStepResult(EFail); |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 INFO_PRINTF1(_L("No Contacts file specified. Open default file.")); |
|
99 TRAPD(r, iDatabase=CContactDatabase::ReplaceL()) |
|
100 if (r!=KErrNone) |
|
101 { |
|
102 ERR_PRINTF2(_L("Creating Contacts file failed. Error %d"), r); |
|
103 SetTestStepResult(EFail); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 void CTestContactsBase::OpenDatabase() |
|
109 { |
|
110 TPtrC ptrFileName; |
|
111 TBool returnValue =GetStringFromConfig(ConfigSection(), KFileName(), ptrFileName); |
|
112 if (!returnValue) |
|
113 returnValue=GetStringFromConfig(KDef(), KFileName(), ptrFileName); |
|
114 |
|
115 // Open database |
|
116 if (returnValue) |
|
117 { |
|
118 INFO_PRINTF2(_L("filename = %S"), &ptrFileName); |
|
119 RaiseInstrumentationEventNotificationL(17); |
|
120 TRAPD(r, iDatabase=CContactDatabase::OpenL(ptrFileName)); |
|
121 RaiseInstrumentationEventNotificationL(18); |
|
122 if (r!=KErrNone) |
|
123 { |
|
124 ERR_PRINTF2(_L("Opening Contacts file failed. Error %d"), r); |
|
125 SetTestStepResult(EFail); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 INFO_PRINTF1(_L("No Contacts file specified. Open default file.")); |
|
131 RaiseInstrumentationEventNotificationL(17); |
|
132 TRAPD(r, iDatabase=CContactDatabase::OpenL(CContactDatabase::EMultiThread)); |
|
133 RaiseInstrumentationEventNotificationL(18); |
|
134 if (r!=KErrNone) |
|
135 { |
|
136 ERR_PRINTF2(_L("Opening Contacts file failed. Error %d"), r); |
|
137 SetTestStepResult(EFail); |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 void CTestContactsBase::CleanupDatabase() |
|
143 { |
|
144 delete iDatabase; |
|
145 iDatabase=NULL; |
|
146 } |
|
147 |
|
148 void CTestContactsBase::RaiseInstrumentationEventNotificationL(TInt aEventTag) |
|
149 { |
|
150 INFO_PRINTF2(_L("RaiseEventNotification %d"), aEventTag); |
|
151 } |
|
152 |
|
153 CContactIdArray* CTestContactsBase::SearchEntriesL() |
|
154 /** |
|
155 This function searches in the contacts database and populates an array |
|
156 with ids' of the contacts which satisfy the search criterion |
|
157 read from the ini file. |
|
158 @return - Pointer to the contact ID array |
|
159 @leave system wide error code |
|
160 */ |
|
161 { |
|
162 TPtrC ptrKey; |
|
163 if (!GetStringFromConfig(ConfigSection(), KKey, ptrKey)) |
|
164 { |
|
165 ERR_PRINTF1(_L("No key value for entry")); |
|
166 SetTestStepResult(EFail); |
|
167 } |
|
168 INFO_PRINTF2(_L("Key Value for Entry Search = %S"), &ptrKey); |
|
169 |
|
170 // The function searches the fields contained in the field definition |
|
171 INFO_PRINTF1(_L("Searching through the database for entry")); |
|
172 |
|
173 CContactIdArray* ret=iDatabase->FindLC(ptrKey, iFieldDef); |
|
174 CleanupStack::Pop(ret); |
|
175 return ret; |
|
176 } |