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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • util
qtest_kde.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2006 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef QTEST_KDE_H
20 #define QTEST_KDE_H
21 
22 #include <QtTest/QtTest>
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <kaboutdata.h>
26 #include <kcmdlineargs.h>
27 #include <kcomponentdata.h>
28 #include <kglobal.h>
29 #include <kurl.h>
30 #include <QtGui/QApplication>
31 #include <QtCore/QEventLoop>
32 #include <QtTest/QSignalSpy>
33 
34 namespace QTest
35 {
45  KDECORE_EXPORT bool kWaitForSignal(QObject *obj, const char *signal, int timeout = 0);
46 } // namespace QTest
47 
48 // By default, unit tests get no gui.
49 // Pass GUI if you use any GUI classes
50 enum KDEMainFlag { NoGUI = 0, GUI = 1 }; // bitfield, next item is 2!
51 Q_DECLARE_FLAGS(KDEMainFlags, KDEMainFlag)
52 Q_DECLARE_OPERATORS_FOR_FLAGS(KDEMainFlags)
68 #define QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, componentName) \
69 int main(int argc, char *argv[]) \
70 { \
71  setenv("LC_ALL", "C", 1); \
72  assert( !QDir::homePath().isEmpty() ); \
73  setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test") ), 1); \
74  setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/local") ), 1); \
75  setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/config") ), 1); \
76  setenv("KDE_SKIP_KDERC", "1", 1); \
77  unsetenv("KDE_COLOR_DEBUG"); \
78  QFile::remove(QDir::homePath() + QString::fromLatin1("/.kde-unit-test/share/config/qttestrc")); \
79  KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); \
80  KDEMainFlags mainFlags = flags; \
81  KComponentData cData(&aboutData); \
82  QApplication app( argc, argv, (mainFlags & GUI) != 0 ); \
83  app.setApplicationName( QLatin1String("qttest") ); \
84  qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
85  qRegisterMetaType<KUrl::List>(); \
86  TestObject tc; \
87  KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
88  return QTest::qExec( &tc, argc, argv ); \
89 }
90 
104 #define QTEST_KDEMAIN(TestObject, flags) QTEST_KDEMAIN_WITH_COMPONENTNAME(TestObject, flags, "qttest")
105 
119 #define QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, componentName) \
120 int main(int argc, char *argv[]) \
121 { \
122  setenv("LC_ALL", "C", 1); \
123  assert( !QDir::homePath().isEmpty() ); \
124  setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test" )), 1); \
125  setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/local") ), 1); \
126  setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/config") ), 1); \
127  setenv("KDE_SKIP_KDERC", "1", 1); \
128  unsetenv("KDE_COLOR_DEBUG"); \
129  QFile::remove(QDir::homePath() + QString::fromLatin1("/.kde-unit-test/share/config/qttestrc")); \
130  KAboutData aboutData( QByteArray(componentName), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); \
131  KComponentData cData(&aboutData); \
132  QCoreApplication app( argc, argv ); \
133  app.setApplicationName( QLatin1String("qttest") ); \
134  qRegisterMetaType<KUrl>(); /*as done by kapplication*/ \
135  qRegisterMetaType<KUrl::List>(); \
136  TestObject tc; \
137  KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ \
138  return QTest::qExec( &tc, argc, argv ); \
139 }
140 
153 #define QTEST_KDEMAIN_CORE(TestObject) QTEST_KDEMAIN_CORE_WITH_COMPONENTNAME(TestObject, "qttest")
154 
155 #endif /* QTEST_KDE_H */
kurl.h
timeout
int timeout
Definition: kkernel_mac.cpp:46
NoGUI
Definition: qtest_kde.h:50
QObject
QTest::kWaitForSignal
bool kWaitForSignal(QObject *obj, const char *signal, int timeout=0)
Starts an event loop that runs until the given signal is received.
Definition: qtest_kde.cpp:57
KDEMainFlag
KDEMainFlag
Definition: qtest_kde.h:50
kglobal.h
kcmdlineargs.h
GUI
Definition: qtest_kde.h:50
kaboutdata.h
kcomponentdata.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal