run indent twice, it alternates between two 'canonical' forms, also run whitespace...
[oweals/gnunet.git] / src / nat / test_nat_test.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * Testcase for the NAT testing code.
23  *
24  * @file nat/test_nat_test.c
25  * @brief Testcase for NAT testing functions
26  * @author Christian Grothoff
27  */
28 #include "platform.h"
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_nat_lib.h"
32
33
34 #define VERBOSE GNUNET_NO
35
36
37 /**
38  * Time to wait before stopping NAT test, in seconds
39  */
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
41
42
43 static int ret = 1;
44
45 static struct GNUNET_NAT_Test *tst;
46
47 static GNUNET_SCHEDULER_TaskIdentifier end;
48
49 static void
50 end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
51 {
52   GNUNET_NAT_test_stop (tst);
53 }
54
55 static void
56 report_success (void *cls, int success)
57 {
58   GNUNET_assert (GNUNET_OK == success);
59   ret = 0;
60   GNUNET_SCHEDULER_cancel (end);
61   end = GNUNET_SCHEDULER_add_now (&end_test, NULL);
62 }
63
64 /**
65  * Main function run with scheduler.
66  */
67 static void
68 run (void *cls, char *const *args, const char *cfgfile,
69      const struct GNUNET_CONFIGURATION_Handle *cfg)
70 {
71   tst =
72       GNUNET_NAT_test_start (cfg, GNUNET_YES, 1285, 1285, &report_success,
73                              NULL);
74   if (NULL == tst)
75     return;
76   end = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL);
77 }
78
79
80 int
81 main (int argc, char *const argv[])
82 {
83   struct GNUNET_GETOPT_CommandLineOption options[] = {
84     GNUNET_GETOPT_OPTION_END
85   };
86   struct GNUNET_OS_Process *gns;
87
88   char *const argv_prog[] = {
89     "test-nat-test",
90     "-c",
91     "test_nat_test_data.conf",
92     "-L",
93 #if VERBOSE
94     "DEBUG",
95 #else
96     "WARNING",
97 #endif
98     NULL
99   };
100
101   GNUNET_log_setup ("test-nat-test",
102 #if VERBOSE
103                     "DEBUG",
104 #else
105                     "WARNING",
106 #endif
107                     NULL);
108   gns =
109       GNUNET_OS_start_process (NULL, NULL, "gnunet-nat-server",
110                                "gnunet-nat-server",
111 #if VERBOSE
112                                "-L", "DEBUG",
113 #endif
114                                "-c", "test_nat_test_data.conf", "12345", NULL);
115   GNUNET_assert (NULL != gns);
116   GNUNET_PROGRAM_run (5, argv_prog, "test-nat-test", "nohelp", options, &run,
117                       NULL);
118   GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM));
119   GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (gns));
120   GNUNET_OS_process_close (gns);
121   return ret;
122 }
123
124 /* end of test_nat_test.c */