aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/test_datacache_quota.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datacache/test_datacache_quota.c')
-rw-r--r--src/datacache/test_datacache_quota.c80
1 files changed, 54 insertions, 26 deletions
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index 78b56ce42..21e373608 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.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_quota.c 19 * @file datacache/test_datacache_quota.c
@@ -43,44 +41,63 @@ static const char *plugin_name;
43 * some of the data from the last iteration is still there. 41 * some of the data from the last iteration is still there.
44 */ 42 */
45static void 43static void
46run (void *cls, char *const *args, const char *cfgfile, 44run (void *cls,
45 char *const *args,
46 const char *cfgfile,
47 const struct GNUNET_CONFIGURATION_Handle *cfg) 47 const struct GNUNET_CONFIGURATION_Handle *cfg)
48{ 48{
49 struct GNUNET_DATACACHE_Handle *h; 49 struct GNUNET_DATACACHE_Handle *h;
50 struct GNUNET_HashCode k; 50 struct GNUNET_HashCode k;
51 struct GNUNET_HashCode n; 51 struct GNUNET_HashCode n;
52 unsigned int i;
53 unsigned int j;
54 char buf[3200]; 52 char buf[3200];
55 struct GNUNET_TIME_Absolute exp; 53 struct GNUNET_TIME_Absolute exp;
56 54
55 (void) cls;
56 (void) args;
57 (void) cfgfile;
57 ok = 0; 58 ok = 0;
58 h = GNUNET_DATACACHE_create (cfg, "testcache"); 59 h = GNUNET_DATACACHE_create (cfg,
60 "testcache");
59 61
60 if (h == NULL) 62 if (h == NULL)
61 { 63 {
62 FPRINTF (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 64 FPRINTF (stderr,
65 "%s",
66 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
63 return; 67 return;
64 } 68 }
65 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); 69 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
66 memset (buf, 1, sizeof (buf)); 70 memset (buf, 1, sizeof (buf));
67 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 71 memset (&k, 0, sizeof (struct GNUNET_HashCode));
68 for (i = 0; i < 10; i++) 72 for (unsigned int i = 0; i < 10; i++)
69 { 73 {
70 FPRINTF (stderr, "%s", "."); 74 FPRINTF (stderr,
71 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 75 "%s",
72 for (j = i; j < sizeof (buf); j += 10) 76 ".");
77 GNUNET_CRYPTO_hash (&k,
78 sizeof (struct GNUNET_HashCode),
79 &n);
80 for (unsigned int j = i; j < sizeof (buf); j += 10)
73 { 81 {
74 exp.abs_value_us++; 82 exp.abs_value_us++;
75 buf[j] = i; 83 buf[j] = i;
76 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, &k, j, buf, 1 + i, exp, 0, NULL)); 84 ASSERT (GNUNET_OK ==
85 GNUNET_DATACACHE_put (h,
86 &k,
87 GNUNET_YES,
88 j,
89 buf,
90 1 + i,
91 exp,
92 0,
93 NULL));
77 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); 94 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
78 } 95 }
79 k = n; 96 k = n;
80 } 97 }
81 FPRINTF (stderr, "%s", "\n"); 98 FPRINTF (stderr, "%s", "\n");
82 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 99 memset (&k, 0, sizeof (struct GNUNET_HashCode));
83 for (i = 0; i < 10; i++) 100 for (unsigned int i = 0; i < 10; i++)
84 { 101 {
85 FPRINTF (stderr, "%s", "."); 102 FPRINTF (stderr, "%s", ".");
86 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 103 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
@@ -101,7 +118,8 @@ FAILURE:
101 118
102 119
103int 120int
104main (int argc, char *argv[]) 121main (int argc,
122 char *argv[])
105{ 123{
106 char cfg_name[128]; 124 char cfg_name[128];
107 char *const xargv[] = { 125 char *const xargv[] = {
@@ -114,17 +132,27 @@ main (int argc, char *argv[])
114 GNUNET_GETOPT_OPTION_END 132 GNUNET_GETOPT_OPTION_END
115 }; 133 };
116 134
135 (void) argc;
117 GNUNET_log_setup ("test-datacache-quota", 136 GNUNET_log_setup ("test-datacache-quota",
118 "WARNING", 137 "WARNING",
119 NULL); 138 NULL);
120 139
121 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 140 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
122 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", 141 GNUNET_snprintf (cfg_name,
142 sizeof (cfg_name),
143 "test_datacache_data_%s.conf",
123 plugin_name); 144 plugin_name);
124 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 145 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
125 "test-datacache-quota", "nohelp", options, &run, NULL); 146 xargv,
147 "test-datacache-quota",
148 "nohelp",
149 options,
150 &run,
151 NULL);
126 if (0 != ok) 152 if (0 != ok)
127 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 153 FPRINTF (stderr,
154 "Missed some testcases: %d\n",
155 ok);
128 return ok; 156 return ok;
129} 157}
130 158