KDE/kdelibs/kdecore/tests
Thomas Braxton
kde.braxton at gmail.com
Thu Oct 4 20:19:20 BST 2007
On 10/4/07, David Faure <faure at kde.org> wrote:
>
> SVN commit 721135 by dfaure:
>
> Today's quizz: KConfigGroup(c,"").group() == ?
>
> Answered by this unit test: it's "<default>", i.e. the toplevel entries in
> the config files.
> I thought we had support for the empty group ("[]" in the config file) but
> obviously not.
> Good I guess, one less thing to support. But then we could get rid of the
> "<default>" string altogether,
> and use the empty string instead, no?
> CCMAIL: kde-core-devel at kde.org
>
>
> M +58 -1 kconfigtest.cpp
> M +3 -0 kconfigtest.h
>
>
> --- trunk/KDE/kdelibs/kdecore/tests/kconfigtest.cpp #721134:721135
> @@ -19,6 +19,7 @@
>
> #include <qtest_kde.h>
> #include "kconfigtest.h"
> +#include <kstandarddirs.h>
> #include "kconfigtest.moc"
>
> #include <kconfig.h>
> @@ -287,7 +288,7 @@
> QVERIFY( sc3.readEntry( "flags-bit0", KConfigTest::Flags() ) ==
> KConfigTest::bit0 );
>
> int eid = staticMetaObject.indexOfEnumerator( "Flags" );
> - Q_ASSERT( eid != -1 );
> + QVERIFY( eid != -1 );
> QMetaEnum me = staticMetaObject.enumerator( eid );
> KConfigTest::Flags bitfield = KConfigTest::bit0|KConfigTest::bit1;
>
> @@ -398,6 +399,46 @@
> QVERIFY( sc.entryMap("FooBar").isEmpty() ); //inexistant group
> }
>
> +void KConfigTest::testDefaultGroup()
> +{
> + KConfig sc( "kconfigtest" );
> + KConfigGroup defaultGroup(&sc, "<default>");
> + QCOMPARE(defaultGroup.group(), QString("<default>"));
> + QVERIFY(!defaultGroup.exists());
> + defaultGroup.writeEntry("TestKey", "defaultGroup");
> + QVERIFY(defaultGroup.exists());
> + QCOMPARE(defaultGroup.readEntry("TestKey", QString()),
> QString("defaultGroup"));
> + sc.sync();
> +
> +#ifdef Q_OS_UNIX
> + QList<QByteArray> lines = readLines();
> + QVERIFY(!lines.contains("[]"));
> + QCOMPARE(lines.first(), QByteArray("TestKey=defaultGroup\n"));
> +#endif
> +
> + defaultGroup.deleteGroup();
> +}
> +
> +void KConfigTest::testEmptyGroup()
> +{
> + KConfig sc( "kconfigtest" );
> + KConfigGroup emptyGroup(&sc, "");
> + QCOMPARE(emptyGroup.group(), QString("<default>")); // confusing,
> heh?
> + QVERIFY(!emptyGroup.exists());
> + emptyGroup.writeEntry("TestKey", "emptyGroup");
> + QVERIFY(emptyGroup.exists());
> + QCOMPARE(emptyGroup.readEntry("TestKey", QString()),
> QString("emptyGroup"));
> + sc.sync();
> +
> +#ifdef Q_OS_UNIX
> + QList<QByteArray> lines = readLines();
> + QVERIFY(!lines.contains("[]")); // there's no support for the []
> group, in fact.
> +#endif
> +
> + emptyGroup.deleteGroup();
> +}
> +
> +
> void KConfigTest::testKAboutDataOrganizationDomain()
> {
> KAboutData data( "app", 0, ki18n("program"), "version",
> @@ -412,3 +453,19 @@
> "http://edu.kde.org/kig" );
> QCOMPARE( data2.organizationDomain(), QString::fromLatin1( "kde.org"
> ) );
> }
> +
> +QList<QByteArray> KConfigTest::readLines()
> +{
> + const QString path = KStandardDirs::locateLocal("config",
> "kconfigtest");
> + Q_ASSERT(!path.isEmpty());
> + QFile file(path);
> + Q_ASSERT(file.open(QIODevice::ReadOnly));
> + QList<QByteArray> lines;
> + QByteArray line;
> + do {
> + line = file.readLine();
> + if (!line.isEmpty())
> + lines.append(line);
> + } while(!line.isEmpty());
> + return lines;
> +}
> --- trunk/KDE/kdelibs/kdecore/tests/kconfigtest.h #721134:721135
> @@ -41,6 +41,8 @@
> void testEnums();
> void testInvalid();
> void testDelete();
> + void testDefaultGroup();
> + void testEmptyGroup();
> void testRevertAllEntries();
> void testChangeGroup();
>
> @@ -48,6 +50,7 @@
> void testKAboutDataOrganizationDomain();
> private:
> void revertEntries();
> + QList<QByteArray> readLines();
> };
> Q_DECLARE_OPERATORS_FOR_FLAGS(KConfigTest::Flags)
>
> did we ever support an empty group name? AFAIK that was translated
internally into <default>, no?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071004/e5bfd459/attachment.htm>
More information about the kde-core-devel
mailing list