diff options
author | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2009-08-21 08:41:21 +0000 |
---|---|---|
committer | grothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96> | 2009-08-21 08:41:21 +0000 |
commit | c3a6f7844ec27d8eff49bac5c04ef7711c531b41 (patch) | |
tree | d9ee186c9f61fdc90f128cf39ed113112b21e8ec /src/fs/test_fs_directory.c | |
parent | 678204a33f36026057a3493a26cf4db3f05dc4e2 (diff) |
fixes
git-svn-id: https://gnunet.org/svn/gnunet@8840 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/fs/test_fs_directory.c')
-rw-r--r-- | src/fs/test_fs_directory.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c new file mode 100644 index 0000000000..d643e6ed97 --- /dev/null +++ b/src/fs/test_fs_directory.c @@ -0,0 +1,167 @@ +/* + This file is part of GNUnet. + (C) 2005, 2006, 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 + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file fs/test_fs_directory.c + * @brief Test for fs_directory.c + * @author Christian Grothoff + */ + +#include "platform.h" +#include <extractor.h> +#include "gnunet_util_lib.h" +#include "gnunet_fs_service.h" +#include "fs.h" + +#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } + +struct PCLS +{ + struct GNUNET_FS_Uri **uri; + struct GNUNET_CONTAINER_MetaData **md; + unsigned int pos; + unsigned int max; +}; + +static void +processor (void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *md, + size_t length, + const void *data) +{ + struct PCLS *p = cls; + int i; + + for (i = 0; i < p->max; i++) + { + if (GNUNET_CONTAINER_meta_data_test_equal (p->md[i], + md) && + GNUNET_FS_uri_test_equal (p->uri[i], uri)) + { + p->pos++; + return; + } + } + fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); +} + +static int +testDirectory (unsigned int i) +{ + char *data; + unsigned long long dlen; + struct GNUNET_FS_Uri **uris; + struct GNUNET_CONTAINER_MetaData **mds; + struct GNUNET_CONTAINER_MetaData *meta; + struct PCLS cls; + char *emsg; + int p; + int q; + char uri[512]; + char txt[128]; + int ret = 0; + + cls.max = i; + uris = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri*) * i); + mds = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData*) * i); + for (p = 0; p < i; p++) + { + mds[p] = GNUNET_CONTAINER_meta_data_create (); + for (q = 0; q <= p; q++) + { + GNUNET_snprintf (txt, sizeof(txt), "%u -- %u\n", p, q); + GNUNET_CONTAINER_meta_data_insert (mds[p], + q % + EXTRACTOR_getHighestKeywordTypeNumber + (), txt); + } + GNUNET_snprintf (uri, + sizeof(uri), + "gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.%u", + p); + uris[p] = GNUNET_FS_uri_parse (uri, &emsg); + if (uris[p] == NULL) + { + GNUNET_CONTAINER_meta_data_destroy (mds[p]); + while (--p > 0) + { + GNUNET_CONTAINER_meta_data_destroy (mds[p]); + GNUNET_FS_uri_destroy (uris[p]); + } + GNUNET_free (mds); + GNUNET_free (uris); + ABORT (); /* error in testcase */ + } + } + meta = GNUNET_CONTAINER_meta_data_create (); + GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_TITLE, "A title"); + GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_AUTHOR, "An author"); + if (GNUNET_OK != + GNUNET_FS_directory_create (&dlen, &data, i, uris, mds, meta)) + { + GNUNET_CONTAINER_meta_data_destroy (meta); + for (p = 0; p < i; p++) + { + GNUNET_CONTAINER_meta_data_destroy (mds[p]); + GNUNET_FS_uri_destroy (uris[p]); + } + GNUNET_free (uris); + GNUNET_free (mds); + ABORT (); + } + cls.pos = 0; + cls.uri = uris; + cls.md = mds; + GNUNET_FS_directory_list_contents (dlen, data, 0, + &processor, &cls); + GNUNET_assert (cls.pos == i); + GNUNET_free (data); + GNUNET_CONTAINER_meta_data_destroy (meta); + for (p = 0; p < i; p++) + { + GNUNET_CONTAINER_meta_data_destroy (mds[p]); + GNUNET_FS_uri_destroy (uris[p]); + } + GNUNET_free (uris); + GNUNET_free (mds); + return ret; +} + +int +main (int argc, char *argv[]) +{ + int failureCount = 0; + int i; + + for (i = 17; i < 2000; i *= 2) + { + fprintf (stderr, "."); + failureCount += testDirectory (i); + } + fprintf (stderr, "\n"); + + if (failureCount != 0) + return 1; + return 0; +} + +/* end of test_fs_directory.c */ |