aboutsummaryrefslogtreecommitdiff
path: root/src/arm/test_arm_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r--src/arm/test_arm_api.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c
new file mode 100644
index 000000000..89f63d3ec
--- /dev/null
+++ b/src/arm/test_arm_api.c
@@ -0,0 +1,140 @@
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
39static struct GNUNET_SCHEDULER_Handle *sched;
40
41static struct GNUNET_CONFIGURATION_Handle *cfg;
42
43static int ok = 1;
44
45static void
46dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
47{
48 if (addr == NULL)
49 {
50 GNUNET_assert (ok == 0);
51#if START_ARM
52 GNUNET_ARM_stop_service ("arm", cfg, sched, TIMEOUT, NULL, NULL);
53#endif
54 return;
55 }
56 GNUNET_assert (addr != NULL);
57 ok = 0;
58}
59
60
61static void
62resolver_notify (void *cls, int success)
63{
64 GNUNET_assert (success == GNUNET_YES);
65 sleep (1); /* FIXME: that we need to do this is a problem... */
66 GNUNET_RESOLVER_ip_get (sched,
67 cfg,
68 "localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
69}
70
71static void
72arm_notify (void *cls, int success)
73{
74 GNUNET_assert (success == GNUNET_YES);
75#if START_ARM
76 sleep (1); /* FIXME: that we need to do this is a problem... */
77#endif
78 GNUNET_ARM_start_service ("resolver",
79 cfg, sched, TIMEOUT, &resolver_notify, NULL);
80}
81
82
83static void
84task (void *cls,
85 struct GNUNET_SCHEDULER_Handle *s,
86 char *const *args,
87 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *c)
88{
89 cfg = c;
90 sched = s;
91#if START_ARM
92 GNUNET_ARM_start_service ("arm", cfg, sched, TIMEOUT, &arm_notify, NULL);
93#else
94 arm_notify (NULL, GNUNET_YES);
95#endif
96}
97
98
99
100static int
101check ()
102{
103 char *const argv[] = {
104 "test-arm-api",
105 "-c", "test_arm_api_data.conf",
106#if VERBOSE
107 "-L", "DEBUG",
108#endif
109 NULL
110 };
111 struct GNUNET_GETOPT_CommandLineOption options[] = {
112 GNUNET_GETOPT_OPTION_END
113 };
114 GNUNET_assert (GNUNET_OK ==
115 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
116 argv,
117 "test-arm-api",
118 "nohelp", options, &task, NULL));
119 return ok;
120}
121
122int
123main (int argc, char *argv[])
124{
125 int ret;
126
127
128 GNUNET_log_setup ("test-arm-api",
129#if VERBOSE
130 "DEBUG",
131#else
132 "WARNING",
133#endif
134 NULL);
135 ret = check ();
136
137 return ret;
138}
139
140/* end of test_arm_api.c */