stuff
[oweals/gnunet.git] / src / fs / test_fs_collection.c
1 /*
2      This file is part of GNUnet.
3      (C) 2006, 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 /**
22  * @file fs/test_fs_collection.c
23  * @brief testcase for fs_collection.c
24  * @author Christian Grothoff
25  */
26
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_fs_service.h"
30
31 static struct GNUNET_CONFIGURATION_Handle *cfg;
32
33 static void* progress_cb (void *cls,
34                           const struct GNUNET_FS_ProgressInfo *info)
35 {
36   GNUNET_break (0);
37   return NULL;
38 }
39
40
41 static void
42 task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
43 {
44   struct GNUNET_FS_Namespace *have;
45   struct GNUNET_FS_Namespace *ns;
46   char *emsg;
47   struct GNUNET_FS_Uri *uri;
48   struct GNUNET_FS_Handle *fsh;
49   struct GNUNET_CONTAINER_MetaData *md;
50
51   fsh = GNUNET_FS_start (tc->sched,
52                          cfg,
53                          "test-fs-collection",
54                          &progress_cb,
55                          NULL);
56   GNUNET_assert (NULL != fsh);
57   GNUNET_FS_collection_stop (fsh);
58   GNUNET_assert (NULL == GNUNET_FS_collection_get (fsh));
59   ns = GNUNET_FS_namespace_create (fsh, "test-namespace");
60   GNUNET_assert (NULL != ns);
61   GNUNET_assert (GNUNET_OK == GNUNET_FS_collection_start (fsh, 
62                                                           ns));
63   GNUNET_FS_namespace_delete (ns, GNUNET_NO);
64   have = GNUNET_FS_collection_get (fsh);
65   GNUNET_assert (NULL != have);
66   GNUNET_FS_namespace_delete (have, GNUNET_NO);
67   uri =
68     GNUNET_FS_uri_parse ("gnunet://fs/chk/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0", &emsg);
69   GNUNET_assert (NULL != uri);
70   md = GNUNET_CONTAINER_meta_data_create ();
71   GNUNET_FS_collection_add (fsh, uri, md);
72   GNUNET_CONTAINER_meta_data_destroy (md);
73   GNUNET_FS_uri_destroy (uri);
74   GNUNET_FS_stop (fsh);
75   fsh = GNUNET_FS_start (tc->sched,
76                          cfg,
77                          "test-fs-collection",
78                          &progress_cb,
79                          NULL);
80   have = GNUNET_FS_collection_get (fsh);
81   GNUNET_assert (NULL != have);
82   GNUNET_FS_namespace_delete (have, GNUNET_NO);
83   GNUNET_FS_collection_publish (fsh);
84   GNUNET_FS_collection_stop (fsh);
85   GNUNET_assert (NULL == GNUNET_FS_collection_get (fsh));
86   GNUNET_FS_stop (fsh);
87 }
88
89
90 int
91 main (int argc, char *argv[])
92 {
93   int ok;
94
95   GNUNET_log_setup ("test_fs_collection", 
96 #if VERBOSE
97                     "DEBUG",
98 #else
99                     "WARNING",
100 #endif
101                     NULL);
102   GNUNET_CRYPTO_random_disable_entropy_gathering ();
103   cfg = GNUNET_CONFIGURATION_create ();
104   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, "test_fs_collection_data.conf"))
105     {
106       GNUNET_CONFIGURATION_destroy (cfg);
107       return -1;
108     }
109   ok = GNUNET_YES;
110   GNUNET_SCHEDULER_run (&task, &ok);
111   GNUNET_CONFIGURATION_destroy (cfg);
112   return (ok == GNUNET_YES) ? 0 : 1;
113 }
114
115 /* end of test_fs_collection.c */