File indexing completed on 2025-03-09 03:57:01

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-11-28
0007  * Description : a unit-test to write metadata with ExifTool and EXV constainer.
0008  *
0009  * SPDX-FileCopyrightText: 2012-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 "exiftoolapplychanges_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QApplication>
0020 #include <QTest>
0021 #include <QFileInfo>
0022 #include <QDir>
0023 
0024 // Local includes
0025 
0026 #include "digikam_debug.h"
0027 #include "wstoolutils.h"
0028 #include "dtestdatadir.h"
0029 #include "metaengine.h"
0030 #include "exiftoolparser.h"
0031 
0032 using namespace Digikam;
0033 
0034 QTEST_GUILESS_MAIN(ExifToolApplyChangesTest)
0035 
0036 ExifToolApplyChangesTest::ExifToolApplyChangesTest(QObject* const parent)
0037     : AbstractUnitTest(parent)
0038 {
0039 }
0040 
0041 void ExifToolApplyChangesTest::testExifToolApplyChanges()
0042 {
0043     QString file = m_originalImageFolder + QLatin1String("2015-07-22_00001.JPG");
0044     qCDebug(DIGIKAM_TESTS_LOG) << "File to process:" << file;
0045     QString path = m_tempDir.filePath(QFileInfo(file).fileName().trimmed());
0046 
0047     qCDebug(DIGIKAM_TESTS_LOG) << "Temporary target file:" << path;
0048 
0049     bool ret = !path.isNull();
0050     QVERIFY(ret);
0051 
0052     QFile::remove(path);
0053     QFile target(file);
0054     ret = target.copy(path);
0055     QVERIFY(ret);
0056 
0057     QScopedPointer<DMetadata> meta(new DMetadata);
0058 
0059     QVERIFY2(meta->load(path),
0060              QString::fromLatin1("Cannot load %1").arg(meta->getFilePath()).toLatin1().constData());
0061 
0062     meta->setImageDateTime(QDateTime::currentDateTime(), true);
0063 
0064     QString exvPath = path + QLatin1String("_changes.exv");
0065     QVERIFY2(meta->exportChanges(exvPath),
0066              QString::fromLatin1("Cannot export metadata to %1").arg(exvPath).toLatin1().constData());
0067 
0068     QScopedPointer<ExifToolParser> parser(new ExifToolParser(qApp));
0069 
0070     QVERIFY2(parser->applyChanges(path, exvPath),
0071              QString::fromLatin1("Cannot apply changes with ExifTool on %1").arg(path).toLatin1().constData());
0072 }
0073 
0074 #include "moc_exiftoolapplychanges_utest.cpp"