2 This file is part of GNUnet.
3 Copyright (C) 2008 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
22 * @file util/test_container_multihashmap32.c
23 * @brief Test for container_multihashmap32.c
24 * @author Christian Grothoff
25 * @author Sree Harsha Totakura
29 #include "gnunet_util_lib.h"
31 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (m != NULL) GNUNET_CONTAINER_multihashmap32_destroy(m); return 1; }
32 #define CHECK(c) { if (! (c)) ABORT(); }
37 struct GNUNET_CONTAINER_MultiHashMap32 *m;
43 CHECK (NULL != (m = GNUNET_CONTAINER_multihashmap32_create (i)));
46 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k1));
47 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k2));
48 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_remove (m, k1, NULL));
49 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_remove (m, k2, NULL));
50 CHECK (NULL == GNUNET_CONTAINER_multihashmap32_get (m, k1));
51 CHECK (NULL == GNUNET_CONTAINER_multihashmap32_get (m, k2));
52 CHECK (0 == GNUNET_CONTAINER_multihashmap32_remove_all (m, k1));
53 CHECK (0 == GNUNET_CONTAINER_multihashmap32_size (m));
54 CHECK (0 == GNUNET_CONTAINER_multihashmap32_iterate (m, NULL, NULL));
55 CHECK (0 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k1, NULL, NULL));
58 GNUNET_CONTAINER_multihashmap32_put (m, k1, "v1",
59 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
60 CHECK (1 == GNUNET_CONTAINER_multihashmap32_size (m));
61 ret = GNUNET_CONTAINER_multihashmap32_get (m, k1);
62 GNUNET_assert (ret != NULL);
63 CHECK (0 == strcmp ("v1", ret));
65 GNUNET_CONTAINER_multihashmap32_put (m, k1, "v1",
66 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
67 CHECK (1 == GNUNET_CONTAINER_multihashmap32_size (m));
69 GNUNET_CONTAINER_multihashmap32_put (m, k1, "v2",
70 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
72 GNUNET_CONTAINER_multihashmap32_put (m, k1, "v3",
73 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
74 CHECK (3 == GNUNET_CONTAINER_multihashmap32_size (m));
75 CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_remove (m, k1, "v3"));
76 CHECK (2 == GNUNET_CONTAINER_multihashmap32_size (m));
77 CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (m, k1));
78 CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k2));
79 CHECK (2 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k1, NULL, NULL));
80 CHECK (0 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k2, NULL, NULL));
81 CHECK (2 == GNUNET_CONTAINER_multihashmap32_iterate (m, NULL, NULL));
82 CHECK (2 == GNUNET_CONTAINER_multihashmap32_remove_all (m, k1));
83 for (j = 0; j < 1024; j++)
85 GNUNET_CONTAINER_multihashmap32_put (m, k1, "v2",
86 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
87 GNUNET_CONTAINER_multihashmap32_destroy (m);
92 main (int argc, char *argv[])
97 GNUNET_log_setup ("test-container-multihashmap", "WARNING", NULL);
98 for (i = 1; i < 255; i++)
99 failureCount += testMap (i);
100 if (failureCount != 0)
105 /* end of test_container_multihashmap.c */