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