File indexing completed on 2024-11-24 05:00:37
0001 /* 0002 SPDX-FileCopyrightText: 2011 Andriy Rysin <rysin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QIcon> 0008 #include <QTest> 0009 0010 #include "../flags.h" 0011 #include "../keyboard_config.h" 0012 #include "../xkb_rules.h" 0013 0014 class FlagsTest : public QObject 0015 { 0016 Q_OBJECT 0017 0018 Flags *flags; 0019 const Rules *rules; 0020 0021 private Q_SLOTS: 0022 void initTestCase() 0023 { 0024 flags = new Flags(); 0025 rules = nullptr; 0026 } 0027 0028 void cleanupTestCase() 0029 { 0030 delete flags; 0031 delete rules; 0032 } 0033 0034 void testRules() 0035 { 0036 QVERIFY(flags != nullptr); 0037 0038 const QIcon iconUs(flags->getIcon(QStringLiteral("us"))); 0039 QVERIFY(!iconUs.isNull()); 0040 QVERIFY(flags->getIcon(QString()).isNull()); 0041 0042 KeyboardConfig *keyboardConfig = new KeyboardConfig(this); 0043 LayoutUnit layoutUnit(QStringLiteral("us")); 0044 LayoutUnit layoutUnit1(QStringLiteral("us"), QStringLiteral("intl")); 0045 layoutUnit1.setDisplayName(QStringLiteral("usi")); 0046 LayoutUnit layoutUnit2(QStringLiteral("us"), QStringLiteral("other")); 0047 0048 keyboardConfig->layouts.append(layoutUnit1); 0049 QCOMPARE(flags->getShortText(layoutUnit, *keyboardConfig), QString("us")); 0050 QCOMPARE(flags->getShortText(layoutUnit1, *keyboardConfig), QString("usi")); 0051 QCOMPARE(flags->getShortText(layoutUnit2, *keyboardConfig), QString("us")); 0052 0053 const Rules *rules = Rules::readRules(Rules::NO_EXTRAS); 0054 QCOMPARE(flags->getLongText(layoutUnit, rules), QString("English (US)")); 0055 QCOMPARE(flags->getLongText(layoutUnit2, rules), QString("other")); 0056 0057 rules = nullptr; // when no rules found 0058 QCOMPARE(flags->getLongText(layoutUnit1, rules), QString("us - intl")); 0059 } 0060 0061 // void loadRulesBenchmark() { 0062 // QBENCHMARK { 0063 // Flags* flags = new Flags(); 0064 // delete flags; 0065 // } 0066 // } 0067 }; 0068 0069 // need GUI for xkb protocol in xkb_rules.cpp 0070 QTEST_MAIN(FlagsTest) 0071 0072 #include "flags_test.moc"