aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_uri.c')
-rw-r--r--src/fs/test_fs_uri.c337
1 files changed, 0 insertions, 337 deletions
diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c
deleted file mode 100644
index aac7b1b97..000000000
--- a/src/fs/test_fs_uri.c
+++ /dev/null
@@ -1,337 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2003-2014 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file fs/test_fs_uri.c
22 * @brief Test for fs_uri.c
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_fs_service.h"
28#include "fs_api.h"
29
30
31static int
32testKeyword ()
33{
34 char *uri;
35 struct GNUNET_FS_Uri *ret;
36 char *emsg;
37
38 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/++", &emsg)))
39 {
40 GNUNET_FS_uri_destroy (ret);
41 GNUNET_assert (0);
42 }
43 GNUNET_free (emsg);
44 ret = GNUNET_FS_uri_parse ("gnunet://fs/ksk/foo+bar", &emsg);
45 if (NULL == ret)
46 {
47 GNUNET_free (emsg);
48 GNUNET_assert (0);
49 }
50 if (! GNUNET_FS_uri_test_ksk (ret))
51 {
52 GNUNET_FS_uri_destroy (ret);
53 GNUNET_assert (0);
54 }
55 if ((2 != ret->data.ksk.keywordCount) ||
56 (0 != strcmp (" foo", ret->data.ksk.keywords[0])) ||
57 (0 != strcmp (" bar", ret->data.ksk.keywords[1])))
58 {
59 GNUNET_FS_uri_destroy (ret);
60 GNUNET_assert (0);
61 }
62
63 uri = GNUNET_FS_uri_to_string (ret);
64 if (0 != strcmp (uri, "gnunet://fs/ksk/foo+bar"))
65 {
66 GNUNET_free (uri);
67 GNUNET_FS_uri_destroy (ret);
68 GNUNET_assert (0);
69 }
70 GNUNET_free (uri);
71 GNUNET_FS_uri_destroy (ret);
72 return 0;
73}
74
75
76static int
77testLocation ()
78{
79 struct GNUNET_FS_Uri *uri;
80 char *uric;
81 struct GNUNET_FS_Uri *uri2;
82 struct GNUNET_FS_Uri *baseURI;
83 char *emsg = NULL;
84 struct GNUNET_CRYPTO_EddsaPrivateKey pk;
85
86 baseURI =
87 GNUNET_FS_uri_parse
88 (
89 "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999",
90 &emsg);
91 GNUNET_assert (baseURI != NULL);
92 GNUNET_assert (emsg == NULL);
93 GNUNET_CRYPTO_eddsa_key_create (&pk);
94 uri = GNUNET_FS_uri_loc_create (baseURI,
95 &pk,
96 GNUNET_TIME_absolute_get ());
97 if (NULL == uri)
98 {
99 GNUNET_break (0);
100 GNUNET_FS_uri_destroy (baseURI);
101 return 1;
102 }
103 if (! GNUNET_FS_uri_test_loc (uri))
104 {
105 GNUNET_break (0);
106 GNUNET_FS_uri_destroy (uri);
107 GNUNET_FS_uri_destroy (baseURI);
108 return 1;
109 }
110 uri2 = GNUNET_FS_uri_loc_get_uri (uri);
111 if (! GNUNET_FS_uri_test_equal (baseURI, uri2))
112 {
113 GNUNET_break (0);
114 GNUNET_FS_uri_destroy (uri);
115 GNUNET_FS_uri_destroy (uri2);
116 GNUNET_FS_uri_destroy (baseURI);
117 return 1;
118 }
119 GNUNET_FS_uri_destroy (uri2);
120 GNUNET_FS_uri_destroy (baseURI);
121 uric = GNUNET_FS_uri_to_string (uri);
122#if 0
123 /* not for the faint of heart: */
124 printf ("URI: `%s'\n", uric);
125#endif
126 uri2 = GNUNET_FS_uri_parse (uric, &emsg);
127 GNUNET_free (uric);
128 if (uri2 == NULL)
129 {
130 fprintf (stderr, "URI parsing failed: %s\n", emsg);
131 GNUNET_break (0);
132 GNUNET_FS_uri_destroy (uri);
133 GNUNET_free (emsg);
134 return 1;
135 }
136 GNUNET_assert (NULL == emsg);
137 if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2))
138 {
139 GNUNET_break (0);
140 GNUNET_FS_uri_destroy (uri);
141 GNUNET_FS_uri_destroy (uri2);
142 return 1;
143 }
144 GNUNET_FS_uri_destroy (uri2);
145 GNUNET_FS_uri_destroy (uri);
146 return 0;
147}
148
149
150static int
151testNamespace (int i)
152{
153 char *uri;
154 struct GNUNET_FS_Uri *ret;
155 char *emsg;
156 struct GNUNET_CRYPTO_EcdsaPrivateKey ph;
157 struct GNUNET_CRYPTO_EcdsaPublicKey id;
158 char buf[1024];
159 char ubuf[1024];
160 char *sret;
161
162 if (NULL !=
163 (ret =
164 GNUNET_FS_uri_parse (
165 "gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK",
166 &emsg)))
167 {
168 GNUNET_FS_uri_destroy (ret);
169 GNUNET_assert (0);
170 }
171 GNUNET_free (emsg);
172 if (NULL !=
173 (ret =
174 GNUNET_FS_uri_parse
175 (
176 "gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this",
177 &emsg)))
178 {
179 GNUNET_FS_uri_destroy (ret);
180 GNUNET_assert (0);
181 }
182 GNUNET_free (emsg);
183 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg)))
184 {
185 GNUNET_FS_uri_destroy (ret);
186 GNUNET_assert (0);
187 }
188 GNUNET_free (emsg);
189 GNUNET_CRYPTO_ecdsa_key_create (&ph);
190 GNUNET_CRYPTO_ecdsa_key_get_public (&ph,
191 &id);
192 sret = GNUNET_STRINGS_data_to_string (&id, sizeof(id),
193 ubuf, sizeof(ubuf) - 1);
194 GNUNET_assert (NULL != sret);
195 sret[0] = '\0';
196 GNUNET_snprintf (buf, sizeof(buf),
197 "gnunet://fs/sks/%s/test",
198 ubuf);
199 ret = GNUNET_FS_uri_parse (buf, &emsg);
200 if (NULL == ret)
201 {
202 GNUNET_free (emsg);
203 GNUNET_assert (0);
204 }
205 if (GNUNET_FS_uri_test_ksk (ret))
206 {
207 GNUNET_FS_uri_destroy (ret);
208 GNUNET_assert (0);
209 }
210 if (! GNUNET_FS_uri_test_sks (ret))
211 {
212 GNUNET_FS_uri_destroy (ret);
213 GNUNET_assert (0);
214 }
215
216 uri = GNUNET_FS_uri_to_string (ret);
217 if (0 !=
218 strcmp (uri,
219 buf))
220 {
221 GNUNET_FS_uri_destroy (ret);
222 GNUNET_free (uri);
223 GNUNET_assert (0);
224 }
225 GNUNET_free (uri);
226 GNUNET_FS_uri_destroy (ret);
227 return 0;
228}
229
230
231static int
232testFile (int i)
233{
234 char *uri;
235 struct GNUNET_FS_Uri *ret;
236 char *emsg;
237
238 if (NULL !=
239 (ret =
240 GNUNET_FS_uri_parse
241 (
242 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
243 &emsg)))
244 {
245 GNUNET_FS_uri_destroy (ret);
246 GNUNET_assert (0);
247 }
248 GNUNET_free (emsg);
249 if (NULL !=
250 (ret =
251 GNUNET_FS_uri_parse
252 (
253 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
254 &emsg)))
255 {
256 GNUNET_FS_uri_destroy (ret);
257 GNUNET_assert (0);
258 }
259 GNUNET_free (emsg);
260 if (NULL !=
261 (ret =
262 GNUNET_FS_uri_parse
263 (
264 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
265 &emsg)))
266 {
267 GNUNET_FS_uri_destroy (ret);
268 GNUNET_assert (0);
269 }
270 GNUNET_free (emsg);
271 ret =
272 GNUNET_FS_uri_parse
273 (
274 "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42",
275 &emsg);
276 if (ret == NULL)
277 {
278 GNUNET_free (emsg);
279 GNUNET_assert (0);
280 }
281 if (GNUNET_FS_uri_test_ksk (ret))
282 {
283 GNUNET_FS_uri_destroy (ret);
284 GNUNET_assert (0);
285 }
286 if (GNUNET_FS_uri_test_sks (ret))
287 {
288 GNUNET_FS_uri_destroy (ret);
289 GNUNET_assert (0);
290 }
291 if (GNUNET_ntohll (ret->data.chk.file_length) != 42)
292 {
293 GNUNET_FS_uri_destroy (ret);
294 GNUNET_assert (0);
295 }
296
297 uri = GNUNET_FS_uri_to_string (ret);
298 if (0 !=
299 strcmp (uri,
300 "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42"))
301 {
302 GNUNET_free (uri);
303 GNUNET_FS_uri_destroy (ret);
304 GNUNET_assert (0);
305 }
306 GNUNET_free (uri);
307 GNUNET_FS_uri_destroy (ret);
308 return 0;
309}
310
311
312int
313main (int argc, char *argv[])
314{
315 int failureCount = 0;
316 int i;
317
318 GNUNET_log_setup ("test_fs_uri",
319 "WARNING",
320 NULL);
321 failureCount += testKeyword ();
322 failureCount += testLocation ();
323 for (i = 0; i < 255; i++)
324 {
325 /* fprintf (stderr, "%s", "."); */
326 failureCount += testNamespace (i);
327 failureCount += testFile (i);
328 }
329 /* fprintf (stderr, "%s", "\n"); */
330 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
331 if (failureCount != 0)
332 return 1;
333 return 0;
334}
335
336
337/* end of test_fs_uri.c */