~macslow/notify-osd/mouse-movement-monitor

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*******************************************************************************
**3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
**      10        20        30        40        50        60        70        80
**
** notify-osd
**
** test-dbus.c - implements unit-tests for dbus glue-code
**
** Copyright 2009 Canonical Ltd.
**
** Authors:
**    Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
**    David Barth <david.barth@canonical.com>
**
** This program is free software: you can redistribute it and/or modify it
** under the terms of the GNU General Public License version 3, as published
** by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranties of
** MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <stdlib.h>
#include "dbus.h"
#include "stack.h"

#define TEST_DBUS_NAME "org.freedesktop.Notificationstest"

static
void
test_dbus_instance (void)
{
	DBusGConnection* connection = NULL;

	connection = dbus_create_service_instance (TEST_DBUS_NAME);
	g_assert (connection != NULL);
}

static
void
test_dbus_collision (void)
{
	DBusGConnection* connection = NULL;

	/* HACK: as we did not destroy the instance after the first test above,
	   this second creation should fail */

	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT |
                               G_TEST_TRAP_SILENCE_STDERR))
        {
		connection = dbus_create_service_instance (TEST_DBUS_NAME);
		exit (0); /* should never be triggered */
        }
	g_test_trap_assert_failed();
}


static void
test_dbus_get_capabilities (void)
{
	char **caps = NULL;
	gboolean ret = FALSE;

	ret = stack_get_capabilities (NULL, &caps);

	g_assert (ret);
	g_assert (!g_strcmp0 (caps[0], "body"));

	int i = 0;
	while (caps[i] != NULL)
	{
		g_assert (!g_strrstr (caps[i++], "actions"));
	}
}

static void
test_dbus_get_server_information (void)
{
	gchar *name = NULL, *vendor = NULL, *version = NULL, *specver = NULL;
	gboolean ret = FALSE;

	ret = stack_get_server_information (NULL, &name, &vendor,
					    &version, &specver);
	g_assert (ret);
	g_assert (g_strrstr (name, "notify-osd"));
	g_assert (g_strrstr (specver, "0.10"));
}

GTestSuite *
test_dbus_create_test_suite (void)
{
	GTestSuite *ts = NULL;

	ts = g_test_create_suite ("dbus");

	g_test_suite_add(ts,
			 g_test_create_case ("can create an instance on the bus",
					     0,
					     NULL,
					     NULL,
					     test_dbus_instance,
					     NULL)
		);

	g_test_suite_add(ts,
			 g_test_create_case ("refuse to have multiple instance on the bus",
					     0,
					     NULL,
					     NULL,
					     test_dbus_collision,
					     NULL)
		);

	g_test_suite_add(ts,
			 g_test_create_case ("can get server capabilities",
					     0,
					     NULL,
					     NULL,
					     test_dbus_get_capabilities,
					     NULL)
		);

	g_test_suite_add(ts,
			 g_test_create_case ("can get server info",
					     0,
					     NULL,
					     NULL,
					     test_dbus_get_server_information,
					     NULL)
		);
	return ts;
}