missing function reference
[oweals/gnunet.git] / src / arm / test_arm_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 2, 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  * @file arm/test_arm_api.c
22  * @brief testcase for arm_api.c
23  */
24 #include "platform.h"
25 #include "gnunet_common.h"
26 #include "gnunet_arm_service.h"
27 #include "gnunet_client_lib.h"
28 #include "gnunet_configuration_lib.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_program_lib.h"
31 #include "gnunet_resolver_service.h"
32
33 #define VERBOSE GNUNET_NO
34
35 #define START_ARM GNUNET_YES
36
37 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
38
39 static struct GNUNET_SCHEDULER_Handle *sched;
40
41 static const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43 static struct GNUNET_ARM_Handle *arm;
44
45 static int ok = 1;
46
47
48 static void
49 arm_notify_stop (void *cls, int success)
50 {
51   GNUNET_assert (success == GNUNET_NO);
52 #if START_ARM
53   GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, NULL, NULL);
54 #endif
55 }
56
57
58 static void
59 dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
60 {
61   if (addr == NULL)
62     {
63       GNUNET_assert (ok == 0);
64       GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
65       return;
66     }
67   GNUNET_assert (addr != NULL);
68   ok = 0;
69 }
70
71
72 static void
73 resolver_notify (void *cls, int success)
74 {
75   GNUNET_assert (success == GNUNET_YES);
76   GNUNET_RESOLVER_ip_get (sched,
77                           cfg,
78                           "localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
79 }
80
81
82 static void
83 arm_notify (void *cls, int success)
84 {
85   GNUNET_assert (success == GNUNET_YES);
86   GNUNET_ARM_start_service (arm, "resolver", TIMEOUT, &resolver_notify, NULL);
87 }
88
89
90 static void
91 task (void *cls,
92       struct GNUNET_SCHEDULER_Handle *s,
93       char *const *args,
94       const char *cfgfile,
95       const struct GNUNET_CONFIGURATION_Handle *c)
96 {
97   cfg = c;
98   sched = s;
99   arm = GNUNET_ARM_connect (cfg, sched, NULL);
100 #if START_ARM
101   GNUNET_ARM_start_service (arm, "arm", TIMEOUT, &arm_notify, NULL);
102 #else
103   arm_notify (NULL, GNUNET_YES);
104 #endif
105 }
106
107
108
109 static int
110 check ()
111 {
112   char *const argv[] = {
113     "test-arm-api",
114     "-c", "test_arm_api_data.conf",
115 #if VERBOSE
116     "-L", "DEBUG",
117 #endif
118     NULL
119   };
120   struct GNUNET_GETOPT_CommandLineOption options[] = {
121     GNUNET_GETOPT_OPTION_END
122   };
123   GNUNET_assert (GNUNET_OK ==
124                  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
125                                      argv,
126                                      "test-arm-api",
127                                      "nohelp", options, &task, NULL));
128   return ok;
129 }
130
131 int
132 main (int argc, char *argv[])
133 {
134   int ret;
135
136
137   GNUNET_log_setup ("test-arm-api",
138 #if VERBOSE
139                     "DEBUG",
140 #else
141                     "WARNING",
142 #endif
143                     NULL);
144   ret = check ();
145
146   return ret;
147 }
148
149 /* end of test_arm_api.c */