DevHeads.net

Review Request: Fix KGlobalSettingsTest failure

Review request for kdelibs, Aurélien Gâteau and David Faure.

Summary
Since commit b064749a754ec358170ecb7f19828e4216f6e965, KDE palette and font settings are only used when running KDE apps in a full KDE session. This makes KGlobalSettingsTest fail if the test is not run in a full KDE session, see

<a href="http://my.cdash.org/testSummary.php?project=16&amp;name=kdeui-kglobalsettingstest&amp;date=2011-07-27" title="http://my.cdash.org/testSummary.php?project=16&amp;name=kdeui-kglobalsettingstest&amp;date=2011-07-27">http://my.cdash.org/testSummary.php?project=16&amp;name=kdeui-kglobalsetting...</a>

This commit changes KGlobalSettings' unit test to reflect that change. My first idea was to change the unit test such that it verifies the expected behaviour for both situations, i.e., apps run in a full KDE session and apps run in some other kind of session, but I could not figure out a way to do this without changing the KDE_FULL_SESSION environment variable before the unit test executable is run.

In the case that the signal is not expected, I reduced the kWaitForSignal timeout to prevent wasting too much time each time the test is run.

Diffs
kdeui/tests/kglobalsettingstest.h 69ed5bf
kdeui/tests/kglobalsettingstest.cpp 464825d

Diff: <a href="http://git.reviewboard.kde.org/r/102098/diff" title="http://git.reviewboard.kde.org/r/102098/diff">http://git.reviewboard.kde.org/r/102098/diff</a>

Testing
The test passes here (run by my kde-devel user in a Konsole inside the regular user's KDE 4.6 session).

Thanks,

Frank

Comments

Re: Review Request: Fix KGlobalSettingsTest failure

By Commit Hook at 08/06/2011 - 19:04

This review has been submitted with commit a383ac8c7d3f666018e31d152fbe97b34260e840 by Frank Reininghaus to branch KDE/4.7.

- Commit

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By Commit Hook at 08/02/2011 - 03:49

This review has been submitted with commit 1b9f388c739e7595e65285014fd09222e71e9785 by Frank Reininghaus to branch master.

- Commit

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By =?UTF-8?B?QXVyw... at 07/28/2011 - 06:26

I don't think it is good for unit-tests to test different things depending on environment variables (
@David, what is your opinion on the subject?)

I was actually about to commit a simpler fix:

@@ -26,11 +26,11 @@ QTEST_KDEMAIN( KGlobalSettingsTest, GUI )
#include <kglobalsettings.h>
#include <kdebug.h>
#include <kprocess.h>
#include <QtCore/QEventLoop>
#include <QtDBus/QtDBus>
void KGlobalSettingsTest::initTestCase()
{
+ // Some signals are only emitted when we are running a full KDE session. If
+ // we are not then KDE applications follow the platform palette and font
+ // settings.
+ setenv("KDE_FULL_SESSION", "1", 1);
+
QDBusConnectionInterface *bus = 0;
if (!QDBusConnection::sessionBus().isConnected() || !(bus = QDBusConnection::sessionBus().interface())) {
QFAIL("Session bus not found");
}
}

- Aurélien

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By =?UTF-8?B?QXVyw... at 08/02/2011 - 04:07

Ah right. The only solution I can think of would be to add to KGlobalSettings a test-only method to force a reread of the environment variable or to manually override it, but that might be overkill. The fix you committed should be good enough for now. Thanks for your work on this issue.

- Aurélien

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By Frank Reininghaus at 08/02/2011 - 03:47

The problem with that is that the value of KDE_FULL_SESSION is read only once by KGlobalSettings (in the constructor of its private class, which is invoked the first time KGlobalSettings::self() is called). So setting and unsetting the variable in different parts of the test does not work. The only possible way I can think of at the moment would be to set/unset the variable in kglobalsettingstest and then do the actual testing in another executable, but maybe that's not worth the effort.

I'll commit your patch (with qputenv instead of setenv) to fix the test failure.

- Frank

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By =?UTF-8?B?QXVyw... at 07/28/2011 - 08:48

I agree testing both would be even nicer. Maybe you can mix your patch with mine to do it, calling setenv("KDE_FULL_SESSION", "1", 1) to fake the "run in KDE session" situation and unsetenv("KDE_FULL_SESSION") to fake the 'run outside KDE session' situation?

- Aurélien

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote:

Re: Review Request: Fix KGlobalSettingsTest failure

By Frank Reininghaus at 07/28/2011 - 07:33

I fully agree that the things that are tested should better not depend on environment variables, and I can confirm that the test passes here with your patch applied. I hadn't tried this myself earlier because I had assumed that the variable has to be set *before* the test executable is run, but that's obviously wrong ;-)

Maybe it would be even better to always test both things (i.e., that signals are emitted when KDE_FULL_SESSION is set and that they aren't when it's not set) if we find a good way to do it? That way, we would also test that the things that your recent commit changed work as they should.

- Frank

On July 27, 2011, 4:31 p.m., Frank Reininghaus wrote: