File indexing completed on 2025-01-19 03:57:49
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-08-12 0007 * Description : metadata settings tests for getImageRating and setImageRating. 0008 * 0009 * SPDX-FileCopyrightText: 2015 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "ratingreadwrite_utest.h" 0016 0017 // Qt includes 0018 0019 #include <QTest> 0020 #include <QString> 0021 0022 // Local includes 0023 0024 #include "dmetadata.h" 0025 #include "digikam_debug.h" 0026 0027 using namespace Digikam; 0028 0029 QTEST_GUILESS_MAIN(RatingReadWriteTest) 0030 0031 RatingReadWriteTest::RatingReadWriteTest(QObject* const parent) 0032 : QObject(parent) 0033 { 0034 } 0035 0036 void RatingReadWriteTest::initTestCase() 0037 { 0038 MetaEngine::initializeExiv2(); 0039 qCDebug(DIGIKAM_TESTS_LOG) << "Using Exiv2 Version:" << MetaEngine::Exiv2Version(); 0040 } 0041 0042 void RatingReadWriteTest::cleanupTestCase() 0043 { 0044 } 0045 0046 void RatingReadWriteTest::testSimpleReadAfterWrite() 0047 { 0048 QScopedPointer<DMetadata> dmeta(new DMetadata); 0049 0050 // Trick dmetadata, so it will think that we have a file path 0051 dmeta->setFilePath(QLatin1String("random.org")); 0052 int rez = -1; 0053 0054 qCDebug(DIGIKAM_TESTS_LOG) << dmeta->supportXmp(); 0055 0056 for (int i = 0; i < 6; i++) 0057 { 0058 dmeta->setItemRating(i); 0059 rez = dmeta->getItemRating(); 0060 QCOMPARE(rez, i); 0061 } 0062 } 0063 0064 void RatingReadWriteTest::testWriteToDisabledNamespaces() 0065 { 0066 QScopedPointer<DMetadata> dmeta(new DMetadata); 0067 dmeta->setFilePath(QLatin1String("random.org")); 0068 0069 DMetadataSettingsContainer dmsettings; 0070 0071 QList<int> defaultVal, microsoftMappings, iptcMappings; 0072 defaultVal << 0 << 1 << 2 << 3 << 4 << 5; 0073 microsoftMappings << 0 << 1 << 25 << 50 << 75 << 99; 0074 iptcMappings << 8 << 6 << 5 << 4 << 2 << 1; 0075 0076 NamespaceEntry ratingNs2; 0077 ratingNs2.namespaceName = QLatin1String("Xmp.acdsee.rating"); 0078 ratingNs2.convertRatio = defaultVal; 0079 ratingNs2.nsType = NamespaceEntry::RATING; 0080 ratingNs2.index = 1; 0081 ratingNs2.subspace = NamespaceEntry::XMP; 0082 ratingNs2.isDisabled = true; 0083 0084 NamespaceEntry ratingNs3; 0085 ratingNs3.namespaceName = QLatin1String("Xmp.MicrosoftPhoto.Rating"); 0086 ratingNs3.convertRatio = microsoftMappings; 0087 ratingNs3.nsType = NamespaceEntry::RATING; 0088 ratingNs3.index = 2; 0089 ratingNs3.subspace = NamespaceEntry::XMP; 0090 0091 0092 dmsettings.getWriteMapping(NamespaceEntry::DM_RATING_CONTAINER()).clear(); 0093 dmsettings.getWriteMapping(NamespaceEntry::DM_RATING_CONTAINER()) 0094 << ratingNs2 0095 << ratingNs3; 0096 0097 for (int i = 0; i < 6; i++) 0098 { 0099 dmeta->setItemRating(i, dmsettings); 0100 0101 QString data; 0102 bool ok; 0103 0104 data = dmeta->getXmpTagString("Xmp.acdsee.rating", false); 0105 0106 QVERIFY(data.isEmpty()); 0107 0108 data = dmeta->getXmpTagString("Xmp.MicrosoftPhoto.Rating", false); 0109 int rez = data.toInt(&ok); 0110 0111 QCOMPARE(ok, true); 0112 QCOMPARE(rez, microsoftMappings.at(i)); 0113 } 0114 } 0115 0116 void RatingReadWriteTest::testReadFromDisabledNamespaces() 0117 { 0118 QScopedPointer<DMetadata> dmeta(new DMetadata); 0119 dmeta->setFilePath(QLatin1String("random.org")); 0120 0121 DMetadataSettingsContainer dmsettings; 0122 0123 QList<int> defaultVal, microsoftMappings, iptcMappings; 0124 defaultVal << 0 << 1 << 2 << 3 << 4 << 5; 0125 microsoftMappings << 0 << 1 << 25 << 50 << 75 << 99; 0126 iptcMappings << 8 << 6 << 5 << 4 << 2 << 1; 0127 0128 NamespaceEntry ratingNs2; 0129 ratingNs2.namespaceName = QLatin1String("Xmp.acdsee.rating"); 0130 ratingNs2.convertRatio = defaultVal; 0131 ratingNs2.nsType = NamespaceEntry::RATING; 0132 ratingNs2.index = 1; 0133 ratingNs2.subspace = NamespaceEntry::XMP; 0134 ratingNs2.isDisabled = true; 0135 0136 NamespaceEntry ratingNs3; 0137 ratingNs3.namespaceName = QLatin1String("Xmp.MicrosoftPhoto.Rating"); 0138 ratingNs3.convertRatio = microsoftMappings; 0139 ratingNs3.nsType = NamespaceEntry::RATING; 0140 ratingNs3.index = 2; 0141 ratingNs3.subspace = NamespaceEntry::XMP; 0142 0143 0144 dmsettings.getReadMapping(NamespaceEntry::DM_RATING_CONTAINER()).clear(); 0145 dmsettings.getReadMapping(NamespaceEntry::DM_RATING_CONTAINER()) 0146 << ratingNs2 0147 << ratingNs3; 0148 0149 for (int i = 0; i < 6; i++) 0150 { 0151 0152 dmeta->setXmpTagString("Xmp.acdsee.rating", QString::number(5-i)); 0153 dmeta->setXmpTagString("Xmp.MicrosoftPhoto.Rating", QString::number(microsoftMappings.at(i))); 0154 0155 int rez = dmeta->getItemRating(dmsettings); 0156 QCOMPARE(rez, i); 0157 } 0158 } 0159 0160 #include "moc_ratingreadwrite_utest.cpp"