aboutsummaryrefslogtreecommitdiff
path: root/tests/name-watch-test.cc
blob: 64f681d58d93b350755e3ba7b9559a3214b13a37 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59

#include <gio/gio.h>
#include <gtest/gtest.h>

extern "C" {
#include "bus-watch-namespace.h"
}

class NameWatchTest : public ::testing::Test
{
	private:
		GTestDBus * testbus = NULL;

	protected:
		virtual void SetUp() {
			testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
			g_test_dbus_up(testbus);
		}

		virtual void TearDown() {
			g_test_dbus_down(testbus);
			g_clear_object(&testbus);
		}
};

typedef struct {
	guint appeared;
	guint vanished;
} callback_count_t;

static void
appeared_simple_cb (GDBusConnection * bus, const gchar * name, const gchar * owner, gpointer user_data)
{
	callback_count_t * callback_count = static_cast<callback_count_t *>(user_data);
	callback_count->appeared++;
}

static void
vanished_simple_cb (GDBusConnection * bus, const gchar * name, gpointer user_data)
{
	callback_count_t * callback_count = static_cast<callback_count_t *>(user_data);
	callback_count->vanished++;
}


TEST_F(NameWatchTest, BaseWatch)
{
	callback_count_t callback_count = {0};

	guint ns_watch = bus_watch_namespace(G_BUS_TYPE_SESSION,
	                                     "com.foo",
	                                     appeared_simple_cb,
	                                     vanished_simple_cb,
	                                     &callback_count,
	                                     NULL);


	bus_unwatch_namespace(ns_watch);
}