[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] KConfig: Rewrite globals only if modified
From: Chusslove Illich <caslav.ilic () gmx ! net>
Date: 2008-02-26 19:20:37
Message-ID: 200802262020.40824.caslav.ilic () gmx ! net
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
> [: David Faure :]
> Look for "utime" in kdelibs/kio/tests/kiotesthelper.h (unix-only, of
> course).
Right, how about the new version: do the utime trick on unix, really sleep
over on non-unix? Or better just ditch the test for non-unix?
--
Chusslove Illich (Часлав Илић)
["kconfigtest-02.diff" (text/x-diff)]
Index: kdecore/tests/kconfigtest.cpp
===================================================================
--- kdecore/tests/kconfigtest.cpp (revision 779437)
+++ kdecore/tests/kconfigtest.cpp (working copy)
@@ -29,6 +29,10 @@
#include <QtNetwork/QHostInfo>
+#ifdef Q_OS_UNIX
+#include <utime.h>
+#endif
+
KCONFIGGROUP_DECLARE_ENUM_QOBJECT(KConfigTest,Testing)
KCONFIGGROUP_DECLARE_FLAGS_QOBJECT(KConfigTest,Flags)
@@ -903,6 +907,54 @@
QCOMPARE( data2.organizationDomain(), QString::fromLatin1( "kde.org" ) );
}
+static void ageTimeStamp(const QString& path, int nsec)
+{
+#ifdef Q_OS_UNIX
+ QDateTime mtime = QFileInfo(path).lastModified().addSecs(-nsec);
+ struct utimbuf utbuf;
+ utbuf.actime = mtime.toTime_t();
+ utbuf.modtime = utbuf.actime;
+ utime(QFile::encodeName(path), &utbuf);
+#else
+ QTest::qSleep(nsec * 1000);
+#endif
+}
+
+void KConfigTest::testConservativeWrites()
+{
+ QDateTime oldStamp, newStamp;
+ KConfig sc("kconfigtest", KConfig::IncludeGlobals);
+
+ // Age the timestamp of global config file a few sec, and collect it.
+ QString globFile = KStandardDirs::locateLocal("config", "kdeglobals");
+ ageTimeStamp(globFile, 2); // age 2 sec
+ oldStamp = QFileInfo(globFile).lastModified();
+
+ // Add a local entry and sync the config.
+ KConfigGroup cgLocal(&sc, "Locals");
+ cgLocal.writeEntry("someLocalString", "whatever");
+ sc.sync();
+
+ // Verify that the timestamp of global config file didn't change.
+ newStamp = QFileInfo(globFile).lastModified();
+ QCOMPARE(newStamp, oldStamp);
+
+ // Age the timestamp of local config file a few sec, and collect it.
+ QString locFile = KStandardDirs::locateLocal("config", "kconfigtest");
+ ageTimeStamp(locFile, 2); // age 2 sec
+ oldStamp = QFileInfo(locFile).lastModified();
+
+ // Add a global entry and sync the config.
+ KConfigGroup cgGlobal(&sc, "Globals");
+ cgGlobal.writeEntry("someGlobalString", "whatever",
+ KConfig::Persistent|KConfig::Global);
+ sc.sync();
+
+ // Verify that the timestamp of local config file didn't change.
+ newStamp = QFileInfo(locFile).lastModified();
+ QCOMPARE(newStamp, oldStamp);
+}
+
QList<QByteArray> KConfigTest::readLines()
{
const QString path = KStandardDirs::locateLocal("config", "kconfigtest");
Index: kdecore/tests/kconfigtest.h
===================================================================
--- kdecore/tests/kconfigtest.h (revision 779437)
+++ kdecore/tests/kconfigtest.h (working copy)
@@ -58,6 +58,7 @@
void testKdeglobals();
void testSubGroup();
void testAddConfigSources();
+ void testConservativeWrites();
// unrelated
void testKAboutDataOrganizationDomain();
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic