|
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: caservice.h |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CASERVICE_H |
|
19 #define CASERVICE_H |
|
20 |
|
21 #include <QObject> |
|
22 #include <QSharedPointer> |
|
23 #include <QMetaType> |
|
24 #include <QCoreApplication> |
|
25 #include <QString> |
|
26 #include <QDebug> |
|
27 |
|
28 |
|
29 #include "caservice.h" |
|
30 #include "caquery.h" |
|
31 #include "caentry.h" |
|
32 #include "canotifier.h" |
|
33 #include "canotifierfilter.h" |
|
34 #include "cadefs.h" |
|
35 |
|
36 typedef QList< QSharedPointer<CaEntry> > CaEntryList; |
|
37 |
|
38 // mocks Content Storage's CaService |
|
39 class CaService: public QObject |
|
40 { |
|
41 Q_OBJECT |
|
42 |
|
43 explicit CaService(QObject *parent = 0); |
|
44 |
|
45 ~CaService(); |
|
46 public: |
|
47 |
|
48 |
|
49 static QSharedPointer<CaService> instance(); |
|
50 |
|
51 // mock only those methods of original CaService that are used in the module |
|
52 QSharedPointer<CaEntry> getEntry(int entryId) const; |
|
53 QList< QSharedPointer<CaEntry> > getEntries(const CaQuery &query) const; |
|
54 QList<int> getEntryIds(const CaQuery &query) const; |
|
55 |
|
56 QSharedPointer<CaEntry> createEntry(const CaEntry &entry) const; |
|
57 |
|
58 bool removeEntry(int entryId) const; |
|
59 bool updateEntry(const CaEntry &entry) const; |
|
60 bool touch(const CaEntry &entry) const; |
|
61 bool removeEntryFromGroup(int groupId, int entryId) const; |
|
62 bool appendEntryToGroup(int groupId, int entryId) const; |
|
63 bool appendEntriesToGroup(int groupId, |
|
64 const QList<int> &entryIdList) const; |
|
65 |
|
66 int executeCommand(int entryId, const QString &command = |
|
67 caCmdOpen, QObject* receiver = NULL, const char* member = NULL) const; |
|
68 int executeCommand(const CaEntry &entry, const QString &command = |
|
69 caCmdOpen, QObject* receiver = NULL, const char* member = NULL) const; |
|
70 |
|
71 |
|
72 bool customSort(int groupId, QList<int> &entryIdList) const; |
|
73 |
|
74 CaNotifier * createNotifier(const CaNotifierFilter &filter) const; |
|
75 |
|
76 mutable int mGetEntryId; |
|
77 mutable QSharedPointer<CaEntry> mGetEntryResult; |
|
78 mutable CaQuery mGetEntriesQuery; |
|
79 mutable QList< QSharedPointer<CaEntry> > mGetEntriesResult; |
|
80 mutable CaQuery mGetEntryIdQuery; |
|
81 mutable QList<int> mGetEntryIdsResult; |
|
82 mutable CaEntry mCreatedEntry; |
|
83 mutable QSharedPointer<CaEntry>mCreateEntryResult; |
|
84 |
|
85 mutable int mRemoveEntryId; |
|
86 mutable bool mRemoveEntryForIdResult; |
|
87 |
|
88 mutable CaEntry mUpdateEntry; |
|
89 mutable bool mUpdateEntryResult; |
|
90 |
|
91 mutable CaEntry mTouchEntry; |
|
92 mutable QList<int> mTouchEntriesId; |
|
93 mutable bool mTouchResult; |
|
94 |
|
95 mutable int mRemoveGroupId; |
|
96 mutable int mRemoveEntryFromGroupId; |
|
97 mutable bool mRemoveEntryFromGroupResult; |
|
98 |
|
99 mutable int mAppendGroupId; |
|
100 mutable int mAppenEntryId; |
|
101 mutable bool mAppendEntryToGroupResult; |
|
102 |
|
103 mutable int mAppendListGroupId; |
|
104 mutable QList<int> mAppendEntryIdList; |
|
105 mutable bool mAppendEntriesToGroupResult; |
|
106 |
|
107 mutable int mExecuteEntryId; |
|
108 mutable QString mExecuteCommand; |
|
109 mutable int mExecuteCommandResult; |
|
110 |
|
111 mutable CaEntry mExecuteEntry; |
|
112 |
|
113 mutable int mCustomSortGroupId; |
|
114 mutable QList<int> mCustomSortEntryIdList; |
|
115 mutable bool mCustomSortResult; |
|
116 |
|
117 mutable CaNotifierFilter mCreateNotifierFilter; |
|
118 mutable CaNotifier *mCreateNotifierResult; |
|
119 |
|
120 // helper for tests, not belonging to CaService |
|
121 void clear() |
|
122 { |
|
123 mGetEntryId = 0; |
|
124 mGetEntryResult.clear(); |
|
125 mGetEntriesQuery.clear(); |
|
126 mGetEntriesResult.clear(); |
|
127 mGetEntryIdQuery.clear(); |
|
128 mGetEntryIdsResult.clear(); |
|
129 mCreatedEntry.clear(); |
|
130 mCreateEntryResult.clear(); |
|
131 mRemoveEntryId = 0; |
|
132 mRemoveEntryForIdResult = false; |
|
133 |
|
134 mUpdateEntry.clear(); |
|
135 mUpdateEntryResult = false; |
|
136 |
|
137 mTouchEntry.clear(); |
|
138 mTouchEntriesId.clear(); |
|
139 mTouchResult = false; |
|
140 |
|
141 mRemoveGroupId = 0; |
|
142 mRemoveEntryFromGroupId = 0; |
|
143 mRemoveEntryFromGroupResult = false; |
|
144 |
|
145 mAppendGroupId = 0; |
|
146 mAppenEntryId = 0; |
|
147 mAppendEntryToGroupResult = false; |
|
148 |
|
149 mAppendListGroupId = 0; |
|
150 mAppendEntryIdList.clear(); |
|
151 mAppendEntriesToGroupResult = false; |
|
152 |
|
153 mExecuteEntryId = 0; |
|
154 mExecuteCommand.clear(); |
|
155 mExecuteCommandResult = -333; |
|
156 |
|
157 mCustomSortGroupId = 0; |
|
158 mCustomSortEntryIdList.clear(); |
|
159 mCustomSortResult = false; |
|
160 |
|
161 mCreateNotifierFilter = CaNotifierFilter(); |
|
162 mCreateNotifierResult = 0; |
|
163 } |
|
164 private: |
|
165 Q_DISABLE_COPY(CaService) |
|
166 friend class QtSharedPointer::ExternalRefCount<CaService>; |
|
167 }; |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 inline CaService::CaService(QObject *parent) : |
|
174 QObject(parent), |
|
175 mGetEntryId(0), |
|
176 mRemoveEntryId(0), |
|
177 mRemoveEntryForIdResult(false), |
|
178 mUpdateEntryResult(false), |
|
179 mTouchResult(false), |
|
180 mRemoveGroupId(0), |
|
181 mRemoveEntryFromGroupId(0), |
|
182 mRemoveEntryFromGroupResult(false), |
|
183 mAppendGroupId(0), |
|
184 mAppenEntryId(0), |
|
185 mAppendEntryToGroupResult(false), |
|
186 mAppendListGroupId(0), |
|
187 mAppendEntriesToGroupResult(false), |
|
188 mExecuteEntryId(0), |
|
189 mExecuteCommandResult(false), |
|
190 mCustomSortGroupId(0), |
|
191 mCustomSortResult(false), |
|
192 mCreateNotifierResult(0) |
|
193 |
|
194 { |
|
195 } |
|
196 |
|
197 inline QSharedPointer<CaService> CaService::instance() |
|
198 { |
|
199 static QSharedPointer<CaService> service(new CaService); |
|
200 return service; |
|
201 } |
|
202 |
|
203 inline CaService::~CaService() |
|
204 { |
|
205 } |
|
206 |
|
207 inline QSharedPointer<CaEntry> CaService::getEntry(int entryId) const |
|
208 { |
|
209 mGetEntryId = entryId; |
|
210 if (!mGetEntryResult.isNull()) { |
|
211 mGetEntryResult->mIdResult = entryId; |
|
212 } |
|
213 return mGetEntryResult; |
|
214 } |
|
215 |
|
216 |
|
217 inline QList< QSharedPointer<CaEntry> > CaService::getEntries(const CaQuery &query) const |
|
218 { |
|
219 mGetEntriesQuery = query; |
|
220 return mGetEntriesResult; |
|
221 } |
|
222 |
|
223 inline QList<int> CaService::getEntryIds(const CaQuery &query) const |
|
224 { |
|
225 mGetEntryIdQuery = query; |
|
226 return mGetEntryIdsResult; |
|
227 } |
|
228 |
|
229 inline QSharedPointer<CaEntry> CaService::createEntry(const CaEntry &entry) const |
|
230 { |
|
231 mCreatedEntry = entry; |
|
232 return mCreateEntryResult; |
|
233 } |
|
234 |
|
235 inline bool CaService::removeEntry(int entryId) const |
|
236 { |
|
237 mRemoveEntryId = entryId; |
|
238 return mRemoveEntryForIdResult; |
|
239 } |
|
240 |
|
241 |
|
242 inline bool CaService::updateEntry(const CaEntry &entry) const |
|
243 { |
|
244 mUpdateEntry = entry; |
|
245 return mUpdateEntryResult; |
|
246 } |
|
247 |
|
248 inline bool CaService::touch(const CaEntry &entry) const |
|
249 { |
|
250 if (entry.flags() & RemovableEntryFlag && |
|
251 (entry.flags() & UsedEntryFlag) == 0 && |
|
252 entry.role() == ItemEntryRole && |
|
253 entry.entryTypeName() != QString("package")) { //packageTypeName |
|
254 mTouchEntry = entry; |
|
255 mTouchEntriesId.append(entry.id()); |
|
256 return mTouchResult; |
|
257 } else { |
|
258 return true; |
|
259 } |
|
260 } |
|
261 |
|
262 inline bool CaService::removeEntryFromGroup(int groupId, int entryId) const |
|
263 { |
|
264 mRemoveGroupId = groupId; |
|
265 mRemoveEntryFromGroupId = entryId; |
|
266 return mRemoveEntryFromGroupResult; |
|
267 } |
|
268 |
|
269 inline bool CaService::appendEntryToGroup(int groupId, int entryId) const |
|
270 { |
|
271 mAppendGroupId = groupId; |
|
272 mAppenEntryId = entryId; |
|
273 return mAppendEntryToGroupResult; |
|
274 } |
|
275 |
|
276 inline bool CaService::appendEntriesToGroup(int groupId, |
|
277 const QList<int> &entryIdList) const |
|
278 { |
|
279 mAppendListGroupId = groupId; |
|
280 mAppendEntryIdList = entryIdList; |
|
281 return mAppendEntriesToGroupResult; |
|
282 } |
|
283 |
|
284 inline int CaService::executeCommand(int entryId, const QString &command, |
|
285 QObject* receiver, const char* member) const |
|
286 { |
|
287 Q_UNUSED(receiver); |
|
288 Q_UNUSED(member); |
|
289 mExecuteEntryId = entryId; |
|
290 mExecuteCommand = command; |
|
291 return mExecuteCommandResult; |
|
292 } |
|
293 |
|
294 inline int CaService::executeCommand(const CaEntry &entry, const QString &command, |
|
295 QObject* receiver, const char* member) const |
|
296 { |
|
297 Q_UNUSED(receiver); |
|
298 Q_UNUSED(member); |
|
299 mExecuteEntry = entry; |
|
300 mExecuteCommand = command; |
|
301 return mExecuteCommandResult; |
|
302 } |
|
303 |
|
304 inline bool CaService::customSort(int groupId, QList<int> &entryIdList) const |
|
305 { |
|
306 mCustomSortGroupId = groupId; |
|
307 mCustomSortEntryIdList = entryIdList; |
|
308 return mCustomSortResult; |
|
309 } |
|
310 |
|
311 inline CaNotifier * CaService::createNotifier(const CaNotifierFilter &filter) const |
|
312 { |
|
313 mCreateNotifierFilter = filter; |
|
314 return mCreateNotifierResult; |
|
315 } |
|
316 |
|
317 |
|
318 #endif // CASERVICE_H |