1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2010 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
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
26 #include <gio/gunixsocketaddress.h>
29 /* ---------------------------------------------------------------------------------------------------- */
32 test_empty_address (void)
36 g_dbus_address_get_stream_sync ("",
40 g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
46 test_unix_address (void)
48 g_assert (!g_dbus_is_supported_address ("some-imaginary-transport:foo=bar", NULL));
49 g_assert (g_dbus_is_supported_address ("unix:path=/tmp/dbus-test", NULL));
50 g_assert (g_dbus_is_supported_address ("unix:abstract=/tmp/dbus-another-test", NULL));
51 g_assert (g_dbus_is_address ("unix:foo=bar"));
52 g_assert (!g_dbus_is_supported_address ("unix:foo=bar", NULL));
53 g_assert (!g_dbus_is_address ("unix:path=/foo;abstract=/bar"));
54 g_assert (!g_dbus_is_supported_address ("unix:path=/foo;abstract=/bar", NULL));
55 g_assert (g_dbus_is_supported_address ("unix:path=/tmp/concrete;unix:abstract=/tmp/abstract", NULL));
56 g_assert (g_dbus_is_address ("some-imaginary-transport:foo=bar"));
58 g_assert (g_dbus_is_address ("some-imaginary-transport:foo=bar;unix:path=/this/is/valid"));
59 g_assert (!g_dbus_is_supported_address ("some-imaginary-transport:foo=bar;unix:path=/this/is/valid", NULL));
64 test_nonce_tcp_address (void)
66 g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar", NULL));
67 g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv6", NULL));
68 g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv4", NULL));
70 g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=blah", NULL));
71 g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=420000,noncefile=/foo/bar,family=ipv4", NULL));
72 g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=x42,noncefile=/foo/bar,family=ipv4", NULL));
73 g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=42x,noncefile=/foo/bar,family=ipv4", NULL));
74 g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=420000,noncefile=/foo/bar,family=ipv4", NULL));
78 test_tcp_address (void)
80 g_assert (g_dbus_is_supported_address ("tcp:host=localhost", NULL));
81 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,noncefile=/tmp/foo", NULL));
82 g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42", NULL));
83 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=-1", NULL));
84 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=420000", NULL));
85 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42x", NULL));
86 g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=ipv4", NULL));
87 g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=ipv6", NULL));
88 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=sopranos", NULL));
92 test_autolaunch_address (void)
94 g_assert (g_dbus_is_supported_address ("autolaunch:", NULL));
98 test_mixed_address (void)
100 g_assert (g_dbus_is_supported_address ("unix:path=/tmp/dbus1;unix:path=/tmp/dbus2", NULL));
101 g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42;autolaunch:", NULL));
102 g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42;tcp:family=bla", NULL));
110 g_test_init (&argc, &argv, NULL);
112 g_test_add_func ("/gdbus/empty-address", test_empty_address);
114 g_test_add_func ("/gdbus/unix-address", test_unix_address);
116 g_test_add_func ("/gdbus/nonce-tcp-address", test_nonce_tcp_address);
117 g_test_add_func ("/gdbus/tcp-address", test_tcp_address);
118 g_test_add_func ("/gdbus/autolaunch-address", test_autolaunch_address);
119 g_test_add_func ("/gdbus/mixed-address", test_mixed_address);