Imported Upstream version 0.1.17
[platform/upstream/libnice.git] / tests / test-fullmode-with-stun.c
1 #include <gio/gio.h>
2
3 int
4 main (int argc, char ** argv)
5 {
6    int retval = 0;
7    char *stund;
8    char *test_fullmode;
9    GSubprocess *stund_proc, *test_subprocess;
10    const gchar NICE_STUN_SERVER[] = "127.0.0.1";
11    const gchar NICE_STUN_SERVER_PORT[] = "3800";
12    GError *gerr = NULL;
13
14    if (argc < 3) {
15          g_printerr ("Usage: %s <stund path> <test fullmode path>\n",
16                      argv[0]);
17          return 77;
18    }
19
20    stund = argv[1];
21    test_fullmode = argv[2];
22
23    g_print ("Starting ICE full-mode with STUN unit test.\n");
24    g_print ("Launching %s on port %s.\n", stund, NICE_STUN_SERVER_PORT);
25
26
27    stund_proc = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, &gerr,
28                                   stund, NICE_STUN_SERVER_PORT, NULL);
29
30    g_usleep(G_USEC_PER_SEC);
31
32    g_setenv("NICE_STUN_SERVER", NICE_STUN_SERVER, TRUE);
33    g_setenv("NICE_STUN_SERVER_PORT", NICE_STUN_SERVER_PORT, TRUE);
34
35    g_print ("Running test fullmode as %s\n", test_fullmode);
36    test_subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, &gerr,
37                                        test_fullmode, NULL);
38    g_assert_no_error (gerr);
39    g_subprocess_wait (test_subprocess, NULL, &gerr);
40    g_assert_no_error (gerr);
41    retval = g_subprocess_get_exit_status (test_subprocess);
42    g_print ("Test process returned %d\n", retval);
43    g_object_unref (test_subprocess);
44  
45    g_subprocess_force_exit (stund_proc);
46    g_subprocess_wait (stund_proc, NULL, &gerr);
47    g_assert_no_error (gerr);
48    g_object_unref(stund_proc);
49
50    return retval;
51 }