KDECore
qtest_kde.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2006 David Faure <faure@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef QTEST_KDE_H 00020 #define QTEST_KDE_H 00021 00022 #include <QtTest/QtTest> 00023 #include <stdlib.h> 00024 #include <assert.h> 00025 #include <kaboutdata.h> 00026 #include <kcmdlineargs.h> 00027 #include <kcomponentdata.h> 00028 #include <kglobal.h> 00029 #include <kurl.h> 00030 #include <QtGui/QApplication> 00031 #include <QtCore/QEventLoop> 00032 #include <QtTest/QSignalSpy> 00033 00034 namespace QTest 00035 { 00045 KDECORE_EXPORT bool kWaitForSignal(QObject *obj, const char *signal, int timeout = 0); 00046 } // namespace QTest 00047 00048 // By default, unit tests get no gui. 00049 // Pass GUI if you use any GUI classes 00050 enum KDEMainFlag { NoGUI = 0, GUI = 1 }; // bitfield, next item is 2! 00051 Q_DECLARE_FLAGS(KDEMainFlags, KDEMainFlag) 00052 Q_DECLARE_OPERATORS_FOR_FLAGS(KDEMainFlags) 00068 #define QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, componentName) \ 00069 int main(int argc, char *argv[]) \ 00070 { \ 00071 setenv("LC_ALL", "C", 1); \ 00072 assert( !QDir::homePath().isEmpty() ); \ 00073 setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test") ), 1); \ 00074 setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/local") ), 1); \ 00075 setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/config") ), 1); \ 00076 setenv("KDE_SKIP_KDERC", "1", 1); \ 00077 unsetenv("KDE_COLOR_DEBUG"); \ 00078 QFile::remove(QDir::homePath() + QLatin1String("/.kde-unit-test/share/config/qttestrc")); \ 00079 KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); \ 00080 KDEMainFlags mainFlags = flags; \ 00081 KComponentData cData(&aboutData); \ 00082 QApplication app( argc, argv, (mainFlags & GUI) != 0 ); \ 00083 app.setApplicationName( QLatin1String("qttest") ); \ 00084 qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \ 00085 qRegisterMetaType<KUrl::List>(); \ 00086 TestObject tc; \ 00087 KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \ 00088 return QTest::qExec( &tc, argc, argv ); \ 00089 } 00090 00104 #define QTEST_KDEMAIN(TestObject, flags) QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, "qttest") 00105 00119 #define QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, componentName) \ 00120 int main(int argc, char *argv[]) \ 00121 { \ 00122 setenv("LC_ALL", "C", 1); \ 00123 assert( !QDir::homePath().isEmpty() ); \ 00124 setenv("KDEHOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test" ), 1); \ 00125 setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/local" ), 1); \ 00126 setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/config" ), 1); \ 00127 setenv("KDE_SKIP_KDERC", "1", 1); \ 00128 unsetenv("KDE_COLOR_DEBUG"); \ 00129 QFile::remove(QDir::homePath() + "/.kde-unit-test/share/config/qttestrc"); \ 00130 KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); \ 00131 KComponentData cData(&aboutData); \ 00132 QCoreApplication app( argc, argv ); \ 00133 app.setApplicationName( "qttest" ); \ 00134 qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \ 00135 qRegisterMetaType<KUrl::List>(); \ 00136 TestObject tc; \ 00137 KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \ 00138 return QTest::qExec( &tc, argc, argv ); \ 00139 } 00140 00153 #define QTEST_KDEMAIN_CORE(TestObject) QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, "qttest") 00154 00155 #endif /* QTEST_KDE_H */
KDE 4.6 API Reference