2 This file is part of GNUnet.
3 Copyright (C) 2003-2014 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_uri.c
22 * @brief Test for fs_uri.c
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_fs_service.h"
35 struct GNUNET_FS_Uri *ret;
38 if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/++", &emsg)))
40 GNUNET_FS_uri_destroy(ret);
44 ret = GNUNET_FS_uri_parse("gnunet://fs/ksk/foo+bar", &emsg);
50 if (!GNUNET_FS_uri_test_ksk(ret))
52 GNUNET_FS_uri_destroy(ret);
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])))
59 GNUNET_FS_uri_destroy(ret);
63 uri = GNUNET_FS_uri_to_string(ret);
64 if (0 != strcmp(uri, "gnunet://fs/ksk/foo+bar"))
67 GNUNET_FS_uri_destroy(ret);
71 GNUNET_FS_uri_destroy(ret);
79 struct GNUNET_FS_Uri *uri;
81 struct GNUNET_FS_Uri *uri2;
82 struct GNUNET_FS_Uri *baseURI;
84 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
88 ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.15999",
90 GNUNET_assert(baseURI != NULL);
91 GNUNET_assert(emsg == NULL);
92 pk = GNUNET_CRYPTO_eddsa_key_create();
93 uri = GNUNET_FS_uri_loc_create(baseURI,
95 GNUNET_TIME_absolute_get());
100 GNUNET_FS_uri_destroy(baseURI);
103 if (!GNUNET_FS_uri_test_loc(uri))
106 GNUNET_FS_uri_destroy(uri);
107 GNUNET_FS_uri_destroy(baseURI);
110 uri2 = GNUNET_FS_uri_loc_get_uri(uri);
111 if (!GNUNET_FS_uri_test_equal(baseURI, uri2))
114 GNUNET_FS_uri_destroy(uri);
115 GNUNET_FS_uri_destroy(uri2);
116 GNUNET_FS_uri_destroy(baseURI);
119 GNUNET_FS_uri_destroy(uri2);
120 GNUNET_FS_uri_destroy(baseURI);
121 uric = GNUNET_FS_uri_to_string(uri);
123 /* not for the faint of heart: */
124 printf("URI: `%s'\n", uric);
126 uri2 = GNUNET_FS_uri_parse(uric, &emsg);
130 fprintf(stderr, "URI parsing failed: %s\n", emsg);
132 GNUNET_FS_uri_destroy(uri);
136 GNUNET_assert(NULL == emsg);
137 if (GNUNET_YES != GNUNET_FS_uri_test_equal(uri, uri2))
140 GNUNET_FS_uri_destroy(uri);
141 GNUNET_FS_uri_destroy(uri2);
144 GNUNET_FS_uri_destroy(uri2);
145 GNUNET_FS_uri_destroy(uri);
154 struct GNUNET_FS_Uri *ret;
156 struct GNUNET_CRYPTO_EcdsaPrivateKey *ph;
157 struct GNUNET_CRYPTO_EcdsaPublicKey id;
164 GNUNET_FS_uri_parse("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK",
167 GNUNET_FS_uri_destroy(ret);
174 ("gnunet://fs/sks/XQHH4R288W26EBV369F6RCE0PJVJTX2Y74Q2FJPMPGA31HJX2JG/this", &emsg)))
176 GNUNET_FS_uri_destroy(ret);
180 if (NULL != (ret = GNUNET_FS_uri_parse("gnunet://fs/sks/test", &emsg)))
182 GNUNET_FS_uri_destroy(ret);
186 ph = GNUNET_CRYPTO_ecdsa_key_create();
187 GNUNET_CRYPTO_ecdsa_key_get_public(ph, &id);
188 sret = GNUNET_STRINGS_data_to_string(&id, sizeof(id),
189 ubuf, sizeof(ubuf) - 1);
190 GNUNET_assert(NULL != sret);
192 GNUNET_snprintf(buf, sizeof(buf),
193 "gnunet://fs/sks/%s/test",
195 ret = GNUNET_FS_uri_parse(buf, &emsg);
201 if (GNUNET_FS_uri_test_ksk(ret))
203 GNUNET_FS_uri_destroy(ret);
206 if (!GNUNET_FS_uri_test_sks(ret))
208 GNUNET_FS_uri_destroy(ret);
212 uri = GNUNET_FS_uri_to_string(ret);
217 GNUNET_FS_uri_destroy(ret);
222 GNUNET_FS_uri_destroy(ret);
231 struct GNUNET_FS_Uri *ret;
237 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
240 GNUNET_FS_uri_destroy(ret);
247 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
250 GNUNET_FS_uri_destroy(ret);
257 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
260 GNUNET_FS_uri_destroy(ret);
266 ("gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42",
273 if (GNUNET_FS_uri_test_ksk(ret))
275 GNUNET_FS_uri_destroy(ret);
278 if (GNUNET_FS_uri_test_sks(ret))
280 GNUNET_FS_uri_destroy(ret);
283 if (GNUNET_ntohll(ret->data.chk.file_length) != 42)
285 GNUNET_FS_uri_destroy(ret);
289 uri = GNUNET_FS_uri_to_string(ret);
292 "gnunet://fs/chk/4QZP479A9SKGFNMQ2ZBCYE71YV2QMTVGWTVPB6A10ASVCKXDHB05DKPSC7ZF6E9P9W1VE47394EQY7NXA47Q6R35M7P1MJPGP59D1Z8.D54QD1K5XCG5878T6YZ19AM60MQ6FC0YNVK7QY08KK0KM0FJJ3KQWYG112FN5T07KN7J0X35DF6WVBT9B8ZMZ3X2BXJ22X3KFQ6MV2G.42"))
295 GNUNET_FS_uri_destroy(ret);
299 GNUNET_FS_uri_destroy(ret);
305 main(int argc, char *argv[])
307 int failureCount = 0;
310 GNUNET_log_setup("test_fs_uri",
313 failureCount += testKeyword();
314 failureCount += testLocation();
315 for (i = 0; i < 255; i++)
317 /* fprintf (stderr, "%s", "."); */
318 failureCount += testNamespace(i);
319 failureCount += testFile(i);
321 /* fprintf (stderr, "%s", "\n"); */
322 GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-uri");
323 if (failureCount != 0)
328 /* end of test_fs_uri.c */