|
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 // |
|
15 |
|
16 #include <bookmarkdatabase.h> |
|
17 #include "testutils.h" |
|
18 |
|
19 _LIT(KFilename, "tfoldertests.cpp"); |
|
20 |
|
21 _LIT(KTxtSubRootName, "Test sub-root"); |
|
22 _LIT(KTxtFolder2_1, "Folder 2.1"); |
|
23 _LIT(KTxtFolder2_2, "Folder 2.2"); |
|
24 _LIT(KTxtFolder2_3, "Folder 2.3"); |
|
25 _LIT(KTxtFolder2_2_1, "Folder 2.2.1"); |
|
26 |
|
27 const TUid KUid = {0x111}; |
|
28 _LIT8(KData8Bit, "8BitData"); |
|
29 _LIT(KData16Bit, "16BitData"); |
|
30 const TInt KInt = 999; |
|
31 const TReal KReal = 42.999; |
|
32 |
|
33 const TInt KGeneralDelay = 1000 * 1000; |
|
34 |
|
35 _LIT ( KMyFolder, "MyFolder" ); |
|
36 _LIT ( KMyFolderDesc, "Testing last modified time in bookmark." ); |
|
37 _LIT ( KMyFolderNewDesc, "1: Testing last modified time in bookmark." ); |
|
38 |
|
39 LOCAL_D CTestWrapper* gTestWrapper; |
|
40 LOCAL_D RBkDatabase gDatabase; |
|
41 |
|
42 LOCAL_C void CreateFolderL() |
|
43 { |
|
44 gTestWrapper->Next(_L("[Folders tests] unique folder names")); |
|
45 RBkFolder testSubRoot; |
|
46 TRAPD(err, testSubRoot = gDatabase.OpenFolderL(KTxtSubRootName)); |
|
47 gTestWrapper->TEST(err == KErrNotFound); |
|
48 |
|
49 testSubRoot = gDatabase.CreateFolderL(KTxtSubRootName); |
|
50 testSubRoot.Close(); |
|
51 testSubRoot = gDatabase.OpenFolderL(KTxtSubRootName); |
|
52 Bookmark::TItemId subRootId = testSubRoot.Id(); |
|
53 testSubRoot.Close(); |
|
54 |
|
55 gDatabase.CommitL(); |
|
56 |
|
57 RBkFolder duplicate; |
|
58 TRAP(err, duplicate = gDatabase.CreateFolderL(KTxtSubRootName)); |
|
59 gTestWrapper->TESTE(err == Bookmark::KErrTitleAlreadyUsed, err); |
|
60 |
|
61 gDatabase.DeleteItemL(subRootId, ETrue); |
|
62 |
|
63 TRAP(err, testSubRoot = gDatabase.OpenFolderL(KTxtSubRootName)); |
|
64 gTestWrapper->TEST(err == KErrNotFound); |
|
65 |
|
66 RBkFolder root = gDatabase.OpenRootL(); |
|
67 CleanupClosePushL(root); |
|
68 gTestWrapper->TEST(root.Count() == 0); |
|
69 CleanupStack::PopAndDestroy(&root); |
|
70 |
|
71 gDatabase.CommitL(); |
|
72 } |
|
73 |
|
74 LOCAL_C void CreateManyFoldersL() |
|
75 { |
|
76 gTestWrapper->Next(_L("[Folders tests] creating levels of folders")); |
|
77 // Create a sub-root folder |
|
78 RBkFolder subroot; |
|
79 subroot = gDatabase.CreateFolderL(KTxtSubRootName); |
|
80 CleanupClosePushL(subroot); |
|
81 |
|
82 // Create three folders in the sub-root |
|
83 RBkFolder folderL2; |
|
84 folderL2 = gDatabase.CreateFolderL(KTxtFolder2_1, &subroot); |
|
85 folderL2.Close(); |
|
86 |
|
87 folderL2 = gDatabase.CreateFolderL(KTxtFolder2_2, &subroot); |
|
88 CleanupClosePushL(folderL2); |
|
89 // Create a folder in folder 2.2 |
|
90 RBkFolder folderL3; |
|
91 folderL3 = gDatabase.CreateFolderL(KTxtFolder2_2_1, &folderL2); |
|
92 folderL3.Close(); |
|
93 CleanupStack::PopAndDestroy(&folderL2); |
|
94 |
|
95 folderL2 = gDatabase.CreateFolderL(KTxtFolder2_3, &subroot); |
|
96 folderL2.Close(); |
|
97 |
|
98 CleanupStack::PopAndDestroy(&subroot); |
|
99 |
|
100 // Check that there are three folders in the sub-root |
|
101 RBkFolder folder = gDatabase.OpenFolderL(KTxtSubRootName); |
|
102 gTestWrapper->TEST(folder.Count() == 3); |
|
103 folder.Close(); |
|
104 |
|
105 // Check that there is a folder in the folder 2.2 |
|
106 folder = gDatabase.OpenFolderL(KTxtFolder2_2); |
|
107 gTestWrapper->TEST(folder.Count() == 1); |
|
108 Bookmark::TItemId id = folder.Id(); |
|
109 folder.Close(); |
|
110 |
|
111 // Delete folder 2.2. The default action is dump any children to the root folder |
|
112 gDatabase.DeleteItemL(id); |
|
113 |
|
114 // Check that folder 2.2 can not be found |
|
115 TRAPD(error, folder = gDatabase.OpenFolderL(KTxtFolder2_2)); |
|
116 gTestWrapper->TEST(error == KErrNotFound); |
|
117 |
|
118 // There should now be 2 folders in the sub-root |
|
119 folder = gDatabase.OpenFolderL(KTxtSubRootName); |
|
120 gTestWrapper->TEST(folder.Count() == 2); |
|
121 folder.Close(); |
|
122 |
|
123 // The folder 2.2.1 should now be in the root |
|
124 // Check it exists and check that it's parent is the root |
|
125 folder = gDatabase.OpenFolderL(KTxtFolder2_2_1); |
|
126 CleanupClosePushL(folder); |
|
127 subroot = folder.OpenParentL(); |
|
128 CleanupClosePushL(subroot); |
|
129 gTestWrapper->TEST(subroot.Title().Compare(Bookmark::KTxtRootTitle) == 0); |
|
130 CleanupStack::PopAndDestroy(2); |
|
131 |
|
132 // Get the sub-root and delete it with all it's children |
|
133 subroot = gDatabase.OpenFolderL(KTxtSubRootName); |
|
134 id = subroot.Id(); |
|
135 subroot.Close(); |
|
136 gDatabase.DeleteItemL(id, ETrue); |
|
137 |
|
138 // There should now be only one item in the root |
|
139 // delete it |
|
140 folder = gDatabase.OpenRootL(); |
|
141 gTestWrapper->TEST(folder.Count() == 1); |
|
142 folder.Close(); |
|
143 folder = gDatabase.OpenFolderL(KTxtFolder2_2_1); |
|
144 id = folder.Id(); |
|
145 folder.Close(); |
|
146 gDatabase.DeleteItemL(id, ETrue); |
|
147 } |
|
148 |
|
149 |
|
150 LOCAL_D void MoveBookmarksTest() |
|
151 { |
|
152 RBkFolder root; |
|
153 root = gDatabase.OpenRootL(); |
|
154 CleanupClosePushL(root); |
|
155 gTestWrapper->TEST(root.Count() == 0); |
|
156 |
|
157 RBkFolder folder1 = gDatabase.CreateFolderL(KTxtFolder2_1); |
|
158 CleanupClosePushL(folder1); |
|
159 RBkFolder folder2 = gDatabase.CreateFolderL(KTxtFolder2_2); |
|
160 CleanupClosePushL(folder2); |
|
161 |
|
162 RBkBookmark bookmark = gDatabase.CreateBookmarkL(&folder1); |
|
163 CleanupClosePushL(bookmark); |
|
164 Bookmark::TItemId id1 = bookmark.Id(); |
|
165 CleanupStack::PopAndDestroy(&bookmark); |
|
166 |
|
167 bookmark = gDatabase.CreateBookmarkL(&folder1); |
|
168 CleanupClosePushL(bookmark); |
|
169 Bookmark::TItemId id2 = bookmark.Id(); |
|
170 CleanupStack::PopAndDestroy(&bookmark); |
|
171 |
|
172 bookmark = gDatabase.CreateBookmarkL(&folder2); |
|
173 CleanupClosePushL(bookmark); |
|
174 Bookmark::TItemId id3 = bookmark.Id(); |
|
175 CleanupStack::PopAndDestroy(&bookmark); |
|
176 |
|
177 bookmark = gDatabase.CreateBookmarkL(&folder2); |
|
178 CleanupClosePushL(bookmark); |
|
179 Bookmark::TItemId id4 = bookmark.Id(); |
|
180 CleanupStack::PopAndDestroy(&bookmark); |
|
181 |
|
182 gTestWrapper->TEST(folder1.Count() == 2); |
|
183 gTestWrapper->TEST(folder2.Count() == 2); |
|
184 |
|
185 RBkNode item = folder1.OpenItemL(0); |
|
186 CleanupClosePushL(item); |
|
187 folder2.AppendL(item); |
|
188 CleanupStack::PopAndDestroy(&item); |
|
189 |
|
190 gTestWrapper->TEST(folder1.Count() == 1); |
|
191 gTestWrapper->TEST(folder2.Count() == 3); |
|
192 |
|
193 folder2.Move(0,2); |
|
194 |
|
195 item = folder2.OpenItemL(0); |
|
196 CleanupClosePushL(item); |
|
197 folder1.InsertL(item, 0); |
|
198 CleanupStack::PopAndDestroy(&item); |
|
199 |
|
200 gTestWrapper->TEST(folder1.Count() == 2); |
|
201 gTestWrapper->TEST(folder2.Count() == 2); |
|
202 |
|
203 item = folder1.OpenItemL(0); |
|
204 CleanupClosePushL(item); |
|
205 gTestWrapper->TEST(item.Id() == id4); |
|
206 CleanupStack::PopAndDestroy(&item); |
|
207 |
|
208 item = folder1.OpenItemL(1); |
|
209 CleanupClosePushL(item); |
|
210 gTestWrapper->TEST(item.Id() == id2); |
|
211 CleanupStack::PopAndDestroy(&item); |
|
212 |
|
213 item = folder2.OpenItemL(0); |
|
214 CleanupClosePushL(item); |
|
215 gTestWrapper->TEST(item.Id() == id1); |
|
216 CleanupStack::PopAndDestroy(&item); |
|
217 |
|
218 item = folder2.OpenItemL(1); |
|
219 CleanupClosePushL(item); |
|
220 gTestWrapper->TEST(item.Id() == id3); |
|
221 CleanupStack::PopAndDestroy(&item); |
|
222 |
|
223 CleanupStack::PopAndDestroy(2); //folders |
|
224 CleanupStack::PopAndDestroy(&root); |
|
225 } |
|
226 |
|
227 LOCAL_D void RootFolderTestL() |
|
228 { |
|
229 gTestWrapper->Next(_L("[Folders tests] root folder tests")); |
|
230 |
|
231 RBkFolder root; |
|
232 root = gDatabase.OpenRootL(); |
|
233 CleanupClosePushL(root); |
|
234 |
|
235 TRAPD(err, root.SetTitleL(KTxtSubRootName)); |
|
236 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
237 TRAP(err, root.SetDescriptionL(KTxtSubRootName)); |
|
238 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
239 TRAP(err, root.SetPublicL(EFalse)); |
|
240 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
241 TRAP(err, root.SetWritableL(EFalse)); |
|
242 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
243 TRAP(err, root.SetOwnerL(0x0001234)); |
|
244 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
245 TRAP(err, root.SetIconIdL(EFalse)); |
|
246 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
247 TRAP(err, root.SetCustomPropertyL(KUid, KInt)); |
|
248 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
249 TRAP(err, root.SetCustomPropertyL(KUid, KReal)); |
|
250 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
251 TRAP(err, root.SetCustomPropertyL(KUid, KData8Bit)); |
|
252 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
253 TRAP(err, root.SetCustomPropertyL(KUid, KData16Bit)); |
|
254 gTestWrapper->TESTE(err == Bookmark::KErrOperationDenied, err); |
|
255 |
|
256 CleanupStack::PopAndDestroy(&root); |
|
257 } |
|
258 |
|
259 LOCAL_D void TestBKLastModifiedTimeL () |
|
260 { |
|
261 TTime currentTime; |
|
262 |
|
263 RBkDatabase db; |
|
264 db.OpenL (); |
|
265 CleanupClosePushL ( db ); |
|
266 // Create a new folder. |
|
267 RBkFolder folder = db.CreateFolderL ( KMyFolder ); |
|
268 CleanupClosePushL ( folder ); |
|
269 folder.SetDescriptionL ( KMyFolderDesc ); |
|
270 |
|
271 db.CommitL(); // Commit the transaction. |
|
272 User::After ( KGeneralDelay ); |
|
273 currentTime.HomeTime (); |
|
274 gTestWrapper->TEST( folder.LastModifiedL() < currentTime ); // Creation time. |
|
275 TTime newTime; |
|
276 newTime.HomeTime (); |
|
277 TRAPD( err, folder.SetLastModifiedL( newTime ) ); |
|
278 // Should leave with KErrPermissionDenied error |
|
279 gTestWrapper->TESTE( err == KErrPermissionDenied, err ); |
|
280 |
|
281 CleanupStack::PopAndDestroy ( &folder ); // destroy/close |
|
282 // Open the above created folder. |
|
283 folder = db.OpenFolderL ( KMyFolder ); |
|
284 CleanupClosePushL ( folder ); |
|
285 folder.SetDescriptionL ( KMyFolderNewDesc ); |
|
286 |
|
287 db.CommitL (); |
|
288 User::After ( KGeneralDelay ); |
|
289 currentTime.HomeTime (); |
|
290 gTestWrapper->TEST( folder.LastModifiedL() < currentTime ); // Save time. |
|
291 |
|
292 Bookmark::TItemId id = folder.Id(); |
|
293 CleanupStack::PopAndDestroy ( &folder ); |
|
294 db.DeleteItemL ( id ); // mark for deleting |
|
295 db.CommitL (); |
|
296 |
|
297 CleanupStack::PopAndDestroy ( &db ); |
|
298 } |
|
299 |
|
300 LOCAL_D void TestBKLastModifiedTime1L () |
|
301 { |
|
302 RBkDatabase db; |
|
303 db.OpenL (); |
|
304 CleanupClosePushL ( db ); |
|
305 |
|
306 // Create a new folder. |
|
307 RBkFolder folder = db.CreateFolderL ( KMyFolder ); |
|
308 CleanupClosePushL ( folder ); |
|
309 folder.SetDescriptionL ( KMyFolderDesc ); |
|
310 |
|
311 db.CommitL(); // Commit the transaction. |
|
312 |
|
313 TTime modifiedTime = folder.LastModifiedL (); |
|
314 |
|
315 CleanupStack::PopAndDestroy ( &folder ); |
|
316 CleanupStack::PopAndDestroy ( &db ); // close the db |
|
317 |
|
318 // re-open it |
|
319 db.OpenL (); |
|
320 CleanupClosePushL ( db ); |
|
321 folder = db.OpenFolderL ( KMyFolder ); |
|
322 CleanupClosePushL ( folder ); |
|
323 gTestWrapper->TEST ( modifiedTime == folder.LastModifiedL() ); |
|
324 |
|
325 Bookmark::TItemId id = folder.Id(); |
|
326 CleanupStack::PopAndDestroy ( &folder ); |
|
327 db.DeleteItemL ( id ); // mark for deleting |
|
328 db.CommitL (); |
|
329 |
|
330 CleanupStack::PopAndDestroy ( &db ); |
|
331 } |
|
332 void DoFolderTestsL(CTestWrapper* aTest) |
|
333 { |
|
334 gTestWrapper = aTest; |
|
335 gTestWrapper->SetFile(KFilename); |
|
336 gTestWrapper->Next(_L("*** Folder tests ***")); |
|
337 |
|
338 gDatabase.OpenL(); |
|
339 CleanupClosePushL(gDatabase); |
|
340 |
|
341 CreateFolderL(); |
|
342 CreateManyFoldersL(); |
|
343 RootFolderTestL(); |
|
344 |
|
345 MoveBookmarksTest(); |
|
346 |
|
347 TestBKLastModifiedTimeL (); |
|
348 TestBKLastModifiedTime1L (); |
|
349 |
|
350 CleanupStack::PopAndDestroy(&gDatabase); |
|
351 } |