diff --git a/core/tests/metadataengine/printiteminfotest.cpp b/core/tests/metadataengine/printiteminfotest.cpp index fd5580b0af..0b43233482 100644 --- a/core/tests/metadataengine/printiteminfotest.cpp +++ b/core/tests/metadataengine/printiteminfotest.cpp @@ -1,217 +1,218 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-06-11 * Description : An unit-test to print item info from file using DMetadata. * * Copyright (C) 2009-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "printiteminfotest.h" // Qt includes #include #include QTEST_MAIN(PrintItemInfoTest) void PrintItemInfoTest::testPrintItemInfo() { - // Expected tags to found in Comments, Titles, - // IptcContact, IptcLocation, IptcSubjects, - // PhotoInfo, VideoInfo, - // XmpKeywords, XmpSubjects, XmpSubCategories - printItemInfo(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"), false, false, - false, false, false, - true, true, - true, false, false); - - printItemInfo(m_originalImageFolder + QLatin1String("_27A1417.CR2"), false, false, - false, false, false, - true, true, - false, false, false); - - printItemInfo(m_originalImageFolder + QLatin1String("2015-07-22_00001.JPG"), false, false, - false, false, false, - true, false, - false, false, false); + // Expected tags to found in Comments, Titles, + // IptcContact, IptcLocation, IptcSubjects, + // PhotoInfo, VideoInfo, + // XmpKeywords, XmpSubjects, XmpSubCategories, expectedRead + printItemInfo(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"), false, false, + false, false, false, + true, true, + true, false, false, true); + + printItemInfo(m_originalImageFolder + QLatin1String("_27A1417.CR2"), false, false, + false, false, false, + true, true, + false, false, false, true); + + printItemInfo(m_originalImageFolder + QLatin1String("2015-07-22_00001.JPG"), false, false, + false, false, false, + true, false, + false, false, false, true); // The file cannot be loaded with Exiv2-0.26, only test the newer versions bool ok = true; if ((MetaEngine::Exiv2Version().section(QLatin1Char('.'), 0, 1).toDouble(&ok) > 0.26) && ok) { - printItemInfo(m_originalImageFolder + QLatin1String("20160821035715.jpg"), false, false, - false, false, false, - false, true, - false, false, false); + printItemInfo(m_originalImageFolder + QLatin1String("20160821035715.jpg"), false, false, + false, false, false, + false, false, + false, false, false, false); } } void PrintItemInfoTest::printItemInfo(const QString& filePath, bool com, bool ttl, // Comments and titles bool cnt, bool loc, bool isb, // Iptc bool pho, bool vid, // Media - bool key, bool xsb, bool cat // Xmp + bool key, bool xsb, bool cat, // Xmp + bool expectedRead ) { DMetadata meta; bool ret = meta.load(filePath); - QVERIFY(ret); + QCOMPARE(ret, expectedRead); // Comments and titles printComments(meta, com); printTitles(meta, ttl); // Iptc printIptcContact(meta, cnt); printIptcLocation(meta, loc); printIptcSubjects(meta, isb), // Media printPhotoInfo(meta, pho); printVideoInfo(meta, vid); // Xmp printXmpKeywords(meta, key); printXmpSubjects(meta, xsb); printXmpSubCategories(meta, cat); } void PrintItemInfoTest::printComments(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- Comments from %1 --------------------------").arg(meta.getFilePath()); CaptionsMap map = meta.getItemComments(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printTitles(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- Titles from %1 --").arg(meta.getFilePath()); CaptionsMap map = meta.getItemTitles(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printIptcContact(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- IptcContact from %1 --").arg(meta.getFilePath()); IptcCoreContactInfo map = meta.getCreatorContactInfo(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printIptcLocation(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- IptcLocation from %1 --").arg(meta.getFilePath()); IptcCoreLocationInfo map = meta.getIptcCoreLocation(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printIptcSubjects(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- IptcSubjects from %1 --").arg(meta.getFilePath()); QStringList map = meta.getIptcCoreSubjects(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printPhotoInfo(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- PhotoInfo from %1 --").arg(meta.getFilePath()); PhotoInfoContainer map = meta.getPhotographInformation(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printVideoInfo(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- VideoInfo from %1 --").arg(meta.getFilePath()); VideoInfoContainer map = meta.getVideoInformation(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } void PrintItemInfoTest::printXmpKeywords(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- XmpKeywords from %1 --").arg(meta.getFilePath()); if (meta.supportXmp()) { QStringList map = meta.getXmpKeywords(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } else { QWARN("Exiv2 has no XMP support..."); } } void PrintItemInfoTest::printXmpSubjects(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- XmpSubjects from %1 --").arg(meta.getFilePath()); if (meta.supportXmp()) { QStringList map = meta.getXmpSubjects(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } else { QWARN("Exiv2 has no XMP support..."); } } void PrintItemInfoTest::printXmpSubCategories(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- XmpSubCategories from %1 --").arg(meta.getFilePath()); if (meta.supportXmp()) { QStringList map = meta.getXmpSubCategories(); QCOMPARE(!map.isEmpty(), expected); qDebug() << map; } else { QWARN("Exiv2 has no XMP support..."); } } diff --git a/core/tests/metadataengine/printiteminfotest.h b/core/tests/metadataengine/printiteminfotest.h index 7133e1f196..91674c7e2c 100644 --- a/core/tests/metadataengine/printiteminfotest.h +++ b/core/tests/metadataengine/printiteminfotest.h @@ -1,68 +1,69 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-06-11 * Description : An unit-test to print item info from file using DMetadata. * * Copyright (C) 2009-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_PRINT_ITEM_INFO_TEST_H #define DIGIKAM_PRINT_ITEM_INFO_TEST_H // Local includes #include "abstractunittest.h" #include "dmetadata.h" using namespace Digikam; class PrintItemInfoTest : public AbstractUnitTest { Q_OBJECT private: void printMetadataMap(const DMetadata::MetaDataMap& map); void printItemInfo(const QString& filePath, bool com, bool ttl, // Comments and titles bool cnt, bool loc, bool isb, // Iptc bool pho, bool vid, // Media - bool key, bool xsb, bool cat // Xmp + bool key, bool xsb, bool cat, // Xmp + bool expectedRead ); /// NOTE: 'expected' paramareters want mean that we expect a info container non empty void printComments(const DMetadata& meta, bool expected); void printTitles(const DMetadata& meta, bool expected); void printIptcContact(const DMetadata& meta, bool expected); void printIptcLocation(const DMetadata& meta, bool expected); void printIptcSubjects(const DMetadata& meta, bool expected); void printPhotoInfo(const DMetadata& meta, bool expected); void printVideoInfo(const DMetadata& meta, bool expected); void printXmpKeywords(const DMetadata& meta, bool expected); void printXmpSubjects(const DMetadata& meta, bool expected); void printXmpSubCategories(const DMetadata& meta, bool expected); private Q_SLOTS: void testPrintItemInfo(); }; #endif // DIGIKAM_PRINT_ITEM_INFO_TEST_H diff --git a/core/tests/metadataengine/printmetadatatest.cpp b/core/tests/metadataengine/printmetadatatest.cpp index 77c926d22b..e4a319b24b 100644 --- a/core/tests/metadataengine/printmetadatatest.cpp +++ b/core/tests/metadataengine/printmetadatatest.cpp @@ -1,131 +1,131 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-06-11 * Description : An unit-test to print metadata tags from file using DMetadata. * * Copyright (C) 2009-2019 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "printmetadatatest.h" // Qt includes #include QTEST_MAIN(PrintMetadataTest) void PrintMetadataTest::printMetadataMap(const DMetadata::MetaDataMap& map) { QString output; QTextStream stream(&output); stream << endl; qDebug() << "Found" << map.size() << "tags:" << endl; for (DMetadata::MetaDataMap::const_iterator it = map.constBegin() ; it != map.constEnd() ; ++it) { QString key = it.key(); QString value = it.value(); // None of these strings can be null, event if strings are translated. QVERIFY(!key.isNull()); QVERIFY(!value.isNull()); QString tagName = key.simplified(); tagName.append(QString().fill(QLatin1Char(' '), 48 - tagName.length())); QString tagVal = value.simplified(); if (tagVal.length() > 48) { tagVal.truncate(48); tagVal.append(QString::fromLatin1("... (%1 bytes)").arg(value.length())); } stream << tagName << " : " << tagVal << endl; } qDebug().noquote() << output; } void PrintMetadataTest::testPrintMetadata() { - // Expected tags to found in Exif, Iptc, Xmp - printMetadata(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"), true, true, true, true); - printMetadata(m_originalImageFolder + QLatin1String("_27A1417.CR2"), true, false, true, true); - printMetadata(m_originalImageFolder + QLatin1String("2008-05_DSC_0294.JPG"), true, true, true, true); + // Expected tags to found in Exif, Iptc, Xmp, expectedRead + printMetadata(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"), true, true, true, true); + printMetadata(m_originalImageFolder + QLatin1String("_27A1417.CR2"), true, false, true, true); + printMetadata(m_originalImageFolder + QLatin1String("2008-05_DSC_0294.JPG"), true, true, true, true); // The file cannot be loaded with Exiv2-0.26, only test the newer versions bool ok = true; if ((MetaEngine::Exiv2Version().section(QLatin1Char('.'), 0, 1).toDouble(&ok) > 0.26) && ok) { - printMetadata(m_originalImageFolder + QLatin1String("20160821035715.jpg"), false, false, false, false); + printMetadata(m_originalImageFolder + QLatin1String("20160821035715.jpg"), false, false, false, false); } } void PrintMetadataTest::printMetadata(const QString& filePath, bool exif, bool iptc, bool xmp, bool expectedRead) { DMetadata meta; bool ret = meta.load(filePath); QCOMPARE(ret, expectedRead); loadExif(meta, exif); loadIptc(meta, iptc); loadXmp(meta, xmp); } void PrintMetadataTest::loadExif(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- Exif metadata from %1 --").arg(meta.getFilePath()); DMetadata::MetaDataMap map = meta.getExifTagsDataList(); QCOMPARE(!map.isEmpty(), expected); printMetadataMap(map); } void PrintMetadataTest::loadIptc(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- Iptc metadata from %1 --").arg(meta.getFilePath()); DMetadata::MetaDataMap map = meta.getIptcTagsDataList(); QCOMPARE(!map.isEmpty(), expected); printMetadataMap(map); } void PrintMetadataTest::loadXmp(const DMetadata& meta, bool expected) { qDebug() << QString::fromUtf8("-- Xmp metadata from %1 --").arg(meta.getFilePath()); if (meta.supportXmp()) { DMetadata::MetaDataMap map = meta.getXmpTagsDataList(); QCOMPARE(!map.isEmpty(), expected); printMetadataMap(map); } else { QWARN("Exiv2 has no XMP support..."); } }