|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Main test class for hspluginmodel library. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "t_caclient.h" |
|
20 #include "caservice.h" |
|
21 #include "caquery.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 void TestCaClient::TestCreateItem() |
|
27 { |
|
28 { |
|
29 const CaEntry constItem; |
|
30 QCOMPARE(constItem.role(), ItemEntryRole); |
|
31 |
|
32 //create item |
|
33 //check if proper entry returned |
|
34 CaEntry item; |
|
35 item.setText("testName"); |
|
36 item.setAttribute("attrName1", "attrVal1"); |
|
37 item.setEntryTypeName("test"); |
|
38 item.setFlags(RemovableEntryFlag); |
|
39 item.setDescription("description"); |
|
40 CaIconDescription iconDescription; |
|
41 iconDescription.setFilename("iconFileName"); |
|
42 iconDescription.setSkinId("iconSkinId"); |
|
43 iconDescription.setApplicationId("268458321"); |
|
44 |
|
45 item.setIconDescription(iconDescription); |
|
46 |
|
47 QSharedPointer<CaService> service = CaService::instance(); |
|
48 QSharedPointer<CaEntry> resultItem = service->createEntry(item); |
|
49 QCOMPARE(service->lastError(), NoErrorCode); |
|
50 QVERIFY(!resultItem.isNull()); |
|
51 QCOMPARE(resultItem->role(), ItemEntryRole); |
|
52 QCOMPARE(item.text(),resultItem->text()); |
|
53 QCOMPARE(item.description(),resultItem->description()); |
|
54 QCOMPARE(item.entryTypeName(),resultItem->entryTypeName()); |
|
55 QCOMPARE(QString("attrVal1"),resultItem->attribute("attrName1")); |
|
56 QCOMPARE(item.flags(),resultItem->flags()); |
|
57 int itId =item.id(); |
|
58 int resItId =resultItem->id(); |
|
59 QVERIFY(itId != resItId); |
|
60 QCOMPARE(iconDescription.filename(),resultItem->iconDescription().filename()); |
|
61 QCOMPARE(iconDescription.skinId(),resultItem->iconDescription().skinId()); |
|
62 QCOMPARE(iconDescription.applicationId(),resultItem->iconDescription().applicationId()); |
|
63 |
|
64 // entry from storage |
|
65 QSharedPointer<CaEntry> storageItem1 = service->getEntry(resultItem->id()); |
|
66 QVERIFY(storageItem1); |
|
67 QCOMPARE(QString("testName"),storageItem1->text()); |
|
68 QCOMPARE(QString("description"),storageItem1->description()); |
|
69 QCOMPARE(QString("test"),storageItem1->entryTypeName()); |
|
70 QCOMPARE(QString("attrVal1"),storageItem1->attribute("attrName1")); |
|
71 EntryFlags flags = item.flags(); |
|
72 EntryFlags storageFlags = storageItem1->flags(); |
|
73 QCOMPARE(iconDescription.filename(),storageItem1->iconDescription().filename()); |
|
74 QCOMPARE(iconDescription.skinId(),storageItem1->iconDescription().skinId()); |
|
75 QCOMPARE(iconDescription.applicationId(),storageItem1->iconDescription().applicationId()); |
|
76 QVERIFY(storageItem1->iconDescription().id() > 0); |
|
77 |
|
78 QCOMPARE(flags ,storageFlags); |
|
79 |
|
80 //Cleanup |
|
81 service->removeEntry(*resultItem); |
|
82 } |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void TestCaClient::TestCreateItemNotAllParams() |
|
89 { |
|
90 { |
|
91 //create item |
|
92 //check if proper entry returned |
|
93 CaEntry item; |
|
94 QSharedPointer<CaService> service = CaService::instance(); |
|
95 QSharedPointer<CaEntry> resultItem1 = service->createEntry(item); |
|
96 QVERIFY(resultItem1.isNull()); |
|
97 QVERIFY(service->lastError() != NoErrorCode); |
|
98 item.setText("text"); |
|
99 QSharedPointer<CaEntry> resultItem2 = service->createEntry(item); |
|
100 QVERIFY(resultItem2.isNull()); |
|
101 QVERIFY(service->lastError() != NoErrorCode); |
|
102 item.setEntryTypeName("type"); |
|
103 item.setText(""); |
|
104 QSharedPointer<CaEntry> resultItem3 = service->createEntry(item); |
|
105 QVERIFY(resultItem3.isNull()); |
|
106 QVERIFY(service->lastError() != NoErrorCode); |
|
107 item.setText("text"); |
|
108 QSharedPointer<CaEntry> resultItem4 = service->createEntry(item); |
|
109 QVERIFY(!resultItem4.isNull()); |
|
110 QCOMPARE(service->lastError() , NoErrorCode); |
|
111 |
|
112 //Cleanup |
|
113 service->removeEntry(*resultItem4); |
|
114 } |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void TestCaClient::TestCreateGroup() |
|
121 { |
|
122 { |
|
123 const CaEntry constGroup(GroupEntryRole); |
|
124 QCOMPARE(constGroup.role(), GroupEntryRole); |
|
125 |
|
126 //create group |
|
127 //check if proper entry returned |
|
128 CaEntry group(GroupEntryRole); |
|
129 group.setText("testName"); |
|
130 group.setAttribute("attrName1", "attrVal1"); |
|
131 group.setEntryTypeName("test"); |
|
132 group.setFlags(RemovableEntryFlag); |
|
133 CaIconDescription iconDescription; |
|
134 iconDescription.setFilename("iconFileName"); |
|
135 iconDescription.setSkinId("iconSkinId"); |
|
136 iconDescription.setApplicationId("268458321"); |
|
137 group.setIconDescription(iconDescription); |
|
138 |
|
139 QSharedPointer<CaService> service = CaService::instance(); |
|
140 QSharedPointer<CaEntry> resultGroup = service->createEntry(group); |
|
141 QCOMPARE(service->lastError(), NoErrorCode); |
|
142 |
|
143 QVERIFY(!resultGroup.isNull()); |
|
144 QCOMPARE(resultGroup->role(), GroupEntryRole); |
|
145 |
|
146 QCOMPARE(group.text(),resultGroup->text()); |
|
147 QCOMPARE(group.entryTypeName(),resultGroup->entryTypeName()); |
|
148 QCOMPARE(QString("attrVal1"),resultGroup->attribute("attrName1")); |
|
149 QCOMPARE(group.flags(),resultGroup->flags()); |
|
150 QVERIFY(group.id() != resultGroup->id()); |
|
151 QCOMPARE(iconDescription.filename(),resultGroup->iconDescription().filename()); |
|
152 QCOMPARE(iconDescription.skinId(),resultGroup->iconDescription().skinId()); |
|
153 QCOMPARE(iconDescription.applicationId(),resultGroup->iconDescription().applicationId()); |
|
154 |
|
155 // entry from storage |
|
156 QSharedPointer<CaEntry> storageGroup1 = service->getEntry(resultGroup->id()); |
|
157 QVERIFY(!storageGroup1.isNull()); |
|
158 QCOMPARE(QString("testName"),storageGroup1->text()); |
|
159 QCOMPARE(QString("test"),storageGroup1->entryTypeName()); |
|
160 QCOMPARE(QString("attrVal1"),storageGroup1->attribute("attrName1")); |
|
161 QCOMPARE(group.flags(),storageGroup1->flags()); |
|
162 QCOMPARE(iconDescription.filename(),storageGroup1->iconDescription().filename()); |
|
163 QCOMPARE(iconDescription.skinId(),storageGroup1->iconDescription().skinId()); |
|
164 QCOMPARE(iconDescription.applicationId(),storageGroup1->iconDescription().applicationId()); |
|
165 //Cleanup |
|
166 service->removeEntry(*resultGroup); |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void TestCaClient::TestCreateGroupNotAllParams() |
|
174 { |
|
175 { |
|
176 //create group |
|
177 //check if proper entry returned |
|
178 CaEntry group(GroupEntryRole); |
|
179 QSharedPointer<CaService> service = CaService::instance(); |
|
180 QSharedPointer<CaEntry> result1 = service->createEntry(group); |
|
181 QVERIFY(result1.isNull()); |
|
182 QVERIFY(service->lastError() != NoErrorCode); |
|
183 group.setText("text"); |
|
184 QSharedPointer<CaEntry> result2 = service->createEntry(group); |
|
185 QVERIFY(result2.isNull()); |
|
186 QVERIFY(service->lastError() != NoErrorCode); |
|
187 group.setEntryTypeName("type"); |
|
188 group.setText(""); |
|
189 QSharedPointer<CaEntry> result3 = service->createEntry(group); |
|
190 QVERIFY(result3.isNull()); |
|
191 QVERIFY(service->lastError() != NoErrorCode); |
|
192 group.setText("text"); |
|
193 QSharedPointer<CaEntry> result4 = service->createEntry(group); |
|
194 QVERIFY(!result4.isNull() ); |
|
195 QCOMPARE(service->lastError() , NoErrorCode); |
|
196 |
|
197 //Cleanup |
|
198 service->removeEntry(*result4); |
|
199 } |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void TestCaClient::TestUpdateItem() |
|
206 { |
|
207 { |
|
208 CaEntry item1; |
|
209 item1.setText("testName"); |
|
210 item1.setAttribute("attrName1", "attrVal1"); |
|
211 item1.setEntryTypeName("test"); |
|
212 item1.setFlags(RemovableEntryFlag); |
|
213 CaIconDescription iconDescription1; |
|
214 iconDescription1.setFilename("iconFileName"); |
|
215 iconDescription1.setSkinId("iconSkinId"); |
|
216 iconDescription1.setApplicationId("268458321"); //Bluetouth app UID |
|
217 item1.setIconDescription(iconDescription1); |
|
218 |
|
219 CaIconDescription iconDescription2; |
|
220 iconDescription2.setFilename("iconFileName2"); |
|
221 iconDescription2.setSkinId("iconSkinId2"); |
|
222 iconDescription2.setApplicationId("537001519"); //SW update app UID |
|
223 |
|
224 QSharedPointer<CaService> service = CaService::instance(); |
|
225 QSharedPointer<CaEntry> resultItem1 = service->createEntry(item1); |
|
226 QCOMPARE(service->lastError(), NoErrorCode); |
|
227 |
|
228 QVERIFY(!resultItem1.isNull()); |
|
229 |
|
230 int id1 = resultItem1->id(); |
|
231 resultItem1->setText("testName2"); |
|
232 resultItem1->setAttribute("attrName2", "attrVal2"); |
|
233 resultItem1->setAttribute("attrName1", "attrVal2"); |
|
234 resultItem1->setEntryTypeName("test2"); |
|
235 resultItem1->setFlags(UninstallEntryFlag); |
|
236 resultItem1->setIconDescription(iconDescription2); |
|
237 |
|
238 bool updateResult1 = service->updateEntry(item1); |
|
239 QVERIFY(service->lastError() != NoErrorCode); |
|
240 |
|
241 QVERIFY(!updateResult1); // no id -> return false |
|
242 |
|
243 bool updateResult2 = service->updateEntry(*resultItem1); |
|
244 QCOMPARE(service->lastError(), NoErrorCode); |
|
245 QVERIFY(updateResult2); // id present -> true |
|
246 |
|
247 QSharedPointer<CaEntry> resultItem2 = service->createEntry(*resultItem1); |
|
248 QCOMPARE(service->lastError(), NoErrorCode); |
|
249 QVERIFY(!resultItem2.isNull()); |
|
250 |
|
251 int id2 = resultItem2->id(); |
|
252 QVERIFY(id1 != id2); //entry clone created |
|
253 |
|
254 QSharedPointer<CaEntry> storageItem1 = service->getEntry(id1); |
|
255 QVERIFY(!storageItem1.isNull()); |
|
256 |
|
257 QSharedPointer<CaEntry> storageItem2 = service->getEntry(id2); |
|
258 QVERIFY(!storageItem2.isNull()); |
|
259 |
|
260 // check if attributes were updated |
|
261 QCOMPARE(QString("testName2"),storageItem1->text()); |
|
262 QCOMPARE(QString("test2"),storageItem1->entryTypeName()); |
|
263 |
|
264 QCOMPARE(QString("attrVal2"),storageItem1->attribute("attrName1")); |
|
265 QCOMPARE(QString("attrVal2"),storageItem1->attribute("attrName2")); |
|
266 QCOMPARE(resultItem1->flags(),storageItem1->flags()); |
|
267 QCOMPARE(iconDescription2.filename(),storageItem1->iconDescription().filename()); |
|
268 QCOMPARE(iconDescription2.skinId(),storageItem1->iconDescription().skinId()); |
|
269 QCOMPARE(iconDescription2.applicationId(),storageItem1->iconDescription().applicationId()); |
|
270 // cloned item should have the same attributes |
|
271 QCOMPARE(QString("testName2"),storageItem2->text()); |
|
272 QCOMPARE(QString("test2"),storageItem2->entryTypeName()); |
|
273 QCOMPARE(QString("attrVal2"),storageItem2->attribute("attrName1")); |
|
274 QCOMPARE(QString("attrVal2"),storageItem2->attribute("attrName2")); |
|
275 QCOMPARE(resultItem1->flags(),storageItem2->flags()); |
|
276 |
|
277 //Cleanup |
|
278 service->removeEntry(id1); |
|
279 service->removeEntry(id2); |
|
280 } |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void TestCaClient::TestUpdateGroup() |
|
287 { |
|
288 { |
|
289 CaEntry group1(GroupEntryRole); |
|
290 group1.setText("testName"); |
|
291 group1.setAttribute("attrName1", "attrVal1"); |
|
292 group1.setEntryTypeName("test"); |
|
293 group1.setFlags(RemovableEntryFlag); |
|
294 CaIconDescription iconDescription1; |
|
295 iconDescription1.setFilename("iconFileName"); |
|
296 iconDescription1.setSkinId("iconSkinId"); |
|
297 iconDescription1.setApplicationId("268458321"); |
|
298 group1.setIconDescription(iconDescription1); |
|
299 CaIconDescription iconDescription2; |
|
300 iconDescription2.setFilename("iconFileName2"); |
|
301 iconDescription2.setSkinId("iconSkinId2"); |
|
302 iconDescription2.setApplicationId("537001519"); |
|
303 |
|
304 QSharedPointer<CaService> service = CaService::instance(); |
|
305 QSharedPointer<CaEntry> resultGroup1 = service->createEntry(group1); |
|
306 QCOMPARE(service->lastError(), NoErrorCode); |
|
307 QVERIFY(!resultGroup1.isNull()); |
|
308 |
|
309 int id1 = resultGroup1->id(); |
|
310 resultGroup1->setText("testName2"); |
|
311 resultGroup1->setAttribute("attrName2", "attrVal2"); |
|
312 resultGroup1->setEntryTypeName("test2"); |
|
313 resultGroup1->setFlags(UninstallEntryFlag); |
|
314 resultGroup1->setIconDescription(iconDescription2); |
|
315 |
|
316 bool updateResult1 = service->updateEntry(group1); |
|
317 QVERIFY(!updateResult1); // no id -> return false |
|
318 QVERIFY(service->lastError() != NoErrorCode); |
|
319 |
|
320 |
|
321 bool updateResult2 = service->updateEntry(*resultGroup1); |
|
322 QCOMPARE(service->lastError(), NoErrorCode); |
|
323 QVERIFY(updateResult2); // id present -> true |
|
324 |
|
325 QSharedPointer<CaEntry> resultGroup2 = service->createEntry(*resultGroup1); |
|
326 QCOMPARE(service->lastError(), NoErrorCode); |
|
327 int id2 = resultGroup2->id(); |
|
328 QVERIFY(id1 != id2); //entry clone created |
|
329 |
|
330 QSharedPointer<CaEntry> storageGroup1 = service->getEntry(id1); |
|
331 QVERIFY(!storageGroup1.isNull()); |
|
332 |
|
333 QSharedPointer<CaEntry> storageGroup2 = service->getEntry(id2); |
|
334 QVERIFY(!storageGroup2.isNull()); |
|
335 |
|
336 // check if attributes were updated |
|
337 QCOMPARE(QString("testName2"),storageGroup1->text()); |
|
338 QCOMPARE(QString("test2"),storageGroup1->entryTypeName()); |
|
339 QCOMPARE(QString("attrVal1"),storageGroup1->attribute("attrName1")); |
|
340 QCOMPARE(QString("attrVal2"),storageGroup1->attribute("attrName2")); |
|
341 QCOMPARE(resultGroup1->flags(),storageGroup1->flags()); |
|
342 QCOMPARE(iconDescription2.filename(),storageGroup1->iconDescription().filename()); |
|
343 QCOMPARE(iconDescription2.skinId(),storageGroup1->iconDescription().skinId()); |
|
344 QCOMPARE(iconDescription2.applicationId(),storageGroup1->iconDescription().applicationId()); |
|
345 // cloned item should have the same attributes |
|
346 QCOMPARE(QString("testName2"),storageGroup2->text()); |
|
347 QCOMPARE(QString("test2"),storageGroup2->entryTypeName()); |
|
348 QCOMPARE(QString("attrVal1"),storageGroup2->attribute("attrName1")); |
|
349 QCOMPARE(QString("attrVal2"),storageGroup2->attribute("attrName2")); |
|
350 QCOMPARE(resultGroup1->flags(),storageGroup2->flags()); |
|
351 |
|
352 //Cleanup |
|
353 service->removeEntry(id1); |
|
354 service->removeEntry(id2); |
|
355 |
|
356 } |
|
357 } |
|
358 //TODO: change name |
|
359 void TestCaClient::TestCreateItemWhenServerWasTerminated() |
|
360 { |
|
361 terminatServer(); |
|
362 TestCreateItem(); |
|
363 terminatServer(); |
|
364 TestUpdateItem(); |
|
365 terminatServer(); |
|
366 TestGetEntry(); |
|
367 terminatServer(); |
|
368 TestGetEntriesByIds(); |
|
369 terminatServer(); |
|
370 TestGetEntriesByRole(); |
|
371 terminatServer(); |
|
372 TestGetEntriesIdsByRole(); |
|
373 terminatServer(); |
|
374 TestRemoveItem(); |
|
375 terminatServer(); |
|
376 TestInsertEntriesIntoGroup1(); |
|
377 terminatServer(); |
|
378 TestRemoveEntriesFromGroup1(); |
|
379 terminatServer(); |
|
380 TestCustomSort(); |
|
381 terminatServer(); |
|
382 TestAppendEntriesIntoGroup1(); |
|
383 terminatServer(); |
|
384 TestPrependEntryIntoGroup1(); |
|
385 } |
|
386 |
|
387 void TestCaClient::terminatServer() |
|
388 { |
|
389 TFindProcess processFinder; |
|
390 processFinder.Find(_L("camenuserver*")); |
|
391 TFullName caName; |
|
392 while ( KErrNone == processFinder.Next( caName ) ) { |
|
393 RProcess caProcess; |
|
394 TInt err = caProcess.Open(caName); |
|
395 if( KErrNone == err ) { |
|
396 caProcess.Terminate(0); |
|
397 } |
|
398 caProcess.Close(); |
|
399 } |
|
400 } |
|
401 |
|
402 QTEST_MAIN(TestCaClient) |