diff options
Diffstat (limited to 'src/datacache/test_datacache.c')
-rw-r--r-- | src/datacache/test_datacache.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 5740d2b7d..b5d978995 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
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, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -39,26 +39,18 @@ static int ok; | |||
39 | static const char *plugin_name; | 39 | static const char *plugin_name; |
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static enum GNUNET_GenericReturnValue |
43 | checkIt (void *cls, | 43 | checkIt (void *cls, |
44 | const struct GNUNET_HashCode *key, | 44 | const struct GNUNET_DATACACHE_Block *block) |
45 | size_t size, const char *data, | ||
46 | enum GNUNET_BLOCK_Type type, | ||
47 | struct GNUNET_TIME_Absolute exp, | ||
48 | unsigned int path_len, | ||
49 | const struct GNUNET_DHT_PathElement *path) | ||
50 | { | 45 | { |
51 | (void) key; | 46 | if (block->data_size != sizeof(struct GNUNET_HashCode)) |
52 | (void) type; | ||
53 | (void) exp; | ||
54 | (void) path_len; | ||
55 | (void) path; | ||
56 | if (size != sizeof(struct GNUNET_HashCode)) | ||
57 | { | 47 | { |
58 | GNUNET_break (0); | 48 | GNUNET_break (0); |
59 | ok = 2; | 49 | ok = 2; |
60 | } | 50 | } |
61 | if (0 != memcmp (data, cls, size)) | 51 | if (0 != memcmp (block->data, |
52 | cls, | ||
53 | block->data_size)) | ||
62 | { | 54 | { |
63 | GNUNET_break (0); | 55 | GNUNET_break (0); |
64 | ok = 3; | 56 | ok = 3; |
@@ -74,9 +66,9 @@ run (void *cls, | |||
74 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 66 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
75 | { | 67 | { |
76 | struct GNUNET_DATACACHE_Handle *h; | 68 | struct GNUNET_DATACACHE_Handle *h; |
69 | struct GNUNET_DATACACHE_Block block; | ||
77 | struct GNUNET_HashCode k; | 70 | struct GNUNET_HashCode k; |
78 | struct GNUNET_HashCode n; | 71 | struct GNUNET_HashCode n; |
79 | struct GNUNET_TIME_Absolute exp; | ||
80 | 72 | ||
81 | (void) cls; | 73 | (void) cls; |
82 | (void) args; | 74 | (void) args; |
@@ -84,7 +76,7 @@ run (void *cls, | |||
84 | ok = 0; | 76 | ok = 0; |
85 | h = GNUNET_DATACACHE_create (cfg, | 77 | h = GNUNET_DATACACHE_create (cfg, |
86 | "testcache"); | 78 | "testcache"); |
87 | if (h == NULL) | 79 | if (NULL == h) |
88 | { | 80 | { |
89 | fprintf (stderr, | 81 | fprintf (stderr, |
90 | "%s", | 82 | "%s", |
@@ -92,19 +84,28 @@ run (void *cls, | |||
92 | ok = 77; /* mark test as skipped */ | 84 | ok = 77; /* mark test as skipped */ |
93 | return; | 85 | return; |
94 | } | 86 | } |
95 | exp = GNUNET_TIME_absolute_get (); | 87 | block.expiration_time = GNUNET_TIME_absolute_get (); |
96 | exp.abs_value_us += 5 * 60 * 1000 * 1000LL; | 88 | block.expiration_time.abs_value_us += 5 * 60 * 1000 * 1000LL; |
97 | memset (&k, 0, sizeof(struct GNUNET_HashCode)); | 89 | memset (&k, |
90 | 0, | ||
91 | sizeof(struct GNUNET_HashCode)); | ||
98 | for (unsigned int i = 0; i < 100; i++) | 92 | for (unsigned int i = 0; i < 100; i++) |
99 | { | 93 | { |
100 | GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n); | 94 | GNUNET_CRYPTO_hash (&k, |
95 | sizeof(struct GNUNET_HashCode), | ||
96 | &n); | ||
97 | block.key = k; | ||
98 | block.data = &n; | ||
99 | block.data_size = sizeof (n); | ||
100 | block.ro = 42; | ||
101 | block.type = (enum GNUNET_BLOCK_Type) (1 + i % 16); | ||
102 | block.put_path = NULL; | ||
103 | block.put_path_length = 0; | ||
104 | block.ro = GNUNET_DHT_RO_RECORD_ROUTE; | ||
101 | ASSERT (GNUNET_OK == | 105 | ASSERT (GNUNET_OK == |
102 | GNUNET_DATACACHE_put (h, | 106 | GNUNET_DATACACHE_put (h, |
103 | &k, | 107 | 42, |
104 | GNUNET_YES, | 108 | &block)); |
105 | sizeof(struct GNUNET_HashCode), | ||
106 | (const char *) &n, 1 + i % 16, exp, | ||
107 | 0, NULL)); | ||
108 | k = n; | 109 | k = n; |
109 | } | 110 | } |
110 | memset (&k, | 111 | memset (&k, |
@@ -117,7 +118,7 @@ run (void *cls, | |||
117 | &n); | 118 | &n); |
118 | ASSERT (1 == GNUNET_DATACACHE_get (h, | 119 | ASSERT (1 == GNUNET_DATACACHE_get (h, |
119 | &k, | 120 | &k, |
120 | 1 + i % 16, | 121 | (enum GNUNET_BLOCK_Type) (1 + i % 16), |
121 | &checkIt, | 122 | &checkIt, |
122 | &n)); | 123 | &n)); |
123 | k = n; | 124 | k = n; |
@@ -129,16 +130,19 @@ run (void *cls, | |||
129 | GNUNET_CRYPTO_hash (&k, | 130 | GNUNET_CRYPTO_hash (&k, |
130 | sizeof(struct GNUNET_HashCode), | 131 | sizeof(struct GNUNET_HashCode), |
131 | &n); | 132 | &n); |
133 | block.key = k; | ||
134 | block.data = &n; | ||
135 | block.data_size = sizeof (n); | ||
136 | block.ro = 42; | ||
137 | block.type = (enum GNUNET_BLOCK_Type) 792; | ||
138 | block.put_path = NULL; | ||
139 | block.put_path_length = 0; | ||
140 | block.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
141 | block.ro = GNUNET_DHT_RO_RECORD_ROUTE; | ||
132 | ASSERT (GNUNET_OK == | 142 | ASSERT (GNUNET_OK == |
133 | GNUNET_DATACACHE_put (h, | 143 | GNUNET_DATACACHE_put (h, |
134 | &k, | 144 | 42, |
135 | GNUNET_YES, | 145 | &block)); |
136 | sizeof(struct GNUNET_HashCode), | ||
137 | (const char *) &n, | ||
138 | 792, | ||
139 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
140 | 0, | ||
141 | NULL)); | ||
142 | ASSERT (0 != GNUNET_DATACACHE_get (h, | 146 | ASSERT (0 != GNUNET_DATACACHE_get (h, |
143 | &k, | 147 | &k, |
144 | 792, | 148 | 792, |