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.
16 * @file fs/test_fs_directory.c
17 * @brief Test for fs_directory.c
18 * @author Christian Grothoff
22 #include <extractor.h>
24 #include "gnunet_util_lib.h"
25 #include "gnunet_fs_service.h"
28 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
32 struct GNUNET_FS_Uri **uri;
33 struct GNUNET_CONTAINER_MetaData **md;
39 processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
40 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
47 return; /* ignore directory's meta data */
48 for (i = 0; i < p->max; i++)
50 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
51 GNUNET_FS_uri_test_equal (p->uri[i], uri))
57 FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
61 testDirectory (unsigned int i)
63 struct GNUNET_FS_DirectoryBuilder *db;
66 struct GNUNET_FS_Uri **uris;
67 struct GNUNET_CONTAINER_MetaData **mds;
68 struct GNUNET_CONTAINER_MetaData *meta;
76 struct GNUNET_TIME_Absolute start;
80 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i);
81 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i);
82 meta = GNUNET_CONTAINER_meta_data_create ();
83 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE,
84 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
85 "A title", strlen ("A title") + 1);
86 GNUNET_CONTAINER_meta_data_insert (meta, "<test>",
87 EXTRACTOR_METATYPE_AUTHOR_NAME,
88 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
89 "An author", strlen ("An author") + 1);
90 for (p = 0; p < i; p++)
92 mds[p] = GNUNET_CONTAINER_meta_data_create ();
93 for (q = 0; q <= p; q++)
95 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q);
96 GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>",
97 #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
98 q % EXTRACTOR_metatype_get_max (),
102 EXTRACTOR_METAFORMAT_UTF8,
103 "text/plain", txt, strlen (txt) + 1);
105 GNUNET_snprintf (uri, sizeof (uri),
106 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
109 uris[p] = GNUNET_FS_uri_parse (uri, &emsg);
112 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
115 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
116 GNUNET_FS_uri_destroy (uris[p]);
121 GNUNET_CONTAINER_meta_data_destroy (meta);
122 ABORT (); /* error in testcase */
124 GNUNET_assert (emsg == NULL);
126 start = GNUNET_TIME_absolute_get ();
127 db = GNUNET_FS_directory_builder_create (meta);
128 for (p = 0; p < i; p++)
129 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL);
130 GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data);
131 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
135 "Creating directory with %u entires and total size %llu took %s\n",
136 i, (unsigned long long) dlen, s);
142 GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls);
143 GNUNET_assert (cls.pos == i);
146 GNUNET_CONTAINER_meta_data_destroy (meta);
147 for (p = 0; p < i; p++)
149 GNUNET_CONTAINER_meta_data_destroy (mds[p]);
150 GNUNET_FS_uri_destroy (uris[p]);
159 main (int argc, char *argv[])
161 int failureCount = 0;
164 GNUNET_log_setup ("test_fs_directory",
171 for (i = 17; i < 1000; i *= 2)
172 failureCount += testDirectory (i);
173 if (failureCount != 0)
178 /* end of test_fs_directory.c */