1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* GCompris - ApplicationInfoTest.cpp
*
* SPDX-FileCopyrightText: 2018 Billy Laws <blaws05@gmail.com>
* GCompris (C) 2018 GCompris Developers <gcompris-devel@kde.org>
*
* Authors:
* Billy Laws <blaws05@gmail.com>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <QObject>
#include <QTest>
#include "src/core/ApplicationInfo.h"
class ApplicationInfoTest : public QObject
{
public:
Q_OBJECT
private Q_SLOTS:
void LocaleTest_data();
void LocaleTest();
void WindowTest_data();
void WindowTest();
void getVoicesLocaleTest_data();
void getVoicesLocaleTest();
void getAudioFilePathForLocaleTest_data();
void getAudioFilePathForLocaleTest();
};
void ApplicationInfoTest::LocaleTest_data()
{
QTest::addColumn<QString>("localeFull");
QTest::addColumn<QString>("localeShort");
QTest::addColumn<QString>("higherWord");
QTest::addColumn<QString>("lowerWord");
QTest::newRow("British English") << QStringLiteral("en_GB")
<< QStringLiteral("en")
<< QStringLiteral("apple")
<< QStringLiteral("banana");
}
void ApplicationInfoTest::LocaleTest()
{
ApplicationInfo appInfo;
ApplicationInfo::getInstance();
QFETCH(QString, localeFull);
QFETCH(QString, localeShort);
QFETCH(QString, higherWord);
QFETCH(QString, lowerWord);
QVERIFY(appInfo.localeShort(localeFull) == localeShort);
QVERIFY(appInfo.localeCompare(higherWord, lowerWord, localeFull) == -1);
QVERIFY(appInfo.localeCompare(lowerWord, higherWord, localeFull) == 1);
QVERIFY(appInfo.localeCompare(higherWord, higherWord, localeFull) == 0);
QVariantList sortList;
sortList.append(QVariant(higherWord));
sortList.append(QVariant(lowerWord));
sortList.append(QVariant(higherWord));
sortList.append(QVariant(lowerWord));
sortList = appInfo.localeSort(sortList, localeFull);
QVERIFY(sortList[0] == higherWord);
QVERIFY(sortList[1] == higherWord);
QVERIFY(sortList[2] == lowerWord);
QVERIFY(sortList[3] == lowerWord);
}
void ApplicationInfoTest::WindowTest_data()
{
QTest::addColumn<bool>("useSoftwareRenderer");
QTest::addColumn<int>("applicationWidth");
QTest::addColumn<bool>("portraitMode");
QTest::newRow("dummy1") << true
<< 1920
<< true;
}
void ApplicationInfoTest::WindowTest()
{
ApplicationInfo appInfo;
ApplicationInfo::getInstance();
QFETCH(bool, useSoftwareRenderer);
QFETCH(int, applicationWidth);
QFETCH(bool, portraitMode);
appInfo.setApplicationWidth(applicationWidth);
appInfo.setIsPortraitMode(portraitMode);
appInfo.setUseSoftwareRenderer(useSoftwareRenderer);
QVERIFY(appInfo.useSoftwareRenderer() == useSoftwareRenderer);
QVERIFY(appInfo.applicationWidth() == applicationWidth);
QVERIFY(appInfo.isPortraitMode() == portraitMode);
}
void ApplicationInfoTest::getVoicesLocaleTest_data()
{
QTest::addColumn<QString>("actual");
QTest::addColumn<QString>("expected");
QTest::newRow("default") << GC_DEFAULT_LOCALE
<< "en_US";
QTest::newRow("en_US") << "en_US"
<< "en_US";
QTest::newRow("pt_BR") << "pt_BR"
<< "pt_BR";
QTest::newRow("pt_PT") << "pt_PT"
<< "pt";
QTest::newRow("fr_FR") << "fr_FR"
<< "fr";
}
void ApplicationInfoTest::getVoicesLocaleTest()
{
// Set default locale to "C". ALlows to test GC_DEFAULT_LOCALE
QLocale defaultLocale = QLocale::system();
QLocale::setDefault(QLocale::c());
ApplicationInfo appInfo;
ApplicationInfo::getInstance();
QFETCH(QString, actual);
QFETCH(QString, expected);
QCOMPARE(appInfo.getVoicesLocale(actual), expected);
QLocale::setDefault(defaultLocale);
}
void ApplicationInfoTest::getAudioFilePathForLocaleTest_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<QString>("locale");
QTest::addColumn<QString>("expected");
QTest::newRow("absolutePath_en") << "/$LOCALE/$CA"
<< "en"
<< QString("/en/%1").arg(COMPRESSED_AUDIO);
QTest::newRow("absolutePath_pt_BR") << "qrc:/$LOCALE/test"
<< "pt_BR"
<< "qrc:/pt_BR/test";
QTest::newRow("absolute_fr") << ":/test/test2"
<< "unused"
<< ":/test/test2";
QTest::newRow("relative_fr") << "$LOCALE/$CA"
<< "fr"
<< QString("qrc:/gcompris/data/fr/%1").arg(COMPRESSED_AUDIO);
}
void ApplicationInfoTest::getAudioFilePathForLocaleTest()
{
ApplicationInfo appInfo;
ApplicationInfo::getInstance();
QFETCH(QString, file);
QFETCH(QString, locale);
QFETCH(QString, expected);
QCOMPARE(appInfo.getAudioFilePathForLocale(file, locale), expected);
}
QTEST_MAIN(ApplicationInfoTest)
#include "ApplicationInfoTest.moc"
|