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        : 2013-02-21
0007  * Description : an unit-test to set and clear faces in Picassa format with DMetadata
0008  *
0009  * SPDX-FileCopyrightText: 2013      by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
0010  * SPDX-FileCopyrightText: 2019-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "setxmpface_utest.h"
0017 
0018 // Qt includes
0019 
0020 #include <QFile>
0021 #include <QMultiMap>
0022 #include <QRectF>
0023 
0024 QTEST_MAIN(SetXmpFaceTest)
0025 
0026 SetXmpFaceTest::SetXmpFaceTest(QObject* const parent)
0027     : AbstractUnitTest(parent)
0028 {
0029 }
0030 
0031 void SetXmpFaceTest::testSetXmpFace()
0032 {
0033     setXmpFace(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"));
0034 }
0035 
0036 void SetXmpFaceTest::setXmpFace(const QString& file)
0037 {
0038     qCDebug(DIGIKAM_TESTS_LOG) << "File to process:          " << file;
0039 
0040     QString filePath = m_tempDir.filePath(QFileInfo(file).fileName().trimmed());
0041 
0042     qCDebug(DIGIKAM_TESTS_LOG) << "Temporary target file:    " << filePath;
0043 
0044     bool ret = !filePath.isNull();
0045     QVERIFY(ret);
0046 
0047     // Copy image file in temporary dir.
0048     QFile::remove(filePath);
0049     QFile target(file);
0050     ret = target.copy(filePath);
0051     QVERIFY(ret);
0052 
0053     QScopedPointer<DMetadata> meta(new DMetadata);
0054     ret = meta->load(filePath);
0055     QVERIFY(ret);
0056 
0057     qCDebug(DIGIKAM_TESTS_LOG) << "Add region with face tags in file...";
0058 
0059     QMultiMap<QString, QVariant> faces;
0060 
0061     QString name  = QLatin1String("Bob Marley");
0062     QRectF rect(10, 100, 60, 80);
0063     faces.insert(name, QVariant(rect));
0064 
0065     QString name2 = QLatin1String("Alice in wonderland");
0066     QRectF rect2(20, 40, 90, 70);
0067     faces.insert(name2, QVariant(rect2));
0068 
0069     ret = meta->setItemFacesMap(faces, true);
0070     QVERIFY(ret);
0071 
0072     ret = meta->applyChanges();
0073     QVERIFY(ret);
0074 
0075     qCDebug(DIGIKAM_TESTS_LOG) << "Check if face tags are well assigned in file...";
0076 
0077     QScopedPointer<DMetadata> meta2(new DMetadata);
0078     ret = meta2->load(filePath);
0079     QVERIFY(ret);
0080 
0081     QMultiMap<QString, QVariant> faces2;
0082     ret = meta2->getItemFacesMap(faces2);
0083     QVERIFY(ret);
0084 
0085     QVERIFY(!faces2.isEmpty());
0086     QVERIFY(faces2.contains(name));
0087     QVERIFY(faces2.contains(name2));
0088     QVERIFY(faces2.value(name)  == rect);
0089     QVERIFY(faces2.value(name2) == rect2);
0090     ret = meta2->applyChanges();
0091     QVERIFY(ret);
0092 
0093     qCDebug(DIGIKAM_TESTS_LOG) << "Clear face tags from file...";
0094 
0095     QScopedPointer<DMetadata> meta3(new DMetadata);
0096     ret = meta3->load(filePath);
0097     QVERIFY(ret);
0098 
0099     meta3->removeItemFacesMap();
0100     ret = meta3->applyChanges();
0101     QVERIFY(ret);
0102 
0103     qCDebug(DIGIKAM_TESTS_LOG) << "Check if face tags are well removed from file...";
0104 
0105     QScopedPointer<DMetadata> meta4(new DMetadata);
0106     ret = meta4->load(filePath);
0107     QVERIFY(ret);
0108 
0109     QMultiMap<QString, QVariant> faces4;
0110     ret = meta4->getItemFacesMap(faces4);
0111     QVERIFY(!ret);   // Empty map must be returned
0112 }
0113 
0114 #include "moc_setxmpface_utest.cpp"