File indexing completed on 2024-12-08 03:28:44
0001 /* GCompris - ApplicationInfoTest.cpp 0002 * 0003 * SPDX-FileCopyrightText: 2018 Billy Laws <blaws05@gmail.com> 0004 * GCompris (C) 2018 GCompris Developers <gcompris-devel@kde.org> 0005 * 0006 * Authors: 0007 * Billy Laws <blaws05@gmail.com> 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 #include <QObject> 0013 #include <QTest> 0014 0015 #include "src/core/ApplicationInfo.h" 0016 0017 class ApplicationInfoTest : public QObject 0018 { 0019 public: 0020 Q_OBJECT 0021 private Q_SLOTS: 0022 void LocaleTest_data(); 0023 void LocaleTest(); 0024 void WindowTest_data(); 0025 void WindowTest(); 0026 0027 void getVoicesLocaleTest_data(); 0028 void getVoicesLocaleTest(); 0029 void getAudioFilePathForLocaleTest_data(); 0030 void getAudioFilePathForLocaleTest(); 0031 }; 0032 0033 void ApplicationInfoTest::LocaleTest_data() 0034 { 0035 QTest::addColumn<QString>("localeFull"); 0036 QTest::addColumn<QString>("localeShort"); 0037 QTest::addColumn<QString>("higherWord"); 0038 QTest::addColumn<QString>("lowerWord"); 0039 QTest::newRow("British English") << QStringLiteral("en_GB") 0040 << QStringLiteral("en") 0041 << QStringLiteral("apple") 0042 << QStringLiteral("banana"); 0043 } 0044 0045 void ApplicationInfoTest::LocaleTest() 0046 { 0047 ApplicationInfo appInfo; 0048 ApplicationInfo::getInstance(); 0049 0050 QFETCH(QString, localeFull); 0051 QFETCH(QString, localeShort); 0052 QFETCH(QString, higherWord); 0053 QFETCH(QString, lowerWord); 0054 0055 QVERIFY(appInfo.localeShort(localeFull) == localeShort); 0056 QVERIFY(appInfo.localeCompare(higherWord, lowerWord, localeFull) == -1); 0057 QVERIFY(appInfo.localeCompare(lowerWord, higherWord, localeFull) == 1); 0058 QVERIFY(appInfo.localeCompare(higherWord, higherWord, localeFull) == 0); 0059 0060 QVariantList sortList; 0061 0062 sortList.append(QVariant(higherWord)); 0063 sortList.append(QVariant(lowerWord)); 0064 sortList.append(QVariant(higherWord)); 0065 sortList.append(QVariant(lowerWord)); 0066 0067 sortList = appInfo.localeSort(sortList, localeFull); 0068 0069 QVERIFY(sortList[0] == higherWord); 0070 QVERIFY(sortList[1] == higherWord); 0071 QVERIFY(sortList[2] == lowerWord); 0072 QVERIFY(sortList[3] == lowerWord); 0073 } 0074 0075 void ApplicationInfoTest::WindowTest_data() 0076 { 0077 QTest::addColumn<bool>("useOpenGL"); 0078 QTest::addColumn<int>("applicationWidth"); 0079 QTest::addColumn<bool>("portraitMode"); 0080 QTest::newRow("dummy1") << true 0081 << 1920 0082 << true; 0083 } 0084 0085 void ApplicationInfoTest::WindowTest() 0086 { 0087 ApplicationInfo appInfo; 0088 ApplicationInfo::getInstance(); 0089 0090 QFETCH(bool, useOpenGL); 0091 QFETCH(int, applicationWidth); 0092 QFETCH(bool, portraitMode); 0093 0094 appInfo.setApplicationWidth(applicationWidth); 0095 appInfo.setIsPortraitMode(portraitMode); 0096 appInfo.setUseOpenGL(useOpenGL); 0097 0098 QVERIFY(appInfo.useOpenGL() == useOpenGL); 0099 QVERIFY(appInfo.applicationWidth() == applicationWidth); 0100 QVERIFY(appInfo.isPortraitMode() == portraitMode); 0101 } 0102 0103 void ApplicationInfoTest::getVoicesLocaleTest_data() 0104 { 0105 QTest::addColumn<QString>("actual"); 0106 QTest::addColumn<QString>("expected"); 0107 QTest::newRow("default") << GC_DEFAULT_LOCALE 0108 << "en_US"; 0109 QTest::newRow("en_US") << "en_US" 0110 << "en_US"; 0111 QTest::newRow("pt_BR") << "pt_BR" 0112 << "pt_BR"; 0113 QTest::newRow("pt_PT") << "pt_PT" 0114 << "pt"; 0115 QTest::newRow("fr_FR") << "fr_FR" 0116 << "fr"; 0117 } 0118 0119 void ApplicationInfoTest::getVoicesLocaleTest() 0120 { 0121 // Set default locale to "C". ALlows to test GC_DEFAULT_LOCALE 0122 QLocale defaultLocale = QLocale::system(); 0123 QLocale::setDefault(QLocale::c()); 0124 ApplicationInfo appInfo; 0125 ApplicationInfo::getInstance(); 0126 0127 QFETCH(QString, actual); 0128 QFETCH(QString, expected); 0129 0130 QCOMPARE(appInfo.getVoicesLocale(actual), expected); 0131 0132 QLocale::setDefault(defaultLocale); 0133 } 0134 0135 void ApplicationInfoTest::getAudioFilePathForLocaleTest_data() 0136 { 0137 QTest::addColumn<QString>("file"); 0138 QTest::addColumn<QString>("locale"); 0139 QTest::addColumn<QString>("expected"); 0140 QTest::newRow("absolutePath_en") << "/$LOCALE/$CA" 0141 << "en" 0142 << QString("/en/%1").arg(COMPRESSED_AUDIO); 0143 QTest::newRow("absolutePath_pt_BR") << "qrc:/$LOCALE/test" 0144 << "pt_BR" 0145 << "qrc:/pt_BR/test"; 0146 QTest::newRow("absolute_fr") << ":/test/test2" 0147 << "unused" 0148 << ":/test/test2"; 0149 QTest::newRow("relative_fr") << "$LOCALE/$CA" 0150 << "fr" 0151 << QString("qrc:/gcompris/data/fr/%1").arg(COMPRESSED_AUDIO); 0152 } 0153 0154 void ApplicationInfoTest::getAudioFilePathForLocaleTest() 0155 { 0156 ApplicationInfo appInfo; 0157 ApplicationInfo::getInstance(); 0158 0159 QFETCH(QString, file); 0160 QFETCH(QString, locale); 0161 QFETCH(QString, expected); 0162 0163 QCOMPARE(appInfo.getAudioFilePathForLocale(file, locale), expected); 0164 } 0165 0166 QTEST_MAIN(ApplicationInfoTest) 0167 #include "ApplicationInfoTest.moc"