gnunet service manager creates listening sockets for services having port fields...
[oweals/gnunet.git] / src / arm / test_gnunet_service_manager.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_gnunet_service_manager.c (A mockup testcase, not functionally complete)
22  * @brief testcase for gnunet-service-manager.c
23  */
24
25 #include "platform.h"
26 #include "gnunet_arm_service.h"
27 #include "gnunet_resolver_service.h"
28 #include "gnunet_program_lib.h"
29
30 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
31
32 /* Global Variables */
33 static int isOK = GNUNET_OK;
34
35 static void 
36 hostNameResolveCB(void *cls, 
37                                   const struct sockaddr *addr, 
38                                   socklen_t addrlen)
39 {
40         if (NULL == addr)
41                 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Name not resolved!\n");
42 }
43
44
45 static void
46 run(void *cls, 
47         struct GNUNET_SCHEDULER_Handle *sched, 
48         char * const *args,
49     const char *cfgfile, 
50     const struct GNUNET_CONFIGURATION_Handle *cfg)
51 {
52         struct GNUNET_RESOLVER_RequestHandle *resolveRet;
53         
54         /* connect to the resolver service */
55         resolveRet =
56         GNUNET_RESOLVER_hostname_resolve (sched,
57                                           cfg, AF_UNSPEC,
58                                           TIMEOUT,
59                                           &hostNameResolveCB,
60                                           NULL);
61         if (NULL == resolveRet) {
62                 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unable to resolve our own hostname!\n");
63                 isOK = GNUNET_NO;
64         }
65 }
66
67
68 static int
69 check()
70 {
71         char *const argv[] = {
72             "test-gnunet-service-manager",
73             "-c", "test_arm_api_data.conf",
74         #if VERBOSE
75             "-L", "DEBUG",
76         #endif
77             NULL
78           };
79           struct GNUNET_GETOPT_CommandLineOption options[] = {
80             GNUNET_GETOPT_OPTION_END
81           };
82           
83           /* Running ARM  and running the do_nothing task */
84           GNUNET_assert (GNUNET_OK ==
85                          GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
86                                              argv,
87                                              "test-gnunet-service-manager",
88                                              "nohelp", options, &run, NULL));
89           return isOK;
90 }
91
92
93 int
94 main (int argc, char *argv[])
95 {
96   int ret;
97   GNUNET_log_setup("test-gnunet-service-manager",
98   #if VERBOSE
99         "DEBUG",
100   #else
101         "WARNING",
102   #endif
103         NULL);
104   ret = check();
105   return ret;
106 }