File indexing completed on 2025-01-05 03:58:14

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-06-11
0007  * Description : An unit-test to print item info from file using DMetadata.
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "printiteminfo_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QTextStream>
0020 #include <QStringList>
0021 
0022 QTEST_MAIN(PrintItemInfoTest)
0023 
0024 PrintItemInfoTest::PrintItemInfoTest(QObject* const parent)
0025     : AbstractUnitTest(parent)
0026 {
0027 }
0028 
0029 void PrintItemInfoTest::testPrintItemInfo()
0030 {
0031     //                                                   Expected tags to found in Comments,    Titles,
0032     //                                                                             IptcContact, IptcLocation, IptcSubjects,
0033     //                                                                             PhotoInfo,   VideoInfo,
0034     //                                                                             XmpKeywords, XmpSubjects,  XmpSubCategories, expectedRead
0035     printItemInfo(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"),        false,       false,
0036                                                                                    false,       false,        false,
0037                                                                                    true,        true,
0038                                                                                    true,        false,        false,            true);
0039 
0040     printItemInfo(m_originalImageFolder + QLatin1String("_27A1417.CR2"),           false,       false,
0041                                                                                    false,       false,        false,
0042                                                                                    true,        true,
0043                                                                                    false,       false,        false,            true);
0044 
0045     printItemInfo(m_originalImageFolder + QLatin1String("2015-07-22_00001.JPG"),   false,       false,
0046                                                                                    false,       false,        false,
0047                                                                                    true,        false,
0048                                                                                    false,       false,        false,            true);
0049 
0050     // The file cannot be loaded with Exiv2-0.26, only test the newer versions
0051 
0052     bool ok = true;
0053 
0054     if ((MetaEngine::Exiv2Version().section(QLatin1Char('.'), 0, 1).toDouble(&ok) > 0.26) && ok && m_hasExifTool)
0055     {
0056         printItemInfo(m_originalImageFolder + QLatin1String("20160821035715.jpg"), false,       false,
0057                                                                                    false,       false,        false,
0058                                                                                    true,        true,
0059                                                                                    false,       false,        false,            true);
0060     }
0061 }
0062 
0063 void PrintItemInfoTest::printItemInfo(const QString& filePath,
0064                                       bool com, bool ttl,            // Comments and titles
0065                                       bool cnt, bool loc, bool isb,  // Iptc
0066                                       bool pho, bool vid,            // Media
0067                                       bool key, bool xsb, bool cat,  // Xmp
0068                                       bool expectedRead
0069                                      )
0070 {
0071     QScopedPointer<DMetadata> meta(new DMetadata);
0072 
0073     bool ret = meta->load(filePath);
0074     QCOMPARE(ret, expectedRead);
0075 
0076     // Comments and titles
0077     printComments(*meta,         com);
0078     printTitles(*meta,           ttl);
0079 
0080     // Iptc
0081     printIptcContact(*meta,      cnt);
0082     printIptcLocation(*meta,     loc);
0083     printIptcSubjects(*meta,     isb),
0084 
0085     // Media
0086     printPhotoInfo(*meta,        pho);
0087     printVideoInfo(*meta,        vid);
0088 
0089     // Xmp
0090     printXmpKeywords(*meta,      key);
0091     printXmpSubjects(*meta,      xsb);
0092     printXmpSubCategories(*meta, cat);
0093 }
0094 
0095 void PrintItemInfoTest::printComments(const DMetadata& meta, bool expected)
0096 {
0097     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- Comments from %1 --------------------------").arg(meta.getFilePath());
0098 
0099     CaptionsMap map = meta.getItemComments();
0100     QCOMPARE(!map.isEmpty(), expected);
0101 
0102     qCDebug(DIGIKAM_TESTS_LOG) << map;
0103 }
0104 
0105 void PrintItemInfoTest::printTitles(const DMetadata& meta, bool expected)
0106 {
0107     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- Titles from %1 --").arg(meta.getFilePath());
0108 
0109     CaptionsMap map = meta.getItemTitles();
0110     QCOMPARE(!map.isEmpty(), expected);
0111 
0112     qCDebug(DIGIKAM_TESTS_LOG) << map;
0113 }
0114 
0115 void PrintItemInfoTest::printIptcContact(const DMetadata& meta, bool expected)
0116 {
0117     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- IptcContact from %1 --").arg(meta.getFilePath());
0118 
0119     IptcCoreContactInfo map = meta.getCreatorContactInfo();
0120     QCOMPARE(!map.isEmpty(), expected);
0121 
0122     qCDebug(DIGIKAM_TESTS_LOG) << map;
0123 }
0124 
0125 void PrintItemInfoTest::printIptcLocation(const DMetadata& meta, bool expected)
0126 {
0127     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- IptcLocation from %1 --").arg(meta.getFilePath());
0128 
0129     IptcCoreLocationInfo map = meta.getIptcCoreLocation();
0130     QCOMPARE(!map.isEmpty(), expected);
0131 
0132     qCDebug(DIGIKAM_TESTS_LOG) << map;
0133 }
0134 
0135 void PrintItemInfoTest::printIptcSubjects(const DMetadata& meta, bool expected)
0136 {
0137     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- IptcSubjects from %1 --").arg(meta.getFilePath());
0138 
0139     QStringList map = meta.getIptcCoreSubjects();
0140     QCOMPARE(!map.isEmpty(), expected);
0141 
0142     qCDebug(DIGIKAM_TESTS_LOG) << map;
0143 }
0144 
0145 void PrintItemInfoTest::printPhotoInfo(const DMetadata& meta, bool expected)
0146 {
0147     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- PhotoInfo from %1 --").arg(meta.getFilePath());
0148 
0149     PhotoInfoContainer map = meta.getPhotographInformation();
0150     QCOMPARE(!map.isEmpty(), expected);
0151 
0152     qCDebug(DIGIKAM_TESTS_LOG) << map;
0153 }
0154 
0155 void PrintItemInfoTest::printVideoInfo(const DMetadata& meta, bool expected)
0156 {
0157     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- VideoInfo from %1 --").arg(meta.getFilePath());
0158 
0159     VideoInfoContainer map = meta.getVideoInformation();
0160     QCOMPARE(!map.isEmpty(), expected);
0161 
0162     qCDebug(DIGIKAM_TESTS_LOG) << map;
0163 }
0164 
0165 void PrintItemInfoTest::printXmpKeywords(const DMetadata& meta, bool expected)
0166 {
0167     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- XmpKeywords from %1 --").arg(meta.getFilePath());
0168 
0169     if (meta.supportXmp())
0170     {
0171         QStringList map = meta.getXmpKeywords();
0172         QCOMPARE(!map.isEmpty(), expected);
0173 
0174         qCDebug(DIGIKAM_TESTS_LOG) << map;
0175     }
0176     else
0177     {
0178         QWARN("Exiv2 has no XMP support...");
0179     }
0180 }
0181 
0182 void PrintItemInfoTest::printXmpSubjects(const DMetadata& meta, bool expected)
0183 {
0184     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- XmpSubjects from %1 --").arg(meta.getFilePath());
0185 
0186     if (meta.supportXmp())
0187     {
0188         QStringList map = meta.getXmpSubjects();
0189         QCOMPARE(!map.isEmpty(), expected);
0190 
0191         qCDebug(DIGIKAM_TESTS_LOG) << map;
0192     }
0193     else
0194     {
0195         QWARN("Exiv2 has no XMP support...");
0196     }
0197 }
0198 
0199 void PrintItemInfoTest::printXmpSubCategories(const DMetadata& meta, bool expected)
0200 {
0201     qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- XmpSubCategories from %1 --").arg(meta.getFilePath());
0202 
0203     if (meta.supportXmp())
0204     {
0205         QStringList map = meta.getXmpSubCategories();
0206         QCOMPARE(!map.isEmpty(), expected);
0207 
0208         qCDebug(DIGIKAM_TESTS_LOG) << map;
0209     }
0210     else
0211     {
0212         QWARN("Exiv2 has no XMP support...");
0213     }
0214 }
0215 
0216 #include "moc_printiteminfo_utest.cpp"