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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file fs/test_fs_directory.c
22 * @brief Test for fs_directory.c
23 * @author Christian Grothoff
27 #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; }
36 struct GNUNET_FS_Uri **uri;
37 struct GNUNET_CONTAINER_MetaData **md;
43 processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
44 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
51 return; /* ignore directory's meta data */
52 for (i = 0; i < p->max; i++)
54 if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) &&
55 GNUNET_FS_uri_test_equal(p->uri[i], uri))
61 fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__);
65 testDirectory(unsigned int i)
67 struct GNUNET_FS_DirectoryBuilder *db;
70 struct GNUNET_FS_Uri **uris;
71 struct GNUNET_CONTAINER_MetaData **mds;
72 struct GNUNET_CONTAINER_MetaData *meta;
80 struct GNUNET_TIME_Absolute start;
84 uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i);
85 mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i);
86 meta = GNUNET_CONTAINER_meta_data_create();
87 GNUNET_CONTAINER_meta_data_insert(meta, "<test>", EXTRACTOR_METATYPE_TITLE,
88 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
89 "A title", strlen("A title") + 1);
90 GNUNET_CONTAINER_meta_data_insert(meta, "<test>",
91 EXTRACTOR_METATYPE_AUTHOR_NAME,
92 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
93 "An author", strlen("An author") + 1);
94 for (p = 0; p < i; p++)
96 mds[p] = GNUNET_CONTAINER_meta_data_create();
97 for (q = 0; q <= p; q++)
99 GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q);
100 GNUNET_CONTAINER_meta_data_insert(mds[p], "<test>",
101 #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
102 q % EXTRACTOR_metatype_get_max(),
106 EXTRACTOR_METAFORMAT_UTF8,
107 "text/plain", txt, strlen(txt) + 1);
109 GNUNET_snprintf(uri, sizeof(uri),
110 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
113 uris[p] = GNUNET_FS_uri_parse(uri, &emsg);
116 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
119 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
120 GNUNET_FS_uri_destroy(uris[p]);
125 GNUNET_CONTAINER_meta_data_destroy(meta);
126 ABORT(); /* error in testcase */
128 GNUNET_assert(emsg == NULL);
130 start = GNUNET_TIME_absolute_get();
131 db = GNUNET_FS_directory_builder_create(meta);
132 for (p = 0; p < i; p++)
133 GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL);
134 GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data);
135 s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration
139 "Creating directory with %u entires and total size %llu took %s\n",
140 i, (unsigned long long)dlen, s);
146 GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls);
147 GNUNET_assert(cls.pos == i);
150 GNUNET_CONTAINER_meta_data_destroy(meta);
151 for (p = 0; p < i; p++)
153 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
154 GNUNET_FS_uri_destroy(uris[p]);
163 main(int argc, char *argv[])
165 int failureCount = 0;
168 GNUNET_log_setup("test_fs_directory",
175 for (i = 17; i < 1000; i *= 2)
176 failureCount += testDirectory(i);
177 if (failureCount != 0)
182 /* end of test_fs_directory.c */