2 This file is part of GNUnet.
3 (C) 2008 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 2, 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.
22 * @file util/test_container_multihashmap.c
23 * @brief Test for container_multihashmap.c
24 * @author Christian Grothoff
28 #include "gnunet_common.h"
29 #include "gnunet_container_lib.h"
31 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (m != NULL) GNUNET_CONTAINER_multihashmap_destroy(m); return 1; }
32 #define CHECK(c) { if (! (c)) ABORT(); }
37 struct GNUNET_CONTAINER_MultiHashMap *m;
43 CHECK (NULL != (m = GNUNET_CONTAINER_multihashmap_create (i)));
44 memset (&k1, 0, sizeof (k1));
45 memset (&k2, 1, sizeof (k2));
46 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k1));
47 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2));
48 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (m, &k1, NULL));
49 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (m, &k2, NULL));
50 CHECK (NULL == GNUNET_CONTAINER_multihashmap_get (m, &k1));
51 CHECK (NULL == GNUNET_CONTAINER_multihashmap_get (m, &k2));
52 CHECK (0 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
53 CHECK (0 == GNUNET_CONTAINER_multihashmap_size (m));
54 CHECK (0 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
56 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
58 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m,
61 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
62 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
63 CHECK (0 == strcmp ("v1", GNUNET_CONTAINER_multihashmap_get (m, &k1)));
64 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_put (m,
67 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
68 CHECK (1 == GNUNET_CONTAINER_multihashmap_size (m));
69 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m,
72 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
73 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m,
76 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
77 CHECK (3 == GNUNET_CONTAINER_multihashmap_size (m));
78 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (m, &k1, "v3"));
79 CHECK (2 == GNUNET_CONTAINER_multihashmap_size (m));
80 CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (m, &k1));
81 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k2));
83 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k1, NULL, NULL));
85 GNUNET_CONTAINER_multihashmap_get_multiple (m, &k2, NULL, NULL));
86 CHECK (2 == GNUNET_CONTAINER_multihashmap_iterate (m, NULL, NULL));
87 CHECK (2 == GNUNET_CONTAINER_multihashmap_remove_all (m, &k1));
88 for (j = 0; j < 1024; j++)
89 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (m,
92 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
93 GNUNET_CONTAINER_multihashmap_destroy (m);
98 main (int argc, char *argv[])
100 int failureCount = 0;
103 GNUNET_log_setup ("test-container-multihashmap", "WARNING", NULL);
104 for (i = 1; i < 255; i++)
105 failureCount += testMap (i);
106 if (failureCount != 0)
111 /* end of maptest.c */