Add some more cases to the app-id unit tests
[glib.git] / gio / tests / socket-listener.c
blobdcbbfdbc14eecad5de420b3d1eba6a7eac0a0a2c
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/>.
20 #include <gio/gio.h>
22 static void
23 event_cb (GSocketListener *listener,
24 GSocketListenerEvent event,
25 GSocket *socket,
26 gpointer data)
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);
35 switch (event)
37 case G_SOCKET_LISTENER_BINDING:
38 expected_event = G_SOCKET_LISTENER_BOUND;
39 break;
40 case G_SOCKET_LISTENER_BOUND:
41 expected_event = G_SOCKET_LISTENER_LISTENING;
42 break;
43 case G_SOCKET_LISTENER_LISTENING:
44 expected_event = G_SOCKET_LISTENER_LISTENED;
45 break;
46 case G_SOCKET_LISTENER_LISTENED:
47 *success = TRUE;
48 break;
52 static void
53 test_event_signal (void)
55 gboolean success = FALSE;
56 GInetAddress *iaddr;
57 GSocketAddress *saddr;
58 GSocketListener *listener;
59 GError *error = NULL;
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,
70 saddr,
71 G_SOCKET_TYPE_STREAM,
72 G_SOCKET_PROTOCOL_TCP,
73 NULL,
74 NULL,
75 &error);
76 g_assert_no_error (error);
77 g_assert_true (success);
79 g_object_unref (saddr);
80 g_object_unref (listener);
83 int
84 main (int argc,
85 char *argv[])
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);
93 return g_test_run();