|
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 "canotifier.h" |
|
22 #include "canotifierfilter.h" |
|
23 #include "t_caclientNotifier.h" |
|
24 |
|
25 const int entryIdFake(-1); |
|
26 const int waitTime500ms(500); |
|
27 const int waitTime1sec(1000); |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 void TestCaClient::TestAddItemChangeTypeNotifier3Clients() |
|
33 { |
|
34 #ifdef Q_OS_SYMBIAN |
|
35 #ifdef UT_MEMORY_CHECK |
|
36 // __UHEAP_MARK; |
|
37 #endif//UT_MEMORY_CHECK |
|
38 #endif//Q_OS_SYMBIAN |
|
39 { |
|
40 QSharedPointer<CaService> service = CaService::instance(); |
|
41 TestCaClientNotifier *clientNotifier_1 = new TestCaClientNotifier(*service); |
|
42 CaNotifier *notifier_1 = clientNotifier_1->getNotifier(); |
|
43 |
|
44 TestCaClientNotifier *clientNotifier_2 = new TestCaClientNotifier(*service); |
|
45 CaNotifier *notifier_2 = clientNotifier_2->getNotifier(); |
|
46 |
|
47 TestCaClientNotifier *clientNotifier_3 = new TestCaClientNotifier(*service); |
|
48 CaNotifier *notifier_3 = clientNotifier_3->getNotifier(); |
|
49 |
|
50 connect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
51 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
52 connect(notifier_2, SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
53 clientNotifier_2, SLOT(entryChanged(CaEntry,ChangeType))); |
|
54 connect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
55 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
56 QTest::qWait(waitTime1sec); |
|
57 |
|
58 clientNotifier_1->mChangeType = RemoveChangeType; |
|
59 clientNotifier_2->mChangeType = RemoveChangeType; |
|
60 clientNotifier_3->mChangeType = RemoveChangeType; |
|
61 terminatServer(); |
|
62 CaEntry item; |
|
63 item.setText("Text"); |
|
64 item.setEntryTypeName("TypeName"); |
|
65 QSharedPointer<CaEntry> entry = service->createEntry(item); |
|
66 QTest::qWait(waitTime1sec); |
|
67 |
|
68 QCOMPARE(clientNotifier_1->mChangeType, AddChangeType); |
|
69 QVERIFY(clientNotifier_1->mEntryId > 0); |
|
70 QCOMPARE(clientNotifier_1->mEntryId, entry->id()); |
|
71 QCOMPARE(clientNotifier_1->mEntryId, clientNotifier_2->mEntryId); |
|
72 QCOMPARE(clientNotifier_3->mEntryId, clientNotifier_2->mEntryId); |
|
73 QCOMPARE(clientNotifier_2->mChangeType, AddChangeType); |
|
74 QCOMPARE(entry->text(), clientNotifier_2->mEntry->text()); |
|
75 QCOMPARE(clientNotifier_3->mChangeType, AddChangeType); |
|
76 |
|
77 |
|
78 // cleanup |
|
79 disconnect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
80 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
81 disconnect(notifier_2, SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
82 clientNotifier_2, SLOT(entryChanged(CaEntry,ChangeType))); |
|
83 disconnect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
84 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
85 QTest::qWait(waitTime1sec); |
|
86 delete clientNotifier_1; |
|
87 delete clientNotifier_2; |
|
88 delete clientNotifier_3; |
|
89 service->removeEntry(entry->id()); |
|
90 } |
|
91 #ifdef Q_OS_SYMBIAN |
|
92 #ifdef UT_MEMORY_CHECK |
|
93 // __UHEAP_MARKEND; |
|
94 #endif//UT_MEMORY_CHECK |
|
95 #endif//Q_OS_SYMBIAN |
|
96 } |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void TestCaClient::TestRemoveEntryChangeTypeNotifier3Clients() |
|
100 { |
|
101 #ifdef Q_OS_SYMBIAN |
|
102 #ifdef UT_MEMORY_CHECK |
|
103 // __UHEAP_MARK; |
|
104 #endif//UT_MEMORY_CHECK |
|
105 #endif//Q_OS_SYMBIAN |
|
106 { |
|
107 QSharedPointer<CaService> service = CaService::instance(); |
|
108 TestCaClientNotifier *clientNotifier_1 = new TestCaClientNotifier(*service); |
|
109 CaNotifier *notifier_1 = clientNotifier_1->getNotifier(); |
|
110 |
|
111 TestCaClientNotifier *clientNotifier_2 = new TestCaClientNotifier(*service); |
|
112 CaNotifier *notifier_2 = clientNotifier_2->getNotifier(); |
|
113 |
|
114 TestCaClientNotifier *clientNotifier_3 = new TestCaClientNotifier(*service); |
|
115 CaNotifier *notifier_3 = clientNotifier_3->getNotifier(); |
|
116 |
|
117 connect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
118 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
119 connect(notifier_2, SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
120 clientNotifier_2, SLOT(entryChanged(CaEntry,ChangeType))); |
|
121 connect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
122 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
123 QTest::qWait(waitTime1sec); |
|
124 terminatServer(); |
|
125 CaEntry item; |
|
126 item.setText("Text"); |
|
127 item.setEntryTypeName("TypeName"); |
|
128 |
|
129 QSharedPointer<CaEntry> entry = service->createEntry(item); |
|
130 QTest::qWait(waitTime1sec); |
|
131 |
|
132 QCOMPARE(clientNotifier_1->mChangeType, AddChangeType); |
|
133 QVERIFY(clientNotifier_2->mEntryId > 0); |
|
134 QCOMPARE(clientNotifier_3->mEntryId, entry->id()); |
|
135 |
|
136 int entryId_1 = clientNotifier_1->mEntryId; |
|
137 clientNotifier_1->mEntryId = 0; |
|
138 int entryId_2 = clientNotifier_2->mEntryId; |
|
139 clientNotifier_2->mEntryId = 0; |
|
140 int entryId_3 = clientNotifier_3->mEntryId; |
|
141 clientNotifier_3->mEntryId = 0; |
|
142 |
|
143 bool removed = service->removeEntry(*entry); |
|
144 QTest::qWait(waitTime1sec); |
|
145 |
|
146 QCOMPARE(clientNotifier_1->mChangeType, RemoveChangeType); |
|
147 QCOMPARE(clientNotifier_2->mChangeType, RemoveChangeType); |
|
148 QCOMPARE(clientNotifier_3->mChangeType, RemoveChangeType); |
|
149 QVERIFY(clientNotifier_1->mEntryId > 0); |
|
150 QCOMPARE(clientNotifier_1->mEntryId, entryId_1); |
|
151 QCOMPARE(clientNotifier_2->mEntryId, entryId_2); |
|
152 QCOMPARE(clientNotifier_3->mEntryId, entryId_3); |
|
153 QCOMPARE(entryId_1, entryId_3); |
|
154 QCOMPARE(entryId_2, entryId_3); |
|
155 QCOMPARE(removed, TRUE); |
|
156 |
|
157 // cleanup |
|
158 disconnect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
159 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
160 disconnect(notifier_2, SIGNAL(entryChanged(const CaEntry &,ChangeType)), |
|
161 clientNotifier_2, SLOT(entryChanged(const CaEntry &,ChangeType))); |
|
162 disconnect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
163 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
164 QTest::qWait(waitTime500ms); |
|
165 delete clientNotifier_1; |
|
166 delete clientNotifier_2; |
|
167 delete clientNotifier_3; |
|
168 service->removeEntry(entry->id()); |
|
169 } |
|
170 #ifdef Q_OS_SYMBIAN |
|
171 #ifdef UT_MEMORY_CHECK |
|
172 // __UHEAP_MARKEND; |
|
173 #endif//UT_MEMORY_CHECK |
|
174 #endif//Q_OS_SYMBIAN |
|
175 } |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void TestCaClient::TestRemoveEntriesChangeTypeNotifier3Clients() |
|
179 { |
|
180 #ifdef Q_OS_SYMBIAN |
|
181 #ifdef UT_MEMORY_CHECK |
|
182 // __UHEAP_MARK; |
|
183 #endif//UT_MEMORY_CHECK |
|
184 #endif//Q_OS_SYMBIAN |
|
185 { |
|
186 QSharedPointer<CaService> service = CaService::instance(); |
|
187 TestCaClientNotifier *clientNotifier_1 = new TestCaClientNotifier(*service); |
|
188 CaNotifier *notifier_1 = clientNotifier_1->getNotifier(); |
|
189 |
|
190 TestCaClientNotifier *clientNotifier_2 = new TestCaClientNotifier(*service); |
|
191 CaNotifier *notifier_2 = clientNotifier_2->getNotifier(); |
|
192 |
|
193 TestCaClientNotifier *clientNotifier_3 = new TestCaClientNotifier(*service); |
|
194 CaNotifier *notifier_3 = clientNotifier_3->getNotifier(); |
|
195 |
|
196 connect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
197 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
198 connect(notifier_2, SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
199 clientNotifier_2, SLOT(entryChanged(CaEntry,ChangeType))); |
|
200 connect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
201 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
202 QTest::qWait(waitTime1sec); |
|
203 |
|
204 CaEntry item1; |
|
205 item1.setText("Text1"); |
|
206 item1.setEntryTypeName("TypeName1"); |
|
207 QSharedPointer<CaEntry> entry1 = service->createEntry(item1); |
|
208 QTest::qWait(waitTime1sec); |
|
209 CaEntry item2; |
|
210 item2.setText("Text2"); |
|
211 item2.setEntryTypeName("TypeName2"); |
|
212 QSharedPointer<CaEntry> entry2 = service->createEntry(item2); |
|
213 QTest::qWait(waitTime1sec); |
|
214 CaEntry item3; |
|
215 item3.setText("Text3"); |
|
216 item3.setEntryTypeName("TypeName3"); |
|
217 QSharedPointer<CaEntry> entry3 = service->createEntry(item3); |
|
218 QTest::qWait(waitTime1sec); |
|
219 CaEntry item4; |
|
220 item4.setText("Text4"); |
|
221 item4.setEntryTypeName("TypeName4"); |
|
222 QSharedPointer<CaEntry> entry4 = service->createEntry(item4); |
|
223 QTest::qWait(waitTime1sec); |
|
224 |
|
225 QList<QSharedPointer<CaEntry> > entriesList; |
|
226 entriesList.append(entry1); |
|
227 entriesList.append(entry2); |
|
228 entriesList.append(entry3); |
|
229 entriesList.append(entry4); |
|
230 |
|
231 clientNotifier_1->mEntryId = clientNotifier_2->mEntryId = |
|
232 clientNotifier_3->mEntryId = 0; |
|
233 |
|
234 bool removed = service->removeEntries(entriesList); |
|
235 QTest::qWait(waitTime1sec); |
|
236 |
|
237 QCOMPARE(clientNotifier_1->mChangeType, RemoveChangeType); |
|
238 QCOMPARE(clientNotifier_2->mChangeType, RemoveChangeType); |
|
239 QCOMPARE(clientNotifier_3->mChangeType, RemoveChangeType); |
|
240 QVERIFY(clientNotifier_1->mEntryId > 0); |
|
241 QCOMPARE(clientNotifier_1->mEntryId, clientNotifier_2->mEntryId); |
|
242 QCOMPARE(clientNotifier_1->mEntryId, clientNotifier_3->mEntryId); |
|
243 QCOMPARE(removed, TRUE); |
|
244 |
|
245 // cleanup |
|
246 disconnect(notifier_1, SIGNAL(entryChanged(int,ChangeType)), |
|
247 clientNotifier_1, SLOT(entryChanged(int,ChangeType))); |
|
248 disconnect(notifier_2, SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
249 clientNotifier_2, SLOT(entryChanged(CaEntry,ChangeType))); |
|
250 disconnect(notifier_3, SIGNAL(entryChanged(int,ChangeType)), |
|
251 clientNotifier_3, SLOT(entryChanged(int,ChangeType))); |
|
252 QTest::qWait(waitTime1sec); |
|
253 |
|
254 delete clientNotifier_1; |
|
255 delete clientNotifier_2; |
|
256 delete clientNotifier_3; |
|
257 service->removeEntries(entriesList); |
|
258 QTest::qWait(waitTime500ms); |
|
259 entriesList.clear(); |
|
260 } |
|
261 #ifdef Q_OS_SYMBIAN |
|
262 #ifdef UT_MEMORY_CHECK |
|
263 // __UHEAP_MARKEND; |
|
264 #endif//UT_MEMORY_CHECK |
|
265 #endif//Q_OS_SYMBIAN |
|
266 } |
|
267 |