File indexing completed on 2024-06-02 04:17:13

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-06-09
0007  * Description : an unit-test to load PGF data and convert to QImage
0008  *
0009  * SPDX-FileCopyrightText: 2011-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 "loadpgfdata_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QTest>
0020 #include <QFile>
0021 #include <QIODevice>
0022 #include <QImage>
0023 
0024 // Local includes
0025 
0026 #include "digikam_debug.h"
0027 #include "dtestdatadir.h"
0028 #include "pgfutils.h"
0029 
0030 using namespace Digikam;
0031 
0032 QTEST_GUILESS_MAIN(LoadPGFDataTest)
0033 
0034 LoadPGFDataTest::LoadPGFDataTest(QObject* const parent)
0035     : QObject(parent)
0036 {
0037 }
0038 
0039 void LoadPGFDataTest::testLoadData()
0040 {
0041     qCDebug(DIGIKAM_TESTS_LOG) << "Using LibPGF version: " << PGFUtils::libPGFVersion();
0042     QImage img;
0043 
0044     // Write PGF file.
0045 
0046     QString fname = DTestDataDir::TestData(QString::fromUtf8("core/tests/fileio"))
0047                        .root().path() + QLatin1String("/raw.pgf");
0048     qCDebug(DIGIKAM_TESTS_LOG) << "Test Data File:" << fname;
0049 
0050     QFile file(fname);
0051 
0052     QVERIFY2(file.open(QIODevice::ReadOnly), "Cannot read Raw PGF stream...");
0053 
0054     QByteArray data(file.size(), '\x00');
0055     QDataStream stream(&file);
0056     stream.readRawData(data.data(), data.size());
0057 
0058     // PGF => QImage conversion
0059 
0060     QVERIFY2(PGFUtils::readPGFImageData(data, img), "Failed to read Raw PGF stream...");
0061 
0062     qCDebug(DIGIKAM_TESTS_LOG) << "Raw PGF stream image size:"         << img.size();
0063     qCDebug(DIGIKAM_TESTS_LOG) << "Raw PGF stream image color depth:"  << img.depth();
0064     qCDebug(DIGIKAM_TESTS_LOG) << "Raw PGF stream image color format:" << img.format();
0065 
0066     QVERIFY2(!img.isNull(), "Raw PGF stream image is null...");
0067     QVERIFY2(img.size()  == QSize(256, 170), "Incorrect Raw PGF stream image size...");
0068     QVERIFY2(img.depth() == 32, "Incorrect Raw PGF stream image color depth...");
0069     QVERIFY2(img.format() == QImage::Format_ARGB32, "Incorrect Raw PGF stream image color format...");
0070 }
0071 
0072 #include "moc_loadpgfdata_utest.cpp"