File indexing completed on 2024-04-14 05:39:24

0001 /***************************************************************************
0002  *   Copyright © 2015 Harald Sitter <sitter@kde.org>                       *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or         *
0005  *   modify it under the terms of the GNU General Public License as        *
0006  *   published by the Free Software Foundation; either version 2 of        *
0007  *   the License or (at your option) version 3 or any later version        *
0008  *   accepted by the membership of KDE e.V. (or its successor approved     *
0009  *   by the membership of KDE e.V.), which shall act as a proxy            *
0010  *   defined in Section 14 of version 3 of the license.                    *
0011  *                                                                         *
0012  *   This program is distributed in the hope that it will be useful,       *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0015  *   GNU General Public License for more details.                          *
0016  *                                                                         *
0017  *   You should have received a copy of the GNU General Public License     *
0018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0019  ***************************************************************************/
0020 
0021 #include <QObject>
0022 #include <QtTest>
0023 
0024 #include "../src/daemon/hookevent/hook.h"
0025 
0026 class HookTest : public QObject
0027 {
0028     Q_OBJECT
0029 private Q_SLOTS:
0030     void initTestCase();
0031     void init();
0032 
0033     void ctor();
0034     void validFile();
0035     void invalidFile();
0036 
0037 private:
0038     QString data(const QString func);
0039 
0040     QString m_dataPath;
0041 };
0042 
0043 void HookTest::initTestCase()
0044 {
0045     m_dataPath = QStringLiteral(TEST_DATA) + QStringLiteral("/hooktest");
0046 }
0047 
0048 void HookTest::init()
0049 {
0050     setlocale(LC_ALL, "en_US.UTF-8");
0051 }
0052 
0053 void HookTest::ctor()
0054 {
0055     Hook h(nullptr, QStringLiteral("/"));
0056 }
0057 
0058 void HookTest::validFile()
0059 {
0060     Hook h(nullptr, data("validFile"));
0061     QVERIFY(h.isValid());
0062     QCOMPARE(h.getField("Name"), QString("apt-file update needed"));
0063     QCOMPARE(h.getField("Terminal"), QString("True"));
0064     QCOMPARE(h.getField("Command"), QString("\"/usr/share/apt-file/do-apt-file-update\""));
0065     h.setLocale("de_DE.UTF-8");
0066     QCOMPARE(h.getField("Name"), QString("sauerkraut lederhosen"));
0067     QCOMPARE(h.getField("Terminal"), QString("True"));
0068     QCOMPARE(h.getField("Command"), QString("\"/usr/share/apt-file/do-apt-file-update\""));
0069     h.setLocale("fr_FR.UTF-8");
0070     QCOMPARE(h.getField("Name"), QString("Échec du téléchargement des données supplémentaires"));
0071 }
0072 
0073 void HookTest::invalidFile()
0074 {
0075     Hook h(nullptr, data("invalidFile"));
0076     QVERIFY(!h.isValid());
0077 }
0078 
0079 QString HookTest::data(const QString func)
0080 {
0081     return m_dataPath + "/" + func;
0082 }
0083 
0084 QTEST_GUILESS_MAIN(HookTest);
0085 
0086 #include "hooktest.moc"