Changeset View
Changeset View
Standalone View
Standalone View
libcolorcorrect/autotests/qtest_dbus.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2014 Alejandro Fiestas Olivares <afiestas@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | | ||||
22 | #ifndef COLORCORRECT_AUTOTESTS_QTEST_DBUS_H | ||||
23 | #define COLORCORRECT_AUTOTESTS_QTEST_DBUS_H | ||||
24 | | ||||
25 | #include <QtTest> | ||||
26 | #include <stdlib.h> | ||||
27 | | ||||
28 | #define QTEST_GUILESS_MAIN_SYSTEM_DBUS(TestObject) \ | ||||
29 | int main(int argc, char *argv[]) \ | ||||
30 | { \ | ||||
31 | QProcess dbus; \ | ||||
32 | dbus.start(QStringLiteral("dbus-launch")); \ | ||||
33 | dbus.waitForFinished(10000); \ | ||||
34 | QByteArray session = dbus.readLine(); \ | ||||
35 | if (session.isEmpty()) { \ | ||||
36 | qFatal("Couldn't execute new dbus session"); \ | ||||
37 | } \ | ||||
38 | int pos = session.indexOf('='); \ | ||||
39 | qputenv("DBUS_SESSION_BUS_ADDRESS", session.right(session.count() - pos - 1).trimmed().constData()); \ | ||||
40 | session = dbus.readLine(); \ | ||||
41 | pos = session.indexOf('='); \ | ||||
42 | QByteArray pid = session.right(session.count() - pos - 1).trimmed(); \ | ||||
43 | QCoreApplication app( argc, argv ); \ | ||||
44 | app.setApplicationName( QLatin1String("qttest") ); \ | ||||
45 | TestObject tc; \ | ||||
46 | int result = QTest::qExec( &tc, argc, argv ); \ | ||||
47 | dbus.start(QStringLiteral("kill"), QStringList() << QStringLiteral("-9") << QString::fromLatin1(pid)); \ | ||||
48 | dbus.waitForFinished(); \ | ||||
49 | return result; \ | ||||
50 | } | ||||
51 | #endif //COLORCORRECT_AUTOTESTS_QTEST_DBUS_H |