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 <QtDocGallery/qdocumentgallery.h>
45
46#include <QtTest/QtTest>
47
48Q_DECLARE_METATYPE(QT_DOCGALLERY_PREPEND_NAMESPACE(QGalleryProperty::Attributes))
49
50QT_USE_DOCGALLERY_NAMESPACE
51
52class tst_QDocumentGallery : public QObject
53{
54 Q_OBJECT
55private Q_SLOTS:
56 void isRequestSupported();
57 void itemTypeProperties_data();
58 void itemTypeProperties();
59 void propertyAttributes_data();
60 void propertyAttributes();
61
62private:
63 QDocumentGallery gallery;
64};
65
66void tst_QDocumentGallery::isRequestSupported()
67{
68#if (defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED))
69 const bool platformSupported = true;
70#else
71 const bool platformSupported = false;
72#endif
73
74 QCOMPARE(gallery.isRequestSupported(QGalleryAbstractRequest::QueryRequest), platformSupported);
75 QCOMPARE(gallery.isRequestSupported(QGalleryAbstractRequest::ItemRequest), platformSupported);
76 QCOMPARE(gallery.isRequestSupported(QGalleryAbstractRequest::TypeRequest), platformSupported);
77 QCOMPARE(gallery.isRequestSupported(QGalleryAbstractRequest::RequestType(1000)), false);
78}
79
80void tst_QDocumentGallery::itemTypeProperties_data()
81{
82 QTest::addColumn<QString>(name: "itemType");
83 QTest::addColumn<QStringList>(name: "propertyNames");
84
85 QTest::newRow(dataTag: "null item type") << QString() << QStringList();
86 QTest::newRow(dataTag: "non-existent item type") << QString::fromLatin1(str: "Hello") << QStringList();
87
88 const QStringList fileProperties = QStringList()
89#if defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED)
90 << QDocumentGallery::author
91 << QDocumentGallery::comments
92 << QDocumentGallery::copyright
93 << QDocumentGallery::description
94 << QDocumentGallery::fileExtension
95 << QDocumentGallery::fileName
96 << QDocumentGallery::filePath
97 << QDocumentGallery::fileSize
98 << QDocumentGallery::keywords
99 << QDocumentGallery::language
100 << QDocumentGallery::lastAccessed
101 << QDocumentGallery::lastModified
102 << QDocumentGallery::mimeType
103 << QDocumentGallery::path
104 << QDocumentGallery::rating
105 << QDocumentGallery::subject
106 << QDocumentGallery::title
107 << QDocumentGallery::url;
108#endif
109 ;
110 QTest::newRow(dataTag: "File") << QString(QDocumentGallery::File) << (QStringList(fileProperties));
111
112 QTest::newRow(dataTag: "Audio") << QString(QDocumentGallery::Audio) << (QStringList(fileProperties)
113#if defined(Q_OS_LINUX)
114#if defined(QT_TRACKER_ENABLED)
115 << QDocumentGallery::albumArtist
116 << QDocumentGallery::albumTitle
117 << QDocumentGallery::artist
118 << QDocumentGallery::audioBitRate
119 << QDocumentGallery::audioCodec
120 << QDocumentGallery::channelCount
121 << QDocumentGallery::discNumber
122 << QDocumentGallery::duration
123 << QDocumentGallery::genre
124 << QDocumentGallery::lastPlayed
125 << QDocumentGallery::lyrics
126 << QDocumentGallery::playCount
127 << QDocumentGallery::sampleRate
128 << QDocumentGallery::trackNumber
129 << QDocumentGallery::performer
130 << QDocumentGallery::composer
131#endif
132#endif
133 );
134
135 QTest::newRow(dataTag: "Album") << QString(QDocumentGallery::Album) << (QStringList()
136#if defined(Q_OS_LINUX)
137#if defined(QT_TRACKER_ENABLED)
138 << QDocumentGallery::albumArtist
139 << QDocumentGallery::albumTitle
140 << QDocumentGallery::artist
141 << QDocumentGallery::duration
142 << QDocumentGallery::title
143 << QDocumentGallery::trackCount
144#endif
145#endif
146 );
147 QTest::newRow(dataTag: "PhotoAlbum") << QString(QDocumentGallery::PhotoAlbum) << (QStringList()
148#if defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED)
149 << QDocumentGallery::count
150 << QDocumentGallery::title
151#endif
152 );
153}
154
155void tst_QDocumentGallery::itemTypeProperties()
156{
157 QFETCH(QString, itemType);
158 QFETCH(QStringList, propertyNames);
159
160 QStringList galleryPropertyNames = gallery.itemTypePropertyNames(itemType);
161 propertyNames.sort();
162 galleryPropertyNames.sort();
163
164 QCOMPARE(galleryPropertyNames, propertyNames);
165}
166
167void tst_QDocumentGallery::propertyAttributes_data()
168{
169 QTest::addColumn<QString>(name: "itemType");
170 QTest::addColumn<QString>(name: "propertyName");
171 QTest::addColumn<QGalleryProperty::Attributes>(name: "propertyAttributes");
172
173 QTest::newRow(dataTag: "Null itemType, propertyName")
174 << QString()
175 << QString()
176 << QGalleryProperty::Attributes();
177 QTest::newRow(dataTag: "Null itemType, invalid propertyName")
178 << QString()
179 << QString::fromLatin1(str: "Goodbye")
180 << QGalleryProperty::Attributes();
181 QTest::newRow(dataTag: "Null itemType, valid propertyName")
182 << QString()
183 << QString(QDocumentGallery::fileName)
184 << QGalleryProperty::Attributes();
185 QTest::newRow(dataTag: "Invalid itemType, invalid propertyName")
186 << QString::fromLatin1(str: "Hello")
187 << QString::fromLatin1(str: "Goodbye")
188 << QGalleryProperty::Attributes();
189 QTest::newRow(dataTag: "Invalid itemType, valid propertyName")
190 << QString::fromLatin1(str: "Hello")
191 << QString(QDocumentGallery::fileName)
192 << QGalleryProperty::Attributes();
193 QTest::newRow(dataTag: "Valid itemType, invalid propertyName")
194 << QString(QDocumentGallery::File)
195 << QString::fromLatin1(str: "Goodbye")
196 << QGalleryProperty::Attributes();
197 QTest::newRow(dataTag: "File.fileName")
198 << QString(QDocumentGallery::File)
199 << QString(QDocumentGallery::fileName)
200#if (defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED))
201 << (QGalleryProperty::CanRead
202 | QGalleryProperty::CanFilter
203 | QGalleryProperty::CanSort);
204#else
205 << QGalleryProperty::Attributes();
206#endif
207 QTest::newRow(dataTag: "File.filePath")
208 << QString(QDocumentGallery::File)
209 << QString(QDocumentGallery::filePath)
210#if (defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED))
211 << (QGalleryProperty::CanRead | QGalleryProperty::CanFilter);
212#else
213 << QGalleryProperty::Attributes();
214#endif
215
216 QTest::newRow(dataTag: "Audio.albumTitle")
217 << QString(QDocumentGallery::Audio)
218 << QString(QDocumentGallery::albumTitle)
219#if (defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED))
220 << (QGalleryProperty::CanRead
221 | QGalleryProperty::CanFilter
222 | QGalleryProperty::CanSort);
223#else
224 << QGalleryProperty::Attributes();
225#endif
226 QTest::newRow(dataTag: "Album.duration")
227 << QString(QDocumentGallery::Album)
228 << QString(QDocumentGallery::duration)
229#if defined(Q_OS_LINUX) && defined(QT_TRACKER_ENABLED)
230 << (QGalleryProperty::CanRead
231 | QGalleryProperty::CanFilter
232 | QGalleryProperty::CanSort);
233#else
234 << QGalleryProperty::Attributes();
235#endif
236}
237
238void tst_QDocumentGallery::propertyAttributes()
239{
240 QFETCH(QString, itemType);
241 QFETCH(QString, propertyName);
242 QFETCH(QGalleryProperty::Attributes, propertyAttributes);
243 QCOMPARE(int(gallery.propertyAttributes(propertyName, itemType)), int(propertyAttributes));
244}
245
246#include "tst_qdocumentgallery.moc"
247
248QTEST_MAIN(tst_QDocumentGallery)
249

source code of qtdocgallery/tests/auto/qdocumentgallery/tst_qdocumentgallery.cpp