| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <QTest> |
| 5 |
#include <QDebug> |
| 6 |
#include <QCoreApplication> |
| 7 |
#include <QDBusConnection> |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
/* This test uses an appless main, to ensure that no D-Bus stuff is implicitly done |
| 12 |
It also sets the magic "QT_SIMULATE_DBUS_LIBFAIL" env variable, that is only available |
| 13 |
in developer builds. That env variable simulates a D-Bus library load fail. |
| 14 |
|
| 15 |
In no case should the QDBus module crash because D-Bus libs couldn't be loaded */ |
| 16 |
|
| 17 |
class tst_QDBusConnectionNoBus : public QObject |
| 18 |
{ |
| 19 |
Q_OBJECT |
| 20 |
|
| 21 |
public: |
| 22 |
tst_QDBusConnectionNoBus() |
| 23 |
{ |
| 24 |
qputenv("DBUS_SESSION_BUS_ADDRESS", "unix:abstract=/tmp/does_not_exist"); |
| 25 |
#ifdef SIMULATE_LOAD_FAIL |
| 26 |
qputenv("QT_SIMULATE_DBUS_LIBFAIL", "1"); |
| 27 |
#endif |
| 28 |
} |
| 29 |
|
| 30 |
private slots: |
| 31 |
void connectToBus(); |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
void tst_QDBusConnectionNoBus::connectToBus() |
| 36 |
{ |
| 37 |
int argc = 0; |
| 38 |
QCoreApplication app(argc, 0); |
| 39 |
|
| 40 |
QDBusConnection con = QDBusConnection::sessionBus(); |
| 41 |
|
| 42 |
QVERIFY(!con.isConnected()); // if we didn't crash here, the test passed :) |
| 43 |
} |
| 44 |
|
| 45 |
QTEST_APPLESS_MAIN(tst_QDBusConnectionNoBus) |
| 46 |
|
| 47 |
#include "tst_qdbusconnection_no_bus.moc" |
| 48 |
|