db489240fc076652d48402aa2443253f32548427
[platform/upstream/libnice.git] / tests / test-socket-is-based-on.c
1 /*
2  * This file is part of the Nice GLib ICE library.
3  *
4  * (C) 2016 Jakub Adam <jakub.adam@ktknet.cz>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is the Nice GLib ICE library.
17  *
18  * The Initial Developers of the Original Code are Collabora Ltd and Nokia
19  * Corporation. All Rights Reserved.
20  *
21  * Alternatively, the contents of this file may be used under the terms of the
22  * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
23  * case the provisions of LGPL are applicable instead of those above. If you
24  * wish to allow use of your version of this file only under the terms of the
25  * LGPL and not to allow others to use your version of this file under the
26  * MPL, indicate your decision by deleting the provisions above and replace
27  * them with the notice and other provisions required by the LGPL. If you do
28  * not delete the provisions above, a recipient may use your version of this
29  * file under either the MPL or the LGPL.
30  */
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <locale.h>
36 #include <gio/gnetworking.h>
37
38 #include "socket.h"
39
40 static NiceSocket *udp_bsd;
41 static NiceSocket *tcp_active;
42 static NiceSocket *pseudossl;
43 static NiceSocket *udp_turn_over_tcp;
44
45 static void
46 socket_base_udp_bsd (void)
47 {
48   g_assert (nice_socket_is_based_on (udp_bsd, udp_bsd));
49   g_assert (!nice_socket_is_based_on (udp_bsd, tcp_active));
50   g_assert (!nice_socket_is_based_on (udp_bsd, pseudossl));
51   g_assert (!nice_socket_is_based_on (udp_bsd, udp_turn_over_tcp));
52 }
53
54 static void
55 socket_base_tcp_active (void)
56 {
57   g_assert (!nice_socket_is_based_on (tcp_active, udp_bsd));
58   g_assert (nice_socket_is_based_on (tcp_active, tcp_active));
59   g_assert (!nice_socket_is_based_on (tcp_active, pseudossl));
60   g_assert (!nice_socket_is_based_on (tcp_active, udp_turn_over_tcp));
61 }
62
63 static void
64 socket_base_pseudossl (void)
65 {
66   g_assert (!nice_socket_is_based_on (pseudossl, udp_bsd));
67   g_assert (nice_socket_is_based_on (pseudossl, tcp_active));
68   g_assert (nice_socket_is_based_on (pseudossl, pseudossl));
69   g_assert (!nice_socket_is_based_on (pseudossl, udp_turn_over_tcp));
70 }
71
72 static void
73 socket_base_udp_turn_over_tcp (void)
74 {
75   g_assert (!nice_socket_is_based_on (udp_turn_over_tcp, udp_bsd));
76   g_assert (nice_socket_is_based_on (udp_turn_over_tcp, tcp_active));
77   g_assert (nice_socket_is_based_on (udp_turn_over_tcp, pseudossl));
78   g_assert (nice_socket_is_based_on (udp_turn_over_tcp, udp_turn_over_tcp));
79 }
80
81 int
82 main (int argc, char *argv[])
83 {
84   GMainLoop *mainloop = NULL;
85
86   NiceAddress addr;
87
88   g_networking_init ();
89
90   setlocale (LC_ALL, "");
91   g_test_init (&argc, &argv, NULL);
92
93   mainloop = g_main_loop_new (NULL, TRUE);
94
95   nice_address_set_from_string (&addr, "127.0.0.1");
96
97   /* Standalone socket */
98   udp_bsd = nice_udp_bsd_socket_new (&addr);
99
100   /* tcp_passive -> pseudossl -> udp_turn_over_tcp */
101   tcp_active = nice_tcp_active_socket_new (g_main_loop_get_context (mainloop),
102       &addr);
103   pseudossl = nice_pseudossl_socket_new (tcp_active,
104       NICE_PSEUDOSSL_SOCKET_COMPATIBILITY_GOOGLE);
105   udp_turn_over_tcp = nice_udp_turn_over_tcp_socket_new (pseudossl,
106       NICE_TURN_SOCKET_COMPATIBILITY_GOOGLE);
107
108   g_test_add_func ("/socket/is-base-of/udp-bsd",
109       socket_base_udp_bsd);
110   g_test_add_func ("/socket/is-base-of/tcp-active",
111       socket_base_tcp_active);
112   g_test_add_func ("/socket/is-base-of/pseudossl",
113       socket_base_pseudossl);
114   g_test_add_func ("/socket/is-base-of/udp-turn-over-tcp",
115       socket_base_udp_turn_over_tcp);
116
117   g_test_run ();
118
119   nice_socket_free (udp_bsd);
120   nice_socket_free (udp_turn_over_tcp);
121
122   g_main_loop_unref (mainloop);
123
124   return 0;
125 }