File: test_dbus_pending_data.c

package info (click to toggle)
libnih 1.0.3-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,824 kB
  • sloc: ansic: 188,730; sh: 11,217; makefile: 1,117; yacc: 291; xml: 239; sed: 16
file content (130 lines) | stat: -rw-r--r-- 3,053 bytes parent folder | download | duplicates (6)
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
/* libnih
 *
 * test_dbus_pending_data.c - test suite for nih-dbus/dbus_pending_data.c
 *
 * Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
 * Copyright © 2009 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, 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 warranty of
 * MERCHANTABILITY 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, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <nih/test.h>
#include <nih-dbus/test_dbus.h>

#include <dbus/dbus.h>

#include <nih/macros.h>
#include <nih/alloc.h>

#include <nih-dbus/dbus_connection.h>

#include <nih-dbus/dbus_message.h>
#include <nih-dbus/dbus_pending_data.h>


void
my_reply_handler (void *          data,
		  NihDBusMessage *message,
		  const char *    arg1,
		  int32_t         arg2)
{
}

void
my_error_handler (void *          data,
		  NihDBusMessage *message)
{
}


void
test_new (void)
{
	NihDBusPendingData *pending_data;
	pid_t               dbus_pid;
	DBusConnection *    conn;

	TEST_FUNCTION ("nih_dbus_pending_data_new");
	TEST_DBUS (dbus_pid);
	TEST_DBUS_OPEN (conn);


	/* Check that we can create a new NihDBusPendingData structure,
	 * with all the details filled in correctly, and that it references
	 * the connection.
	 */
	TEST_FEATURE ("with handler");
	TEST_ALLOC_FAIL {
		pending_data = nih_dbus_pending_data_new (NULL, conn,
							  (NihDBusReplyHandler)my_reply_handler,
							  my_error_handler,
							  &conn);

		if (test_alloc_failed) {
			TEST_EQ_P (pending_data, NULL);

			continue;
		}

		TEST_ALLOC_SIZE (pending_data, sizeof (NihDBusPendingData));
		TEST_EQ_P (pending_data->connection, conn);
		TEST_EQ_P (pending_data->handler, (NihDBusReplyHandler)my_reply_handler);
		TEST_EQ_P (pending_data->error_handler, my_error_handler);
		TEST_EQ_P (pending_data->data, &conn);

		nih_free (pending_data);
	}


	/* Check that the handler argument is optional and NULL may be
	 * specified for it.
	 */
	TEST_FEATURE ("with no handler");
	TEST_ALLOC_FAIL {
		pending_data = nih_dbus_pending_data_new (NULL, conn,
							  NULL,
							  my_error_handler,
							  &conn);

		if (test_alloc_failed) {
			TEST_EQ_P (pending_data, NULL);

			continue;
		}

		TEST_ALLOC_SIZE (pending_data, sizeof (NihDBusPendingData));
		TEST_EQ_P (pending_data->connection, conn);
		TEST_EQ_P (pending_data->handler, NULL);
		TEST_EQ_P (pending_data->error_handler, my_error_handler);
		TEST_EQ_P (pending_data->data, &conn);

		nih_free (pending_data);
	}


	TEST_DBUS_CLOSE (conn);
	TEST_DBUS_END (dbus_pid);

	dbus_shutdown ();
}


int
main (int   argc,
      char *argv[])
{
	test_new ();

	return 0;
}