2 This file is part of GNUnet.
3 (C) 2003, 2004, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
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_CONFIGURATION_Handle *cfg;
88 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
90 GNUNET_assert (baseURI != NULL);
91 GNUNET_assert (emsg == NULL);
92 cfg = GNUNET_CONFIGURATION_create ();
93 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, "test_fs_uri_data.conf"))
95 FPRINTF (stderr, "%s", "Failed to parse configuration file\n");
96 GNUNET_FS_uri_destroy (baseURI);
97 GNUNET_CONFIGURATION_destroy (cfg);
100 uri = GNUNET_FS_uri_loc_create (baseURI, cfg, GNUNET_TIME_absolute_get ());
104 GNUNET_FS_uri_destroy (baseURI);
105 GNUNET_CONFIGURATION_destroy (cfg);
108 if (!GNUNET_FS_uri_test_loc (uri))
111 GNUNET_FS_uri_destroy (uri);
112 GNUNET_FS_uri_destroy (baseURI);
113 GNUNET_CONFIGURATION_destroy (cfg);
116 uri2 = GNUNET_FS_uri_loc_get_uri (uri);
117 if (!GNUNET_FS_uri_test_equal (baseURI, uri2))
120 GNUNET_FS_uri_destroy (uri);
121 GNUNET_FS_uri_destroy (uri2);
122 GNUNET_FS_uri_destroy (baseURI);
123 GNUNET_CONFIGURATION_destroy (cfg);
126 GNUNET_FS_uri_destroy (uri2);
127 GNUNET_FS_uri_destroy (baseURI);
128 uric = GNUNET_FS_uri_to_string (uri);
130 /* not for the faint of heart: */
131 printf ("URI: `%s'\n", uric);
133 uri2 = GNUNET_FS_uri_parse (uric, &emsg);
137 fprintf (stderr, "URI parsing failed: %s\n", emsg);
139 GNUNET_FS_uri_destroy (uri);
140 GNUNET_CONFIGURATION_destroy (cfg);
144 GNUNET_assert (NULL == emsg);
145 if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2))
148 GNUNET_FS_uri_destroy (uri);
149 GNUNET_FS_uri_destroy (uri2);
150 GNUNET_CONFIGURATION_destroy (cfg);
153 GNUNET_FS_uri_destroy (uri2);
154 GNUNET_FS_uri_destroy (uri);
155 GNUNET_CONFIGURATION_destroy (cfg);
161 testNamespace (int i)
164 struct GNUNET_FS_Uri *ret;
166 struct GNUNET_CRYPTO_EcdsaPrivateKey *ph;
167 struct GNUNET_CRYPTO_EcdsaPublicKey id;
174 GNUNET_FS_uri_parse ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK",
177 GNUNET_FS_uri_destroy (ret);
184 ("gnunet://fs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)))
186 GNUNET_FS_uri_destroy (ret);
190 if (NULL != (ret = GNUNET_FS_uri_parse ("gnunet://fs/sks/test", &emsg)))
192 GNUNET_FS_uri_destroy (ret);
196 ph = GNUNET_CRYPTO_ecdsa_key_create ();
197 GNUNET_CRYPTO_ecdsa_key_get_public (ph, &id);
198 sret = GNUNET_STRINGS_data_to_string (&id, sizeof (id),
199 ubuf, sizeof (ubuf) - 1);
200 GNUNET_assert (NULL != sret);
202 GNUNET_snprintf (buf, sizeof (buf),
203 "gnunet://fs/sks/%s/test",
205 ret = GNUNET_FS_uri_parse (buf, &emsg);
211 if (GNUNET_FS_uri_test_ksk (ret))
213 GNUNET_FS_uri_destroy (ret);
216 if (!GNUNET_FS_uri_test_sks (ret))
218 GNUNET_FS_uri_destroy (ret);
222 uri = GNUNET_FS_uri_to_string (ret);
227 GNUNET_FS_uri_destroy (ret);
232 GNUNET_FS_uri_destroy (ret);
241 struct GNUNET_FS_Uri *ret;
247 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42",
250 GNUNET_FS_uri_destroy (ret);
257 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000",
260 GNUNET_FS_uri_destroy (ret);
267 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH",
270 GNUNET_FS_uri_destroy (ret);
276 ("gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42",
283 if (GNUNET_FS_uri_test_ksk (ret))
285 GNUNET_FS_uri_destroy (ret);
288 if (GNUNET_FS_uri_test_sks (ret))
290 GNUNET_FS_uri_destroy (ret);
293 if (GNUNET_ntohll (ret->data.chk.file_length) != 42)
295 GNUNET_FS_uri_destroy (ret);
299 uri = GNUNET_FS_uri_to_string (ret);
302 "gnunet://fs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"))
305 GNUNET_FS_uri_destroy (ret);
309 GNUNET_FS_uri_destroy (ret);
315 main (int argc, char *argv[])
317 int failureCount = 0;
320 GNUNET_log_setup ("test_fs_uri",
323 failureCount += testKeyword ();
324 failureCount += testLocation ();
325 for (i = 0; i < 255; i++)
327 /* FPRINTF (stderr, "%s", "."); */
328 failureCount += testNamespace (i);
329 failureCount += testFile (i);
331 /* FPRINTF (stderr, "%s", "\n"); */
332 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
333 if (failureCount != 0)
338 /* end of test_fs_uri.c */