Hi,
This week-end, I did a little hacking on Rekonq and tried to help with
the improvement of test coverage. I miserably failed and I'll share why
here so hopefully that will be better next time. :)
I was trying to make tests for the class MainView. At first, the test
were crashing because this class relies heavily on Application, via all
the call to the unique application instance: Application::instance().
To get that up, I replaced QTEST_KDEMAIN by a custom KDE version
initializing Rekonq's Application.
This was not enough because Application is a subclass of
KUniqueApplication, so that messes up with my running Rekonq instance.
So I extended my custom macro to start the unique instance with the
KUniqueApplication::NonUniqueInstance (final macro attached).
At that point, I could run the test without crashing, but the test were
failing because of configuation issues (and KConfigSkeleton was doing
tons of warning). Basically, I needed to setup a temporary Rekonfig,
setup some stuff, and tear down the temporary config. I felt short on
time and ideas, so I did not have test with my patch.
Hopefully someone here will have ideas to improve testing, and I'll be
able to finish my test next time :)
cheers,
Benjamin
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2006 David Faure <[email protected]>
* Copyright (C) 2010 Benjamin Poulain <[email protected]>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
#include <qtest_kde.h>
#include "application.h"
#include "rekonq.h"
#include <QEventLoop>
#include <QSignalSpy>
/*
Rekonq rely heavily on Application, its subclass of KUniqueApplication.
In order to make the test working, we have our own test macro.
*/
#define QTEST_REKONQMAIN(TestObject, flags) \
int main(int argc, char *argv[]) \
{ \
setenv("LC_ALL", "C", 1); \
assert( !QDir::homePath().isEmpty() ); \
setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test") ), 1); \
setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/local") ), 1); \
setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/config") ), 1); \
setenv("KDE_SKIP_KDERC", "1", 1); \
unsetenv("KDE_COLOR_DEBUG"); \
QFile::remove(QDir::homePath() + QLatin1String("/.kde-unit-test/share/config/qttestrc")); \
KAboutData aboutData( QByteArray("qttest"), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); \
KCmdLineArgs::init(argc, argv, &aboutData); \
KDEMainFlags mainFlags = flags; \
KComponentData cData(&aboutData); \
KCmdLineOptions options;\
KCmdLineArgs::addCmdLineOptions(options);\
Application::addCmdLineOptions(); \
Application::start(KUniqueApplication::NonUniqueInstance); \
Application app; \
app.setApplicationName( QLatin1String("qttest") ); \
qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
qRegisterMetaType<KUrl::List>(); \
TestObject tc; \
KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
return QTest::qExec( &tc, argc, argv ); \
}
bool waitForSignal(QObject* obj, const char* signal, int timeout = 3000)
{
QEventLoop loop;
QObject::connect(obj, signal, &loop, SLOT(quit()));
QTimer timer;
QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
if (timeout > 0) {
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.setSingleShot(true);
timer.start(timeout);
}
loop.exec();
return timeoutSpy.isEmpty();
}
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq