File indexing completed on 2024-04-14 03:54:11
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef KNOTIFICATIONS_QTEST_DBUS_H 0008 #define KNOTIFICATIONS_QTEST_DBUS_H 0009 0010 #include <QProcess> 0011 #include <QTest> 0012 0013 #include <stdlib.h> 0014 0015 /* clang-format off */ 0016 #define QTEST_GUILESS_MAIN_SYSTEM_DBUS(TestObject) \ 0017 int main(int argc, char *argv[]) \ 0018 { \ 0019 QProcess dbus; \ 0020 dbus.start(QStringLiteral("dbus-launch")); \ 0021 dbus.waitForFinished(10000); \ 0022 QByteArray session = dbus.readLine(); \ 0023 if (session.isEmpty()) { \ 0024 qFatal("Couldn't execute new dbus session"); \ 0025 } \ 0026 int pos = session.indexOf('='); \ 0027 qputenv("DBUS_SESSION_BUS_ADDRESS", session.right(session.count() - pos - 1).trimmed().constData()); \ 0028 session = dbus.readLine(); \ 0029 pos = session.indexOf('='); \ 0030 QByteArray pid = session.right(session.count() - pos - 1).trimmed(); \ 0031 QCoreApplication app(argc, argv); \ 0032 app.setApplicationName(QLatin1String("qttest")); \ 0033 TestObject tc; \ 0034 int result = QTest::qExec(&tc, argc, argv); \ 0035 dbus.start(QStringLiteral("kill"), QStringList() << QStringLiteral("-9") << QString::fromLatin1(pid)); \ 0036 dbus.waitForFinished(); \ 0037 return result; \ 0038 } 0039 /* clang-format on */ 0040 #endif // KNOTIFICATIONS_QTEST_DBUS_H