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        : 2009-06-11
0007  * Description : An unit test to load metadata from byte array
0008  *
0009  * SPDX-FileCopyrightText: 2009-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 "loadfromba_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QFile>
0020 #include <QDataStream>
0021 #include <QImage>
0022 #include <QByteArray>
0023 
0024 QTEST_MAIN(LoadFromBATest)
0025 
0026 LoadFromBATest::LoadFromBATest(QObject* const parent)
0027     : AbstractUnitTest(parent)
0028 {
0029 }
0030 
0031 void LoadFromBATest::testLoadFromByteArray()
0032 {
0033     loadFromByteArray(m_originalImageFolder + QLatin1String("nikon-e2100.jpg"));
0034 }
0035 
0036 void LoadFromBATest::loadFromByteArray(const QString& file)
0037 {
0038     qCDebug(DIGIKAM_TESTS_LOG) << "File to process:" << file;
0039     QString path = m_tempDir.filePath(QFileInfo(file).fileName().trimmed());
0040 
0041     qCDebug(DIGIKAM_TESTS_LOG) << "Temporary target file:" << path;
0042 
0043     bool ret = !path.isNull();
0044     QVERIFY(ret);
0045 
0046     QFile target(file);
0047     ret = target.copy(path);
0048     QVERIFY(ret);
0049 
0050     QString baFile(path + QLatin1String("ba.dat"));
0051 
0052     QImage image(file);
0053     ret = image.save(baFile, "PNG");
0054     QVERIFY(ret);
0055 
0056     QFile baf(baFile);
0057     ret = baf.open(QIODevice::ReadOnly);
0058     QVERIFY(ret);
0059 
0060     QByteArray data;
0061     data.resize(baf.size());
0062     QDataStream stream(&baf);
0063     ret = stream.readRawData(data.data(), data.size());
0064     baf.close();
0065     QVERIFY(ret);
0066 
0067     QScopedPointer<DMetadata> meta(new DMetadata);
0068     ret = meta->loadFromData(data);
0069     QVERIFY(ret);
0070 }
0071 
0072 #include "moc_loadfromba_utest.cpp"