|
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 CTestCreateBookmarkItemsStep class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 // System Include |
|
24 #include <bookmarkdatabase.h> |
|
25 |
|
26 // User Include |
|
27 #include "TestCreateBookmarkItemsStep.h" |
|
28 |
|
29 /** |
|
30 Constructor. Sets the test step name |
|
31 @internalTechnology |
|
32 @test |
|
33 */ |
|
34 CTestCreateBookmarkItemsStep::CTestCreateBookmarkItemsStep(CTestBookmarksServer& aTestServer) : CTestBookmarksBaseStep(aTestServer) |
|
35 { |
|
36 //Call base class method to set human readable name for test step |
|
37 SetTestStepName(KTestCreateBookmarkItemsStep); |
|
38 } |
|
39 |
|
40 |
|
41 /** |
|
42 Base class pure virtual. |
|
43 @internalTechnology |
|
44 @test |
|
45 @param None |
|
46 @return EPass or EFail indicating the result of the test step. |
|
47 */ |
|
48 TVerdict CTestCreateBookmarkItemsStep::doTestStepL() |
|
49 { |
|
50 TPtrC typeOfItem; |
|
51 TPtrC title; |
|
52 TPtrC parent; |
|
53 if(!GetStringFromConfig(ConfigSection(), KIniTypeOfItem, typeOfItem ) || |
|
54 !GetStringFromConfig(ConfigSection(), KIniTitle, title ) || |
|
55 !GetStringFromConfig(ConfigSection(), KIniParent, parent ) |
|
56 ) |
|
57 { |
|
58 ERR_PRINTF4(_L("Problem in reading values from ini. \ |
|
59 \nExpected fields are: \n%S\n%S\n%S\n" |
|
60 ),&KIniTypeOfItem, &KIniTitle, &KIniParent |
|
61 ); |
|
62 SetTestStepResult(EFail); |
|
63 } |
|
64 else |
|
65 { |
|
66 TRAPD(error, DoTestL(typeOfItem, title, parent)); |
|
67 if(error != KErrNone) |
|
68 { |
|
69 ERR_PRINTF2(_L("Error occured in CTestCreateBookmarkItemsStep::DoTestL"), error); |
|
70 SetTestStepResult(EFail); |
|
71 } |
|
72 } |
|
73 return TestStepResult(); |
|
74 } // doTestStepL |
|
75 |
|
76 /** |
|
77 Performs the actual test. Creates the bookmark item. |
|
78 @internalTechnology |
|
79 @test |
|
80 @param Descriptor indicating type of item |
|
81 @param Descriptor indicating title of item to be created |
|
82 @param Title of parent folder under which current item is to be created |
|
83 @return None |
|
84 */ |
|
85 void CTestCreateBookmarkItemsStep::DoTestL(const TPtrC& aTypeOfItem, const TPtrC& aTitle, const TPtrC& aParent) |
|
86 { |
|
87 TInt err = KErrNone; |
|
88 Bookmark::TItemId id; |
|
89 RBkFolder parentFolder; |
|
90 if ((err = GetParentFolder(aParent, parentFolder)) != KErrNone) |
|
91 { |
|
92 ERR_PRINTF3(_L("Error %D occured while opening parent folder %S"), err, &aParent); |
|
93 SetTestStepResult(EFail); |
|
94 return; |
|
95 } |
|
96 CleanupClosePushL(parentFolder); |
|
97 RBkNode bkNode; |
|
98 |
|
99 if(aTypeOfItem == KFolder) |
|
100 {// Folder |
|
101 TRAP(err, bkNode = iBkDb.CreateFolderL(aTitle, &parentFolder)); |
|
102 } |
|
103 else |
|
104 {// Bookmark |
|
105 TRAP(err, bkNode = iBkDb.CreateBookmarkL(&parentFolder)); |
|
106 } |
|
107 if(err == KErrNone) |
|
108 {// Creation successful, commit. |
|
109 INFO_PRINTF2(_L("Creating item : %U"), bkNode.Id()); |
|
110 CleanupClosePushL(bkNode); |
|
111 id = bkNode.Id(); |
|
112 INFO_PRINTF2(_L("Id of item created = %U"), id); |
|
113 AppendArraysL(bkNode.Id(), aTitle); |
|
114 CommitDb(); |
|
115 CleanupStack::PopAndDestroy(&bkNode); |
|
116 } |
|
117 else |
|
118 {// Error occured |
|
119 if(err == Bookmark::KErrTitleAlreadyUsed && aTitle == KMainTestFolder) |
|
120 { |
|
121 INFO_PRINTF1(_L("Main folder already exists")); |
|
122 } |
|
123 else |
|
124 { |
|
125 // Creation failed |
|
126 ERR_PRINTF2(_L("Error occured while creating item : %D"), err); |
|
127 SetTestStepError(err); |
|
128 } |
|
129 } |
|
130 CleanupStack::PopAndDestroy(&parentFolder); |
|
131 } // DoTestL |
|
132 |
|
133 /** |
|
134 Update the arrays with the id and title of item created |
|
135 @internalTechnology |
|
136 @test |
|
137 @param Id of the item to be appended in id array |
|
138 @param Title of the item to be appended in titles array |
|
139 @return None |
|
140 */ |
|
141 void CTestCreateBookmarkItemsStep::AppendArraysL(const Bookmark::TItemId& aId, const TPtrC& aTitle) |
|
142 { |
|
143 // Append id |
|
144 iTestServer.iIds.AppendL(aId); |
|
145 |
|
146 // Append title after allocating a new replica on the heap |
|
147 // as the pointer returned by GetStingConfig() is destroyed when this |
|
148 // test step perishes |
|
149 HBufC* hBufC = aTitle.AllocLC(); |
|
150 iTestServer.iTitles.AppendL(hBufC); |
|
151 CleanupStack::Pop(hBufC); |
|
152 } // AppendArraysL |
|
153 |