2 This file is part of GNUnet.
3 Copyright (C) 2005, 2006, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file fs/test_fs_directory.c
20 * @brief Test for fs_directory.c
21 * @author Christian Grothoff
25 #include <extractor.h>
27 #include "gnunet_util_lib.h"
28 #include "gnunet_fs_service.h"
31 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
35 struct GNUNET_FS_Uri **uri;
36 struct GNUNET_CONTAINER_MetaData **md;
42 processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
43 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
50 return; /* ignore directory's meta data */
51 for (i = 0; i < p->max; i++)
53 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
54 GNUNET_FS_uri_test_equal (p->uri[i], uri))
60 FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
64 testDirectory (unsigned int i)
66 struct GNUNET_FS_DirectoryBuilder *db;
69 struct GNUNET_FS_Uri **uris;
70 struct GNUNET_CONTAINER_MetaData **mds;
71 struct GNUNET_CONTAINER_MetaData *meta;
79 struct GNUNET_TIME_Absolute start;
83 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
84 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
85 meta = GNUNET_CONTAINER_meta_data_create ();
86 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
87 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
88 "A title", strlen ("A title") + 1);
89 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
90 EXTRACTOR_METATYPE_AUTHOR_NAME,
91 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
92 "An author", strlen ("An author") + 1);
93 for (p = 0; p < i; p++)
95 mds[p] = GNUNET_CONTAINER_meta_data_create ();
96 for (q = 0; q <= p; q++)
98 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
99 GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>",
100 #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
101 q % EXTRACTOR_metatype_get_max (),
105 EXTRACTOR_METAFORMAT_UTF8,
106 "text/plain", txt, strlen (txt) + 1);
108 GNUNET_snprintf (uri, sizeof (uri),
109 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
112 uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
115 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
118 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
119 GNUNET_FS_uri_destroy (uris[p]);
124 GNUNET_CONTAINER_meta_data_destroy (meta);
125 ABORT (); /* error in testcase */
127 GNUNET_assert (emsg == NULL);
129 start = GNUNET_TIME_absolute_get ();
130 db = GNUNET_FS_directory_builder_create (meta);
131 for (p = 0; p < i; p++)
132 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
133 GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
134 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
138 "Creating directory with %u entires and total size %llu took %s\n",
139 i, (unsigned long long) dlen, s);
145 GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
146 GNUNET_assert (cls.pos == i);
149 GNUNET_CONTAINER_meta_data_destroy (meta);
150 for (p = 0; p < i; p++)
152 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
153 GNUNET_FS_uri_destroy (uris[p]);
162 main (int argc, char *argv[])
164 int failureCount = 0;
167 GNUNET_log_setup ("test_fs_directory",
174 for (i = 17; i < 1000; i *= 2)
175 failureCount += testDirectory (i);
176 if (failureCount != 0)
181 /* end of test_fs_directory.c */