|
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 // Contains implementation of CTestSetPropertyStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // System Includes |
|
24 #include <bookmarkdatabase.h> |
|
25 #include <escapeutils.h> |
|
26 #include <cauthentication.h> |
|
27 |
|
28 // User Include |
|
29 #include "TestSetPropertyStep.h" |
|
30 |
|
31 /** |
|
32 Constructor. Sets the test step name |
|
33 @internalTechnology |
|
34 @test |
|
35 */ |
|
36 CTestSetPropertyStep::CTestSetPropertyStep(CTestBookmarksServer& aTestServer) : CTestBookmarksBaseStep(aTestServer) |
|
37 { |
|
38 //Call base class method to set human readable name for test step |
|
39 SetTestStepName(KTestSetPropertyStep); |
|
40 } |
|
41 |
|
42 |
|
43 /** |
|
44 Base class pure virtual. |
|
45 @internalTechnology |
|
46 @test |
|
47 @param None |
|
48 @return EPass or EFail indicating the result of the test step. |
|
49 */ |
|
50 TVerdict CTestSetPropertyStep::doTestStepL() |
|
51 { |
|
52 TInt property; |
|
53 TPtrC value; |
|
54 if(!GetIntFromConfig(ConfigSection(), KIniProperty, property ) || |
|
55 (!GetStringFromConfig(ConfigSection(), KIniValue, value ) && property != EBookmarkAuth) |
|
56 ) |
|
57 { |
|
58 ERR_PRINTF3(_L("Problem in reading values from ini. \ |
|
59 \nExpected fields are: \n%S\n%S\n" |
|
60 ),&KIniProperty, &KIniValue |
|
61 ); |
|
62 SetTestStepResult(EFail); |
|
63 } |
|
64 else |
|
65 { |
|
66 TRAPD(error, DoTestL(property, value)); |
|
67 if(error != KErrNone) |
|
68 { |
|
69 ERR_PRINTF2(_L("Error occured in CTestSetPropertyStep::DoTestL"), error); |
|
70 SetTestStepResult(EFail); |
|
71 } |
|
72 } |
|
73 return TestStepResult(); |
|
74 } // doTestStepL |
|
75 |
|
76 /** |
|
77 Checks whether DB or item property is to be set and calls the appropriate |
|
78 function |
|
79 @internalTechnology |
|
80 @test |
|
81 @param Enumeration indicating the property to be set |
|
82 @param Value to be set for the property |
|
83 @return None |
|
84 */ |
|
85 void CTestSetPropertyStep::DoTestL(const TInt& aProperty, const TPtrC& aValue) |
|
86 { |
|
87 TPtrC title; |
|
88 TPtrC typeOfItem; |
|
89 if(aProperty < KDbGeneralPropertiesStart) |
|
90 {// Item property |
|
91 if(!GetStringFromConfig(ConfigSection(), KIniTitle, title ) || |
|
92 !GetStringFromConfig(ConfigSection(), KIniTypeOfItem, typeOfItem ) |
|
93 ) |
|
94 { |
|
95 ERR_PRINTF3(_L("%S and %S must also be provided for item property"),&KIniTypeOfItem, &KIniTitle); |
|
96 SetTestStepResult(EFail); |
|
97 } |
|
98 else |
|
99 { |
|
100 TInt error = KErrNone; |
|
101 RBkNode bkNode; |
|
102 if((error = GetBkNode(title, typeOfItem, bkNode)) != KErrNone) |
|
103 { |
|
104 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &title, error); |
|
105 SetTestStepError(error); |
|
106 } |
|
107 else |
|
108 { |
|
109 // Node opened, set the property |
|
110 CleanupClosePushL(bkNode); |
|
111 SetItemPropertyValueL(bkNode, aProperty, aValue); |
|
112 CleanupStack::PopAndDestroy(&bkNode); |
|
113 } |
|
114 } |
|
115 } |
|
116 else |
|
117 {// Database property |
|
118 SetDbPropertyValueL(aProperty, aValue); |
|
119 } |
|
120 } // DoTestL |
|
121 |
|
122 /** |
|
123 Sets an item's property |
|
124 @internalTechnology |
|
125 @test |
|
126 @param Reference to the handle of the node whose property is to be set |
|
127 @param Enumeration indicating the property to be set |
|
128 @param Value to be set for the property |
|
129 @return None |
|
130 */ |
|
131 void CTestSetPropertyStep::SetItemPropertyValueL(RBkNode& aBkNode, const TInt& aProperty, const TPtrC& aValue) |
|
132 { |
|
133 INFO_PRINTF2(_L("Property length = %D"), aValue.Length()); |
|
134 TInt error = KErrNone; |
|
135 switch(aProperty) |
|
136 { |
|
137 case EItemWritable: |
|
138 TRAP(error, aBkNode.SetWritableL(CTestBookmarksServer::GetBool(aValue))); |
|
139 break; |
|
140 case EItemPublic: |
|
141 TRAP(error, aBkNode.SetPublicL(CTestBookmarksServer::GetBool(aValue))); |
|
142 break; |
|
143 case EItemDescription: |
|
144 TRAP(error, aBkNode.SetDescriptionL(aValue)); |
|
145 break; |
|
146 case EItemParent: |
|
147 { |
|
148 error = SetItemParent(aBkNode, aValue); |
|
149 break; |
|
150 } |
|
151 case EItemTitle: |
|
152 TRAP(error, aBkNode.SetTitleL(aValue)); |
|
153 break; |
|
154 case EBookmarkNap: |
|
155 { |
|
156 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
157 TRAP(error, bkBkMrk.SetNapL(CTestBookmarksServer::GetTUint32(aValue))); |
|
158 bkBkMrk.Close(); |
|
159 break; |
|
160 } |
|
161 case EBookmarkProxy: |
|
162 { |
|
163 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
164 TRAP(error, bkBkMrk.SetProxyL(CTestBookmarksServer::GetTUint32(aValue))); |
|
165 bkBkMrk.Close(); |
|
166 break; |
|
167 } |
|
168 case EBookmarkUri: |
|
169 { |
|
170 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
171 CleanupClosePushL(bkBkMrk); |
|
172 // Convert to 8-bit |
|
173 HBufC8* hBufC8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aValue); |
|
174 TRAP(error, bkBkMrk.SetUriL(hBufC8->Des())); |
|
175 delete hBufC8; |
|
176 CleanupStack::PopAndDestroy(&bkBkMrk); |
|
177 break; |
|
178 } |
|
179 case EBookmarkAuth: |
|
180 { |
|
181 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
182 TRAP(error, DoSetAuthenticationL(bkBkMrk)); |
|
183 bkBkMrk.Close(); |
|
184 break; |
|
185 } |
|
186 case EBookmarkLastVisited: |
|
187 { |
|
188 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
189 TTime time(aValue); |
|
190 TRAP(error, bkBkMrk.SetLastVisitedL(time)); |
|
191 bkBkMrk.Close(); |
|
192 break; |
|
193 } |
|
194 case EBookmarkLastModified: |
|
195 { |
|
196 RBkBookmark bkBkMrk = aBkNode.OpenBookmarkL(); |
|
197 TTime time(aValue); |
|
198 TRAP(error, bkBkMrk.SetLastModifiedL(time)); |
|
199 bkBkMrk.Close(); |
|
200 break; |
|
201 } |
|
202 case EItemOwner: |
|
203 TRAP(error, aBkNode.SetOwnerL(CTestBookmarksServer::GetTUint32(aValue))); |
|
204 break; |
|
205 default: |
|
206 INFO_PRINTF2(_L("Invalid property number : %D"), aProperty); |
|
207 SetTestStepResult(EFail); |
|
208 break; |
|
209 } |
|
210 |
|
211 // Examine the result |
|
212 CheckErrorAndCommit(error); |
|
213 } // SetItemPropertyValueL |
|
214 |
|
215 /** |
|
216 Sets the item's parent to a folder with the title passed as parameter |
|
217 @internalTechnology |
|
218 @test |
|
219 @param Reference to the handle to the node whose parent we have to set |
|
220 @param The title of the parent folder to be set |
|
221 @return Error resulting out of the operation, if any. Else, KErrNone |
|
222 */ |
|
223 TInt CTestSetPropertyStep::SetItemParent(RBkNode& aBkNode, const TPtrC& aValue) |
|
224 { |
|
225 TInt error = KErrNone; |
|
226 RBkNode parentNode; |
|
227 if((error = GetBkNode(aValue, KFolder(), parentNode)) != KErrNone) |
|
228 { |
|
229 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &aValue, error); |
|
230 SetTestStepError(error); |
|
231 } |
|
232 else |
|
233 { |
|
234 RBkFolder parentFolder; |
|
235 TRAP(error, parentFolder = parentNode.OpenFolderL()); |
|
236 if(error == KErrNone) |
|
237 { |
|
238 TRAP(error, aBkNode.SetParentL(parentFolder)); |
|
239 parentFolder.Close(); |
|
240 } |
|
241 parentNode.Close(); |
|
242 } |
|
243 return error; |
|
244 } |
|
245 |
|
246 /** |
|
247 Sets a database property |
|
248 @internalTechnology |
|
249 @test |
|
250 @param Enumeration indicating the property to be set |
|
251 @param Value to be set for the property |
|
252 @return None |
|
253 */ |
|
254 void CTestSetPropertyStep::SetDbPropertyValueL(const TInt& aProperty, const TPtrC& aValue) |
|
255 { |
|
256 TInt error = KErrNone; |
|
257 switch(aProperty) |
|
258 { |
|
259 case EDbDefaultNap: |
|
260 iBkDb.SetDefaultNap(CTestBookmarksServer::GetTUint32(aValue)); |
|
261 break; |
|
262 case EDbDefaultProxy: |
|
263 iBkDb.SetDefaultProxy(CTestBookmarksServer::GetTUint32(aValue)); |
|
264 break; |
|
265 case EDbHome: |
|
266 { |
|
267 error = SetHomePageBookmark(aValue); |
|
268 break; |
|
269 } |
|
270 case EDbHomePageText: |
|
271 TRAP(error, iBkDb.SetHomePageTextL(aValue)); |
|
272 break; |
|
273 case EDbSearchUri: |
|
274 { |
|
275 // Convert to 8-bit |
|
276 HBufC8* hBufC8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aValue); |
|
277 TRAP(error, iBkDb.SetSearchUriL(hBufC8->Des())); |
|
278 delete hBufC8; |
|
279 break; |
|
280 } |
|
281 default: |
|
282 INFO_PRINTF2(_L("Invalid property number : %D"), aProperty); |
|
283 SetTestStepResult(EFail); |
|
284 break; |
|
285 } |
|
286 |
|
287 // Examine the result |
|
288 CheckErrorAndCommit(error); |
|
289 } // SetDbPropertyValueL |
|
290 |
|
291 /** |
|
292 Sets the item's homepage bookmark to a bookmark indicated by the parameter |
|
293 @internalTechnology |
|
294 @test |
|
295 @param Descriptor identifying the bookmark to be set as homepage |
|
296 @return Error resulting out of the operation, if any. Else, KErrNone |
|
297 */ |
|
298 TInt CTestSetPropertyStep::SetHomePageBookmark(const TPtrC& aValue) |
|
299 { |
|
300 TInt error = KErrNone; |
|
301 RBkNode bkNode; |
|
302 if((error = GetBkNode(aValue, KBookmark(), bkNode)) != KErrNone) |
|
303 { |
|
304 ERR_PRINTF3(_L("Error occured while opening item %S : %D"), &aValue, error); |
|
305 SetTestStepError(error); |
|
306 } |
|
307 else |
|
308 { |
|
309 CleanupClosePushL(bkNode); |
|
310 RBkBookmark homePageBkMrk = bkNode.OpenBookmarkL(); |
|
311 iBkDb.SetHome(homePageBkMrk); |
|
312 homePageBkMrk.Close(); |
|
313 CleanupStack::PopAndDestroy(&bkNode); |
|
314 } |
|
315 return error; |
|
316 } |
|
317 |
|
318 /** |
|
319 Reads authentication detail from ini, constructs an authentication object |
|
320 and sets it to the bookmark. |
|
321 @internalTechnology |
|
322 @test |
|
323 @param Reference to handle to the bookmark whose auth-params are to be set |
|
324 @return None |
|
325 */ |
|
326 void CTestSetPropertyStep::DoSetAuthenticationL(RBkBookmark& bkBkMrk) |
|
327 { |
|
328 TPtrC name; |
|
329 TPtrC password; |
|
330 |
|
331 if(!GetStringFromConfig(ConfigSection(), KIniAuthName, name ) || |
|
332 !GetStringFromConfig(ConfigSection(), KIniAuthPassword, password ) |
|
333 ) |
|
334 { |
|
335 ERR_PRINTF3(_L("%S and %S must also be mentioned in ini file"),&KIniAuthName, &KIniAuthPassword); |
|
336 SetTestStepResult(EFail); |
|
337 } |
|
338 else |
|
339 { |
|
340 HBufC8* name8 = EscapeUtils::ConvertFromUnicodeToUtf8L(name); |
|
341 CleanupStack::PushL(name8); |
|
342 HBufC8* password8 = EscapeUtils::ConvertFromUnicodeToUtf8L(password); |
|
343 CleanupStack::PushL(password8); |
|
344 |
|
345 TPtrC method; |
|
346 CAuthentication *auth = NULL; |
|
347 // Construct authentication object |
|
348 if(!GetStringFromConfig(ConfigSection(), KIniAuthMethod, method)) |
|
349 { |
|
350 // No method supplied |
|
351 INFO_PRINTF1(_L("No method supplied, calling without method argument")); |
|
352 auth = CAuthentication::NewL(name8->Des(), password8->Des()); |
|
353 } |
|
354 else if(method.Compare(KMethodBasic()) == KErrNone) |
|
355 { |
|
356 auth = CAuthentication::NewL(name8->Des(), password8->Des(), CAuthentication::EBasic); |
|
357 } |
|
358 else if(method.Compare(KMethodDigest()) == KErrNone) |
|
359 { |
|
360 auth = CAuthentication::NewL(name8->Des(), password8->Des(), CAuthentication::EDigest); |
|
361 } |
|
362 else |
|
363 { |
|
364 INFO_PRINTF2(_L("Invalid method %S"), &method); |
|
365 SetTestStepResult(EFail); |
|
366 } |
|
367 |
|
368 if(auth != NULL) |
|
369 { |
|
370 CleanupStack::PushL(auth); |
|
371 // Set the bookmark's authentication object |
|
372 bkBkMrk.SetAuthenticationL(*auth); |
|
373 CleanupStack::PopAndDestroy(auth); |
|
374 } |
|
375 |
|
376 CleanupStack::PopAndDestroy(2, name8); |
|
377 } |
|
378 } // DoSetAuthenticationL |