diff options
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r-- | src/datacache/test_datacache.c | 98 |
1 files changed, 44 insertions, 54 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 7d55ef8b7..c04facc15 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c | |||
@@ -40,22 +40,20 @@ static const char *plugin_name; | |||
40 | 40 | ||
41 | static int | 41 | static int |
42 | checkIt (void *cls, | 42 | checkIt (void *cls, |
43 | struct GNUNET_TIME_Absolute exp, | 43 | struct GNUNET_TIME_Absolute exp, |
44 | const GNUNET_HashCode * key, | 44 | const GNUNET_HashCode * key, |
45 | size_t size, | 45 | size_t size, const char *data, enum GNUNET_BLOCK_Type type) |
46 | const char *data, | ||
47 | enum GNUNET_BLOCK_Type type) | ||
48 | { | 46 | { |
49 | if (size != sizeof (GNUNET_HashCode)) | 47 | if (size != sizeof (GNUNET_HashCode)) |
50 | { | 48 | { |
51 | printf ("ERROR: Invalid size\n"); | 49 | printf ("ERROR: Invalid size\n"); |
52 | ok = 2; | 50 | ok = 2; |
53 | } | 51 | } |
54 | if (0 != memcmp (data, cls, size)) | 52 | if (0 != memcmp (data, cls, size)) |
55 | { | 53 | { |
56 | printf ("ERROR: Invalid data\n"); | 54 | printf ("ERROR: Invalid data\n"); |
57 | ok = 3; | 55 | ok = 3; |
58 | } | 56 | } |
59 | return GNUNET_OK; | 57 | return GNUNET_OK; |
60 | } | 58 | } |
61 | 59 | ||
@@ -63,8 +61,7 @@ checkIt (void *cls, | |||
63 | static void | 61 | static void |
64 | run (void *cls, | 62 | run (void *cls, |
65 | char *const *args, | 63 | char *const *args, |
66 | const char *cfgfile, | 64 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
67 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
68 | { | 65 | { |
69 | struct GNUNET_DATACACHE_Handle *h; | 66 | struct GNUNET_DATACACHE_Handle *h; |
70 | GNUNET_HashCode k; | 67 | GNUNET_HashCode k; |
@@ -73,39 +70,35 @@ run (void *cls, | |||
73 | unsigned int i; | 70 | unsigned int i; |
74 | 71 | ||
75 | ok = 0; | 72 | ok = 0; |
76 | h = GNUNET_DATACACHE_create (cfg, | 73 | h = GNUNET_DATACACHE_create (cfg, "testcache"); |
77 | "testcache"); | ||
78 | if (h == NULL) | 74 | if (h == NULL) |
79 | { | 75 | { |
80 | fprintf (stderr, | 76 | fprintf (stderr, |
81 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); | 77 | "Failed to initialize datacache. Database likely not setup, skipping test.\n"); |
82 | return; | 78 | return; |
83 | } | 79 | } |
84 | exp = GNUNET_TIME_absolute_get (); | 80 | exp = GNUNET_TIME_absolute_get (); |
85 | exp.abs_value += 5 * 60 * 1000; | 81 | exp.abs_value += 5 * 60 * 1000; |
86 | memset (&k, 0, sizeof (GNUNET_HashCode)); | 82 | memset (&k, 0, sizeof (GNUNET_HashCode)); |
87 | for (i = 0; i < 100; i++) | 83 | for (i = 0; i < 100; i++) |
88 | { | 84 | { |
89 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | 85 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); |
90 | ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, | 86 | ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, |
91 | &k, | 87 | &k, |
92 | sizeof (GNUNET_HashCode), | 88 | sizeof (GNUNET_HashCode), |
93 | (const char *) &n, | 89 | (const char *) &n, |
94 | 1+i%16, | 90 | 1 + i % 16, exp)); |
95 | exp)); | 91 | k = n; |
96 | k = n; | 92 | } |
97 | } | ||
98 | memset (&k, 0, sizeof (GNUNET_HashCode)); | 93 | memset (&k, 0, sizeof (GNUNET_HashCode)); |
99 | for (i = 0; i < 100; i++) | 94 | for (i = 0; i < 100; i++) |
100 | { | 95 | { |
101 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | 96 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); |
102 | ASSERT (1 == | 97 | ASSERT (1 == GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n)); |
103 | GNUNET_DATACACHE_get (h, &k, 1+i%16, | 98 | k = n; |
104 | &checkIt, &n)); | 99 | } |
105 | k = n; | 100 | |
106 | } | 101 | memset (&k, 42, sizeof (GNUNET_HashCode)); |
107 | |||
108 | memset(&k, 42, sizeof(GNUNET_HashCode)); | ||
109 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); | 102 | GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); |
110 | ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, | 103 | ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, |
111 | &k, | 104 | &k, |
@@ -113,9 +106,7 @@ run (void *cls, | |||
113 | (const char *) &n, | 106 | (const char *) &n, |
114 | 792, | 107 | 792, |
115 | GNUNET_TIME_UNIT_FOREVER_ABS)); | 108 | GNUNET_TIME_UNIT_FOREVER_ABS)); |
116 | ASSERT (0 != | 109 | ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); |
117 | GNUNET_DATACACHE_get (h, &k, 792, | ||
118 | &checkIt, &n)); | ||
119 | 110 | ||
120 | GNUNET_DATACACHE_destroy (h); | 111 | GNUNET_DATACACHE_destroy (h); |
121 | ASSERT (ok == 0); | 112 | ASSERT (ok == 0); |
@@ -132,7 +123,8 @@ main (int argc, char *argv[]) | |||
132 | { | 123 | { |
133 | char *pos; | 124 | char *pos; |
134 | char cfg_name[128]; | 125 | char cfg_name[128]; |
135 | char *const xargv[] = { | 126 | |
127 | char *const xargv[] = { | ||
136 | "test-datacache", | 128 | "test-datacache", |
137 | "-c", | 129 | "-c", |
138 | cfg_name, | 130 | cfg_name, |
@@ -154,22 +146,20 @@ main (int argc, char *argv[]) | |||
154 | NULL); | 146 | NULL); |
155 | /* determine name of plugin to use */ | 147 | /* determine name of plugin to use */ |
156 | plugin_name = argv[0]; | 148 | plugin_name = argv[0]; |
157 | while (NULL != (pos = strstr(plugin_name, "_"))) | 149 | while (NULL != (pos = strstr (plugin_name, "_"))) |
158 | plugin_name = pos+1; | 150 | plugin_name = pos + 1; |
159 | if (NULL != (pos = strstr(plugin_name, "."))) | 151 | if (NULL != (pos = strstr (plugin_name, "."))) |
160 | pos[0] = 0; | 152 | pos[0] = 0; |
161 | else | 153 | else |
162 | pos = (char *) plugin_name; | 154 | pos = (char *) plugin_name; |
163 | 155 | ||
164 | GNUNET_snprintf (cfg_name, | 156 | GNUNET_snprintf (cfg_name, |
165 | sizeof (cfg_name), | 157 | sizeof (cfg_name), |
166 | "test_datacache_data_%s.conf", | 158 | "test_datacache_data_%s.conf", plugin_name); |
167 | plugin_name); | ||
168 | if (pos != plugin_name) | 159 | if (pos != plugin_name) |
169 | pos[0] = '.'; | 160 | pos[0] = '.'; |
170 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, | 161 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, |
171 | xargv, "test-datacache", "nohelp", | 162 | xargv, "test-datacache", "nohelp", options, &run, NULL); |
172 | options, &run, NULL); | ||
173 | if (ok != 0) | 163 | if (ok != 0) |
174 | fprintf (stderr, "Missed some testcases: %d\n", ok); | 164 | fprintf (stderr, "Missed some testcases: %d\n", ok); |
175 | return ok; | 165 | return ok; |