• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 {
00043     KDECORE_EXPORT bool kWaitForSignal(QObject *obj, const char *signal, int timeout = 0);
00044 } // namespace QTest
00045 
00046 // By default, unit tests get no gui.
00047 // Pass GUI if you use any GUI classes
00048 enum KDEMainFlag { NoGUI = 0, GUI = 1 }; // bitfield, next item is 2!
00049 Q_DECLARE_FLAGS(KDEMainFlags, KDEMainFlag)
00050 Q_DECLARE_OPERATORS_FOR_FLAGS(KDEMainFlags)
00066 #define QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, componentName) \
00067 int main(int argc, char *argv[]) \
00068 { \
00069     setenv("LC_ALL", "C", 1); \
00070     assert( !QDir::homePath().isEmpty() ); \
00071     setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test") ), 1); \
00072     setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/local") ), 1); \
00073     setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QLatin1String("/.kde-unit-test/xdg/config") ), 1); \
00074     setenv("KDE_SKIP_KDERC", "1", 1); \
00075     unsetenv("KDE_COLOR_DEBUG"); \
00076     QFile::remove(QDir::homePath() + QLatin1String("/.kde-unit-test/share/config/qttestrc"));  \
00077     KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") );  \
00078     KDEMainFlags mainFlags = flags;                         \
00079     KComponentData cData(&aboutData); \
00080     QApplication app( argc, argv, (mainFlags & GUI) != 0 ); \
00081     app.setApplicationName( QLatin1String("qttest") ); \
00082     qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
00083     qRegisterMetaType<KUrl::List>(); \
00084     TestObject tc; \
00085     KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
00086     return QTest::qExec( &tc, argc, argv ); \
00087 }
00088 
00102 #define QTEST_KDEMAIN(TestObject, flags) QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, "qttest")
00103 
00117 #define QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, componentName) \
00118 int main(int argc, char *argv[]) \
00119 { \
00120     setenv("LC_ALL", "C", 1); \
00121     assert( !QDir::homePath().isEmpty() ); \
00122     setenv("KDEHOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test" ), 1); \
00123     setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/local" ), 1); \
00124     setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/config" ), 1); \
00125     setenv("KDE_SKIP_KDERC", "1", 1); \
00126     unsetenv("KDE_COLOR_DEBUG"); \
00127     QFile::remove(QDir::homePath() + "/.kde-unit-test/share/config/qttestrc");  \
00128     KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") );  \
00129     KComponentData cData(&aboutData); \
00130     QCoreApplication app( argc, argv ); \
00131     app.setApplicationName( "qttest" ); \
00132     qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
00133     qRegisterMetaType<KUrl::List>(); \
00134     TestObject tc; \
00135     KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
00136     return QTest::qExec( &tc, argc, argv ); \
00137 }
00138 
00151 #define QTEST_KDEMAIN_CORE(TestObject) QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, "qttest")
00152 
00153 #endif /* QTEST_KDE_H */

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal