|
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 // --------------------------------------------------------------------------- |
|
27 // |
|
28 void TestCaClient::Test_instance() |
|
29 { |
|
30 { |
|
31 QSharedPointer<CaService> service = CaService::instance(); |
|
32 QVERIFY(!service.isNull()); |
|
33 } |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void TestCaClient::Test_lastError() |
|
41 { |
|
42 { |
|
43 //create item |
|
44 CaEntry item; |
|
45 item.setText("testName"); |
|
46 item.setAttribute("attrName1", "attrVal1"); |
|
47 item.setEntryTypeName("test"); |
|
48 item.setFlags(RemovableEntryFlag); |
|
49 item.setDescription("description"); |
|
50 CaIconDescription iconDescription; |
|
51 iconDescription.setFilename("iconFileName"); |
|
52 iconDescription.setSkinId("iconSkinId"); |
|
53 iconDescription.setApplicationId("268458321"); |
|
54 |
|
55 item.setIconDescription(iconDescription); |
|
56 |
|
57 QSharedPointer<CaService> service = CaService::instance(); |
|
58 QSharedPointer<CaEntry> resultItem = service->createEntry(item); |
|
59 QCOMPARE(service->lastError(), NoErrorCode); |
|
60 |
|
61 //Cleanup |
|
62 service->removeEntry(*resultItem); |
|
63 QCOMPARE(service->lastError(), NoErrorCode); |
|
64 } |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void TestCaClient::Test_createEntry() |
|
72 { |
|
73 { |
|
74 const CaEntry constItem; |
|
75 QCOMPARE(constItem.role(), ItemEntryRole); |
|
76 |
|
77 //create item |
|
78 //check if proper entry returned |
|
79 CaEntry item; |
|
80 item.setText("testName"); |
|
81 item.setAttribute("attrName1", "attrVal1"); |
|
82 item.setEntryTypeName("test"); |
|
83 item.setFlags(RemovableEntryFlag); |
|
84 item.setDescription("description"); |
|
85 CaIconDescription iconDescription; |
|
86 iconDescription.setFilename("iconFileName"); |
|
87 iconDescription.setSkinId("iconSkinId"); |
|
88 iconDescription.setApplicationId("268458321"); |
|
89 |
|
90 item.setIconDescription(iconDescription); |
|
91 |
|
92 QSharedPointer<CaService> service = CaService::instance(); |
|
93 QSharedPointer<CaEntry> resultItem = service->createEntry(item); |
|
94 QCOMPARE(service->lastError(), NoErrorCode); |
|
95 QVERIFY(!resultItem.isNull()); |
|
96 QCOMPARE(resultItem->role(), ItemEntryRole); |
|
97 QCOMPARE(item.text(),resultItem->text()); |
|
98 QCOMPARE(item.description(),resultItem->description()); |
|
99 QCOMPARE(item.entryTypeName(),resultItem->entryTypeName()); |
|
100 QCOMPARE(QString("attrVal1"),resultItem->attribute("attrName1")); |
|
101 QCOMPARE(item.flags(),resultItem->flags()); |
|
102 int itId =item.id(); |
|
103 int resItId =resultItem->id(); |
|
104 QVERIFY(itId != resItId); |
|
105 QCOMPARE(iconDescription.filename(),resultItem->iconDescription().filename()); |
|
106 QCOMPARE(iconDescription.skinId(),resultItem->iconDescription().skinId()); |
|
107 QCOMPARE(iconDescription.applicationId(),resultItem->iconDescription().applicationId()); |
|
108 |
|
109 // entry from storage |
|
110 QSharedPointer<CaEntry> storageItem1 = service->getEntry(resultItem->id()); |
|
111 QVERIFY(storageItem1); |
|
112 QCOMPARE(QString("testName"),storageItem1->text()); |
|
113 QCOMPARE(QString("description"),storageItem1->description()); |
|
114 QCOMPARE(QString("test"),storageItem1->entryTypeName()); |
|
115 QCOMPARE(QString("attrVal1"),storageItem1->attribute("attrName1")); |
|
116 EntryFlags flags = item.flags(); |
|
117 EntryFlags storageFlags = storageItem1->flags(); |
|
118 QCOMPARE(iconDescription.filename(),storageItem1->iconDescription().filename()); |
|
119 QCOMPARE(iconDescription.skinId(),storageItem1->iconDescription().skinId()); |
|
120 QCOMPARE(iconDescription.applicationId(),storageItem1->iconDescription().applicationId()); |
|
121 QVERIFY(storageItem1->iconDescription().id() > 0); |
|
122 |
|
123 QCOMPARE(flags ,storageFlags); |
|
124 |
|
125 //Cleanup |
|
126 service->removeEntry(*resultItem); |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void TestCaClient::Test_epdateEntry() |
|
135 { |
|
136 { |
|
137 CaEntry item1; |
|
138 item1.setText("testName"); |
|
139 item1.setAttribute("attrName1", "attrVal1"); |
|
140 item1.setEntryTypeName("test"); |
|
141 item1.setFlags(RemovableEntryFlag); |
|
142 CaIconDescription iconDescription1; |
|
143 iconDescription1.setFilename("iconFileName"); |
|
144 iconDescription1.setSkinId("iconSkinId"); |
|
145 iconDescription1.setApplicationId("268458321"); //Bluetouth app UID |
|
146 item1.setIconDescription(iconDescription1); |
|
147 |
|
148 CaIconDescription iconDescription2; |
|
149 iconDescription2.setFilename("iconFileName2"); |
|
150 iconDescription2.setSkinId("iconSkinId2"); |
|
151 iconDescription2.setApplicationId("537001519"); //SW update app UID |
|
152 |
|
153 QSharedPointer<CaService> service = CaService::instance(); |
|
154 QSharedPointer<CaEntry> resultItem1 = service->createEntry(item1); |
|
155 QCOMPARE(service->lastError(), NoErrorCode); |
|
156 |
|
157 QVERIFY(!resultItem1.isNull()); |
|
158 |
|
159 int id1 = resultItem1->id(); |
|
160 resultItem1->setText("testName2"); |
|
161 resultItem1->setAttribute("attrName2", "attrVal2"); |
|
162 resultItem1->setAttribute("attrName1", "attrVal2"); |
|
163 resultItem1->setEntryTypeName("test2"); |
|
164 resultItem1->setFlags(UninstallEntryFlag); |
|
165 resultItem1->setIconDescription(iconDescription2); |
|
166 |
|
167 bool updateResult1 = service->updateEntry(item1); |
|
168 QVERIFY(service->lastError() != NoErrorCode); |
|
169 |
|
170 QVERIFY(!updateResult1); // no id -> return false |
|
171 |
|
172 bool updateResult2 = service->updateEntry(*resultItem1); |
|
173 QCOMPARE(service->lastError(), NoErrorCode); |
|
174 QVERIFY(updateResult2); // id present -> true |
|
175 |
|
176 QSharedPointer<CaEntry> resultItem2 = service->createEntry(*resultItem1); |
|
177 QCOMPARE(service->lastError(), NoErrorCode); |
|
178 QVERIFY(!resultItem2.isNull()); |
|
179 |
|
180 int id2 = resultItem2->id(); |
|
181 QVERIFY(id1 != id2); //entry clone created |
|
182 |
|
183 QSharedPointer<CaEntry> storageItem1 = service->getEntry(id1); |
|
184 QVERIFY(!storageItem1.isNull()); |
|
185 |
|
186 QSharedPointer<CaEntry> storageItem2 = service->getEntry(id2); |
|
187 QVERIFY(!storageItem2.isNull()); |
|
188 |
|
189 // check if attributes were updated |
|
190 QCOMPARE(QString("testName2"),storageItem1->text()); |
|
191 QCOMPARE(QString("test2"),storageItem1->entryTypeName()); |
|
192 |
|
193 QCOMPARE(QString("attrVal2"),storageItem1->attribute("attrName1")); |
|
194 QCOMPARE(QString("attrVal2"),storageItem1->attribute("attrName2")); |
|
195 QCOMPARE(resultItem1->flags(),storageItem1->flags()); |
|
196 QCOMPARE(iconDescription2.filename(),storageItem1->iconDescription().filename()); |
|
197 QCOMPARE(iconDescription2.skinId(),storageItem1->iconDescription().skinId()); |
|
198 QCOMPARE(iconDescription2.applicationId(),storageItem1->iconDescription().applicationId()); |
|
199 // cloned item should have the same attributes |
|
200 QCOMPARE(QString("testName2"),storageItem2->text()); |
|
201 QCOMPARE(QString("test2"),storageItem2->entryTypeName()); |
|
202 QCOMPARE(QString("attrVal2"),storageItem2->attribute("attrName1")); |
|
203 QCOMPARE(QString("attrVal2"),storageItem2->attribute("attrName2")); |
|
204 QCOMPARE(resultItem1->flags(),storageItem2->flags()); |
|
205 |
|
206 //Cleanup |
|
207 service->removeEntry(id1); |
|
208 service->removeEntry(id2); |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void TestCaClient::terminatServer() |
|
217 { |
|
218 TFindProcess processFinder; |
|
219 processFinder.Find(_L("camenuserver*")); |
|
220 TFullName caName; |
|
221 while ( KErrNone == processFinder.Next( caName ) ) { |
|
222 RProcess caProcess; |
|
223 TInt err = caProcess.Open(caName); |
|
224 if( KErrNone == err ) { |
|
225 caProcess.Terminate(0); |
|
226 } |
|
227 caProcess.Close(); |
|
228 } |
|
229 } |
|
230 |
|
231 QTEST_MAIN(TestCaClient) |