1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtDocGallery module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | //TESTED_COMPONENT=src/gallery |
43 | |
44 | #include <qgalleryfilter.h> |
45 | #include <qgalleryproperty.h> |
46 | #include <qgallerytype.h> |
47 | |
48 | #include <QtTest/QtTest> |
49 | |
50 | Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QVariant)) |
51 | Q_DECLARE_METATYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QGalleryFilter)) |
52 | Q_DECLARE_METATYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QGalleryFilter::Comparator)) |
53 | Q_DECLARE_METATYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QGalleryMetaDataFilter)) |
54 | |
55 | QT_USE_DOCGALLERY_NAMESPACE |
56 | |
57 | class tst_QGalleryFilter : public QObject |
58 | { |
59 | Q_OBJECT |
60 | private Q_SLOTS: |
61 | void nullFilter(); |
62 | void metaDataFilter_data(); |
63 | void metaDataFilter(); |
64 | void unionFilter(); |
65 | void intersectionFilter(); |
66 | void assignment(); |
67 | void copy(); |
68 | void copyOnWrite(); |
69 | void cast(); |
70 | void intersectionOperator(); |
71 | void unionOperator(); |
72 | void intersectionStreamOperator(); |
73 | void unionStreamOperator(); |
74 | void propertyOperators_data(); |
75 | void propertyOperators(); |
76 | void equality_data(); |
77 | void equality(); |
78 | void inequality_data(); |
79 | void inequality(); |
80 | void galleryType(); |
81 | void galleryProperty(); |
82 | |
83 | #ifndef QT_NO_DEBUG_STREAM |
84 | void debugMessage_data(); |
85 | void debugMessage(); |
86 | #endif |
87 | // Test case for missing scenarios. |
88 | |
89 | void intersectionFilterInsert(); |
90 | void intersectionFilterPrepend(); |
91 | void unionFilterInsert(); |
92 | void unionFilterPrepend(); |
93 | }; |
94 | |
95 | void tst_QGalleryFilter::nullFilter() |
96 | { |
97 | QGalleryFilter filter; |
98 | |
99 | QCOMPARE(filter.type(), QGalleryFilter::Invalid); |
100 | QCOMPARE(filter.isValid(), false); |
101 | } |
102 | |
103 | void tst_QGalleryFilter::metaDataFilter_data() |
104 | { |
105 | QTest::addColumn<QString>(name: "propertyName" ); |
106 | QTest::addColumn<QVariant>(name: "value" ); |
107 | QTest::addColumn<QGalleryFilter::Comparator>(name: "comparator" ); |
108 | QTest::addColumn<bool>(name: "negated" ); |
109 | |
110 | QTest::newRow(dataTag: "album title" ) |
111 | << QString::fromLatin1(str: "albumTitle" ) |
112 | << QVariant(QString::fromLatin1(str: "Greatest" )) |
113 | << QGalleryFilter::StartsWith |
114 | << false; |
115 | |
116 | QTest::newRow(dataTag: "not album title" ) |
117 | << QString::fromLatin1(str: "albumTitle" ) |
118 | << QVariant(QString::fromLatin1(str: "Greatest" )) |
119 | << QGalleryFilter::StartsWith |
120 | << false; |
121 | } |
122 | |
123 | void tst_QGalleryFilter::metaDataFilter() |
124 | { |
125 | QFETCH(QString, propertyName); |
126 | QFETCH(QVariant, value); |
127 | QFETCH(QGalleryFilter::Comparator, comparator); |
128 | QFETCH(bool, negated); |
129 | |
130 | { |
131 | QGalleryMetaDataFilter filter; |
132 | |
133 | QCOMPARE(filter.isValid(), true); |
134 | QCOMPARE(filter.propertyName(), QString()); |
135 | QCOMPARE(filter.value(), QVariant()); |
136 | QCOMPARE(filter.comparator(), QGalleryFilter::Equals); |
137 | QCOMPARE(filter.isNegated(), false); |
138 | |
139 | filter.setPropertyName(propertyName); |
140 | filter.setValue(value); |
141 | filter.setComparator(comparator); |
142 | filter.setNegated(negated); |
143 | |
144 | QCOMPARE(filter.propertyName(), propertyName); |
145 | QCOMPARE(filter.value(), value); |
146 | QCOMPARE(filter.comparator(), comparator); |
147 | QCOMPARE(filter.isNegated(), negated); |
148 | } |
149 | |
150 | { |
151 | QGalleryMetaDataFilter filter(propertyName, value, comparator); |
152 | |
153 | if (negated) |
154 | filter = !filter; |
155 | |
156 | QCOMPARE(filter.isValid(), true); |
157 | |
158 | QCOMPARE(filter.propertyName(), propertyName); |
159 | QCOMPARE(filter.value(), value); |
160 | QCOMPARE(filter.comparator(), comparator); |
161 | QCOMPARE(filter.isNegated(), negated); |
162 | } |
163 | } |
164 | |
165 | void tst_QGalleryFilter::unionFilter() |
166 | { |
167 | QList<QGalleryFilter> filters; |
168 | |
169 | QGalleryMetaDataFilter metaDataFilter; |
170 | QGalleryIntersectionFilter intersectionFilter; |
171 | |
172 | QGalleryUnionFilter unionFilter; |
173 | |
174 | QCOMPARE(unionFilter.isValid(), true); |
175 | QCOMPARE(unionFilter.isEmpty(), true); |
176 | QCOMPARE(unionFilter.filterCount(), 0); |
177 | |
178 | unionFilter.append(filter: metaDataFilter); |
179 | unionFilter.append(filter: metaDataFilter); |
180 | unionFilter.append(filter: intersectionFilter); |
181 | unionFilter.append(filter: metaDataFilter); |
182 | QCOMPARE(unionFilter.isEmpty(), false); |
183 | QCOMPARE(unionFilter.filterCount(), 4); |
184 | |
185 | filters = unionFilter.filters(); |
186 | QCOMPARE(filters.count(), 4); |
187 | |
188 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
189 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
190 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Intersection); |
191 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
192 | |
193 | unionFilter.append(filter: unionFilter); |
194 | QCOMPARE(unionFilter.isEmpty(), false); |
195 | QCOMPARE(unionFilter.filterCount(), 8); |
196 | |
197 | filters = unionFilter.filters(); |
198 | QCOMPARE(filters.count(), 8); |
199 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
200 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Intersection); |
201 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
202 | QCOMPARE(filters.at(6).type(), QGalleryFilter::Intersection); |
203 | |
204 | unionFilter.insert(index: 1, filter: intersectionFilter); |
205 | unionFilter.insert(index: 2, filter: metaDataFilter); |
206 | |
207 | QCOMPARE(unionFilter.isEmpty(), false); |
208 | QCOMPARE(unionFilter.filterCount(), 10); |
209 | |
210 | filters = unionFilter.filters(); |
211 | QCOMPARE(filters.count(), 10); |
212 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
213 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
214 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
215 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Intersection); |
216 | |
217 | unionFilter.insert(index: 0, filter: QGalleryUnionFilter(intersectionFilter)); |
218 | unionFilter.insert(index: 4, filter: QGalleryUnionFilter(metaDataFilter)); |
219 | |
220 | QCOMPARE(unionFilter.isEmpty(), false); |
221 | QCOMPARE(unionFilter.filterCount(), 12); |
222 | |
223 | filters = unionFilter.filters(); |
224 | QCOMPARE(filters.count(), 12); |
225 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Intersection); |
226 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
227 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
228 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
229 | |
230 | unionFilter.replace(index: 0, filter: metaDataFilter); |
231 | unionFilter.replace(index: 4, filter: intersectionFilter); |
232 | QCOMPARE(unionFilter.isEmpty(), false); |
233 | QCOMPARE(unionFilter.filterCount(), 12); |
234 | |
235 | filters = unionFilter.filters(); |
236 | QCOMPARE(filters.count(), 12); |
237 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
238 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
239 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Intersection); |
240 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
241 | |
242 | unionFilter.remove(index: 0); |
243 | unionFilter.remove(index: 3); |
244 | QCOMPARE(unionFilter.isEmpty(), false); |
245 | QCOMPARE(unionFilter.filterCount(), 10); |
246 | |
247 | filters = unionFilter.filters(); |
248 | QCOMPARE(filters.count(), 10); |
249 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
250 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
251 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
252 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Intersection); |
253 | |
254 | unionFilter.clear(); |
255 | QCOMPARE(unionFilter.isEmpty(), true); |
256 | QCOMPARE(unionFilter.filterCount(), 0); |
257 | |
258 | filters = unionFilter.filters(); |
259 | QCOMPARE(filters.count(), 0); |
260 | |
261 | unionFilter.prepend(filter: metaDataFilter); |
262 | unionFilter.prepend(filter: metaDataFilter); |
263 | unionFilter.prepend(filter: intersectionFilter); |
264 | unionFilter.prepend(filter: metaDataFilter); |
265 | QCOMPARE(unionFilter.isEmpty(), false); |
266 | QCOMPARE(unionFilter.filterCount(), 4); |
267 | |
268 | filters = unionFilter.filters(); |
269 | QCOMPARE(filters.count(), 4); |
270 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
271 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
272 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
273 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
274 | |
275 | unionFilter.prepend(filter: intersectionFilter || metaDataFilter); |
276 | QCOMPARE(unionFilter.isEmpty(), false); |
277 | QCOMPARE(unionFilter.filterCount(), 6); |
278 | |
279 | filters = unionFilter.filters(); |
280 | QCOMPARE(filters.count(), 6); |
281 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Intersection); |
282 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
283 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
284 | QCOMPARE(filters.at(3).type(), QGalleryFilter::Intersection); |
285 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
286 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
287 | } |
288 | |
289 | void tst_QGalleryFilter::intersectionFilter() |
290 | { |
291 | QList<QGalleryFilter> filters; |
292 | |
293 | QGalleryMetaDataFilter metaDataFilter; |
294 | QGalleryUnionFilter unionFilter; |
295 | |
296 | QGalleryIntersectionFilter intersectionFilter; |
297 | |
298 | QCOMPARE(intersectionFilter.isValid(), true); |
299 | QCOMPARE(intersectionFilter.isEmpty(), true); |
300 | QCOMPARE(intersectionFilter.filterCount(), 0); |
301 | |
302 | intersectionFilter.append(filter: metaDataFilter); |
303 | intersectionFilter.append(filter: metaDataFilter); |
304 | intersectionFilter.append(filter: unionFilter); |
305 | intersectionFilter.append(filter: metaDataFilter); |
306 | QCOMPARE(intersectionFilter.isEmpty(), false); |
307 | QCOMPARE(intersectionFilter.filterCount(), 4); |
308 | |
309 | filters = intersectionFilter.filters(); |
310 | QCOMPARE(filters.count(), 4); |
311 | |
312 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
313 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
314 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Union); |
315 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
316 | |
317 | intersectionFilter.append(filter: intersectionFilter); |
318 | QCOMPARE(intersectionFilter.isEmpty(), false); |
319 | QCOMPARE(intersectionFilter.filterCount(), 8); |
320 | |
321 | filters = intersectionFilter.filters(); |
322 | QCOMPARE(filters.count(), 8); |
323 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
324 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Union); |
325 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
326 | QCOMPARE(filters.at(6).type(), QGalleryFilter::Union); |
327 | |
328 | intersectionFilter.insert(index: 1, filter: unionFilter); |
329 | intersectionFilter.insert(index: 2, filter: metaDataFilter); |
330 | |
331 | QCOMPARE(intersectionFilter.isEmpty(), false); |
332 | QCOMPARE(intersectionFilter.filterCount(), 10); |
333 | |
334 | filters = intersectionFilter.filters(); |
335 | QCOMPARE(filters.count(), 10); |
336 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
337 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
338 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
339 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Union); |
340 | |
341 | intersectionFilter.insert(index: 0, filter: QGalleryIntersectionFilter(unionFilter)); |
342 | intersectionFilter.insert(index: 4, filter: QGalleryIntersectionFilter(metaDataFilter)); |
343 | |
344 | QCOMPARE(intersectionFilter.isEmpty(), false); |
345 | QCOMPARE(intersectionFilter.filterCount(), 12); |
346 | |
347 | filters = intersectionFilter.filters(); |
348 | QCOMPARE(filters.count(), 12); |
349 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Union); |
350 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
351 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
352 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
353 | |
354 | intersectionFilter.replace(index: 0, filter: metaDataFilter); |
355 | intersectionFilter.replace(index: 4, filter: unionFilter); |
356 | QCOMPARE(intersectionFilter.isEmpty(), false); |
357 | QCOMPARE(intersectionFilter.filterCount(), 12); |
358 | |
359 | filters = intersectionFilter.filters(); |
360 | QCOMPARE(filters.count(), 12); |
361 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
362 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
363 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Union); |
364 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
365 | |
366 | intersectionFilter.remove(index: 0); |
367 | intersectionFilter.remove(index: 3); |
368 | QCOMPARE(intersectionFilter.isEmpty(), false); |
369 | QCOMPARE(intersectionFilter.filterCount(), 10); |
370 | |
371 | filters = intersectionFilter.filters(); |
372 | QCOMPARE(filters.count(), 10); |
373 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
374 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
375 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
376 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Union); |
377 | |
378 | intersectionFilter.clear(); |
379 | QCOMPARE(intersectionFilter.isEmpty(), true); |
380 | QCOMPARE(intersectionFilter.filterCount(), 0); |
381 | |
382 | filters = intersectionFilter.filters(); |
383 | QCOMPARE(filters.count(), 0); |
384 | |
385 | intersectionFilter.prepend(filter: metaDataFilter); |
386 | intersectionFilter.prepend(filter: metaDataFilter); |
387 | intersectionFilter.prepend(filter: unionFilter); |
388 | intersectionFilter.prepend(filter: metaDataFilter); |
389 | QCOMPARE(intersectionFilter.isEmpty(), false); |
390 | QCOMPARE(intersectionFilter.filterCount(), 4); |
391 | |
392 | filters = intersectionFilter.filters(); |
393 | QCOMPARE(filters.count(), 4); |
394 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
395 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
396 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
397 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
398 | |
399 | intersectionFilter.prepend(filter: unionFilter && metaDataFilter); |
400 | QCOMPARE(intersectionFilter.isEmpty(), false); |
401 | QCOMPARE(intersectionFilter.filterCount(), 6); |
402 | |
403 | filters = intersectionFilter.filters(); |
404 | QCOMPARE(filters.count(), 6); |
405 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Union); |
406 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
407 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
408 | QCOMPARE(filters.at(3).type(), QGalleryFilter::Union); |
409 | QCOMPARE(filters.at(4).type(), QGalleryFilter::MetaData); |
410 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
411 | } |
412 | |
413 | void tst_QGalleryFilter::assignment() |
414 | { |
415 | QGalleryFilter filter; |
416 | |
417 | QGalleryMetaDataFilter metaDataFilter; |
418 | QGalleryUnionFilter unionFilter; |
419 | QGalleryIntersectionFilter intersectionFilter; |
420 | |
421 | QCOMPARE(filter.isValid(), false); |
422 | QCOMPARE(filter.type(), QGalleryFilter::Invalid); |
423 | |
424 | filter = metaDataFilter; |
425 | QCOMPARE(filter.isValid(), true); |
426 | QCOMPARE(filter.type(), QGalleryFilter::MetaData); |
427 | |
428 | filter = unionFilter; |
429 | QCOMPARE(filter.isValid(), true); |
430 | QCOMPARE(filter.type(), QGalleryFilter::Union); |
431 | |
432 | filter = intersectionFilter; |
433 | QCOMPARE(filter.isValid(), true); |
434 | QCOMPARE(filter.type(), QGalleryFilter::Intersection); |
435 | } |
436 | |
437 | void tst_QGalleryFilter::copy() |
438 | { |
439 | QGalleryMetaDataFilter metaDataFilter; |
440 | QGalleryUnionFilter unionFilter; |
441 | QGalleryIntersectionFilter intersectionFilter; |
442 | |
443 | { |
444 | QGalleryFilter filter(metaDataFilter); |
445 | QCOMPARE(filter.isValid(), true); |
446 | QCOMPARE(filter.type(), QGalleryFilter::MetaData); |
447 | } { |
448 | QGalleryFilter filter(unionFilter); |
449 | QCOMPARE(filter.isValid(), true); |
450 | QCOMPARE(filter.type(), QGalleryFilter::Union); |
451 | } { |
452 | QGalleryFilter filter(intersectionFilter); |
453 | QCOMPARE(filter.isValid(), true); |
454 | QCOMPARE(filter.type(), QGalleryFilter::Intersection); |
455 | } |
456 | } |
457 | |
458 | void tst_QGalleryFilter::copyOnWrite() |
459 | { |
460 | QList<QGalleryFilter> filters; |
461 | |
462 | QGalleryMetaDataFilter metaDataFilter; |
463 | QGalleryUnionFilter unionFilter; |
464 | QGalleryIntersectionFilter intersectionFilter; |
465 | |
466 | { |
467 | QGalleryMetaDataFilter filter; |
468 | filter.setPropertyName(QLatin1String("albumTitle" )); |
469 | filter.setValue(QLatin1String("Greatest Hits" )); |
470 | filter.setComparator(QGalleryFilter::EndsWith); |
471 | filter.setNegated(true); |
472 | |
473 | metaDataFilter = filter; |
474 | |
475 | QGalleryMetaDataFilter filterCopy(filter); |
476 | filter.setPropertyName(QLatin1String("artist" )); |
477 | filter.setValue(QLatin1String("Self Titled" )); |
478 | filter.setComparator(QGalleryFilter::StartsWith); |
479 | |
480 | QCOMPARE(filterCopy.propertyName(), QLatin1String("albumTitle" )); |
481 | QCOMPARE(filterCopy.value(), QVariant(QLatin1String("Greatest Hits" ))); |
482 | QCOMPARE(filterCopy.comparator(), QGalleryFilter::EndsWith); |
483 | QCOMPARE(filterCopy.isNegated(), true); |
484 | |
485 | QCOMPARE(filter.propertyName(), QLatin1String("artist" )); |
486 | QCOMPARE(filter.value(), QVariant(QLatin1String("Self Titled" ))); |
487 | QCOMPARE(filter.comparator(), QGalleryFilter::StartsWith); |
488 | QCOMPARE(filter.isNegated(), true); |
489 | } { |
490 | QGalleryUnionFilter filter; |
491 | filter.append(filter: QGalleryMetaDataFilter()); |
492 | |
493 | unionFilter = filter; |
494 | |
495 | QGalleryUnionFilter filterCopy(filter); |
496 | filter.append(filter: QGalleryIntersectionFilter()); |
497 | filter.append(filter: filterCopy); |
498 | filter.remove(index: 0); |
499 | |
500 | filters = filterCopy.filters(); |
501 | QCOMPARE(filters.count(), 1); |
502 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
503 | |
504 | filters = filter.filters(); |
505 | QCOMPARE(filters.count(), 2); |
506 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Intersection); |
507 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
508 | } { |
509 | QGalleryIntersectionFilter filter; |
510 | filter.append(filter: QGalleryMetaDataFilter()); |
511 | |
512 | intersectionFilter = filter; |
513 | |
514 | QGalleryIntersectionFilter filterCopy(filter); |
515 | filter.append(filter: QGalleryUnionFilter()); |
516 | filter.append(filter: filterCopy); |
517 | filter.remove(index: 0); |
518 | |
519 | filters = filterCopy.filters(); |
520 | QCOMPARE(filters.count(), 1); |
521 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
522 | |
523 | filters = filter.filters(); |
524 | QCOMPARE(filters.count(), 2); |
525 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Union); |
526 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
527 | } |
528 | |
529 | QCOMPARE(metaDataFilter.propertyName(), QLatin1String("albumTitle" )); |
530 | QCOMPARE(metaDataFilter.value(), QVariant(QLatin1String("Greatest Hits" ))); |
531 | QCOMPARE(metaDataFilter.comparator(), QGalleryFilter::EndsWith); |
532 | QCOMPARE(metaDataFilter.isNegated(), true); |
533 | |
534 | filters = unionFilter.filters(); |
535 | QCOMPARE(filters.count(), 1); |
536 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
537 | |
538 | filters = intersectionFilter.filters(); |
539 | QCOMPARE(filters.count(), 1); |
540 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
541 | } |
542 | |
543 | void tst_QGalleryFilter::cast() |
544 | { |
545 | QGalleryFilter metaDataFilter = QGalleryMetaDataFilter(); |
546 | QGalleryFilter unionFilter = QGalleryUnionFilter(); |
547 | QGalleryFilter intersectionFilter = QGalleryIntersectionFilter(); |
548 | |
549 | QCOMPARE(metaDataFilter.type(), QGalleryFilter::MetaData); |
550 | QCOMPARE(unionFilter.type(), QGalleryFilter::Union); |
551 | QCOMPARE(intersectionFilter.type(), QGalleryFilter::Intersection); |
552 | |
553 | QCOMPARE(metaDataFilter.isValid(), true); |
554 | QCOMPARE(unionFilter.isValid(), true); |
555 | QCOMPARE(intersectionFilter.isValid(), true); |
556 | |
557 | QCOMPARE(metaDataFilter.toMetaDataFilter().isValid(), true); |
558 | QCOMPARE(metaDataFilter.toUnionFilter().isValid(), false); |
559 | QCOMPARE(metaDataFilter.toIntersectionFilter().isValid(), false); |
560 | |
561 | QCOMPARE(unionFilter.toMetaDataFilter().isValid(), false); |
562 | QCOMPARE(unionFilter.toUnionFilter().isValid(), true); |
563 | QCOMPARE(unionFilter.toIntersectionFilter().isValid(), false); |
564 | |
565 | QCOMPARE(intersectionFilter.toMetaDataFilter().isValid(), false); |
566 | QCOMPARE(intersectionFilter.toUnionFilter().isValid(), false); |
567 | QCOMPARE(intersectionFilter.toIntersectionFilter().isValid(), true); |
568 | |
569 | QCOMPARE(QGalleryFilter().toMetaDataFilter().isValid(), false); |
570 | QCOMPARE(QGalleryFilter().toUnionFilter().isValid(), false); |
571 | QCOMPARE(QGalleryFilter().toIntersectionFilter().isValid(), false); |
572 | } |
573 | |
574 | void tst_QGalleryFilter::intersectionOperator() |
575 | { |
576 | QList<QGalleryFilter> filters; |
577 | |
578 | QGalleryMetaDataFilter metaDataFilter; |
579 | QGalleryUnionFilter unionFilter; |
580 | QGalleryIntersectionFilter intersectionFilter; |
581 | |
582 | intersectionFilter = metaDataFilter && intersectionFilter; |
583 | QCOMPARE(intersectionFilter.isValid(), true); |
584 | QCOMPARE(intersectionFilter.isEmpty(), false); |
585 | QCOMPARE(intersectionFilter.filterCount(), 1); |
586 | |
587 | filters = intersectionFilter.filters(); |
588 | QCOMPARE(filters.count(), 1); |
589 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
590 | |
591 | intersectionFilter = metaDataFilter && unionFilter; |
592 | QCOMPARE(intersectionFilter.isValid(), true); |
593 | QCOMPARE(intersectionFilter.isEmpty(), false); |
594 | QCOMPARE(intersectionFilter.filterCount(), 2); |
595 | |
596 | filters = intersectionFilter.filters(); |
597 | QCOMPARE(filters.count(), 2); |
598 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
599 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
600 | |
601 | intersectionFilter = unionFilter && metaDataFilter; |
602 | QCOMPARE(intersectionFilter.isValid(), true); |
603 | QCOMPARE(intersectionFilter.isEmpty(), false); |
604 | QCOMPARE(intersectionFilter.filterCount(), 2); |
605 | |
606 | filters = intersectionFilter.filters(); |
607 | QCOMPARE(filters.count(), 2); |
608 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Union); |
609 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
610 | |
611 | intersectionFilter = intersectionFilter && metaDataFilter; |
612 | QCOMPARE(intersectionFilter.isValid(), true); |
613 | QCOMPARE(intersectionFilter.isEmpty(), false); |
614 | QCOMPARE(intersectionFilter.filterCount(), 3); |
615 | |
616 | filters = intersectionFilter.filters(); |
617 | QCOMPARE(filters.count(), 3); |
618 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Union); |
619 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
620 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
621 | } |
622 | |
623 | void tst_QGalleryFilter::unionOperator() |
624 | { |
625 | QList<QGalleryFilter> filters; |
626 | |
627 | QGalleryMetaDataFilter metaDataFilter; |
628 | QGalleryIntersectionFilter intersectionFilter; |
629 | QGalleryUnionFilter unionFilter; |
630 | |
631 | unionFilter = metaDataFilter || unionFilter; |
632 | QCOMPARE(unionFilter.isValid(), true); |
633 | QCOMPARE(unionFilter.isEmpty(), false); |
634 | QCOMPARE(unionFilter.filterCount(), 1); |
635 | |
636 | filters = unionFilter.filters(); |
637 | QCOMPARE(filters.count(), 1); |
638 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
639 | |
640 | unionFilter = metaDataFilter || intersectionFilter; |
641 | QCOMPARE(unionFilter.isValid(), true); |
642 | QCOMPARE(unionFilter.isEmpty(), false); |
643 | QCOMPARE(unionFilter.filterCount(), 2); |
644 | |
645 | filters = unionFilter.filters(); |
646 | QCOMPARE(filters.count(), 2); |
647 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
648 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
649 | |
650 | unionFilter = intersectionFilter || metaDataFilter; |
651 | QCOMPARE(unionFilter.isValid(), true); |
652 | QCOMPARE(unionFilter.isEmpty(), false); |
653 | QCOMPARE(unionFilter.filterCount(), 2); |
654 | |
655 | filters = unionFilter.filters(); |
656 | QCOMPARE(filters.count(), 2); |
657 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Intersection); |
658 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
659 | |
660 | unionFilter = unionFilter || metaDataFilter; |
661 | QCOMPARE(unionFilter.isValid(), true); |
662 | QCOMPARE(unionFilter.isEmpty(), false); |
663 | QCOMPARE(unionFilter.filterCount(), 3); |
664 | |
665 | filters = unionFilter.filters(); |
666 | QCOMPARE(filters.count(), 3); |
667 | QCOMPARE(filters.at(0).type(), QGalleryFilter::Intersection); |
668 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
669 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
670 | } |
671 | |
672 | void tst_QGalleryFilter::intersectionStreamOperator() |
673 | { |
674 | QGalleryMetaDataFilter metaDataFilter; |
675 | QGalleryUnionFilter unionFilter; |
676 | |
677 | QGalleryIntersectionFilter intersectionFilter = QGalleryIntersectionFilter() |
678 | << metaDataFilter |
679 | << metaDataFilter |
680 | << unionFilter |
681 | << metaDataFilter; |
682 | |
683 | QCOMPARE(intersectionFilter.isEmpty(), false); |
684 | QCOMPARE(intersectionFilter.filterCount(), 4); |
685 | |
686 | QList<QGalleryFilter> filters = intersectionFilter.filters(); |
687 | QCOMPARE(filters.count(), 4); |
688 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
689 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
690 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Union); |
691 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
692 | } |
693 | |
694 | void tst_QGalleryFilter::unionStreamOperator() |
695 | { |
696 | QGalleryMetaDataFilter metaDataFilter; |
697 | QGalleryIntersectionFilter intersectionFilter; |
698 | |
699 | QGalleryUnionFilter unionFilter = QGalleryUnionFilter() |
700 | <<metaDataFilter |
701 | <<metaDataFilter |
702 | <<intersectionFilter |
703 | <<metaDataFilter; |
704 | |
705 | QCOMPARE(unionFilter.isEmpty(), false); |
706 | QCOMPARE(unionFilter.filterCount(), 4); |
707 | |
708 | QList<QGalleryFilter> filters = unionFilter.filters(); |
709 | QCOMPARE(filters.count(), 4); |
710 | |
711 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
712 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
713 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Intersection); |
714 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
715 | } |
716 | |
717 | void tst_QGalleryFilter::propertyOperators_data() |
718 | { |
719 | QTest::addColumn<QGalleryMetaDataFilter>(name: "filter" ); |
720 | QTest::addColumn<QString>(name: "propertyName" ); |
721 | QTest::addColumn<QVariant>(name: "value" ); |
722 | QTest::addColumn<QGalleryFilter::Comparator>(name: "comparator" ); |
723 | |
724 | const QGalleryProperty albumTitle = {.m_name: "albumTitle" , .m_length: sizeof("albumTitle" )}; |
725 | const QGalleryProperty trackNumber = {.m_name: "trackNumber" , .m_length: sizeof("trackNumber" )}; |
726 | |
727 | QTest::newRow(dataTag: "albumTitle == Self Titled" ) |
728 | << (albumTitle == QLatin1String("Self Titled" )) |
729 | << "albumTitle" |
730 | << QVariant(QLatin1String("Self Titled" )) |
731 | << QGalleryFilter::Equals; |
732 | |
733 | QTest::newRow(dataTag: "trackNumber >= 3" ) |
734 | << (trackNumber >= 3) |
735 | << "trackNumber" |
736 | << QVariant(3) |
737 | << QGalleryFilter::GreaterThanEquals; |
738 | |
739 | QTest::newRow(dataTag: "trackNumber > 3" ) |
740 | << (trackNumber > 3) |
741 | << "trackNumber" |
742 | << QVariant(3) |
743 | << QGalleryFilter::GreaterThan; |
744 | |
745 | QTest::newRow(dataTag: "trackNumber <= 3" ) |
746 | << (trackNumber <= 3) |
747 | << "trackNumber" |
748 | << QVariant(3) |
749 | << QGalleryFilter::LessThanEquals; |
750 | |
751 | QTest::newRow(dataTag: "trackNumber < 3" ) |
752 | << (trackNumber < 3) |
753 | << "trackNumber" |
754 | << QVariant(3) |
755 | << QGalleryFilter::LessThan; |
756 | |
757 | QTest::newRow(dataTag: "albumTitle.contains(lf Titl)" ) |
758 | << albumTitle.contains(string: QLatin1String("lf Titl" )) |
759 | << "albumTitle" |
760 | << QVariant(QLatin1String("lf Titl" )) |
761 | << QGalleryFilter::Contains; |
762 | |
763 | QTest::newRow(dataTag: "albumTitle.startsWith(Self)" ) |
764 | << albumTitle.startsWith(string: QLatin1String("Self" )) |
765 | << "albumTitle" |
766 | << QVariant(QLatin1String("Self" )) |
767 | << QGalleryFilter::StartsWith; |
768 | |
769 | QTest::newRow(dataTag: "albumTitle.endsWith(Self)" ) |
770 | << albumTitle.endsWith(string: QLatin1String("Titled" )) |
771 | << "albumTitle" |
772 | << QVariant(QLatin1String("Titled" )) |
773 | << QGalleryFilter::EndsWith; |
774 | |
775 | QTest::newRow(dataTag: "albumTitle.wildcard(S*f T*d)" ) |
776 | << albumTitle.wildcard(string: QLatin1String("S*f T*d" )) |
777 | << "albumTitle" |
778 | << QVariant(QLatin1String("S*f T*d" )) |
779 | << QGalleryFilter::Wildcard; |
780 | |
781 | QTest::newRow(dataTag: "albumTitle.regExp((Self Titled|Greatest Hits))" ) |
782 | << albumTitle.regExp(rx: QLatin1String("(Self Titled|Greatest Hits)" )) |
783 | << "albumTitle" |
784 | << QVariant(QLatin1String("(Self Titled|Greatest Hits)" )) |
785 | << QGalleryFilter::RegExp; |
786 | |
787 | QTest::newRow(dataTag: "albumTitle.regExp(QRegExp((Self Titled|Greatest Hits)))" ) |
788 | << albumTitle.regExp(rx: QRegExp(QLatin1String("(Self Titled|Greatest Hits)" ))) |
789 | << "albumTitle" |
790 | << QVariant(QRegExp(QLatin1String("(Self Titled|Greatest Hits)" ))) |
791 | << QGalleryFilter::RegExp; |
792 | } |
793 | |
794 | void tst_QGalleryFilter::propertyOperators() |
795 | { |
796 | QFETCH(QGalleryMetaDataFilter, filter); |
797 | QFETCH(QString, propertyName); |
798 | QFETCH(QVariant, value); |
799 | QFETCH(QGalleryFilter::Comparator, comparator); |
800 | |
801 | QCOMPARE(filter.isValid(), true); |
802 | QCOMPARE(filter.propertyName(), propertyName); |
803 | QCOMPARE(filter.value(), value); |
804 | QCOMPARE(filter.comparator(), comparator); |
805 | } |
806 | |
807 | void tst_QGalleryFilter::equality_data() |
808 | { |
809 | const QGalleryProperty albumProperty = {.m_name: "albumTitle" , .m_length: sizeof("albumTitle" )}; |
810 | const QGalleryProperty artistProperty = {.m_name: "artistTitle" , .m_length: sizeof("artistTitle>" )}; |
811 | const QGalleryProperty durationProperty = {.m_name: "duration" , .m_length: sizeof("duration" )}; |
812 | const QGalleryProperty trackProperty = {.m_name: "trackNumber" , .m_length: sizeof("trackNumber" )}; |
813 | |
814 | QGalleryMetaDataFilter metaDataFilter = albumProperty == QLatin1String("Greatest Hits" ); |
815 | QGalleryMetaDataFilter metaDataRangeFilter = durationProperty < 12000; |
816 | QGalleryIntersectionFilter unionFilter |
817 | = metaDataFilter |
818 | && artistProperty == QLatin1String("Them" ) |
819 | && metaDataRangeFilter; |
820 | QGalleryUnionFilter intersectionFilter |
821 | = unionFilter || albumProperty == QLatin1String("Self Titled" ); |
822 | |
823 | QTest::addColumn<QGalleryFilter>(name: "filter1" ); |
824 | QTest::addColumn<QGalleryFilter>(name: "filter2" ); |
825 | QTest::addColumn<bool>(name: "isEqual" ); |
826 | |
827 | QTest::newRow(dataTag: "null filters" ) |
828 | << QGalleryFilter() |
829 | << QGalleryFilter() |
830 | << true; |
831 | QTest::newRow(dataTag: "null meta-data filters" ) |
832 | << QGalleryFilter(QGalleryMetaDataFilter()) |
833 | << QGalleryFilter(QGalleryMetaDataFilter()) |
834 | << true; |
835 | QTest::newRow(dataTag: "null union filters" ) |
836 | << QGalleryFilter(QGalleryUnionFilter()) |
837 | << QGalleryFilter(QGalleryUnionFilter()) |
838 | << true; |
839 | QTest::newRow(dataTag: "null intersection filters" ) |
840 | << QGalleryFilter(QGalleryIntersectionFilter()) |
841 | << QGalleryFilter(QGalleryIntersectionFilter()) |
842 | << true; |
843 | |
844 | QTest::newRow(dataTag: "same meta-data filter" ) |
845 | << QGalleryFilter(metaDataFilter) |
846 | << QGalleryFilter(metaDataFilter) |
847 | << true; |
848 | QTest::newRow(dataTag: "same union filter" ) |
849 | << QGalleryFilter(unionFilter) |
850 | << QGalleryFilter(unionFilter) |
851 | << true; |
852 | QTest::newRow(dataTag: "same intersection filter" ) |
853 | << QGalleryFilter(intersectionFilter) |
854 | << QGalleryFilter(intersectionFilter) |
855 | << true; |
856 | |
857 | QTest::newRow(dataTag: "equal meta-data filters" ) |
858 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" )) |
859 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" )) |
860 | << true; |
861 | QTest::newRow(dataTag: "equal meta-data range filters" ) |
862 | << QGalleryFilter(trackProperty < 14) |
863 | << QGalleryFilter(trackProperty < 14) |
864 | << true; |
865 | QTest::newRow(dataTag: "equal union filters" ) |
866 | << QGalleryFilter(durationProperty > 10000 && metaDataFilter) |
867 | << QGalleryFilter(durationProperty > 10000 && metaDataFilter) |
868 | << true; |
869 | QTest::newRow(dataTag: "equal intersection filters" ) |
870 | << QGalleryFilter(metaDataFilter || albumProperty == QLatin1String("Self Titled" )) |
871 | << QGalleryFilter(metaDataFilter || albumProperty == QLatin1String("Self Titled" )) |
872 | << true; |
873 | |
874 | QTest::newRow(dataTag: "unequal meta-data filter property names" ) |
875 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" )) |
876 | << QGalleryFilter(artistProperty == QLatin1String("Self Titled" )) |
877 | << false; |
878 | QTest::newRow(dataTag: "unequal meta-data filter values" ) |
879 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" )) |
880 | << QGalleryFilter(albumProperty == QLatin1String("Greatest Hits" )) |
881 | << false; |
882 | QTest::newRow(dataTag: "unequal meta-data filter match flags" ) |
883 | << QGalleryFilter(albumProperty.contains(string: QLatin1String("Self Titled" ))) |
884 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" )) |
885 | << false; |
886 | QTest::newRow(dataTag: "unequal meta-data filters" ) |
887 | << QGalleryFilter(albumProperty.contains(string: QLatin1String("Greatest Hits" ))) |
888 | << QGalleryFilter(artistProperty == QLatin1String("Self Titled" )) |
889 | << false; |
890 | |
891 | QTest::newRow(dataTag: "uneuqal meta-data filter property names (less than)" ) |
892 | << QGalleryFilter(trackProperty < 15) |
893 | << QGalleryFilter(durationProperty < 15) |
894 | << false; |
895 | QTest::newRow(dataTag: "uneuqal meta-data filter property names (greater than" ) |
896 | << QGalleryFilter(trackProperty > 15) |
897 | << QGalleryFilter(durationProperty > 15) |
898 | << false; |
899 | QTest::newRow(dataTag: "unequal meta-data filter values (less than)" ) |
900 | << QGalleryFilter(trackProperty < 16) |
901 | << QGalleryFilter(trackProperty < 4) |
902 | << false; |
903 | QTest::newRow(dataTag: "unequal meta-data filter values (greater than)" ) |
904 | << QGalleryFilter(trackProperty > 15) |
905 | << QGalleryFilter(trackProperty > 3) |
906 | << false; |
907 | QTest::newRow(dataTag: "unequal meta-data filter comparison (less than" ) |
908 | << QGalleryFilter(trackProperty < 15) |
909 | << QGalleryFilter(trackProperty <= 15) |
910 | << false; |
911 | QTest::newRow(dataTag: "unequal meta-data filter comparison (greater than" ) |
912 | << QGalleryFilter(trackProperty > 15) |
913 | << QGalleryFilter(trackProperty >= 15) |
914 | << false; |
915 | QTest::newRow(dataTag: "unequal meta-data filter comparison (mixed" ) |
916 | << QGalleryFilter(trackProperty > 15) |
917 | << QGalleryFilter(trackProperty <= 15) |
918 | << false; |
919 | QTest::newRow(dataTag: "unequal meta-data filter" ) |
920 | << QGalleryFilter(trackProperty < 3) |
921 | << QGalleryFilter(durationProperty >= 23004) |
922 | << false; |
923 | QTest::newRow(dataTag: "unequal meta-data filter (negated" ) |
924 | << QGalleryFilter(metaDataFilter) |
925 | << QGalleryFilter(!metaDataFilter) |
926 | << false; |
927 | QTest::newRow(dataTag: "unequal union filter count" ) |
928 | << QGalleryFilter(unionFilter) |
929 | << QGalleryFilter(unionFilter && metaDataFilter) |
930 | << false; |
931 | QTest::newRow(dataTag: "unequal union filter" ) |
932 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" ) |
933 | && artistProperty == QLatin1String("Self Titled" )) |
934 | << QGalleryFilter(albumProperty == QLatin1String("Greatest Hits" ) |
935 | && artistProperty == QLatin1String("Self Titled" )) |
936 | << false; |
937 | |
938 | QTest::newRow(dataTag: "unequal intersection filter count" ) |
939 | << QGalleryFilter(intersectionFilter) |
940 | << QGalleryFilter(intersectionFilter || metaDataFilter) |
941 | << false; |
942 | QTest::newRow(dataTag: "unequal intersection filter" ) |
943 | << QGalleryFilter(albumProperty == QLatin1String("Self Titled" ) |
944 | || artistProperty == QLatin1String("Self Titled" )) |
945 | << QGalleryFilter(albumProperty == QLatin1String("Greatest Hits" ) |
946 | || artistProperty == QLatin1String("Self Titled" )) |
947 | << false; |
948 | |
949 | QTest::newRow(dataTag: "null filter != null meta data filter" ) |
950 | << QGalleryFilter() |
951 | << QGalleryFilter(QGalleryMetaDataFilter()) |
952 | << false; |
953 | QTest::newRow(dataTag: "null filter != null union filter" ) |
954 | << QGalleryFilter() |
955 | << QGalleryFilter(QGalleryUnionFilter()) |
956 | << false; |
957 | QTest::newRow(dataTag: "null filter != null intersection filter" ) |
958 | << QGalleryFilter() |
959 | << QGalleryFilter(QGalleryIntersectionFilter()) |
960 | << false; |
961 | |
962 | QTest::newRow(dataTag: "null filter != populated meta data filter" ) |
963 | << QGalleryFilter() |
964 | << QGalleryFilter(metaDataFilter) |
965 | << false; |
966 | QTest::newRow(dataTag: "null filter != populated union filter" ) |
967 | << QGalleryFilter() |
968 | << QGalleryFilter(unionFilter) |
969 | << false; |
970 | QTest::newRow(dataTag: "null filter != populated intersection filter" ) |
971 | << QGalleryFilter() |
972 | << QGalleryFilter(intersectionFilter) |
973 | << false; |
974 | |
975 | QTest::newRow(dataTag: "null meta-data filter != populated meta data filter" ) |
976 | << QGalleryFilter(QGalleryMetaDataFilter()) |
977 | << QGalleryFilter(metaDataFilter) |
978 | << false; |
979 | QTest::newRow(dataTag: "null union filter != populated union filter" ) |
980 | << QGalleryFilter(QGalleryUnionFilter()) |
981 | << QGalleryFilter(unionFilter) |
982 | << false; |
983 | QTest::newRow(dataTag: "null intersection filter != populated intersection filter" ) |
984 | << QGalleryFilter(QGalleryIntersectionFilter()) |
985 | << QGalleryFilter(intersectionFilter) |
986 | << false; |
987 | QTest::newRow(dataTag: "null meta-data filter != null union filter" ) |
988 | << QGalleryFilter(QGalleryMetaDataFilter()) |
989 | << QGalleryFilter(QGalleryUnionFilter()) |
990 | << false; |
991 | QTest::newRow(dataTag: "null meta-data filter != null intersection filter" ) |
992 | << QGalleryFilter(QGalleryMetaDataFilter()) |
993 | << QGalleryFilter(QGalleryIntersectionFilter()) |
994 | << false; |
995 | QTest::newRow(dataTag: "null union filter != null intersection filter" ) |
996 | << QGalleryFilter(QGalleryUnionFilter()) |
997 | << QGalleryFilter(QGalleryIntersectionFilter()) |
998 | << false; |
999 | } |
1000 | |
1001 | void tst_QGalleryFilter::equality() |
1002 | { |
1003 | QFETCH(QGalleryFilter, filter1); |
1004 | QFETCH(QGalleryFilter, filter2); |
1005 | QFETCH(bool, isEqual); |
1006 | |
1007 | QCOMPARE(filter1 == filter2, isEqual); |
1008 | QCOMPARE(filter2 == filter1, isEqual); |
1009 | } |
1010 | |
1011 | void tst_QGalleryFilter::inequality_data() |
1012 | { |
1013 | equality_data(); |
1014 | } |
1015 | |
1016 | void tst_QGalleryFilter::inequality() |
1017 | { |
1018 | QFETCH(QGalleryFilter, filter1); |
1019 | QFETCH(QGalleryFilter, filter2); |
1020 | QFETCH(bool, isEqual); |
1021 | |
1022 | QCOMPARE(filter1 != filter2, !isEqual); |
1023 | QCOMPARE(filter2 != filter1, !isEqual); |
1024 | } |
1025 | |
1026 | #ifndef QT_NO_DEBUG_STREAM |
1027 | |
1028 | #define TST_QGALLERYMETADATAFILTER_DEBUG_TEXT "QGalleryMetaDataFilter(" \ |
1029 | "propertyName: \"title\" " \ |
1030 | "comparator: 6 " \ |
1031 | "value: QVariant(QString, \"Greatest\") ) " |
1032 | |
1033 | void tst_QGalleryFilter::debugMessage_data() |
1034 | { |
1035 | QTest::addColumn<QGalleryFilter>(name: "filter" ); |
1036 | QTest::addColumn<QByteArray>(name: "message" ); |
1037 | |
1038 | QTest::newRow(dataTag: "null QGalleryFilter" ) |
1039 | << QGalleryFilter(QGalleryFilter()) |
1040 | << QByteArray("QGalleryFilter()" ); |
1041 | QTest::newRow(dataTag: "null QGalleryMetaDataFilter" ) |
1042 | << QGalleryFilter(QGalleryMetaDataFilter()) |
1043 | << QByteArray("QGalleryMetaDataFilter(comparator: 0)" ); |
1044 | QTest::newRow(dataTag: "null QGalleryUnionFilter" ) |
1045 | << QGalleryFilter(QGalleryUnionFilter()) |
1046 | << QByteArray("QGalleryUnionFilter()" ); |
1047 | QTest::newRow(dataTag: "null QGalleryIntersectionFilter" ) |
1048 | << QGalleryFilter(QGalleryIntersectionFilter()) |
1049 | << QByteArray("QGalleryIntersectionFilter()" ); |
1050 | |
1051 | QGalleryMetaDataFilter metaDataFilter; |
1052 | metaDataFilter.setPropertyName(QLatin1String("title" )); |
1053 | metaDataFilter.setValue(QLatin1String("Greatest" )); |
1054 | metaDataFilter.setComparator(QGalleryFilter::StartsWith); |
1055 | |
1056 | QTest::newRow(dataTag: "Populated QGalleryMetaDataFilter" ) |
1057 | << QGalleryFilter(metaDataFilter) |
1058 | << QByteArray(TST_QGALLERYMETADATAFILTER_DEBUG_TEXT); |
1059 | |
1060 | QTest::newRow(dataTag: "Inverse Populated QGallleryMetaDataFilter" ) |
1061 | << QGalleryFilter(!metaDataFilter) |
1062 | << QByteArray("!" TST_QGALLERYMETADATAFILTER_DEBUG_TEXT); |
1063 | |
1064 | QGalleryUnionFilter unionFilter; |
1065 | unionFilter.append(filter: metaDataFilter); |
1066 | |
1067 | QTest::newRow(dataTag: "Single Child QGalleryUnionFilter" ) |
1068 | << QGalleryFilter(unionFilter) |
1069 | << QByteArray("QGalleryUnionFilter(" |
1070 | TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1071 | ") " ); |
1072 | |
1073 | QGalleryIntersectionFilter intersectionFilter; |
1074 | intersectionFilter.append(filter: metaDataFilter); |
1075 | |
1076 | QTest::newRow(dataTag: "Single Child QGalleryIntersectionFilter" ) |
1077 | << QGalleryFilter(intersectionFilter) |
1078 | << QByteArray("QGalleryIntersectionFilter(" |
1079 | TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1080 | ") " ); |
1081 | |
1082 | unionFilter.append(filter: !metaDataFilter); |
1083 | |
1084 | QTest::newRow(dataTag: "Multiple Child QGalleryUnionFilter" ) |
1085 | << QGalleryFilter(unionFilter) |
1086 | << QByteArray("QGalleryUnionFilter(" |
1087 | TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1088 | " && " |
1089 | "!" TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1090 | ") " ); |
1091 | |
1092 | intersectionFilter.append(filter: !metaDataFilter); |
1093 | |
1094 | QTest::newRow(dataTag: "Multiple Child QGalleryIntersectionFilter" ) |
1095 | << QGalleryFilter(intersectionFilter) |
1096 | << QByteArray("QGalleryIntersectionFilter(" |
1097 | TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1098 | " || " |
1099 | "!" TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1100 | ") " ); |
1101 | } |
1102 | |
1103 | #undef TST_QGALLERYMETADATAFILTER_DEBUG_TEXT |
1104 | |
1105 | void tst_QGalleryFilter::debugMessage() |
1106 | { |
1107 | QFETCH(QGalleryFilter, filter); |
1108 | QFETCH(QByteArray, message); |
1109 | |
1110 | QTest::ignoreMessage(type: QtDebugMsg, message: message.constData()); |
1111 | qDebug() << filter; |
1112 | } |
1113 | #endif |
1114 | |
1115 | void tst_QGalleryFilter::galleryType() |
1116 | { |
1117 | { |
1118 | QGalleryType type = { .m_name: "Audio" , .m_length: sizeof("Audio" ) - 1 }; |
1119 | |
1120 | const QString name = QLatin1String("Audio" ); |
1121 | |
1122 | QCOMPARE(type.name(), name); |
1123 | QCOMPARE(QString(type), name); |
1124 | } { |
1125 | QGalleryType type = { .m_name: "Video" , .m_length: sizeof("Video" ) - 1 }; |
1126 | |
1127 | const QString name = QLatin1String("Video" ); |
1128 | |
1129 | QCOMPARE(type.name(), name); |
1130 | QCOMPARE(QString(type), name); |
1131 | } |
1132 | } |
1133 | |
1134 | void tst_QGalleryFilter::galleryProperty() |
1135 | { |
1136 | { |
1137 | QGalleryProperty property = { .m_name: "title" , .m_length: sizeof("title" ) - 1 }; |
1138 | |
1139 | const QString name = QLatin1String("title" ); |
1140 | const QString ascendingName = QLatin1String("+title" ); |
1141 | const QString descendingName = QLatin1String("-title" ); |
1142 | |
1143 | QCOMPARE(property.name(), name); |
1144 | QCOMPARE(QString(property), name); |
1145 | QCOMPARE(property.ascending(), ascendingName); |
1146 | QCOMPARE(property.descending(), descendingName); |
1147 | } { |
1148 | QGalleryProperty property = { .m_name: "duration" , .m_length: sizeof("duration" ) - 1 }; |
1149 | |
1150 | const QString name = QLatin1String("duration" ); |
1151 | const QString ascendingName = QLatin1String("+duration" ); |
1152 | const QString descendingName = QLatin1String("-duration" ); |
1153 | |
1154 | QCOMPARE(property.name(), name); |
1155 | QCOMPARE(QString(property), name); |
1156 | QCOMPARE(property.ascending(), ascendingName); |
1157 | QCOMPARE(property.descending(), descendingName); |
1158 | } |
1159 | } |
1160 | |
1161 | /* Test case for insert QGalleryIntersectionFilter */ |
1162 | void tst_QGalleryFilter::intersectionFilterInsert() |
1163 | { |
1164 | QGalleryIntersectionFilter intersectionFilter; |
1165 | |
1166 | QGalleryMetaDataFilter metaDataFilter; |
1167 | QGalleryUnionFilter unionFilter; |
1168 | |
1169 | QCOMPARE(intersectionFilter.isValid(), true); |
1170 | QCOMPARE(intersectionFilter.isEmpty(), true); |
1171 | QCOMPARE(intersectionFilter.filterCount(), 0); |
1172 | |
1173 | intersectionFilter.append(filter: metaDataFilter); |
1174 | intersectionFilter.append(filter: unionFilter); |
1175 | intersectionFilter.append(filter: metaDataFilter); |
1176 | |
1177 | QCOMPARE(intersectionFilter.filterCount(), 3); |
1178 | |
1179 | QList<QGalleryFilter>filters = intersectionFilter.filters(); |
1180 | QCOMPARE(filters.count(), 3); |
1181 | |
1182 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1183 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
1184 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1185 | |
1186 | intersectionFilter.insert(index: 1,filter: intersectionFilter); |
1187 | filters = intersectionFilter.filters(); |
1188 | QCOMPARE(filters.count(), 6); |
1189 | |
1190 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1191 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
1192 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Union); |
1193 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
1194 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Union); |
1195 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
1196 | |
1197 | QGalleryIntersectionFilter intersectionFilter1; |
1198 | |
1199 | QCOMPARE(intersectionFilter1.isEmpty(), true); |
1200 | intersectionFilter.insert(index: 1,filter: intersectionFilter1); |
1201 | filters = intersectionFilter.filters(); |
1202 | QCOMPARE(filters.count(), 6); |
1203 | |
1204 | |
1205 | } |
1206 | |
1207 | /* Test case for insert QGalleryIntersectionFilter */ |
1208 | void tst_QGalleryFilter::intersectionFilterPrepend() |
1209 | { |
1210 | QGalleryIntersectionFilter intersectionFilter; |
1211 | |
1212 | QGalleryMetaDataFilter metaDataFilter; |
1213 | QGalleryUnionFilter unionFilter; |
1214 | |
1215 | QCOMPARE(intersectionFilter.isValid(), true); |
1216 | QCOMPARE(intersectionFilter.isEmpty(), true); |
1217 | QCOMPARE(intersectionFilter.filterCount(), 0); |
1218 | |
1219 | intersectionFilter.append(filter: metaDataFilter); |
1220 | intersectionFilter.append(filter: unionFilter); |
1221 | intersectionFilter.append(filter: metaDataFilter); |
1222 | |
1223 | QCOMPARE(intersectionFilter.filterCount(), 3); |
1224 | |
1225 | QList<QGalleryFilter>filters = intersectionFilter.filters(); |
1226 | QCOMPARE(filters.count(), 3); |
1227 | |
1228 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1229 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
1230 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1231 | |
1232 | intersectionFilter.prepend(filter: intersectionFilter); |
1233 | filters = intersectionFilter.filters(); |
1234 | QCOMPARE(filters.count(), 6); |
1235 | |
1236 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1237 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Union); |
1238 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1239 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
1240 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Union); |
1241 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
1242 | |
1243 | QGalleryIntersectionFilter intersectionFilter1; |
1244 | |
1245 | QCOMPARE(intersectionFilter1.isEmpty(), true); |
1246 | intersectionFilter.prepend(filter: intersectionFilter1); |
1247 | filters = intersectionFilter.filters(); |
1248 | QCOMPARE(filters.count(), 6); |
1249 | |
1250 | } |
1251 | |
1252 | |
1253 | /* Test case for insert QGalleryUnionFilter */ |
1254 | void tst_QGalleryFilter::unionFilterInsert() |
1255 | { |
1256 | QGalleryIntersectionFilter intersectionFilter; |
1257 | |
1258 | QGalleryMetaDataFilter metaDataFilter; |
1259 | QGalleryUnionFilter unionFilter; |
1260 | |
1261 | QCOMPARE(unionFilter.isValid(), true); |
1262 | QCOMPARE(unionFilter.isEmpty(), true); |
1263 | QCOMPARE(unionFilter.filterCount(), 0); |
1264 | |
1265 | unionFilter.append(filter: metaDataFilter); |
1266 | unionFilter.append(filter: intersectionFilter); |
1267 | unionFilter.append(filter: metaDataFilter); |
1268 | |
1269 | QCOMPARE(unionFilter.filterCount(), 3); |
1270 | |
1271 | QList<QGalleryFilter>filters = unionFilter.filters(); |
1272 | QCOMPARE(filters.count(), 3); |
1273 | |
1274 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1275 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
1276 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1277 | |
1278 | unionFilter.insert(index: 1,filter: unionFilter); |
1279 | filters = unionFilter.filters(); |
1280 | QCOMPARE(filters.count(), 6); |
1281 | |
1282 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1283 | QCOMPARE(filters.at(1).type(), QGalleryFilter::MetaData); |
1284 | QCOMPARE(filters.at(2).type(), QGalleryFilter::Intersection); |
1285 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
1286 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Intersection); |
1287 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
1288 | |
1289 | QGalleryUnionFilter unionFilter1; |
1290 | |
1291 | QCOMPARE(unionFilter1.isEmpty(), true); |
1292 | unionFilter.insert(index: 1,filter: unionFilter1); |
1293 | filters = unionFilter.filters(); |
1294 | QCOMPARE(filters.count(), 6); |
1295 | |
1296 | |
1297 | } |
1298 | |
1299 | /* Test case for Prepend QGalleryUnionFilter */ |
1300 | void tst_QGalleryFilter::unionFilterPrepend() |
1301 | { |
1302 | QGalleryIntersectionFilter intersectionFilter; |
1303 | |
1304 | QGalleryMetaDataFilter metaDataFilter; |
1305 | QGalleryUnionFilter unionFilter; |
1306 | |
1307 | QCOMPARE(unionFilter.isValid(), true); |
1308 | QCOMPARE(unionFilter.isEmpty(), true); |
1309 | QCOMPARE(unionFilter.filterCount(), 0); |
1310 | |
1311 | unionFilter.append(filter: metaDataFilter); |
1312 | unionFilter.append(filter: intersectionFilter); |
1313 | unionFilter.append(filter: metaDataFilter); |
1314 | |
1315 | QCOMPARE(unionFilter.filterCount(), 3); |
1316 | |
1317 | QList<QGalleryFilter>filters = unionFilter.filters(); |
1318 | QCOMPARE(filters.count(), 3); |
1319 | |
1320 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1321 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
1322 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1323 | |
1324 | unionFilter.prepend(filter: unionFilter); |
1325 | filters = unionFilter.filters(); |
1326 | QCOMPARE(filters.count(), 6); |
1327 | |
1328 | QCOMPARE(filters.at(0).type(), QGalleryFilter::MetaData); |
1329 | QCOMPARE(filters.at(1).type(), QGalleryFilter::Intersection); |
1330 | QCOMPARE(filters.at(2).type(), QGalleryFilter::MetaData); |
1331 | QCOMPARE(filters.at(3).type(), QGalleryFilter::MetaData); |
1332 | QCOMPARE(filters.at(4).type(), QGalleryFilter::Intersection); |
1333 | QCOMPARE(filters.at(5).type(), QGalleryFilter::MetaData); |
1334 | |
1335 | QGalleryUnionFilter unionFilter1; |
1336 | |
1337 | QCOMPARE(unionFilter1.isEmpty(), true); |
1338 | unionFilter.prepend(filter: unionFilter1); |
1339 | filters = unionFilter.filters(); |
1340 | QCOMPARE(filters.count(), 6); |
1341 | |
1342 | } |
1343 | |
1344 | |
1345 | QTEST_MAIN(tst_QGalleryFilter) |
1346 | |
1347 | #include "tst_qgalleryfilter.moc" |
1348 | |