File indexing completed on 2022-11-29 18:25:10

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2011 David Faure <faure@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include <QObject>
0021 
0022 #include <qtest_kde.h>
0023 
0024 #include <ksharedconfig.h>
0025 
0026 #include <kconfig.h>
0027 #include <kconfiggroup.h>
0028 #include <kconfiggroup_kurl.h>
0029 #include <qstandardpaths.h>
0030 
0031 class KConfigCompatTest : public QObject
0032 {
0033     Q_OBJECT
0034 
0035 private Q_SLOTS:
0036     void initTestCase();
0037     void testKUrl();
0038     void testDefaultName();
0039     void cleanupTestCase();
0040 };
0041 
0042 void KConfigCompatTest::initTestCase()
0043 {
0044     // Qt5 TODO: should be done by qtestlib+qstandardpaths
0045     QString xdgConfigHome = QDir::home().canonicalPath() + "/.qttest/config";
0046     qputenv("XDG_CONFIG_HOME", QFile::encodeName(xdgConfigHome));
0047 }
0048 
0049 void KConfigCompatTest::cleanupTestCase()
0050 {
0051     QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/kconfig_compat_test"));
0052 }
0053 
0054 void KConfigCompatTest::testKUrl()
0055 {
0056     KConfig config("kconfig_compat_test");
0057     {
0058         KConfigGroup cg(&config, "Group");
0059         cg.writeEntry("kurlEntry", KUrl("http://www.kde.org")); // DO NOT PORT TO QUrl
0060     }
0061     {
0062         KConfigGroup cg(&config, "Group");
0063         QCOMPARE(cg.readEntry("kurlEntry", KUrl()), KUrl("http://www.kde.org"));
0064     }
0065 }
0066 
0067 void KConfigCompatTest::testDefaultName()
0068 {
0069     QCOMPARE(KSharedConfig::openConfig()->name(), QString::fromLatin1("myapprc"));
0070     QCOMPARE(KGlobal::config()->name(), QString::fromLatin1("myapprc"));
0071 }
0072 
0073 QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(KConfigCompatTest, "myapp")
0074 
0075 #include "kconfigcompattest.moc"