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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-08-01
0007  * Description : a test for the DImageHistory
0008  *
0009  * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <user dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "dimghistory_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QDir>
0020 #include <QFile>
0021 #include <QFileInfo>
0022 #include <QTime>
0023 
0024 // Local includes
0025 
0026 #include "digikam_debug.h"
0027 #include "digikam_config.h"
0028 #include "editortooliface.h"
0029 #include "editorwindow.h"
0030 #include "imageiface.h"
0031 #include "iofilesettings.h"
0032 #include "dpluginloader.h"
0033 
0034 using namespace Digikam;
0035 
0036 QTEST_MAIN(DImgHistoryTest)
0037 
0038 DImgHistoryTest::DImgHistoryTest(QObject* const parent)
0039     : DImgAbstractHistoryTest(parent)
0040 {
0041 }
0042 
0043 void DImgHistoryTest::initTestCase()
0044 {
0045     initBaseTestCase();
0046 }
0047 
0048 void DImgHistoryTest::cleanupTestCase()
0049 {
0050     cleanupBaseTestCase();
0051 }
0052 
0053 void DImgHistoryTest::testXml()
0054 {
0055     DImageHistory history  = history1();
0056 
0057     QString xml            = history.toXml();
0058 
0059     DImageHistory history2 = DImageHistory::fromXml(xml);
0060     QString xml2           = history2.toXml();
0061 
0062     QCOMPARE(xml, xml2);
0063 
0064     // Does not need to work: Some fields in the ids like originalUUID are filled out even if not in XML
0065     //QCOMPARE(history2, historyWithoutCurrent);
0066 }
0067 
0068 void DImgHistoryTest::testDImg()
0069 {
0070     QDir imageDir(imagePath());
0071     imageDir.setNameFilters(QStringList() << QLatin1String("*.jpg"));
0072     QList<QFileInfo> imageFiles = imageDir.entryInfoList();
0073 
0074     IOFileSettings container;
0075     m_im->load(imageFiles.first().filePath(), &container);
0076 
0077     m_loop.exec();   // krazy:exclude=crashy
0078 
0079     DImageHistory history = m_im->getImg()->getItemHistory();
0080     QCOMPARE(history.size(), 3);
0081     QCOMPARE(history.entries().first().referredImages.size(), 1);
0082     QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Current);
0083     QVERIFY(history.entries().last().referredImages.isEmpty());
0084 
0085     m_im->saveAs(m_tempFile, &container, true, QString(), QString());
0086 
0087     m_loop.exec();   // krazy:exclude=crashy
0088 
0089     history = m_im->getImg()->getItemHistory();
0090     QCOMPARE(history.size(), 3);
0091     QCOMPARE(history.entries().first().referredImages.size(), 1);
0092     QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Current);
0093     QCOMPARE(history.entries().last().referredImages.size(), 1);
0094     QCOMPARE(history.entries().last().referredImages.first().m_type, HistoryImageId::Intermediate);
0095 
0096     m_im->switchToLastSaved();
0097 
0098     history = m_im->getImg()->getOriginalImageHistory();
0099     QCOMPARE(history.size(), 3);
0100     QCOMPARE(history.entries().first().referredImages.size(), 1);
0101     QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Original);
0102     QCOMPARE(history.entries().last().referredImages.size(), 1);
0103     QCOMPARE(history.entries().last().referredImages.first().m_type, HistoryImageId::Current);
0104 }
0105 
0106 void DImgHistoryTest::slotImageLoaded(const QString&, bool success)
0107 {
0108     QVERIFY(success);
0109 
0110     applyFilters1();
0111 
0112     DImageHistory h = m_im->getImg()->getItemHistory();
0113     h.adjustReferredImages();
0114 
0115     for (int i = 0 ; i < 3 ; ++i)
0116     {
0117         qCDebug(DIGIKAM_TESTS_LOG) << i << h.entries().at(i).referredImages.size();
0118 
0119         if (h.entries().at(i).referredImages.size())
0120         {
0121             qCDebug(DIGIKAM_TESTS_LOG) << " " << i << h.entries().at(i).referredImages.first().m_type;
0122         }
0123     }
0124 
0125     m_loop.quit();
0126 }
0127 
0128 void DImgHistoryTest::slotImageSaved(const QString& fileName, bool success)
0129 {
0130     QVERIFY(success);
0131 
0132     m_im->setLastSaved(fileName);
0133 
0134     DImg img(fileName);
0135     DImageHistory history = img.getItemHistory();
0136     qCDebug(DIGIKAM_TESTS_LOG) << history.toXml();
0137 
0138     QCOMPARE(history.size(), 3);
0139     QCOMPARE(history.entries().first().referredImages.size(), 1);
0140     QCOMPARE(history.entries().first().referredImages.first().m_type, HistoryImageId::Original);
0141     QCOMPARE(history.action(1).category(), FilterAction::ReproducibleFilter);
0142     QCOMPARE(history.action(2).category(), FilterAction::ReproducibleFilter);
0143 
0144     DImageHistory history2 = DImageHistory::fromXml(history.toXml());
0145     QCOMPARE(history2.size(), 3);
0146     QCOMPARE(history2.entries().first().referredImages.size(), 1);
0147     QCOMPARE(history2.entries().first().referredImages.first().m_type, HistoryImageId::Original);
0148     QCOMPARE(history2.action(1).category(), FilterAction::ReproducibleFilter);
0149     QCOMPARE(history2.action(2).category(), FilterAction::ReproducibleFilter);
0150 
0151     m_loop.quit();
0152 }
0153 
0154 #include "moc_dimghistory_utest.cpp"