2 This file is part of GNUnet.
3 (C) 2005, 2006, 2008 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file applications/fs/ecrs/namespacetest.c
23 * @brief Test for namespace.c
24 * @author Christian Grothoff
28 #include "gnunet_util.h"
29 #include "gnunet_ecrs_lib.h"
32 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
33 #define CHECK(c) { do { if (!(c)) ABORT(); } while(0); }
35 #define CHECKNAME "gnunet-namespace-test"
37 static struct GNUNET_GC_Configuration *cfg;
42 spcb (const GNUNET_ECRS_FileInfo * fi,
43 const GNUNET_HashCode * key, int isRoot, void *closure)
45 struct GNUNET_ECRS_URI *want = closure;
47 if (GNUNET_ECRS_uri_test_equal (want, fi->uri))
51 "Namespace search returned unexpected result: \nHAVE: %s\nWANT: %s...\n",
52 GNUNET_ECRS_uri_to_string (fi->uri),
53 GNUNET_ECRS_uri_to_string (want));
69 struct GNUNET_ECRS_URI *adv;
70 struct GNUNET_ECRS_URI *advURI;
71 struct GNUNET_ECRS_URI *rootURI;
72 struct GNUNET_MetaData *meta;
74 meta = GNUNET_meta_data_create ();
75 adv = GNUNET_ECRS_keyword_string_to_uri (NULL, "testNamespace");
77 GNUNET_ECRS_namespace_create (NULL,
82 15 * GNUNET_CRON_MINUTES, adv, "root");
83 CHECK (NULL != rootURI);
84 GNUNET_ECRS_uri_get_namespace_from_sks (rootURI, &pid);
85 advURI = GNUNET_ECRS_namespace_add_content (NULL, cfg, &pid, 1, /* anonymity */
87 5 * GNUNET_CRON_MINUTES +
89 "this", "next", rootURI, meta);
90 CHECK (NULL != advURI);
91 fprintf (stderr, "Starting namespace search...\n");
92 CHECK (GNUNET_OK == GNUNET_ECRS_search (NULL,
94 advURI, 1, &spcb, rootURI, &tt,
96 fprintf (stderr, "Completed namespace search...\n");
97 CHECK (GNUNET_OK == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
98 CHECK (GNUNET_SYSERR == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
99 GNUNET_meta_data_destroy (meta);
100 GNUNET_ECRS_uri_destroy (rootURI);
101 GNUNET_ECRS_uri_destroy (advURI);
107 main (int argc, char *argv[])
110 int failureCount = 0;
112 GNUNET_disable_entropy_gathering ();
113 cfg = GNUNET_GC_create ();
114 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
116 GNUNET_GC_free (cfg);
119 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
120 GNUNET_GE_ASSERT (NULL, daemon > 0);
122 GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS))
128 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
129 failureCount += testNamespace ();
131 GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
133 return (failureCount == 0) ? 0 : 1;
136 /* end of namespacetest.c */