diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2009-07-11 17:42:03 +0100 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-02-23 09:53:34 +1100 |
commit | eeb3e1a6c51c6c32608e82ae0ef17496a3d98639 (patch) | |
tree | 5b59778b850c484145cbf4a135965781eab3c980 /tests/gnio-util.c | |
parent | 4bbd60fcfbe6ff924158f58f530bfc6874b27ece (diff) |
Add test_variant_to_sockaddr_ipv4 testcase
Diffstat (limited to 'tests/gnio-util.c')
-rw-r--r-- | tests/gnio-util.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/gnio-util.c b/tests/gnio-util.c new file mode 100644 index 00000000..aeaea562 --- /dev/null +++ b/tests/gnio-util.c @@ -0,0 +1,67 @@ +/* tests of the GNIO utility functions */ + +#include <string.h> + +#include <glib.h> +#include <gio/gio.h> + +#include <telepathy-glib/gnio-util.h> + +#define IPV4_ADDR "127.0.1.1" +#define PORT 41414 + +static void +test_variant_to_sockaddr_ipv4 (void) +{ + GValueArray *array = g_value_array_new (2); + GValue value = { 0, }; + GSocketAddress *sockaddr; + GInetSocketAddress *inetaddr; + GInetAddress *hostaddr; + char *host; + guint16 port; + + /* set up an address variant */ + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, IPV4_ADDR); + g_value_array_append (array, &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_UINT); + g_value_set_uint (&value, PORT); + g_value_array_append (array, &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_VALUE_ARRAY); + g_value_take_boxed (&value, array); + + /* convert to a GSocketAddress */ + sockaddr = tp_g_socket_address_from_variant (TP_SOCKET_ADDRESS_TYPE_IPV4, + &value); + + /* check the socket address */ + g_assert (sockaddr != NULL); + g_assert (G_IS_INET_SOCKET_ADDRESS (sockaddr)); + + inetaddr = G_INET_SOCKET_ADDRESS (sockaddr); + hostaddr = g_inet_socket_address_get_address (inetaddr); + + host = g_inet_address_to_string (hostaddr); + port = g_inet_socket_address_get_port (inetaddr); + + g_assert (strcmp (host, IPV4_ADDR) == 0); + g_assert (port == PORT); + + g_free (host); + g_object_unref (sockaddr); +} + +int +main (int argc, char **argv) +{ + g_type_init (); + + test_variant_to_sockaddr_ipv4 (); + + return 0; +} |