diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/peerstore/test_plugin_peerstore.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/peerstore/test_plugin_peerstore.c')
-rw-r--r-- | src/peerstore/test_plugin_peerstore.c | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c index 0664659a4..8fce65e23 100644 --- a/src/peerstore/test_plugin_peerstore.c +++ b/src/peerstore/test_plugin_peerstore.c | |||
@@ -48,17 +48,17 @@ static struct GNUNET_PeerIdentity p1; | |||
48 | * @param api api to unload | 48 | * @param api api to unload |
49 | */ | 49 | */ |
50 | static void | 50 | static void |
51 | unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) | 51 | unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) |
52 | { | 52 | { |
53 | char *libname; | 53 | char *libname; |
54 | 54 | ||
55 | GNUNET_asprintf(&libname, | 55 | GNUNET_asprintf (&libname, |
56 | "libgnunet_plugin_peer_%s", | 56 | "libgnunet_plugin_peer_%s", |
57 | plugin_name); | 57 | plugin_name); |
58 | GNUNET_break(NULL == | 58 | GNUNET_break (NULL == |
59 | GNUNET_PLUGIN_unload(libname, | 59 | GNUNET_PLUGIN_unload (libname, |
60 | api)); | 60 | api)); |
61 | GNUNET_free(libname); | 61 | GNUNET_free (libname); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
@@ -69,123 +69,123 @@ unload_plugin(struct GNUNET_PEERSTORE_PluginFunctions *api) | |||
69 | * @return NULL on error | 69 | * @return NULL on error |
70 | */ | 70 | */ |
71 | static struct GNUNET_PEERSTORE_PluginFunctions * | 71 | static struct GNUNET_PEERSTORE_PluginFunctions * |
72 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) | 72 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) |
73 | { | 73 | { |
74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; | 74 | struct GNUNET_PEERSTORE_PluginFunctions *ret; |
75 | char *libname; | 75 | char *libname; |
76 | 76 | ||
77 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 77 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
78 | _("Loading `%s' peer plugin\n"), | 78 | _ ("Loading `%s' peer plugin\n"), |
79 | plugin_name); | ||
80 | GNUNET_asprintf(&libname, | ||
81 | "libgnunet_plugin_peerstore_%s", | ||
82 | plugin_name); | ||
83 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, | ||
84 | (void*)cfg))) | ||
85 | { | ||
86 | fprintf(stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | 79 | plugin_name); |
89 | GNUNET_free(libname); | 80 | GNUNET_asprintf (&libname, |
90 | return NULL; | 81 | "libgnunet_plugin_peerstore_%s", |
91 | } | 82 | plugin_name); |
92 | GNUNET_free(libname); | 83 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, |
84 | (void*) cfg))) | ||
85 | { | ||
86 | fprintf (stderr, | ||
87 | "Failed to load plugin `%s'!\n", | ||
88 | plugin_name); | ||
89 | GNUNET_free (libname); | ||
90 | return NULL; | ||
91 | } | ||
92 | GNUNET_free (libname); | ||
93 | return ret; | 93 | return ret; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | test_record(void *cls, | 98 | test_record (void *cls, |
99 | const struct GNUNET_PEERSTORE_Record *record, | 99 | const struct GNUNET_PEERSTORE_Record *record, |
100 | const char *error) | 100 | const char *error) |
101 | { | 101 | { |
102 | const struct GNUNET_PeerIdentity *id = cls; | 102 | const struct GNUNET_PeerIdentity *id = cls; |
103 | const char* testval = "test_val"; | 103 | const char*testval = "test_val"; |
104 | 104 | ||
105 | if (NULL == record) | 105 | if (NULL == record) |
106 | { | 106 | { |
107 | unload_plugin(psp); | 107 | unload_plugin (psp); |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | GNUNET_assert(0 == memcmp(&record->peer, | 110 | GNUNET_assert (0 == memcmp (&record->peer, |
111 | id, | 111 | id, |
112 | sizeof(struct GNUNET_PeerIdentity))); | 112 | sizeof(struct GNUNET_PeerIdentity))); |
113 | GNUNET_assert(0 == strcmp("subsys", | 113 | GNUNET_assert (0 == strcmp ("subsys", |
114 | record->sub_system)); | 114 | record->sub_system)); |
115 | GNUNET_assert(0 == strcmp("key", | 115 | GNUNET_assert (0 == strcmp ("key", |
116 | record->key)); | 116 | record->key)); |
117 | GNUNET_assert(0 == memcmp(testval, | 117 | GNUNET_assert (0 == memcmp (testval, |
118 | record->value, | 118 | record->value, |
119 | strlen(testval))); | 119 | strlen (testval))); |
120 | ok = 0; | 120 | ok = 0; |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
125 | get_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, | 125 | get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, |
126 | const struct GNUNET_PeerIdentity *identity) | 126 | const struct GNUNET_PeerIdentity *identity) |
127 | { | 127 | { |
128 | GNUNET_assert(GNUNET_OK == | 128 | GNUNET_assert (GNUNET_OK == |
129 | psp->iterate_records(psp->cls, | 129 | psp->iterate_records (psp->cls, |
130 | "subsys", | 130 | "subsys", |
131 | identity, | 131 | identity, |
132 | "key", | 132 | "key", |
133 | &test_record, | 133 | &test_record, |
134 | (void*)identity)); | 134 | (void*) identity)); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | static void | 138 | static void |
139 | store_cont(void *cls, | 139 | store_cont (void *cls, |
140 | int status) | 140 | int status) |
141 | { | 141 | { |
142 | GNUNET_assert(GNUNET_OK == status); | 142 | GNUNET_assert (GNUNET_OK == status); |
143 | get_record(psp, | 143 | get_record (psp, |
144 | &p1); | 144 | &p1); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | static void | 148 | static void |
149 | put_record(struct GNUNET_PEERSTORE_PluginFunctions *psp, | 149 | put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, |
150 | const struct GNUNET_PeerIdentity *identity) | 150 | const struct GNUNET_PeerIdentity *identity) |
151 | { | 151 | { |
152 | GNUNET_assert(GNUNET_OK == | 152 | GNUNET_assert (GNUNET_OK == |
153 | psp->store_record(psp->cls, | 153 | psp->store_record (psp->cls, |
154 | "subsys", | 154 | "subsys", |
155 | identity, | 155 | identity, |
156 | "key", | 156 | "key", |
157 | "test_value", | 157 | "test_value", |
158 | strlen("test_value"), | 158 | strlen ("test_value"), |
159 | GNUNET_TIME_absolute_get(), | 159 | GNUNET_TIME_absolute_get (), |
160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | 160 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, |
161 | &store_cont, | 161 | &store_cont, |
162 | NULL)); | 162 | NULL)); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | static void | 166 | static void |
167 | run(void *cls, | 167 | run (void *cls, |
168 | char *const *args, | 168 | char *const *args, |
169 | const char *cfgfile, | 169 | const char *cfgfile, |
170 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
171 | { | 171 | { |
172 | ok = 1; | 172 | ok = 1; |
173 | psp = load_plugin(cfg); | 173 | psp = load_plugin (cfg); |
174 | if (NULL == psp) | 174 | if (NULL == psp) |
175 | { | 175 | { |
176 | fprintf(stderr, | 176 | fprintf (stderr, |
177 | "%s", | 177 | "%s", |
178 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); | 178 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); |
179 | return; | 179 | return; |
180 | } | 180 | } |
181 | memset(&p1, 1, sizeof(p1)); | 181 | memset (&p1, 1, sizeof(p1)); |
182 | put_record(psp, | 182 | put_record (psp, |
183 | &p1); | 183 | &p1); |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | int | 187 | int |
188 | main(int argc, char *argv[]) | 188 | main (int argc, char *argv[]) |
189 | { | 189 | { |
190 | char cfg_name[PATH_MAX]; | 190 | char cfg_name[PATH_MAX]; |
191 | char *const xargv[] = { | 191 | char *const xargv[] = { |
@@ -198,25 +198,25 @@ main(int argc, char *argv[]) | |||
198 | GNUNET_GETOPT_OPTION_END | 198 | GNUNET_GETOPT_OPTION_END |
199 | }; | 199 | }; |
200 | 200 | ||
201 | GNUNET_log_setup("test-plugin-peerstore", | 201 | GNUNET_log_setup ("test-plugin-peerstore", |
202 | "WARNING", | 202 | "WARNING", |
203 | NULL); | 203 | NULL); |
204 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); | 204 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
205 | GNUNET_snprintf(cfg_name, | 205 | GNUNET_snprintf (cfg_name, |
206 | sizeof(cfg_name), | 206 | sizeof(cfg_name), |
207 | "test_plugin_peerstore_%s.conf", | 207 | "test_plugin_peerstore_%s.conf", |
208 | plugin_name); | 208 | plugin_name); |
209 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, | 209 | GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, |
210 | xargv, | 210 | xargv, |
211 | "test-plugin-peerstore", | 211 | "test-plugin-peerstore", |
212 | "nohelp", | 212 | "nohelp", |
213 | options, | 213 | options, |
214 | &run, | 214 | &run, |
215 | NULL); | 215 | NULL); |
216 | if (ok != 0) | 216 | if (ok != 0) |
217 | fprintf(stderr, | 217 | fprintf (stderr, |
218 | "Missed some testcases: %d\n", | 218 | "Missed some testcases: %d\n", |
219 | ok); | 219 | ok); |
220 | return ok; | 220 | return ok; |
221 | } | 221 | } |
222 | 222 | ||