summaryrefslogtreecommitdiff
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.c156
1 files changed, 79 insertions, 77 deletions
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index 36e369abb..26a23d632 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -27,7 +27,9 @@
27#include "gnunet_datacache_lib.h" 27#include "gnunet_datacache_lib.h"
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30#define ASSERT(x) do { if (!(x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE; } } while (0) 30#define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, \
31 __LINE__); goto FAILURE; \
32 } } while (0)
31 33
32static int ok; 34static int ok;
33 35
@@ -43,10 +45,10 @@ static const char *plugin_name;
43 * some of the data from the last iteration is still there. 45 * some of the data from the last iteration is still there.
44 */ 46 */
45static void 47static void
46run(void *cls, 48run (void *cls,
47 char *const *args, 49 char *const *args,
48 const char *cfgfile, 50 const char *cfgfile,
49 const struct GNUNET_CONFIGURATION_Handle *cfg) 51 const struct GNUNET_CONFIGURATION_Handle *cfg)
50{ 52{
51 struct GNUNET_DATACACHE_Handle *h; 53 struct GNUNET_DATACACHE_Handle *h;
52 struct GNUNET_HashCode k; 54 struct GNUNET_HashCode k;
@@ -54,74 +56,74 @@ run(void *cls,
54 char buf[3200]; 56 char buf[3200];
55 struct GNUNET_TIME_Absolute exp; 57 struct GNUNET_TIME_Absolute exp;
56 58
57 (void)cls; 59 (void) cls;
58 (void)args; 60 (void) args;
59 (void)cfgfile; 61 (void) cfgfile;
60 ok = 0; 62 ok = 0;
61 h = GNUNET_DATACACHE_create(cfg, 63 h = GNUNET_DATACACHE_create (cfg,
62 "testcache"); 64 "testcache");
63 65
64 if (h == NULL) 66 if (h == NULL)
65 { 67 {
66 fprintf(stderr, 68 fprintf (stderr,
67 "%s", 69 "%s",
68 "Failed to initialize datacache. Database likely not setup, skipping test.\n"); 70 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
69 return; 71 return;
70 } 72 }
71 exp = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS); 73 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
72 memset(buf, 1, sizeof(buf)); 74 memset (buf, 1, sizeof(buf));
73 memset(&k, 0, sizeof(struct GNUNET_HashCode)); 75 memset (&k, 0, sizeof(struct GNUNET_HashCode));
74 for (unsigned int i = 0; i < 10; i++) 76 for (unsigned int i = 0; i < 10; i++)
77 {
78 fprintf (stderr,
79 "%s",
80 ".");
81 GNUNET_CRYPTO_hash (&k,
82 sizeof(struct GNUNET_HashCode),
83 &n);
84 for (unsigned int j = i; j < sizeof(buf); j += 10)
75 { 85 {
76 fprintf(stderr, 86 exp.abs_value_us++;
77 "%s", 87 buf[j] = i;
78 "."); 88 ASSERT (GNUNET_OK ==
79 GNUNET_CRYPTO_hash(&k, 89 GNUNET_DATACACHE_put (h,
80 sizeof(struct GNUNET_HashCode), 90 &k,
81 &n); 91 GNUNET_YES,
82 for (unsigned int j = i; j < sizeof(buf); j += 10) 92 j,
83 { 93 buf,
84 exp.abs_value_us++; 94 1 + i,
85 buf[j] = i; 95 exp,
86 ASSERT(GNUNET_OK == 96 0,
87 GNUNET_DATACACHE_put(h, 97 NULL));
88 &k, 98 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
89 GNUNET_YES,
90 j,
91 buf,
92 1 + i,
93 exp,
94 0,
95 NULL));
96 ASSERT(0 < GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL));
97 }
98 k = n;
99 } 99 }
100 fprintf(stderr, "%s", "\n"); 100 k = n;
101 memset(&k, 0, sizeof(struct GNUNET_HashCode)); 101 }
102 fprintf (stderr, "%s", "\n");
103 memset (&k, 0, sizeof(struct GNUNET_HashCode));
102 for (unsigned int i = 0; i < 10; i++) 104 for (unsigned int i = 0; i < 10; i++)
103 { 105 {
104 fprintf(stderr, "%s", "."); 106 fprintf (stderr, "%s", ".");
105 GNUNET_CRYPTO_hash(&k, sizeof(struct GNUNET_HashCode), &n); 107 GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n);
106 if (i < 2) 108 if (i < 2)
107 ASSERT(0 == GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL)); 109 ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
108 if (i == 9) 110 if (i == 9)
109 ASSERT(0 < GNUNET_DATACACHE_get(h, &k, 1 + i, NULL, NULL)); 111 ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
110 k = n; 112 k = n;
111 } 113 }
112 fprintf(stderr, "%s", "\n"); 114 fprintf (stderr, "%s", "\n");
113 GNUNET_DATACACHE_destroy(h); 115 GNUNET_DATACACHE_destroy (h);
114 return; 116 return;
115FAILURE: 117FAILURE:
116 if (h != NULL) 118 if (h != NULL)
117 GNUNET_DATACACHE_destroy(h); 119 GNUNET_DATACACHE_destroy (h);
118 ok = GNUNET_SYSERR; 120 ok = GNUNET_SYSERR;
119} 121}
120 122
121 123
122int 124int
123main(int argc, 125main (int argc,
124 char *argv[]) 126 char *argv[])
125{ 127{
126 char cfg_name[PATH_MAX]; 128 char cfg_name[PATH_MAX];
127 char *const xargv[] = { 129 char *const xargv[] = {
@@ -134,27 +136,27 @@ main(int argc,
134 GNUNET_GETOPT_OPTION_END 136 GNUNET_GETOPT_OPTION_END
135 }; 137 };
136 138
137 (void)argc; 139 (void) argc;
138 GNUNET_log_setup("test-datacache-quota", 140 GNUNET_log_setup ("test-datacache-quota",
139 "WARNING", 141 "WARNING",
140 NULL); 142 NULL);
141 143
142 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 144 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
143 GNUNET_snprintf(cfg_name, 145 GNUNET_snprintf (cfg_name,
144 sizeof(cfg_name), 146 sizeof(cfg_name),
145 "test_datacache_data_%s.conf", 147 "test_datacache_data_%s.conf",
146 plugin_name); 148 plugin_name);
147 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, 149 GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1,
148 xargv, 150 xargv,
149 "test-datacache-quota", 151 "test-datacache-quota",
150 "nohelp", 152 "nohelp",
151 options, 153 options,
152 &run, 154 &run,
153 NULL); 155 NULL);
154 if (0 != ok) 156 if (0 != ok)
155 fprintf(stderr, 157 fprintf (stderr,
156 "Missed some testcases: %d\n", 158 "Missed some testcases: %d\n",
157 ok); 159 ok);
158 return ok; 160 return ok;
159} 161}
160 162