fixes
[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 #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; }
32
33 int
34 main (int argc, char *argv[])
35 {
36   struct GNUNET_CONFIGURATION_Handle *cfg;
37   int ok;
38   struct GNUNET_ClientServerConnection *sock;
39   struct GNUNET_CONTAINER_MetaData *meta;
40   struct GNUNET_CONTAINER_MetaData *have;
41   char *emsg;
42   struct GNUNET_FS_Uri *uri;
43   struct GNUNET_CONTAINER_MetaData *md;
44   struct GNUNET_FS_Handle *fsh;
45
46   GNUNET_CRYPTO_random_disable_entropy_gathering ();
47   cfg = GNUNET_CONFIGURATION_create ();
48   if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, "check.conf"))
49     {
50       GNUNET_CONFIGURATION_destroy (cfg);
51       return -1;
52     }
53   sock = NULL;
54   meta = NULL;
55   ok = GNUNET_YES;
56   meta = GNUNET_CONTAINER_meta_data_create ();
57   GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_MIMETYPE, "test/foo");
58
59
60   fsh = GNUNET_FS_start (sched,
61                          cfg,
62                          "test-fs-collection",
63                          &progress_cb,
64                          NULL);
65
66   /* ACTUAL TEST CODE */
67   GNUNET_FS_collection_stop (fsh);
68   CHECK (NULL == GNUNET_FS_collection_get (fsh));
69   CHECK (GNUNET_OK == GNUNET_FS_collection_start (fsh, 
70                                                   namespace));
71   have = GNUNET_FS_collection_get (fsh);
72   CHECK (NULL != have);
73   CHECK (GNUNET_CONTAINER_meta_data_test_equal (have, meta));
74   GNUNET_CONTAINER_meta_data_destroy (have);
75   md = meta;
76   uri =
77     GNUNET_FS_uri_parse ("gnunet://ecrs/chk/0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0", &emsg);
78   GNUNET_FS_collection_add (fsh, uri, md);
79   GNUNET_FS_uri_destroy (uri);
80   GNUNET_FS_stop (fsh);
81   fsh = GNUNET_FS_start (sched, cfg,
82                          "test-fs-collection",
83                          &progress_cb,
84                          NULL);
85   have = GNUNET_FS_collection_get (fsh);
86   CHECK (NULL != have);
87   CHECK (GNUNET_CONTAINER_meta_data_test_equal (have, meta));
88   GNUNET_CONTAINER_meta_data_destroy (have);
89   GNUNET_FS_collection_publish (fsh);
90   GNUNET_FS_collection_stop (fsh);
91   CHECK (NULL == GNUNET_FS_collection_get (fsh));
92   GNUNET_FS_stop (fsh);
93
94   /* END OF TEST CODE */
95 FAILURE:
96   if (meta != NULL)
97     GNUNET_CONTAINER_meta_data_destroy (meta);
98   GNUNET_CONFIGURATION_destroy (cfg);
99   
100   return (ok == GNUNET_YES) ? 0 : 1;
101 }
102
103 /* end of test_fs_collection.c */