• Skip to content
  • Skip to link menu
KDE 4.1 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 <kaboutdata.h>
00025 #include <kcmdlineargs.h>
00026 #include <kcomponentdata.h>
00027 #include <kurl.h>
00028 #include <QtGui/QApplication>
00029 #include <QtCore/QEventLoop>
00030 #include <QtTest/QSignalSpy>
00031 
00032 namespace QTest
00033 {
00041     inline bool kWaitForSignal(QObject *obj, const char *signal, int timeout = 0)
00042     {
00043         QEventLoop loop;
00044         QObject::connect(obj, signal, &loop, SLOT(quit()));
00045         QTimer timer;
00046         QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
00047         if (timeout > 0) {
00048             QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
00049             timer.setSingleShot(true);
00050             timer.start(timeout);
00051         }
00052         loop.exec();
00053         return timeoutSpy.isEmpty();
00054     }
00055 } // namespace QTest
00056 
00057 // By default, unit tests get no gui.
00058 // Pass GUI if you use any GUI classes
00059 enum KDEMainFlag { NoGUI = 0, GUI = 1 }; // bitfield, next item is 2!
00060 Q_DECLARE_FLAGS(KDEMainFlags, KDEMainFlag)
00061 Q_DECLARE_OPERATORS_FOR_FLAGS(KDEMainFlags)
00077 #define QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, componentName) \
00078 int main(int argc, char *argv[]) \
00079 { \
00080     setenv("LC_ALL", "C", 1); \
00081     setenv("KDEHOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test" ), 1); \
00082     setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/local" ), 1); \
00083     setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/config" ), 1); \
00084     unsetenv("KDE_COLOR_DEBUG"); \
00085     KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") );  \
00086     KDEMainFlags mainFlags = flags;                         \
00087     KComponentData cData(&aboutData); \
00088     QApplication app( argc, argv, (mainFlags & GUI) != 0 ); \
00089     app.setApplicationName( "qttest" ); \
00090     qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
00091     qRegisterMetaType<KUrl::List>(); \
00092     TestObject tc; \
00093     return QTest::qExec( &tc, argc, argv ); \
00094 }
00095 
00109 #define QTEST_KDEMAIN(TestObject, flags) QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, "qttest")
00110 
00123 #define QTEST_KDEMAIN_CORE(TestObject) \
00124 int main(int argc, char *argv[]) \
00125 { \
00126     setenv("LC_ALL", "C", 1); \
00127     setenv("KDEHOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test" ), 1); \
00128     setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/local" ), 1); \
00129     setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + "/.kde-unit-test/xdg/config" ), 1); \
00130     unsetenv("KDE_COLOR_DEBUG"); \
00131     KAboutData aboutData( QByteArray("qttest"), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") );  \
00132     KComponentData cData(&aboutData); \
00133     QCoreApplication app( argc, argv ); \
00134     app.setApplicationName( "qttest" ); \
00135     qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
00136     qRegisterMetaType<KUrl::List>(); \
00137     TestObject tc; \
00138     return QTest::qExec( &tc, argc, argv ); \
00139 }
00140 
00141 #endif /* QTEST_KDE_H */
00142 

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
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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