2 This file is part of GNUnet.
3 (C) 2005, 2006, 2009 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 3, 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 fs/test_fs_directory.c
23 * @brief Test for fs_directory.c
24 * @author Christian Grothoff
28 #include <extractor.h>
29 #include "gnunet_util_lib.h"
30 #include "gnunet_fs_service.h"
33 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
37 struct GNUNET_FS_Uri **uri;
38 struct GNUNET_CONTAINER_MetaData **md;
44 processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
45 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
52 return; /* ignore directory's meta data */
53 for (i = 0; i < p->max; i++)
55 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
56 GNUNET_FS_uri_test_equal (p->uri[i], uri))
62 FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
66 testDirectory (unsigned int i)
68 struct GNUNET_FS_DirectoryBuilder *db;
71 struct GNUNET_FS_Uri **uris;
72 struct GNUNET_CONTAINER_MetaData **mds;
73 struct GNUNET_CONTAINER_MetaData *meta;
81 struct GNUNET_TIME_Absolute start;
85 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
86 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
87 meta = GNUNET_CONTAINER_meta_data_create ();
88 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
89 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
90 "A title", strlen ("A title") + 1);
91 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
92 EXTRACTOR_METATYPE_AUTHOR_NAME,
93 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
94 "An author", strlen ("An author") + 1);
95 for (p = 0; p < i; p++)
97 mds[p] = GNUNET_CONTAINER_meta_data_create ();
98 for (q = 0; q <= p; q++)
100 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
101 GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>",
102 q % EXTRACTOR_metatype_get_max (),
103 EXTRACTOR_METAFORMAT_UTF8,
104 "text/plain", txt, strlen (txt) + 1);
106 GNUNET_snprintf (uri, sizeof (uri),
107 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
110 uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
113 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
116 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
117 GNUNET_FS_uri_destroy (uris[p]);
122 GNUNET_CONTAINER_meta_data_destroy (meta);
123 ABORT (); /* error in testcase */
125 GNUNET_assert (emsg == NULL);
127 start = GNUNET_TIME_absolute_get ();
128 db = GNUNET_FS_directory_builder_create (meta);
129 for (p = 0; p < i; p++)
130 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
131 GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
132 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
136 "Creating directory with %u entires and total size %llu took %s\n",
137 i, (unsigned long long) dlen, s);
143 GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
144 GNUNET_assert (cls.pos == i);
147 GNUNET_CONTAINER_meta_data_destroy (meta);
148 for (p = 0; p < i; p++)
150 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
151 GNUNET_FS_uri_destroy (uris[p]);
160 main (int argc, char *argv[])
162 int failureCount = 0;
165 GNUNET_log_setup ("test_fs_directory",
172 for (i = 17; i < 1000; i *= 2)
173 failureCount += testDirectory (i);
174 if (failureCount != 0)
179 /* end of test_fs_directory.c */