|
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 #include <QScopedPointer> |
|
19 #include <qservicemanager.h> |
|
20 |
|
21 #include "t_caclient.h" |
|
22 #include "caservice.h" |
|
23 #include "canotifier.h" |
|
24 #include "canotifierfilter.h" |
|
25 #include "caquery.h" |
|
26 #include "t_caclientNotifier.h" |
|
27 |
|
28 const int entryIdFake(-1); |
|
29 const int waitTime500ms(500); |
|
30 const int waitTime1sec(1000); |
|
31 |
|
32 QTM_USE_NAMESPACE |
|
33 |
|
34 QStringList pluginPaths; |
|
35 QString xmlName("caapphandlerplugin.xml"); |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void TestCaClient::initTestCase() |
|
42 { |
|
43 #ifdef Q_OS_SYMBIAN |
|
44 startThread(); |
|
45 #endif //Q_OS_SYMBIAN |
|
46 mService = CaService::instance(); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 void TestCaClient::cleanupTestCase() |
|
54 { |
|
55 #ifdef Q_OS_SYMBIAN |
|
56 stopThread(); |
|
57 #endif //Q_OS_SYMBIAN |
|
58 QSharedPointer<CaService> serviceNull(NULL); |
|
59 mService = serviceNull; |
|
60 QTest::qWait(5000); |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 int threadFunction(void */*params*/) |
|
69 { |
|
70 #ifdef Q_OS_SYMBIAN |
|
71 while (ETrue) { |
|
72 User::ResetInactivityTime();//it should help for Viewserver11 panic |
|
73 User::After(5000000); |
|
74 } |
|
75 #endif //Q_OS_SYMBIAN |
|
76 return 0; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void TestCaClient::startThread() |
|
84 { |
|
85 #ifdef Q_OS_SYMBIAN |
|
86 User::LeaveIfError(iThread.Create( |
|
87 _L("thread_kill_viewsrv11"), |
|
88 threadFunction, |
|
89 16384, |
|
90 4000, |
|
91 4000, |
|
92 NULL)); |
|
93 iThread.Resume(); |
|
94 #endif //Q_OS_SYMBIAN |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void TestCaClient::stopThread() |
|
102 { |
|
103 #ifdef Q_OS_SYMBIAN |
|
104 iThread.Close(); |
|
105 #endif //Q_OS_SYMBIAN |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void TestCaClient::Test_createNotifier() |
|
113 { |
|
114 #ifdef Q_OS_SYMBIAN |
|
115 #ifdef UT_MEMORY_CHECK |
|
116 // __UHEAP_MARK; |
|
117 #endif//UT_MEMORY_CHECK |
|
118 #endif//Q_OS_SYMBIAN |
|
119 { |
|
120 |
|
121 CaNotifierFilter *filter = new CaNotifierFilter(); |
|
122 filter->setEntryRole(GroupEntryRole); |
|
123 filter->setTypeNames(QStringList() << "TypeName"); |
|
124 TestCaClientNotifier *clientNotifier = new TestCaClientNotifier(*mService, filter); |
|
125 CaNotifier *notifier = clientNotifier->getNotifier(); |
|
126 |
|
127 connect(notifier, SIGNAL(entryChanged(int,ChangeType)), |
|
128 clientNotifier, SLOT(entryChanged(int,ChangeType))); |
|
129 QTest::qWait(waitTime500ms); |
|
130 CaEntry group(GroupEntryRole); |
|
131 group.setText("Text"); |
|
132 group.setEntryTypeName("TypeName"); |
|
133 |
|
134 QSharedPointer<CaEntry> entry = mService->createEntry(group); |
|
135 QTest::qWait(waitTime1sec); |
|
136 |
|
137 QCOMPARE(clientNotifier->mChangeType, AddChangeType); |
|
138 QVERIFY(clientNotifier->mEntryId > 0); |
|
139 QCOMPARE(clientNotifier->mEntryId, entry->id()); |
|
140 |
|
141 // cleanup |
|
142 disconnect(notifier, SIGNAL(entryChanged(int,ChangeType)), |
|
143 clientNotifier, SLOT(entryChanged(int,ChangeType))); |
|
144 QTest::qWait(waitTime500ms); |
|
145 delete clientNotifier; |
|
146 mService->removeEntry(entry->id()); |
|
147 } |
|
148 #ifdef Q_OS_SYMBIAN |
|
149 #ifdef UT_MEMORY_CHECK |
|
150 // __UHEAP_MARKEND; |
|
151 #endif//UT_MEMORY_CHECK |
|
152 #endif//Q_OS_SYMBIAN |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void TestCaClient::Test_touch() |
|
160 { |
|
161 #ifdef Q_OS_SYMBIAN |
|
162 #ifdef UT_MEMORY_CHECK |
|
163 // __UHEAP_MARK; |
|
164 #endif//UT_MEMORY_CHECK |
|
165 #endif//Q_OS_SYMBIAN |
|
166 |
|
167 CaEntry item; |
|
168 item.setText("Text"); |
|
169 item.setEntryTypeName("TypeName"); |
|
170 QSharedPointer<CaEntry> entry = mService->createEntry(item); |
|
171 QTest::qWait(waitTime1sec); |
|
172 |
|
173 CaNotifierFilter *filter = new CaNotifierFilter(); |
|
174 filter->setEntryRole(ItemEntryRole); |
|
175 filter->setIds(QList<int>() << entry->id()); |
|
176 TestCaClientNotifier *clientNotifier = new TestCaClientNotifier(*mService, filter); |
|
177 CaNotifier *notifier = clientNotifier->getNotifier(); |
|
178 |
|
179 connect(notifier, SIGNAL(entryTouched(int)), |
|
180 clientNotifier, SLOT(entryTouched(int))); |
|
181 QTest::qWait(waitTime500ms); |
|
182 |
|
183 bool touched = mService->touch(*entry); |
|
184 QTest::qWait(waitTime1sec); |
|
185 |
|
186 QVERIFY(clientNotifier->mEntryId > 0); |
|
187 QCOMPARE(clientNotifier->mEntryId, entry->id()); |
|
188 QCOMPARE(touched, TRUE); |
|
189 |
|
190 // cleanup |
|
191 disconnect(notifier, SIGNAL(entryTouched(int)), |
|
192 clientNotifier, SLOT(entryTouched(int))); |
|
193 QTest::qWait(waitTime500ms); |
|
194 delete clientNotifier; |
|
195 delete filter; |
|
196 mService->removeEntry(entry->id()); |
|
197 QTest::qWait(waitTime1sec); |
|
198 |
|
199 #ifdef Q_OS_SYMBIAN |
|
200 #ifdef UT_MEMORY_CHECK |
|
201 // __UHEAP_MARKEND; |
|
202 #endif//UT_MEMORY_CHECK |
|
203 #endif//Q_OS_SYMBIAN |
|
204 } |
|
205 |
|
206 //QTEST_MAIN(homescreen::test::TestCaClient) |