summaryrefslogtreecommitdiff
path: root/src/fs/test_fs_directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_directory.c')
-rw-r--r--src/fs/test_fs_directory.c171
1 files changed, 85 insertions, 86 deletions
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c
index 5cdbd9d07..936c3bed4 100644
--- a/src/fs/test_fs_directory.c
+++ b/src/fs/test_fs_directory.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file fs/test_fs_directory.c 21 * @file fs/test_fs_directory.c
22 * @brief Test for fs_directory.c 22 * @brief Test for fs_directory.c
@@ -32,8 +32,7 @@
32 32
33#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } 33#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
34 34
35struct PCLS 35struct PCLS {
36{
37 struct GNUNET_FS_Uri **uri; 36 struct GNUNET_FS_Uri **uri;
38 struct GNUNET_CONTAINER_MetaData **md; 37 struct GNUNET_CONTAINER_MetaData **md;
39 unsigned int pos; 38 unsigned int pos;
@@ -41,9 +40,9 @@ struct PCLS
41}; 40};
42 41
43static void 42static void
44processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, 43processor(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
45 const struct GNUNET_CONTAINER_MetaData *md, size_t length, 44 const struct GNUNET_CONTAINER_MetaData *md, size_t length,
46 const void *data) 45 const void *data)
47{ 46{
48 struct PCLS *p = cls; 47 struct PCLS *p = cls;
49 int i; 48 int i;
@@ -51,19 +50,19 @@ processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
51 if (NULL == uri) 50 if (NULL == uri)
52 return; /* ignore directory's meta data */ 51 return; /* ignore directory's meta data */
53 for (i = 0; i < p->max; i++) 52 for (i = 0; i < p->max; i++)
54 {
55 if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], md) &&
56 GNUNET_FS_uri_test_equal (p->uri[i], uri))
57 { 53 {
58 p->pos++; 54 if (GNUNET_CONTAINER_meta_data_test_equal(p->md[i], md) &&
59 return; 55 GNUNET_FS_uri_test_equal(p->uri[i], uri))
56 {
57 p->pos++;
58 return;
59 }
60 } 60 }
61 } 61 fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__);
62 fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
63} 62}
64 63
65static int 64static int
66testDirectory (unsigned int i) 65testDirectory(unsigned int i)
67{ 66{
68 struct GNUNET_FS_DirectoryBuilder *db; 67 struct GNUNET_FS_DirectoryBuilder *db;
69 char *data; 68 char *data;
@@ -82,99 +81,99 @@ testDirectory (unsigned int i)
82 const char *s; 81 const char *s;
83 82
84 cls.max = i; 83 cls.max = i;
85 uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri *) * i); 84 uris = GNUNET_malloc(sizeof(struct GNUNET_FS_Uri *) * i);
86 mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData *) * i); 85 mds = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_MetaData *) * i);
87 meta = GNUNET_CONTAINER_meta_data_create (); 86 meta = GNUNET_CONTAINER_meta_data_create();
88 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, 87 GNUNET_CONTAINER_meta_data_insert(meta, "<test>", EXTRACTOR_METATYPE_TITLE,
89 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 88 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
90 "A title", strlen ("A title") + 1); 89 "A title", strlen("A title") + 1);
91 GNUNET_CONTAINER_meta_data_insert (meta, "<test>", 90 GNUNET_CONTAINER_meta_data_insert(meta, "<test>",
92 EXTRACTOR_METATYPE_AUTHOR_NAME, 91 EXTRACTOR_METATYPE_AUTHOR_NAME,
93 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 92 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
94 "An author", strlen ("An author") + 1); 93 "An author", strlen("An author") + 1);
95 for (p = 0; p < i; p++) 94 for (p = 0; p < i; p++)
96 {
97 mds[p] = GNUNET_CONTAINER_meta_data_create ();
98 for (q = 0; q <= p; q++)
99 { 95 {
100 GNUNET_snprintf (txt, sizeof (txt), "%u -- %u\n", p, q); 96 mds[p] = GNUNET_CONTAINER_meta_data_create();
101 GNUNET_CONTAINER_meta_data_insert (mds[p], "<test>", 97 for (q = 0; q <= p; q++)
98 {
99 GNUNET_snprintf(txt, sizeof(txt), "%u -- %u\n", p, q);
100 GNUNET_CONTAINER_meta_data_insert(mds[p], "<test>",
102#if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR 101#if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
103 q % EXTRACTOR_metatype_get_max (), 102 q % EXTRACTOR_metatype_get_max(),
104#else 103#else
105 q % 128, 104 q % 128,
106#endif 105#endif
107 EXTRACTOR_METAFORMAT_UTF8, 106 EXTRACTOR_METAFORMAT_UTF8,
108 "text/plain", txt, strlen (txt) + 1); 107 "text/plain", txt, strlen(txt) + 1);
109 } 108 }
110 GNUNET_snprintf (uri, sizeof (uri), 109 GNUNET_snprintf(uri, sizeof(uri),
111 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", 110 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u",
112 p); 111 p);
113 emsg = NULL; 112 emsg = NULL;
114 uris[p] = GNUNET_FS_uri_parse (uri, &emsg); 113 uris[p] = GNUNET_FS_uri_parse(uri, &emsg);
115 if (uris[p] == NULL) 114 if (uris[p] == NULL)
116 { 115 {
117 GNUNET_CONTAINER_meta_data_destroy (mds[p]); 116 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
118 while (--p > 0) 117 while (--p > 0)
119 { 118 {
120 GNUNET_CONTAINER_meta_data_destroy (mds[p]); 119 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
121 GNUNET_FS_uri_destroy (uris[p]); 120 GNUNET_FS_uri_destroy(uris[p]);
122 } 121 }
123 GNUNET_free (mds); 122 GNUNET_free(mds);
124 GNUNET_free (uris); 123 GNUNET_free(uris);
125 GNUNET_free (emsg); 124 GNUNET_free(emsg);
126 GNUNET_CONTAINER_meta_data_destroy (meta); 125 GNUNET_CONTAINER_meta_data_destroy(meta);
127 ABORT (); /* error in testcase */ 126 ABORT(); /* error in testcase */
127 }
128 GNUNET_assert(emsg == NULL);
128 } 129 }
129 GNUNET_assert (emsg == NULL); 130 start = GNUNET_TIME_absolute_get();
130 } 131 db = GNUNET_FS_directory_builder_create(meta);
131 start = GNUNET_TIME_absolute_get ();
132 db = GNUNET_FS_directory_builder_create (meta);
133 for (p = 0; p < i; p++) 132 for (p = 0; p < i; p++)
134 GNUNET_FS_directory_builder_add (db, uris[p], mds[p], NULL); 133 GNUNET_FS_directory_builder_add(db, uris[p], mds[p], NULL);
135 GNUNET_FS_directory_builder_finish (db, &dlen, (void **) &data); 134 GNUNET_FS_directory_builder_finish(db, &dlen, (void **)&data);
136 s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration 135 s = GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration
137 (start), 136 (start),
138 GNUNET_YES); 137 GNUNET_YES);
139 fprintf (stdout, 138 fprintf(stdout,
140 "Creating directory with %u entires and total size %llu took %s\n", 139 "Creating directory with %u entires and total size %llu took %s\n",
141 i, (unsigned long long) dlen, s); 140 i, (unsigned long long)dlen, s);
142 if (i < 100) 141 if (i < 100)
143 { 142 {
144 cls.pos = 0; 143 cls.pos = 0;
145 cls.uri = uris; 144 cls.uri = uris;
146 cls.md = mds; 145 cls.md = mds;
147 GNUNET_FS_directory_list_contents (dlen, data, 0, &processor, &cls); 146 GNUNET_FS_directory_list_contents(dlen, data, 0, &processor, &cls);
148 GNUNET_assert (cls.pos == i); 147 GNUNET_assert(cls.pos == i);
149 } 148 }
150 GNUNET_free (data); 149 GNUNET_free(data);
151 GNUNET_CONTAINER_meta_data_destroy (meta); 150 GNUNET_CONTAINER_meta_data_destroy(meta);
152 for (p = 0; p < i; p++) 151 for (p = 0; p < i; p++)
153 { 152 {
154 GNUNET_CONTAINER_meta_data_destroy (mds[p]); 153 GNUNET_CONTAINER_meta_data_destroy(mds[p]);
155 GNUNET_FS_uri_destroy (uris[p]); 154 GNUNET_FS_uri_destroy(uris[p]);
156 } 155 }
157 GNUNET_free (uris); 156 GNUNET_free(uris);
158 GNUNET_free (mds); 157 GNUNET_free(mds);
159 return ret; 158 return ret;
160} 159}
161 160
162 161
163int 162int
164main (int argc, char *argv[]) 163main(int argc, char *argv[])
165{ 164{
166 int failureCount = 0; 165 int failureCount = 0;
167 int i; 166 int i;
168 167
169 GNUNET_log_setup ("test_fs_directory", 168 GNUNET_log_setup("test_fs_directory",
170#if VERBOSE 169#if VERBOSE
171 "DEBUG", 170 "DEBUG",
172#else 171#else
173 "WARNING", 172 "WARNING",
174#endif 173#endif
175 NULL); 174 NULL);
176 for (i = 17; i < 1000; i *= 2) 175 for (i = 17; i < 1000; i *= 2)
177 failureCount += testDirectory (i); 176 failureCount += testDirectory(i);
178 if (failureCount != 0) 177 if (failureCount != 0)
179 return 1; 178 return 1;
180 return 0; 179 return 0;