File indexing completed on 2024-04-21 05:46: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 #define private public
0025 #include "../src/daemon/hookevent/locale.h"
0026 #undef private
0027 
0028 class LocaleTest : public QObject
0029 {
0030     Q_OBJECT
0031 private Q_SLOTS:
0032     void en();
0033     void enEncoding();
0034     void en_US();
0035     void en_USVariant();
0036     void en_USVariantEncoding();
0037     void en_USEncoding();
0038 };
0039 
0040 void LocaleTest::en()
0041 {
0042     Locale l(QStringLiteral("en"));
0043     QCOMPARE(l.m_language, QStringLiteral("en"));
0044     QCOMPARE(l.m_country, QString());
0045     QCOMPARE(l.m_variant, QString());
0046     QCOMPARE(l.m_encoding, QString());
0047     QCOMPARE(l.combinations(), QStringList() << "en");
0048 }
0049 
0050 void LocaleTest::enEncoding()
0051 {
0052     Locale l(QStringLiteral("en.UTF-8"));
0053     QCOMPARE(l.m_language, QStringLiteral("en"));
0054     QCOMPARE(l.m_country, QString());
0055     QCOMPARE(l.m_variant, QString());
0056     QCOMPARE(l.m_encoding, QStringLiteral("UTF-8"));
0057     QCOMPARE(l.combinations(), QStringList() << "en.UTF-8" << "en");
0058 }
0059 
0060 
0061 void LocaleTest::en_US()
0062 {
0063     Locale l(QStringLiteral("en_US"));
0064     QCOMPARE(l.m_language, QStringLiteral("en"));
0065     QCOMPARE(l.m_country, QStringLiteral("US"));
0066     QCOMPARE(l.m_variant, QString());
0067     QCOMPARE(l.m_encoding, QString());
0068     QCOMPARE(l.combinations(), QStringList() << "en_US" << "en");
0069 }
0070 
0071 void LocaleTest::en_USVariant()
0072 {
0073     Locale l(QStringLiteral("en_US@foo"));
0074     QCOMPARE(l.m_language, QStringLiteral("en"));
0075     QCOMPARE(l.m_country, QStringLiteral("US"));
0076     QCOMPARE(l.m_variant, QStringLiteral("foo"));
0077     QCOMPARE(l.m_encoding, QString());
0078     QCOMPARE(l.combinations(), QStringList() << "en_US@foo" << "en@foo" << "en_US" << "en");
0079 }
0080 
0081 void LocaleTest::en_USVariantEncoding()
0082 {
0083     Locale l(QStringLiteral("en_US@foo.UTF-8"));
0084     QCOMPARE(l.m_language, QStringLiteral("en"));
0085     QCOMPARE(l.m_country, QStringLiteral("US"));
0086     QCOMPARE(l.m_variant, QStringLiteral("foo"));
0087     QCOMPARE(l.m_encoding, QStringLiteral("UTF-8"));
0088     QCOMPARE(l.combinations(), QStringList() << "en_US@foo.UTF-8" << "en_US@foo" << "en@foo.UTF-8" << "en@foo" << "en_US.UTF-8" << "en_US" << "en.UTF-8" << "en");
0089 }
0090 
0091 void LocaleTest::en_USEncoding()
0092 {
0093     Locale l(QStringLiteral("en_US.UTF-8"));
0094     QCOMPARE(l.m_language, QStringLiteral("en"));
0095     QCOMPARE(l.m_country, QStringLiteral("US"));
0096     QCOMPARE(l.m_variant, QString());
0097     QCOMPARE(l.m_encoding, QStringLiteral("UTF-8"));
0098     QCOMPARE(l.combinations(), QStringList() << "en_US.UTF-8" << "en_US" << "en.UTF-8" << "en");
0099 }
0100 
0101 QTEST_GUILESS_MAIN(LocaleTest);
0102 
0103 #include "localetest.moc"