diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-17 09:41:59 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-04-17 09:41:59 +0000 |
commit | 7e53c7855a15eb7049d391f1a1b32aff822c5c5b (patch) | |
tree | ed7e3decb1f79a7721675f4b532e8a684bf104a8 /src/util/test_container_multihashmap32.c | |
parent | 0555e4e107db9c0c1f0caa6c947881c32bf426f4 (diff) | |
download | gnunet-7e53c7855a15eb7049d391f1a1b32aff822c5c5b.tar.gz gnunet-7e53c7855a15eb7049d391f1a1b32aff822c5c5b.zip |
- 32-bit key hashmap
Diffstat (limited to 'src/util/test_container_multihashmap32.c')
-rw-r--r-- | src/util/test_container_multihashmap32.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/util/test_container_multihashmap32.c b/src/util/test_container_multihashmap32.c new file mode 100644 index 000000000..7997c73ac --- /dev/null +++ b/src/util/test_container_multihashmap32.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2008 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/test_container_multihashmap32.c | ||
23 | * @brief Test for container_multihashmap32.c | ||
24 | * @author Christian Grothoff | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_common.h" | ||
30 | #include "gnunet_container_lib.h" | ||
31 | |||
32 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (m != NULL) GNUNET_CONTAINER_multihashmap32_destroy(m); return 1; } | ||
33 | #define CHECK(c) { if (! (c)) ABORT(); } | ||
34 | |||
35 | static int | ||
36 | testMap (int i) | ||
37 | { | ||
38 | struct GNUNET_CONTAINER_MultiHashMap32 *m; | ||
39 | uint32_t k1; | ||
40 | uint32_t k2; | ||
41 | const char *ret; | ||
42 | int j; | ||
43 | |||
44 | CHECK (NULL != (m = GNUNET_CONTAINER_multihashmap32_create (i))); | ||
45 | k1 = 0; | ||
46 | k2 = UINT32_MAX; | ||
47 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k1)); | ||
48 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k2)); | ||
49 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_remove (m, k1, NULL)); | ||
50 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_remove (m, k2, NULL)); | ||
51 | CHECK (NULL == GNUNET_CONTAINER_multihashmap32_get (m, k1)); | ||
52 | CHECK (NULL == GNUNET_CONTAINER_multihashmap32_get (m, k2)); | ||
53 | CHECK (0 == GNUNET_CONTAINER_multihashmap32_remove_all (m, k1)); | ||
54 | CHECK (0 == GNUNET_CONTAINER_multihashmap32_size (m)); | ||
55 | CHECK (0 == GNUNET_CONTAINER_multihashmap32_iterate (m, NULL, NULL)); | ||
56 | CHECK (0 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k1, NULL, NULL)); | ||
57 | |||
58 | CHECK (GNUNET_OK == | ||
59 | GNUNET_CONTAINER_multihashmap32_put (m, k1, "v1", | ||
60 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); | ||
61 | CHECK (1 == GNUNET_CONTAINER_multihashmap32_size (m)); | ||
62 | ret = GNUNET_CONTAINER_multihashmap32_get (m, k1); | ||
63 | GNUNET_assert (ret != NULL); | ||
64 | CHECK (0 == strcmp ("v1", ret)); | ||
65 | CHECK (GNUNET_NO == | ||
66 | GNUNET_CONTAINER_multihashmap32_put (m, k1, "v1", | ||
67 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); | ||
68 | CHECK (1 == GNUNET_CONTAINER_multihashmap32_size (m)); | ||
69 | CHECK (GNUNET_OK == | ||
70 | GNUNET_CONTAINER_multihashmap32_put (m, k1, "v2", | ||
71 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
72 | CHECK (GNUNET_OK == | ||
73 | GNUNET_CONTAINER_multihashmap32_put (m, k1, "v3", | ||
74 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
75 | CHECK (3 == GNUNET_CONTAINER_multihashmap32_size (m)); | ||
76 | CHECK (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_remove (m, k1, "v3")); | ||
77 | CHECK (2 == GNUNET_CONTAINER_multihashmap32_size (m)); | ||
78 | CHECK (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (m, k1)); | ||
79 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap32_contains (m, k2)); | ||
80 | CHECK (2 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k1, NULL, NULL)); | ||
81 | CHECK (0 == GNUNET_CONTAINER_multihashmap32_get_multiple (m, k2, NULL, NULL)); | ||
82 | CHECK (2 == GNUNET_CONTAINER_multihashmap32_iterate (m, NULL, NULL)); | ||
83 | CHECK (2 == GNUNET_CONTAINER_multihashmap32_remove_all (m, k1)); | ||
84 | for (j = 0; j < 1024; j++) | ||
85 | CHECK (GNUNET_OK == | ||
86 | GNUNET_CONTAINER_multihashmap32_put (m, k1, "v2", | ||
87 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
88 | GNUNET_CONTAINER_multihashmap32_destroy (m); | ||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | int | ||
93 | main (int argc, char *argv[]) | ||
94 | { | ||
95 | int failureCount = 0; | ||
96 | int i; | ||
97 | |||
98 | GNUNET_log_setup ("test-container-multihashmap", "WARNING", NULL); | ||
99 | for (i = 1; i < 255; i++) | ||
100 | failureCount += testMap (i); | ||
101 | if (failureCount != 0) | ||
102 | return 1; | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | /* end of test_container_multihashmap.c */ | ||