Merge remote branch 'gvdb/master'
[platform/upstream/glib.git] / gio / tests / gdbus-addresses.c
1 /* GLib testing framework examples and tests
2  *
3  * Copyright (C) 2008-2010 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: David Zeuthen <davidz@redhat.com>
21  */
22
23 #include <gio/gio.h>
24
25 #ifdef G_OS_UNIX
26 #include <gio/gunixsocketaddress.h>
27 #endif
28
29 /* ---------------------------------------------------------------------------------------------------- */
30
31 #ifdef G_OS_UNIX
32 static void
33 test_unix_address (void)
34 {
35   g_assert (!g_dbus_is_supported_address ("some-imaginary-transport:foo=bar", NULL));
36   g_assert (g_dbus_is_supported_address ("unix:path=/tmp/dbus-test", NULL));
37   g_assert (g_dbus_is_supported_address ("unix:abstract=/tmp/dbus-another-test", NULL));
38   g_assert (g_dbus_is_address ("unix:foo=bar"));
39   g_assert (!g_dbus_is_supported_address ("unix:foo=bar", NULL));
40   g_assert (!g_dbus_is_address ("unix:path=/foo;abstract=/bar"));
41   g_assert (!g_dbus_is_supported_address ("unix:path=/foo;abstract=/bar", NULL));
42   g_assert (g_dbus_is_supported_address ("unix:path=/tmp/concrete;unix:abstract=/tmp/abstract", NULL));
43   g_assert (g_dbus_is_address ("some-imaginary-transport:foo=bar"));
44
45   g_assert (g_dbus_is_address ("some-imaginary-transport:foo=bar;unix:path=/this/is/valid"));
46   g_assert (!g_dbus_is_supported_address ("some-imaginary-transport:foo=bar;unix:path=/this/is/valid", NULL));
47 }
48 #endif
49
50 static void
51 test_nonce_tcp_address (void)
52 {
53   g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar", NULL));
54   g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv6", NULL));
55   g_assert (g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=ipv4", NULL));
56
57   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=42,noncefile=/foo/bar,family=blah", NULL));
58   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=localhost,port=420000,noncefile=/foo/bar,family=ipv4", NULL));
59   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=x42,noncefile=/foo/bar,family=ipv4", NULL));
60   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=42x,noncefile=/foo/bar,family=ipv4", NULL));
61   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=420000,noncefile=/foo/bar,family=ipv4", NULL));
62 }
63
64 int
65 main (int   argc,
66       char *argv[])
67 {
68   g_type_init ();
69   g_test_init (&argc, &argv, NULL);
70
71 #ifdef G_OS_UNIX
72   g_test_add_func ("/gdbus/unix-address", test_unix_address);
73 #endif
74   g_test_add_func ("/gdbus/nonce-tcp-address", test_nonce_tcp_address);
75   return g_test_run();
76 }
77