File indexing completed on 2024-05-12 04:33:30

0001 /*
0002     SPDX-FileCopyrightText: 2023 g10 Code GmbH
0003     SPDX-FileContributor: Sune Stolborg Vuorela <sune@vuorela.dk>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #include <QTest>
0008 
0009 #include "../part/signaturepartutils.h"
0010 
0011 class SuggestedFileNameTest : public QObject
0012 {
0013     Q_OBJECT
0014 private Q_SLOTS:
0015     void initTestCase();
0016     void testSuggestedSignedDocumentName();
0017     void testSuggestedSignedDocumentName_data();
0018 };
0019 
0020 void SuggestedFileNameTest::initTestCase()
0021 {
0022     qputenv("LC_ALL", "en_US.UTF-8");
0023 }
0024 
0025 void SuggestedFileNameTest::testSuggestedSignedDocumentName()
0026 {
0027     QFETCH(QString, input);
0028     QFETCH(QString, preferredSuffix);
0029     QFETCH(QString, expected);
0030 
0031     auto output = SignaturePartUtils::getSuggestedFileNameForSignedFile(input, preferredSuffix);
0032     QCOMPARE(output, expected);
0033 }
0034 
0035 void SuggestedFileNameTest::testSuggestedSignedDocumentName_data()
0036 {
0037     QTest::addColumn<QString>("input");
0038     QTest::addColumn<QString>("preferredSuffix"); // normally derived from mimetype of document
0039     QTest::addColumn<QString>("expected");
0040 
0041     QTest::newRow("simple") << QStringLiteral("foo.pdf") << QStringLiteral("pdf") << QStringLiteral("foo_signed.pdf");
0042     QTest::newRow("double extensions") << QStringLiteral("foo.pdf.gz") << QStringLiteral("pdf") << QStringLiteral("foo_signed.pdf"); // while we might read compressed files, we don't write  them out
0043     QTest::newRow("versioning") << QStringLiteral("foo-1.2.3.pdf") << QStringLiteral("pdf") << QStringLiteral("foo-1.2.3_signed.pdf");
0044     QTest::newRow("versioned and double extensions") << QStringLiteral("foo-1.2.3.pdf.gz") << QStringLiteral("pdf") << QStringLiteral("foo-1.2.3_signed.pdf");
0045     QTest::newRow("gif") << QStringLiteral("foo.gif") << QStringLiteral("pdf") << QStringLiteral("foo_signed.pdf");
0046     QTest::newRow("version gif") << QStringLiteral("foo-1.2.3.gif") << QStringLiteral("pdf") << QStringLiteral("foo-1.2.3_signed.pdf");
0047     QTest::newRow("no extension") << QStringLiteral("foo") << QStringLiteral("pdf") << QStringLiteral("foo_signed.pdf");
0048     QTest::newRow("no extension with versions") << QStringLiteral("foo-1.2.3") << QStringLiteral("pdf") << QStringLiteral("foo-1.2_signed.pdf"); // This is not as such expected behavior but more a documentation of implementation.
0049 }
0050 
0051 QTEST_GUILESS_MAIN(SuggestedFileNameTest)
0052 
0053 #include "suggestedfilenametest.moc"