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 : 2010-06-27 0007 * Description : an unit-test to test XMP sidecar creation with DMetadata 0008 * 0009 * SPDX-FileCopyrightText: 2010 by Jakob Malm <jakob dot malm at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-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 "createxmpsidecar_utest.h" 0017 0018 // Qt includes 0019 0020 #include <QFile> 0021 0022 QTEST_MAIN(CreateXmpSidecarTest) 0023 0024 CreateXmpSidecarTest::CreateXmpSidecarTest(QObject* const parent) 0025 : AbstractUnitTest(parent) 0026 { 0027 } 0028 0029 void CreateXmpSidecarTest::testCreateXmpSidecar() 0030 { 0031 MetaEngineSettingsContainer settings; 0032 settings.metadataWritingMode = DMetadata::WRITE_TO_SIDECAR_ONLY; 0033 0034 createXmpSidecar(m_originalImageFolder + QLatin1String("2015-07-22_00001.JPG"), settings); 0035 0036 createXmpSidecar(m_originalImageFolder + QLatin1String("IMG_2520.CR2"), settings); 0037 } 0038 0039 void CreateXmpSidecarTest::createXmpSidecar(const QString& file, 0040 const MetaEngineSettingsContainer& settings) 0041 { 0042 qCDebug(DIGIKAM_TESTS_LOG) << "File to process: " << file; 0043 0044 QString path = m_tempDir.filePath(QFileInfo(file).fileName().trimmed()); 0045 QString pathXmp = path + QLatin1String(".xmp"); 0046 0047 qCDebug(DIGIKAM_TESTS_LOG) << "Temporary target file: " << path; 0048 0049 bool ret = !path.isNull(); 0050 QVERIFY(ret); 0051 0052 // Copy image file in temporary dir. 0053 QFile::remove(path); 0054 QFile target(file); 0055 ret = target.copy(path); 0056 QVERIFY(ret); 0057 0058 // Check if no xmp sidecar relevant is present. 0059 0060 qCDebug(DIGIKAM_TESTS_LOG) << "Temporary XMP target file to create:" << pathXmp; 0061 0062 ret = !pathXmp.isNull(); 0063 QVERIFY(ret); 0064 0065 QFile::remove(pathXmp); 0066 0067 // Export metadata from image to a fresh xmp sidecar. 0068 QScopedPointer<DMetadata> meta(new DMetadata); 0069 meta->setSettings(settings); 0070 ret = meta->load(path); 0071 QVERIFY(ret); 0072 0073 ret = meta->save(path); 0074 QVERIFY(ret); 0075 0076 QFile sidecar(pathXmp); 0077 ret = sidecar.exists(); 0078 QVERIFY(ret); 0079 0080 qCDebug(DIGIKAM_TESTS_LOG) << "Sidecar" << pathXmp << "size :" << sidecar.size(); 0081 0082 // Check if xmp sidecar are created and can be loaded 0083 QScopedPointer<DMetadata> meta2(new DMetadata); 0084 ret = meta2->load(pathXmp); 0085 QVERIFY(ret); 0086 } 0087 0088 #include "moc_createxmpsidecar_utest.cpp"