File indexing completed on 2022-09-20 12:43:22

0001 /*
0002     SPDX-FileCopyrightText: 2014 Kevin Krammer <krammer@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include <ktranscriptcleantest.h>
0008 
0009 #include <QTest>
0010 
0011 #include <QDebug>
0012 
0013 #include <ktranscript_p.h>
0014 
0015 QTEST_MAIN(KTranscriptCleanTest)
0016 
0017 KTranscriptCleanTest::KTranscriptCleanTest()
0018     : m_transcript(nullptr)
0019 {
0020 }
0021 
0022 void KTranscriptCleanTest::init()
0023 {
0024     m_transcript = autotestCreateKTranscriptImp();
0025 }
0026 
0027 void KTranscriptCleanTest::cleanup()
0028 {
0029     autotestDestroyKTranscriptImp();
0030     m_transcript = nullptr;
0031 }
0032 
0033 void KTranscriptCleanTest::test_data()
0034 {
0035     QTest::addColumn<QVariantList>("argv");
0036     QTest::addColumn<bool>("fallsBack");
0037     QTest::addColumn<QString>("expected");
0038 
0039     // Example test case, replace with first clean-slate test
0040     QTest::newRow("test_basic") << QVariantList{"test_basic", "foo"} << false << "foo bar";
0041 }
0042 
0043 void KTranscriptCleanTest::test()
0044 {
0045     QFETCH(QVariantList, argv);
0046     QFETCH(bool, fallsBack);
0047     QFETCH(QString, expected);
0048 
0049     QString language = "fr";
0050     QString country = "fr";
0051     QString msgctxt = "a-context";
0052     QHash<QString, QString> dynamicContext;
0053     dynamicContext.insert("origin", "neverwhere");
0054     QString msgid = "source-text";
0055     QStringList subs;
0056     subs << "10"
0057          << "qwyx";
0058     QList<QVariant> values;
0059     values << 10 << "qwyx";
0060     QString ordinaryTranslation = "translated-text";
0061 
0062     QString testJs = QFINDTESTDATA("test.js");
0063     QList<QStringList> modules;
0064     modules << (QStringList() << testJs << language);
0065 
0066     QString error;
0067     bool fallback;
0068     QString result = m_transcript->eval(argv, language, country, msgctxt, dynamicContext, msgid, subs, values, ordinaryTranslation, modules, error, fallback);
0069 
0070     if (!error.isEmpty()) {
0071         QFAIL(qPrintable(error));
0072     }
0073     if (!fallsBack) {
0074         QVERIFY(!fallback);
0075         QCOMPARE(result, expected);
0076     } else {
0077         QVERIFY(fallback);
0078     }
0079 }