[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: KDE/kdelibs/kdecore/tests
From: "Thomas Braxton" <kde.braxton () gmail ! com>
Date: 2007-10-04 19:19:20
Message-ID: 928c3f1b0710041219v4a499ae9ucc3c4df40dfd2a13 () mail ! gmail ! com
[Download RAW message or body]
On 10/4/07, David Faure <faure@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@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?
[Attachment #3 (text/html)]
<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(!defaultGro \
up.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?
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic