diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2009-07-11 17:45:09 +0100 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-02-23 09:53:34 +1100 |
commit | 2052b468d77ad5e4dcff9af91b4b4f944a28c41a (patch) | |
tree | dcc12110af4f5d688ee3e0fef796bd09b73a39a4 /tests/gnio-util.c | |
parent | eeb3e1a6c51c6c32608e82ae0ef17496a3d98639 (diff) |
Add test_variant_to_sockaddr_ipv6 testcase
Diffstat (limited to 'tests/gnio-util.c')
-rw-r--r-- | tests/gnio-util.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/gnio-util.c b/tests/gnio-util.c index aeaea562..9675f30b 100644 --- a/tests/gnio-util.c +++ b/tests/gnio-util.c @@ -8,6 +8,7 @@ #include <telepathy-glib/gnio-util.h> #define IPV4_ADDR "127.0.1.1" +#define IPV6_ADDR "::1" #define PORT 41414 static void @@ -56,12 +57,59 @@ test_variant_to_sockaddr_ipv4 (void) g_object_unref (sockaddr); } +static void +test_variant_to_sockaddr_ipv6 (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, IPV6_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_IPV6, + &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, IPV6_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 (); + test_variant_to_sockaddr_ipv6 (); return 0; } |