File: README.md

package info (click to toggle)
libqtdbustest 0.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: cpp: 565; sh: 59; makefile: 28
file content (47 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Qt library to help easily test DBus services

A simple library to create a private DBus environment for your test fixtures.

DBus is the most common RPC middleware used in Linux desktop shell development. Unfortunately it does not provide much support for testing services using it. I created [libqtdbustest](https://github.com/pete-woods/libqtdbustest) and [libqtdbusmock](https://github.com/pete-woods/libqtdbusmock) to fill this gap, for Qt/C++ based services, at least.

# A private bus

The first thing you need when testing DBus based services is your own private pair of DBus servers. When you instantiate the `QtDBusTest::DBusTestRunner` class, this is exactly what you get.

It has a zero argument constructor, so can easily be composed into your test fixture. It starts a new set of bus daemons, and terminates them on destrution.

```cpp
class TestMyStuff: public ::testing::Test {
protected:
  QtDBusTest::DBusTestRunner dbus_;
}
```

It provides methods to access the new instances of `QDBusConnection` for the private session and system buses:

```cpp
TEST_F(TestMyStuff, DoesSomething) {
  dbus_.sessionConnection();
  dbus_.systemConnection();
}
```

# Starting services

You can register DBus services to be started and waited for. These services will be terminated when the test runner object is deleted.

```cpp
class TestMyStuff: public ::testing::Test {
protected:
  TestMyStuff() {
    dbus_.registerService(
        DBusServicePtr(new QProcessDBusService("org.freedesktop.MyBusName",
            QDBusConnection::SessionBus, "/path/to/executable/,
            QStringList{argument1, argument2})));

    dbus_.startServices();
  }

  QtDBusTest::DBusTestRunner dbus_;
}
```