diff options
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r-- | src/datacache/test_datacache.c | 101 |
1 files changed, 71 insertions, 30 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 79e6b6d74..50e45012d 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2006, 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2006, 2009, 2010 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /* | 18 | /* |
21 | * @file datacache/test_datacache.c | 19 | * @file datacache/test_datacache.c |
@@ -46,6 +44,11 @@ checkIt (void *cls, | |||
46 | unsigned int path_len, | 44 | unsigned int path_len, |
47 | const struct GNUNET_PeerIdentity *path) | 45 | const struct GNUNET_PeerIdentity *path) |
48 | { | 46 | { |
47 | (void) key; | ||
48 | (void) type; | ||
49 | (void) exp; | ||
50 | (void) path_len; | ||
51 | (void) path; | ||
49 | if (size != sizeof (struct GNUNET_HashCode)) | 52 | if (size != sizeof (struct GNUNET_HashCode)) |
50 | { | 53 | { |
51 | GNUNET_break (0); | 54 | GNUNET_break (0); |
@@ -61,17 +64,22 @@ checkIt (void *cls, | |||
61 | 64 | ||
62 | 65 | ||
63 | static void | 66 | static void |
64 | run (void *cls, char *const *args, const char *cfgfile, | 67 | run (void *cls, |
68 | char *const *args, | ||
69 | const char *cfgfile, | ||
65 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 70 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
66 | { | 71 | { |
67 | struct GNUNET_DATACACHE_Handle *h; | 72 | struct GNUNET_DATACACHE_Handle *h; |
68 | struct GNUNET_HashCode k; | 73 | struct GNUNET_HashCode k; |
69 | struct GNUNET_HashCode n; | 74 | struct GNUNET_HashCode n; |
70 | struct GNUNET_TIME_Absolute exp; | 75 | struct GNUNET_TIME_Absolute exp; |
71 | unsigned int i; | ||
72 | 76 | ||
77 | (void) cls; | ||
78 | (void) args; | ||
79 | (void) cfgfile; | ||
73 | ok = 0; | 80 | ok = 0; |
74 | h = GNUNET_DATACACHE_create (cfg, "testcache"); | 81 | h = GNUNET_DATACACHE_create (cfg, |
82 | "testcache"); | ||
75 | if (h == NULL) | 83 | if (h == NULL) |
76 | { | 84 | { |
77 | FPRINTF (stderr, | 85 | FPRINTF (stderr, |
@@ -83,32 +91,55 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
83 | exp = GNUNET_TIME_absolute_get (); | 91 | exp = GNUNET_TIME_absolute_get (); |
84 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; | 92 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; |
85 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | 93 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); |
86 | for (i = 0; i < 100; i++) | 94 | for (unsigned int i = 0; i < 100; i++) |
87 | { | 95 | { |
88 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 96 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); |
89 | ASSERT (GNUNET_OK == | 97 | ASSERT (GNUNET_OK == |
90 | GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), | 98 | GNUNET_DATACACHE_put (h, |
99 | &k, | ||
100 | GNUNET_YES, | ||
101 | sizeof (struct GNUNET_HashCode), | ||
91 | (const char *) &n, 1 + i % 16, exp, | 102 | (const char *) &n, 1 + i % 16, exp, |
92 | 0, NULL)); | 103 | 0, NULL)); |
93 | k = n; | 104 | k = n; |
94 | } | 105 | } |
95 | memset (&k, 0, sizeof (struct GNUNET_HashCode)); | 106 | memset (&k, |
96 | for (i = 0; i < 100; i++) | 107 | 0, |
108 | sizeof (struct GNUNET_HashCode)); | ||
109 | for (unsigned int i = 0; i < 100; i++) | ||
97 | { | 110 | { |
98 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 111 | GNUNET_CRYPTO_hash (&k, |
99 | ASSERT (1 == GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n)); | 112 | sizeof (struct GNUNET_HashCode), |
113 | &n); | ||
114 | ASSERT (1 == GNUNET_DATACACHE_get (h, | ||
115 | &k, | ||
116 | 1 + i % 16, | ||
117 | &checkIt, | ||
118 | &n)); | ||
100 | k = n; | 119 | k = n; |
101 | } | 120 | } |
102 | 121 | ||
103 | memset (&k, 42, sizeof (struct GNUNET_HashCode)); | 122 | memset (&k, |
104 | GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); | 123 | 42, |
124 | sizeof (struct GNUNET_HashCode)); | ||
125 | GNUNET_CRYPTO_hash (&k, | ||
126 | sizeof (struct GNUNET_HashCode), | ||
127 | &n); | ||
105 | ASSERT (GNUNET_OK == | 128 | ASSERT (GNUNET_OK == |
106 | GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), | 129 | GNUNET_DATACACHE_put (h, |
107 | (const char *) &n, 792, | 130 | &k, |
131 | GNUNET_YES, | ||
132 | sizeof (struct GNUNET_HashCode), | ||
133 | (const char *) &n, | ||
134 | 792, | ||
108 | GNUNET_TIME_UNIT_FOREVER_ABS, | 135 | GNUNET_TIME_UNIT_FOREVER_ABS, |
109 | 0, NULL)); | 136 | 0, |
110 | ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); | 137 | NULL)); |
111 | 138 | ASSERT (0 != GNUNET_DATACACHE_get (h, | |
139 | &k, | ||
140 | 792, | ||
141 | &checkIt, | ||
142 | &n)); | ||
112 | GNUNET_DATACACHE_destroy (h); | 143 | GNUNET_DATACACHE_destroy (h); |
113 | ASSERT (ok == 0); | 144 | ASSERT (ok == 0); |
114 | return; | 145 | return; |
@@ -133,16 +164,26 @@ main (int argc, char *argv[]) | |||
133 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END |
134 | }; | 165 | }; |
135 | 166 | ||
167 | (void) argc; | ||
136 | GNUNET_log_setup ("test-datacache", | 168 | GNUNET_log_setup ("test-datacache", |
137 | "WARNING", | 169 | "WARNING", |
138 | NULL); | 170 | NULL); |
139 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 171 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
140 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", | 172 | GNUNET_snprintf (cfg_name, |
173 | sizeof (cfg_name), | ||
174 | "test_datacache_data_%s.conf", | ||
141 | plugin_name); | 175 | plugin_name); |
142 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 176 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |
143 | "test-datacache", "nohelp", options, &run, NULL); | 177 | xargv, |
178 | "test-datacache", | ||
179 | "nohelp", | ||
180 | options, | ||
181 | &run, | ||
182 | NULL); | ||
144 | if ( (0 != ok) && (77 != ok) ) | 183 | if ( (0 != ok) && (77 != ok) ) |
145 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | 184 | FPRINTF (stderr, |
185 | "Missed some testcases: %d\n", | ||
186 | ok); | ||
146 | return ok; | 187 | return ok; |
147 | } | 188 | } |
148 | 189 | ||