File indexing completed on 2024-04-21 03:54:19
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2006 Chusslove Illich <caslav.ilic@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QQmlComponent> 0008 #include <QQmlContext> 0009 #include <QQmlEngine> 0010 #include <QTest> 0011 0012 #include <KLocalizedContext> 0013 #include <QDebug> 0014 class KI18nDeclarativeTest : public QObject 0015 { 0016 Q_OBJECT 0017 0018 private Q_SLOTS: 0019 void testLocalizedContext_data() 0020 { 0021 QTest::addColumn<QString>("propertyName"); 0022 QTest::addColumn<QString>("value"); 0023 0024 QTest::newRow("translation") << "testString" << QStringLiteral("Awesome"); 0025 QTest::newRow("singular translation") << "testStringSingular" << QStringLiteral("and 1 other window"); 0026 QTest::newRow("plural translation") << "testStringPlural" << QStringLiteral("and 3 other windows"); 0027 QTest::newRow("plural translation with domain") << "testStringPluralWithDomain" << QStringLiteral("in 3 seconds"); 0028 QTest::newRow("null string arg") << "testNullStringArg" << QStringLiteral("Awesome "); 0029 QTest::newRow("zero") << "testZero" << QStringLiteral("I'm 0 years old"); 0030 } 0031 0032 void testLocalizedContext() 0033 { 0034 QFETCH(QString, propertyName); 0035 QFETCH(QString, value); 0036 0037 KLocalizedContext ctx; 0038 QUrl input = QUrl::fromLocalFile(QFINDTESTDATA("test.qml")); 0039 0040 QQmlEngine engine; 0041 engine.rootContext()->setContextObject(&ctx); 0042 QQmlComponent component(&engine, input, QQmlComponent::PreferSynchronous); 0043 QObject *object = component.create(); 0044 0045 if (!object) { 0046 qDebug() << "errors:" << component.errors(); 0047 } 0048 0049 QVERIFY(object); 0050 QVERIFY(!component.isLoading()); 0051 QCOMPARE(object->property(propertyName.toUtf8().constData()).toString(), value); 0052 } 0053 }; 0054 0055 QTEST_MAIN(KI18nDeclarativeTest) 0056 0057 #include "ki18ndeclarativetest.moc"