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

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-12-06
0007  * Description : test for the filesaveoptionsbox
0008  *
0009  * SPDX-FileCopyrightText: 2009 by Johannes Wienke <languitar at semipol dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "filesaveoptionsbox_utest.h"
0016 
0017 // Qt includes
0018 
0019 #include <QTest>
0020 #include <QDir>
0021 
0022 // Local includes
0023 
0024 #include "filesaveoptionsbox.h"
0025 #include "dpluginloader.h"
0026 
0027 using namespace Digikam;
0028 
0029 QTEST_MAIN(FileSaveOptionsBoxTest)
0030 
0031 FileSaveOptionsBoxTest::FileSaveOptionsBoxTest(QObject* const parent)
0032     : QObject(parent)
0033 {
0034 }
0035 
0036 void FileSaveOptionsBoxTest::testDiscoverFormat_data()
0037 {
0038     QTest::addColumn<QString>("filename");
0039     QTest::addColumn<int>("format");
0040 
0041     QTest::newRow("jpg") << "test.jpg" << (int) FileSaveOptionsBox::JPEG;
0042     QTest::newRow("jpeg") << "test.jpeg" << (int) FileSaveOptionsBox::JPEG;
0043     QTest::newRow("JPG") << "test.JPG" << (int) FileSaveOptionsBox::JPEG;
0044     QTest::newRow("jpg") << "jpg" << (int) FileSaveOptionsBox::JPEG;
0045     QTest::newRow("jpeg") << "jpeg" << (int) FileSaveOptionsBox::JPEG;
0046 
0047     QTest::newRow("bla.tiff.jpeg") << "bla.tiff.jpeg" << (int) FileSaveOptionsBox::JPEG;
0048     QTest::newRow("bla.jpg.tiff") << "bla.jpg.tiff" << (int) FileSaveOptionsBox::TIFF;
0049 
0050 #ifdef HAVE_JASPER
0051     QTest::newRow("bla.png.jpeg.pgx") << "bla.png.jpeg.pgx" << (int) FileSaveOptionsBox::JP2K;
0052 #endif // HAVE_JASPER
0053 
0054 #ifdef HAVE_X265
0055     QTest::newRow("bla.png.jpeg.heic") << "bla.png.jpeg.heic" << (int) FileSaveOptionsBox::HEIF;
0056 #endif // HAVE_X265
0057 
0058     QTest::newRow("pgf") << "PGF" << (int) FileSaveOptionsBox::PGF;
0059 
0060     QTest::newRow("unknwon") << "i.dont.know" << (int) FileSaveOptionsBox::NONE; // krazy:exclude=spelling
0061 }
0062 
0063 void FileSaveOptionsBoxTest::testDiscoverFormat()
0064 {
0065     QFETCH(QString, filename);
0066     QFETCH(int, format);
0067 
0068     FileSaveOptionsBox box;
0069     QCOMPARE((int) box.discoverFormat(filename), format);
0070 }
0071 
0072 void FileSaveOptionsBoxTest::testDiscoverFormatDefault()
0073 {
0074     FileSaveOptionsBox box;
0075     QCOMPARE(box.discoverFormat(QLatin1String("unknown")), FileSaveOptionsBox::NONE);
0076     QCOMPARE(box.discoverFormat(QLatin1String("unknown"), FileSaveOptionsBox::PGF), FileSaveOptionsBox::PGF);
0077 }
0078 
0079 void FileSaveOptionsBoxTest::initTestCase()
0080 {
0081     QDir dir(qApp->applicationDirPath());
0082     qputenv("DK_PLUGIN_PATH", dir.canonicalPath().toUtf8());
0083     DPluginLoader::instance()->init();
0084 }
0085 
0086 void FileSaveOptionsBoxTest::cleanupTestCase()
0087 {
0088     DPluginLoader::instance()->cleanUp();
0089 }
0090 
0091 #include "moc_filesaveoptionsbox_utest.cpp"