1 /* GLib testing framework examples and tests
3 * Copyright 2014 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see
17 * <http://www.gnu.org/licenses/>.
23 event_cb (GSocketListener
*listener
,
24 GSocketListenerEvent event
,
28 static GSocketListenerEvent expected_event
= G_SOCKET_LISTENER_BINDING
;
29 gboolean
*success
= (gboolean
*)data
;
31 g_assert (G_IS_SOCKET_LISTENER (listener
));
32 g_assert (G_IS_SOCKET (socket
));
33 g_assert (event
== expected_event
);
37 case G_SOCKET_LISTENER_BINDING
:
38 expected_event
= G_SOCKET_LISTENER_BOUND
;
40 case G_SOCKET_LISTENER_BOUND
:
41 expected_event
= G_SOCKET_LISTENER_LISTENING
;
43 case G_SOCKET_LISTENER_LISTENING
:
44 expected_event
= G_SOCKET_LISTENER_LISTENED
;
46 case G_SOCKET_LISTENER_LISTENED
:
53 test_event_signal (void)
55 gboolean success
= FALSE
;
57 GSocketAddress
*saddr
;
58 GSocketListener
*listener
;
61 iaddr
= g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4
);
62 saddr
= g_inet_socket_address_new (iaddr
, 0);
63 g_object_unref (iaddr
);
65 listener
= g_socket_listener_new ();
67 g_signal_connect (listener
, "event", G_CALLBACK (event_cb
), &success
);
69 g_socket_listener_add_address (listener
,
72 G_SOCKET_PROTOCOL_TCP
,
76 g_assert_no_error (error
);
77 g_assert_true (success
);
79 g_object_unref (saddr
);
80 g_object_unref (listener
);
87 g_test_init (&argc
, &argv
, NULL
);
89 g_test_bug_base ("http://bugzilla.gnome.org/");
91 g_test_add_func ("/socket-listener/event-signal", test_event_signal
);