Changeset View
Changeset View
Standalone View
Standalone View
autotests/taglibextractortest.cpp
Show All 15 Lines | |||||
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this library; if not, write to the Free Software | 17 | * License along with this library; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "taglibextractortest.h" | 22 | #include "taglibextractortest.h" | ||
23 | #include "simpleextractionresult.h" | 23 | #include "simpleextractionresult.h" | ||
24 | #include "propertyinfo.h" | ||||
25 | //TODO: use QTESTFINDDATA and remove this | ||||
24 | #include "indexerextractortestsconfig.h" | 26 | #include "indexerextractortestsconfig.h" | ||
25 | #include "extractors/taglibextractor.h" | 27 | #include "extractors/taglibextractor.h" | ||
26 | 28 | | |||
27 | #include <QDebug> | 29 | #include <QDebug> | ||
28 | #include <QTest> | 30 | #include <QTest> | ||
29 | #include <QDir> | 31 | #include <QDir> | ||
32 | #include <QStringList> | ||||
33 | | ||||
34 | Q_DECLARE_METATYPE(QVariant::Type) | ||||
30 | 35 | | |||
31 | using namespace KFileMetaData; | 36 | using namespace KFileMetaData; | ||
32 | 37 | | |||
33 | QString TagLibExtractorTest::testFilePath(const QString& fileName) const | 38 | QString TagLibExtractorTest::testFilePath(const QString& fileName) const | ||
34 | { | 39 | { | ||
35 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; | 40 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QDir::separator() + fileName; | ||
36 | } | 41 | } | ||
37 | 42 | | |||
43 | const QVariantList TagLibExtractorTest::variantListFromStringList(const QStringList& list) const | ||||
44 | { | ||||
45 | QVariantList result; | ||||
46 | for (const auto& s : list) { | ||||
47 | result << s; | ||||
48 | } | ||||
49 | return result; | ||||
50 | } | ||||
51 | | ||||
38 | void TagLibExtractorTest::test() | 52 | void TagLibExtractorTest::test() | ||
39 | { | 53 | { | ||
40 | QScopedPointer<ExtractorPlugin> plugin(new TagLibExtractor(this)); | 54 | QScopedPointer<ExtractorPlugin> plugin(new TagLibExtractor(this)); | ||
41 | 55 | | |||
42 | SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); | 56 | SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); | ||
43 | plugin->extract(&resultOpus); | 57 | plugin->extract(&resultOpus); | ||
44 | 58 | | |||
45 | QCOMPARE(resultOpus.types().size(), 1); | 59 | QCOMPARE(resultOpus.types().size(), 1); | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
143 | QCOMPARE(resultMp4.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); | 157 | QCOMPARE(resultMp4.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); | ||
144 | QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); | 158 | QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); | ||
145 | QCOMPARE(resultMp4.properties().value(Property::TrackNumber).toInt(), 1); | 159 | QCOMPARE(resultMp4.properties().value(Property::TrackNumber).toInt(), 1); | ||
146 | QCOMPARE(resultMp4.properties().value(Property::ReleaseYear).toInt(), 2015); | 160 | QCOMPARE(resultMp4.properties().value(Property::ReleaseYear).toInt(), 2015); | ||
147 | QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); | 161 | QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); | ||
148 | QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); | 162 | QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); | ||
149 | } | 163 | } | ||
150 | 164 | | |||
165 | void TagLibExtractorTest::testMultiArtist_data() | ||||
166 | { | ||||
167 | const auto propertyName = QStringLiteral("artist"); | ||||
168 | const auto propertyValue = variantListFromStringList({QStringLiteral("Bartist"), QStringLiteral("Artist")}); | ||||
169 | const auto propertyType = PropertyInfo(Property::Artist).valueType(); | ||||
170 | const auto testpasses = QString(); | ||||
171 | QString failMessage; | ||||
172 | | ||||
173 | QTest::addColumn<QString>("path"); | ||||
174 | QTest::addColumn<QString>("mimeType"); | ||||
175 | QTest::addColumn<QString>("propertyName"); | ||||
176 | QTest::addColumn<QVariantList>("valueList"); | ||||
177 | QTest::addColumn<QVariant::Type>("valueType"); | ||||
178 | QTest::addColumn<QString>("failMessage"); | ||||
179 | | ||||
180 | failMessage = QStringLiteral("implementation error"); | ||||
181 | QTest::addRow("mp3") | ||||
182 | << QFINDTESTDATA("samplefiles/multi/test.mp3") | ||||
183 | << QStringLiteral("audio/mp4") | ||||
184 | << propertyName << propertyValue << propertyType << failMessage | ||||
185 | ; | ||||
186 | | ||||
187 | failMessage = testpasses; | ||||
188 | QTest::addRow("m4a") | ||||
189 | << QFINDTESTDATA("samplefiles/multi/test.m4a") | ||||
190 | << QStringLiteral("audio/mp4") | ||||
191 | << propertyName << propertyValue << propertyType << failMessage | ||||
192 | ; | ||||
193 | | ||||
194 | failMessage = testpasses; | ||||
195 | QTest::addRow("flac") | ||||
196 | << QFINDTESTDATA("samplefiles/multi/test.flac") | ||||
197 | << QStringLiteral("audio/flac") | ||||
198 | << propertyName << propertyValue << propertyType << failMessage | ||||
199 | ; | ||||
200 | | ||||
201 | failMessage = testpasses; | ||||
202 | QTest::addRow("opus") | ||||
203 | << QFINDTESTDATA("samplefiles/multi/test.opus") | ||||
204 | << QStringLiteral("audio/opus") | ||||
205 | << propertyName << propertyValue << propertyType << failMessage | ||||
206 | ; | ||||
207 | | ||||
208 | failMessage = testpasses; | ||||
209 | QTest::addRow("ogg") | ||||
210 | << QFINDTESTDATA("samplefiles/multi/test.ogg") | ||||
211 | << QStringLiteral("audio/ogg") | ||||
212 | << propertyName << propertyValue << propertyType << failMessage | ||||
213 | ; | ||||
214 | | ||||
215 | failMessage = QStringLiteral("sample file not adapted"); | ||||
216 | QTest::addRow("mpc") | ||||
217 | << QFINDTESTDATA("samplefiles/multi/test.mpc") | ||||
218 | << QStringLiteral("audio/x-musepack") | ||||
219 | << propertyName << propertyValue << propertyType << failMessage | ||||
220 | ; | ||||
221 | | ||||
222 | } | ||||
223 | | ||||
224 | void TagLibExtractorTest::testMultiArtist() | ||||
225 | { | ||||
226 | QFETCH(QString, path); | ||||
227 | QFETCH(QString, mimeType); | ||||
228 | QFETCH(QString, propertyName); | ||||
229 | QFETCH(QVariantList, valueList); | ||||
230 | QFETCH(QVariant::Type, valueType); | ||||
231 | QFETCH(QString, failMessage); | ||||
232 | | ||||
233 | const auto property = PropertyInfo::fromName(propertyName); | ||||
234 | QScopedPointer<ExtractorPlugin> plugin(new TagLibExtractor(this)); | ||||
235 | SimpleExtractionResult extracted(path, mimeType); | ||||
236 | plugin->extract(&extracted); | ||||
237 | const auto resultList = extracted.properties().values(property.property()); | ||||
238 | QCOMPARE(property.name(), propertyName); | ||||
239 | QVERIFY2(property.valueType() == valueType, "Type mismatch"); | ||||
240 | | ||||
241 | if (!failMessage.isEmpty()) { | ||||
242 | qDebug() << "result: " << extracted.properties().value(property.property()).type() << resultList; | ||||
243 | qDebug() << "expected:" << valueType <<valueList; | ||||
244 | QEXPECT_FAIL("", qPrintable(failMessage), Continue); | ||||
245 | } | ||||
246 | QCOMPARE(extracted.properties().values(property.property()), valueList); | ||||
247 | | ||||
248 | } | ||||
249 | | ||||
250 | void TagLibExtractorTest::testMultiGenre_data() | ||||
251 | { | ||||
252 | const auto propertyName = QStringLiteral("genre"); | ||||
253 | const auto propertyValue = variantListFromStringList({QStringLiteral("Kengre"), QStringLiteral("Genre")}); | ||||
254 | const auto propertyType = PropertyInfo(Property::Genre).valueType(); | ||||
255 | const auto testpasses = QString(); | ||||
256 | QString failMessage; | ||||
257 | | ||||
258 | QTest::addColumn<QString>("path"); | ||||
259 | QTest::addColumn<QString>("mimeType"); | ||||
260 | QTest::addColumn<QString>("propertyName"); | ||||
261 | QTest::addColumn<QVariantList>("valueList"); | ||||
262 | QTest::addColumn<QVariant::Type>("valueType"); | ||||
263 | QTest::addColumn<QString>("failMessage"); | ||||
264 | | ||||
265 | failMessage = QStringLiteral("Not implemented correctly"); | ||||
266 | QTest::addRow("mp3") | ||||
267 | << QFINDTESTDATA("samplefiles/multi/test.mp3") | ||||
268 | << QStringLiteral("audio/mp3") | ||||
269 | << propertyName << propertyValue << propertyType << failMessage | ||||
270 | ; | ||||
271 | | ||||
272 | failMessage = QStringLiteral("Not implemented correctly"); | ||||
273 | QTest::addRow("m4a") | ||||
274 | << QFINDTESTDATA("samplefiles/multi/test.m4a") | ||||
275 | << QStringLiteral("audio/mp4") | ||||
276 | << propertyName << propertyValue << propertyType << failMessage | ||||
277 | ; | ||||
278 | | ||||
279 | failMessage = testpasses; | ||||
280 | QTest::addRow("flac") | ||||
281 | << QFINDTESTDATA("samplefiles/multi/test.flac") | ||||
282 | << QStringLiteral("audio/flac") | ||||
283 | << propertyName << propertyValue << propertyType << failMessage | ||||
284 | ; | ||||
285 | | ||||
286 | failMessage = testpasses; | ||||
287 | QTest::addRow("opus") | ||||
288 | << QFINDTESTDATA("samplefiles/multi/test.opus") | ||||
289 | << QStringLiteral("audio/opus") | ||||
290 | << propertyName << propertyValue << propertyType << failMessage | ||||
291 | ; | ||||
292 | | ||||
293 | failMessage = testpasses; | ||||
294 | QTest::addRow("ogg") | ||||
295 | << QFINDTESTDATA("samplefiles/multi/test.ogg") | ||||
296 | << QStringLiteral("audio/ogg") | ||||
297 | << propertyName << propertyValue << propertyType << failMessage | ||||
298 | ; | ||||
299 | | ||||
300 | failMessage = QStringLiteral("sample file not adapted"); | ||||
301 | QTest::addRow("mpc") | ||||
302 | << QFINDTESTDATA("samplefiles/multi/test.mpc") | ||||
303 | << QStringLiteral("audio/x-musepack") | ||||
304 | << propertyName << propertyValue << propertyType << failMessage | ||||
305 | ; | ||||
306 | | ||||
307 | } | ||||
308 | | ||||
309 | void TagLibExtractorTest::testMultiGenre() | ||||
310 | { | ||||
311 | QFETCH(QString, path); | ||||
312 | QFETCH(QString, mimeType); | ||||
313 | QFETCH(QString, propertyName); | ||||
314 | QFETCH(QVariantList, valueList); | ||||
315 | QFETCH(QVariant::Type, valueType); | ||||
316 | QFETCH(QString, failMessage); | ||||
317 | | ||||
318 | const auto property = PropertyInfo::fromName(propertyName); | ||||
319 | QScopedPointer<ExtractorPlugin> plugin(new TagLibExtractor(this)); | ||||
320 | SimpleExtractionResult extracted(path, mimeType); | ||||
321 | plugin->extract(&extracted); | ||||
322 | | ||||
323 | const auto resultList = extracted.properties().values(property.property()); | ||||
324 | | ||||
325 | QCOMPARE(property.name(), propertyName); | ||||
326 | QVERIFY2(property.valueType() == valueType, "Type mismatch"); | ||||
327 | | ||||
328 | if (!failMessage.isEmpty()) { | ||||
329 | qDebug() << "result: " << extracted.properties().value(property.property()).type() << "=" << resultList; | ||||
330 | qDebug() << "expected:" << valueType << "=" << valueList; | ||||
331 | QEXPECT_FAIL("", qPrintable(failMessage), Continue); | ||||
332 | } | ||||
333 | QCOMPARE(extracted.properties().values(property.property()), valueList); | ||||
334 | } | ||||
335 | | ||||
151 | QTEST_GUILESS_MAIN(TagLibExtractorTest) | 336 | QTEST_GUILESS_MAIN(TagLibExtractorTest) |