Tizen 2.1 base
[platform/upstream/glib2.0.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 static void
32 test_empty_address (void)
33 {
34   GError *error;
35   error = NULL;
36   g_dbus_address_get_stream_sync ("",
37                                   NULL,
38                                   NULL,
39                                   &error);
40   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
41   g_error_free (error);
42 }
43
44 #ifdef G_OS_UNIX
45 static void
46 test_unix_address (void)
47 {
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"));
57
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));
60 }
61 #endif
62
63 static void
64 test_nonce_tcp_address (void)
65 {
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));
69
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));
75 }
76
77 static void
78 test_tcp_address (void)
79 {
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));
89 }
90
91 static void
92 test_autolaunch_address (void)
93 {
94   g_assert (g_dbus_is_supported_address ("autolaunch:", NULL));
95 }
96
97 static void
98 test_mixed_address (void)
99 {
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));
103 }
104
105 int
106 main (int   argc,
107       char *argv[])
108 {
109   g_type_init ();
110   g_test_init (&argc, &argv, NULL);
111
112   g_test_add_func ("/gdbus/empty-address", test_empty_address);
113 #ifdef G_OS_UNIX
114   g_test_add_func ("/gdbus/unix-address", test_unix_address);
115 #endif
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);
120
121   return g_test_run();
122 }
123