File indexing completed on 2024-05-12 05:19:11

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     autotests/stripsuffixtest.cpp
0003 
0004     This file is part of Kleopatra's test suite.
0005     SPDX-FileCopyrightText: 2022 Carlo Vanini <silhusk@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "utils/path-helper.h"
0011 #include <QDebug>
0012 #include <QTest>
0013 
0014 class StripSuffixTest : public QObject
0015 {
0016     Q_OBJECT
0017 
0018 private Q_SLOTS:
0019     void testStripSuffix_data();
0020     void testStripSuffix();
0021 };
0022 
0023 void StripSuffixTest::testStripSuffix_data()
0024 {
0025     QTest::addColumn<QString>("fileName");
0026     QTest::addColumn<QString>("baseName");
0027 
0028     QTest::newRow("absolute path") //
0029         << QString::fromLatin1("/home/user/test.sig") //
0030         << QString::fromLatin1("/home/user/test");
0031     QTest::newRow("relative path") //
0032         << QString::fromLatin1("home/user.name/test.sig") //
0033         << QString::fromLatin1("home/user.name/test");
0034     QTest::newRow("file name") //
0035         << QString::fromLatin1("t.sig") //
0036         << QString::fromLatin1("./t");
0037     QTest::newRow("short extension") //
0038         << QString::fromLatin1("/path/to/test.s") //
0039         << QString::fromLatin1("/path/to/test");
0040     QTest::newRow("long extension") //
0041         << QString::fromLatin1("/test.sign") //
0042         << QString::fromLatin1("/test");
0043     QTest::newRow("multiple extension") //
0044         << QString::fromLatin1("some/test.tar.gz.asc") //
0045         << QString::fromLatin1("some/test.tar.gz");
0046 }
0047 
0048 void StripSuffixTest::testStripSuffix()
0049 {
0050     QFETCH(QString, fileName);
0051     QFETCH(QString, baseName);
0052 
0053     QCOMPARE(Kleo::stripSuffix(fileName), baseName);
0054 }
0055 
0056 QTEST_MAIN(StripSuffixTest)
0057 #include "stripsuffixtest.moc"