skeleton for list_updateable testcase
[oweals/gnunet.git] / src / fs / test_fs_namespace_list_updateable.c
1 /*
2      This file is part of GNUnet.
3      (C) 2005, 2006, 2008, 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 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  * @file fs/test_fs_namespace.c
23  * @brief Test for fs_namespace.c
24  * @author Christian Grothoff
25  *
26  * TODO:
27  * - add timeout task
28  */
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_arm_service.h"
32 #include "gnunet_fs_service.h"
33
34 #define VERBOSE GNUNET_NO
35
36 #define START_ARM GNUNET_YES
37
38 static struct GNUNET_SCHEDULER_Handle *sched;
39
40 static struct PeerContext p1;
41
42 static struct GNUNET_FS_Handle *fs;
43
44 static int err;
45
46 static struct GNUNET_FS_Namespace *ns;
47
48 static struct GNUNET_TIME_Absolute expiration;
49
50 static struct GNUNET_CONTAINER_MetaData *meta;
51
52 static struct GNUNET_FS_Uri *uri_this;
53
54 static struct GNUNET_FS_Uri *uri_next;
55
56
57 struct PeerContext
58 {
59   struct GNUNET_CONFIGURATION_Handle *cfg;
60 #if START_ARM
61   pid_t arm_pid;
62 #endif
63 };
64
65
66 static void *
67 progress_cb (void *cls, 
68              const struct GNUNET_FS_ProgressInfo *event)
69 {
70   return NULL;
71 }
72
73
74 static void
75 setup_peer (struct PeerContext *p, const char *cfgname)
76 {
77   p->cfg = GNUNET_CONFIGURATION_create ();
78 #if START_ARM
79   p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
80                                         "gnunet-service-arm",
81 #if VERBOSE
82                                         "-L", "DEBUG",
83 #endif
84                                         "-c", cfgname, NULL);
85 #endif
86   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
87 }
88
89
90 static void
91 stop_arm (struct PeerContext *p)
92 {
93 #if START_ARM
94   if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
95     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
96   if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
97     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
98   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
99               "ARM process %u stopped\n", p->arm_pid);
100 #endif
101   if (uri_this != NULL)
102     GNUNET_FS_uri_destroy (uri_this);
103   if (uri_next != NULL)
104     GNUNET_FS_uri_destroy (uri_next);
105   if (ns != NULL)
106     GNUNET_FS_namespace_delete (ns, GNUNET_NO);
107   if (meta != NULL)
108     GNUNET_CONTAINER_meta_data_destroy (meta);
109   GNUNET_CONFIGURATION_destroy (p->cfg);
110 }
111
112
113
114 static void
115 sks_cont_next (void *cls,
116                const struct GNUNET_FS_Uri *uri,
117                const char *emsg)
118 {
119   GNUNET_assert (NULL == emsg);
120 }
121
122
123 static void
124 sks_cont_this (void *cls,
125                const struct GNUNET_FS_Uri *uri,
126                const char *emsg)
127 {
128   GNUNET_assert (NULL == emsg);
129
130   GNUNET_FS_publish_sks (fs,
131                          ns,
132                          "next",
133                          "future",
134                          meta,
135                          uri_next,
136                          expiration,
137                          1, 1,
138                          GNUNET_FS_PUBLISH_OPTION_NONE,
139                          &sks_cont_next,
140                          NULL);
141
142 }
143
144
145
146 static void
147 testNamespace ()
148 {
149
150   ns = GNUNET_FS_namespace_create (fs,
151                                    "testNamespace");
152   GNUNET_assert (NULL != ns);
153   expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
154   meta = GNUNET_CONTAINER_meta_data_create ();
155
156   uri_this =
157     GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", NULL);
158   uri_next =
159     GNUNET_FS_uri_parse ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.43", NULL);
160   GNUNET_FS_publish_sks (fs,
161                          ns,
162                          "this",
163                          "next",
164                          meta,
165                          uri_this,
166                          expiration,
167                          1, 1,
168                          GNUNET_FS_PUBLISH_OPTION_NONE,
169                          &sks_cont_this,
170                          NULL);
171 }
172
173
174 static void
175 run (void *cls,
176      struct GNUNET_SCHEDULER_Handle *s,
177      char *const *args,
178      const char *cfgfile,
179      const struct GNUNET_CONFIGURATION_Handle *cfg)
180 {
181   sched = s;
182   setup_peer (&p1, "test_fs_namespace_data.conf");
183   fs = GNUNET_FS_start (sched,
184                         cfg,
185                         "test-fs-namespace",
186                         &progress_cb,
187                         NULL,
188                         GNUNET_FS_FLAGS_NONE,
189                         GNUNET_FS_OPTIONS_END);
190   testNamespace ();
191 }
192
193
194 int
195 main (int argc, char *argv[])
196 {
197   char *const argvx[] = { 
198     "test-fs-namespace",
199     "-c",
200     "test_fs_namespace_data.conf",
201 #if VERBOSE
202     "-L", "DEBUG",
203 #endif
204     NULL
205   };
206   struct GNUNET_GETOPT_CommandLineOption options[] = {
207     GNUNET_GETOPT_OPTION_END
208   };
209
210   GNUNET_log_setup ("test_fs_namespace_list_updateable", 
211 #if VERBOSE
212                     "DEBUG",
213 #else
214                     "WARNING",
215 #endif
216                     NULL);
217   GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
218                       argvx, "test-fs-namespace",
219                       "nohelp", options, &run, NULL);
220   stop_arm (&p1);
221   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
222   return err;
223 }
224
225
226 /* end of test_fs_namespace_list_updateable.c */