From 9a10e9c06a3b08c8ab73edb7d2093a6d452ecc05 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 21 Aug 2009 08:41:21 +0000 Subject: fixes --- src/fs/test_fs_uri.c | 170 ++++++++++++++++++++++++++------------------------- 1 file changed, 87 insertions(+), 83 deletions(-) (limited to 'src/fs/test_fs_uri.c') diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index f07ba4179..6da56a742 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2003, 2004, 2006, 2007 Christian Grothoff (and other contributing authors) + (C) 2003, 2004, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -35,104 +35,110 @@ static int testKeyword () { char *uri; - struct GNUNET_ECRS_URI *ret; + struct GNUNET_FS_Uri *ret; + char *emsg; - if (NULL != GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/ksk/++")) + if (NULL != GNUNET_FS_uri_parse ("gnunet://ecrs/ksk/++", &emsg)) ABORT (); - ret = GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/ksk/foo+bar"); + GNUNET_free (emsg); + ret = GNUNET_FS_uri_parse ("gnunet://ecrs/ksk/foo+bar", &emsg); if (ret == NULL) ABORT (); - if (!GNUNET_ECRS_uri_test_ksk (ret)) + if (!GNUNET_FS_uri_test_ksk (ret)) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } if ((2 != ret->data.ksk.keywordCount) || (0 != strcmp (" foo", ret->data.ksk.keywords[0])) || (0 != strcmp (" bar", ret->data.ksk.keywords[1]))) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - uri = GNUNET_ECRS_uri_to_string (ret); + uri = GNUNET_FS_uri_to_string (ret); if (0 != strcmp (uri, "gnunet://ecrs/ksk/foo+bar")) { GNUNET_free (uri); - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } GNUNET_free (uri); - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); return 0; } static int testLocation () { - struct GNUNET_ECRS_URI *uri; + struct GNUNET_FS_Uri *uri; char *uric; - struct GNUNET_ECRS_URI *uri2; - GNUNET_RSA_PublicKey pk; - struct GNUNET_RSA_PrivateKey *hk; - struct GNUNET_ECRS_URI *baseURI; + struct GNUNET_FS_Uri *uri2; + struct GNUNET_FS_Uri *baseURI; + char *emsg; + struct GNUNET_CONFIGURATION_Handle *cfg; baseURI = - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"); - hk = GNUNET_RSA_create_key (); - GNUNET_RSA_get_public_key (hk, &pk); - uri = GNUNET_ECRS_location_to_uri (baseURI, - &pk, 43, - (GNUNET_ECRS_SignFunction) & - GNUNET_RSA_sign, hk); - GNUNET_RSA_free_key (hk); + GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); + GNUNET_assert (baseURI != NULL); + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != + GNUNET_CONFIGURATION_parse (cfg, "test_fs_uri_data.conf")) + { + fprintf (stderr, "Failed to parse configuration file\n"); + GNUNET_CONFIGURATION_destroy (cfg); + return 1; + } + uri = GNUNET_FS_uri_loc_create (baseURI, + cfg, + GNUNET_TIME_absolute_get ()); if (uri == NULL) { - GNUNET_GE_BREAK (NULL, 0); - GNUNET_ECRS_uri_destroy (baseURI); + GNUNET_break (0); + GNUNET_FS_uri_destroy (baseURI); return 1; } - if (!GNUNET_ECRS_uri_test_loc (uri)) + if (!GNUNET_FS_uri_test_loc (uri)) { - GNUNET_GE_BREAK (NULL, 0); - GNUNET_ECRS_uri_destroy (uri); - GNUNET_ECRS_uri_destroy (baseURI); + GNUNET_break (0); + GNUNET_FS_uri_destroy (uri); + GNUNET_FS_uri_destroy (baseURI); return 1; } - uri2 = GNUNET_ECRS_uri_get_content_uri_from_loc (uri); - if (!GNUNET_ECRS_uri_test_equal (baseURI, uri2)) + uri2 = GNUNET_FS_uri_loc_get_uri (uri); + if (!GNUNET_FS_uri_test_equal (baseURI, uri2)) { - GNUNET_GE_BREAK (NULL, 0); - GNUNET_ECRS_uri_destroy (uri); - GNUNET_ECRS_uri_destroy (uri2); - GNUNET_ECRS_uri_destroy (baseURI); + GNUNET_break (0); + GNUNET_FS_uri_destroy (uri); + GNUNET_FS_uri_destroy (uri2); + GNUNET_FS_uri_destroy (baseURI); return 1; } - GNUNET_ECRS_uri_destroy (uri2); - GNUNET_ECRS_uri_destroy (baseURI); - uric = GNUNET_ECRS_uri_to_string (uri); + GNUNET_FS_uri_destroy (uri2); + GNUNET_FS_uri_destroy (baseURI); + uric = GNUNET_FS_uri_to_string (uri); #if 0 /* not for the faint of heart: */ printf ("URI: `%s'\n", uric); #endif - uri2 = GNUNET_ECRS_string_to_uri (NULL, uric); + uri2 = GNUNET_FS_uri_parse (uric, &emsg); GNUNET_free (uric); if (uri2 == NULL) { - GNUNET_GE_BREAK (NULL, 0); - GNUNET_ECRS_uri_destroy (uri); + GNUNET_break (0); + GNUNET_FS_uri_destroy (uri); return 1; } - if (GNUNET_YES != GNUNET_ECRS_uri_test_equal (uri, uri2)) + if (GNUNET_YES != GNUNET_FS_uri_test_equal (uri, uri2)) { - GNUNET_GE_BREAK (NULL, 0); - GNUNET_ECRS_uri_destroy (uri); - GNUNET_ECRS_uri_destroy (uri2); + GNUNET_break (0); + GNUNET_FS_uri_destroy (uri); + GNUNET_FS_uri_destroy (uri2); return 1; } - GNUNET_ECRS_uri_destroy (uri2); - GNUNET_ECRS_uri_destroy (uri); + GNUNET_FS_uri_destroy (uri2); + GNUNET_FS_uri_destroy (uri); return 0; } @@ -140,44 +146,42 @@ static int testNamespace (int i) { char *uri; - struct GNUNET_ECRS_URI *ret; + struct GNUNET_FS_Uri *ret; + char *emsg; if (NULL != - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK")) + GNUNET_FS_uri_parse ("gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3VUK", &emsg)) ABORT (); if (NULL != - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test")) + GNUNET_FS_uri_parse ("gnunet://ecrs/sks/D1KJS9H2A82Q65VKQ0ML3RFU6U1D3V/test", &emsg)) ABORT (); - if (NULL != GNUNET_ECRS_string_to_uri (NULL, "gnunet://ecrs/sks/test")) + if (NULL != GNUNET_FS_uri_parse ("gnunet://ecrs/sks/test", &emsg)) ABORT (); ret = - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test"); + GNUNET_FS_uri_parse ("gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test", &emsg); if (ret == NULL) ABORT (); - if (GNUNET_ECRS_uri_test_ksk (ret)) + if (GNUNET_FS_uri_test_ksk (ret)) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - if (!GNUNET_ECRS_uri_test_sks (ret)) + if (!GNUNET_FS_uri_test_sks (ret)) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - uri = GNUNET_ECRS_uri_to_string (ret); + uri = GNUNET_FS_uri_to_string (ret); if (0 != strcmp (uri, "gnunet://ecrs/sks/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820/test")) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); GNUNET_free (uri); ABORT (); } GNUNET_free (uri); - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); return 0; } @@ -185,51 +189,51 @@ static int testFile (int i) { char *uri; - struct GNUNET_ECRS_URI *ret; + struct GNUNET_FS_Uri *ret; + char *emsg; if (NULL != - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42")) + GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H00000440000.42", &emsg)) ABORT (); + GNUNET_free (emsg); if (NULL != - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000")) + GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000", &emsg)) ABORT (); + GNUNET_free (emsg); if (NULL != - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH")) + GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.FGH", &emsg)) ABORT (); + GNUNET_free (emsg); ret = - GNUNET_ECRS_string_to_uri (NULL, - "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42"); + GNUNET_FS_uri_parse ("gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42", &emsg); if (ret == NULL) ABORT (); - if (GNUNET_ECRS_uri_test_ksk (ret)) + if (GNUNET_FS_uri_test_ksk (ret)) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - if (GNUNET_ECRS_uri_test_sks (ret)) + if (GNUNET_FS_uri_test_sks (ret)) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - if (GNUNET_ntohll (ret->data.fi.file_length) != 42) + if (GNUNET_ntohll (ret->data.chk.file_length) != 42) { - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } - uri = GNUNET_ECRS_uri_to_string (ret); + uri = GNUNET_FS_uri_to_string (ret); if (0 != strcmp (uri, "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42")) { GNUNET_free (uri); - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); ABORT (); } GNUNET_free (uri); - GNUNET_ECRS_uri_destroy (ret); + GNUNET_FS_uri_destroy (ret); return 0; } @@ -239,7 +243,7 @@ main (int argc, char *argv[]) int failureCount = 0; int i; - GNUNET_disable_entropy_gathering (); + GNUNET_CRYPTO_random_disable_entropy_gathering (); failureCount += testKeyword (); failureCount += testLocation (); for (i = 0; i < 255; i++) @@ -252,4 +256,4 @@ main (int argc, char *argv[]) return 0; } -/* end of uritest.c */ +/* end of test_fs_uri.c */ -- cgit v1.2.3