Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Tests for storage plugins
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : /* -- Imports --------------------------------------------------------------------------------------------------------------------------- */
11 :
12 : #include <tests_internal.h>
13 : #include <tests_plugin.h>
14 :
15 : #include <kdbconfig.h>
16 :
17 : /* -- Macros & Test Configuration ------------------------------------------------------------------------------------------------------- */
18 :
19 : #define TEST_ROOT_KEY "user/tests/storage"
20 :
21 : // below are the plugins suggested for testing, but only compiled plugins are tested
22 : #define NUM_PLUGINS_SUGGESTED 4
23 : static const char * pluginsSuggested[] = { "mmapstorage_crc", "mmapstorage", "dump",
24 : "quickdump" }; // remember to adjust NUM_PLUGINS_SUGGESTED if you add/remove a storage plugin
25 :
26 : // below is the list of available plugins truly tested.
27 : static size_t numPlugins = 0;
28 : static KeySet * modules[NUM_PLUGINS_SUGGESTED];
29 : static Plugin * plugins[NUM_PLUGINS_SUGGESTED];
30 : static const char * pluginNames[NUM_PLUGINS_SUGGESTED];
31 :
32 : #define open_storage_plugin(storagePlugin) \
33 : if (openStoragePlugin (storagePlugin) == -1) \
34 : { \
35 : nbError++; \
36 : printf ("Error opening storage plugin: %s. Skipping test.\n", pluginNames[storagePlugin]); \
37 : return; \
38 : }
39 :
40 : /* -- KeySet test data ------------------------------------------------------------------------------------------------------------------ */
41 :
42 128 : static KeySet * simpleTestKeySet (void)
43 : {
44 128 : return ksNew (10, keyNew ("user/tests/storage/simpleKey", KEY_VALUE, "root key", KEY_END),
45 : keyNew ("user/tests/storage/simpleKey/a", KEY_VALUE, "a value", KEY_END),
46 : keyNew ("user/tests/storage/simpleKey/b", KEY_VALUE, "b value", KEY_END), KS_END);
47 : }
48 :
49 160 : static KeySet * metaTestKeySet (void)
50 : {
51 160 : return ksNew (10, keyNew ("user/tests/storage", KEY_VALUE, "root key", KEY_META, "a", "some metadata for root key", KEY_END),
52 : keyNew ("user/tests/storage/a", KEY_VALUE, "a value", KEY_META, "ab", "other metadata for a key", KEY_END),
53 : keyNew ("user/tests/storage/b", KEY_VALUE, "b value", KEY_META, "longer val", "metadata for key b", KEY_END), KS_END);
54 : }
55 :
56 : /* -- Test helpers ---------------------------------------------------------------------------------------------------------------------- */
57 :
58 2 : static void initPlugins (void)
59 : {
60 : // check if plugin is compiled, and only test if it is
61 10 : for (size_t plugin = 0; plugin < NUM_PLUGINS_SUGGESTED; ++plugin)
62 : {
63 8 : if (strstr (ELEKTRA_PLUGINS, pluginsSuggested[plugin]) != NULL)
64 : {
65 8 : pluginNames[numPlugins] = pluginsSuggested[plugin];
66 8 : numPlugins++;
67 : }
68 : else
69 : {
70 0 : printf ("Warning: Plugin %s is not compiled. Excuding from storage tests.\n", pluginsSuggested[plugin]);
71 : }
72 : }
73 2 : }
74 :
75 464 : static int openStoragePlugin (const size_t storagePlugin)
76 : {
77 464 : modules[storagePlugin] = ksNew (0, KS_END);
78 464 : elektraModulesInit (modules[storagePlugin], 0);
79 464 : KeySet * conf = ksNew (0, KS_END);
80 464 : Key * errorKey = keyNew ("", KEY_END);
81 464 : Plugin * plugin = elektraPluginOpen (pluginNames[storagePlugin], modules[storagePlugin], conf, errorKey);
82 :
83 464 : const Key * metaWarnings = keyGetMeta (errorKey, "warnings");
84 464 : if (metaWarnings) printf ("There are warnings for plugin: %s\n", pluginNames[storagePlugin]);
85 464 : const Key * metaError = keyGetMeta (errorKey, "error");
86 464 : if (metaError) printf ("There are errors for plugin: %s\n", pluginNames[storagePlugin]);
87 :
88 464 : if (plugin == 0)
89 : {
90 0 : printf ("Could not open plugin: %s\n", pluginNames[storagePlugin]);
91 0 : return -1;
92 : }
93 :
94 464 : plugins[storagePlugin] = plugin;
95 464 : keyDel (errorKey);
96 :
97 464 : return 0;
98 : }
99 :
100 464 : static int closeStoragePlugin (const size_t storagePlugin)
101 : {
102 464 : elektraPluginClose (plugins[storagePlugin], 0);
103 464 : elektraModulesClose (modules[storagePlugin], 0);
104 464 : ksDel (modules[storagePlugin]);
105 :
106 464 : return 0;
107 : }
108 :
109 : /* -- KeySet API tests ------------------------------------------------------------------------------------------------------------------ */
110 :
111 16 : static void test_ksDupFun (const size_t storagePlugin, const char * tmpFile, KeySet * copyFunction (const KeySet * source))
112 : {
113 16 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
114 16 : open_storage_plugin (storagePlugin);
115 16 : Plugin * plugin = plugins[storagePlugin];
116 :
117 16 : KeySet * ks = simpleTestKeySet ();
118 16 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
119 16 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
120 :
121 16 : KeySet * dupKs = copyFunction (ks);
122 16 : compare_keyset (dupKs, ks);
123 16 : compare_keyset (ks, dupKs);
124 :
125 16 : ksDel (dupKs);
126 16 : keyDel (parentKey);
127 16 : ksDel (ks);
128 16 : closeStoragePlugin (storagePlugin);
129 : }
130 :
131 8 : static void test_ksCopy (const size_t storagePlugin, const char * tmpFile)
132 : {
133 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
134 8 : open_storage_plugin (storagePlugin);
135 8 : Plugin * plugin = plugins[storagePlugin];
136 :
137 8 : KeySet * ks = simpleTestKeySet ();
138 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
139 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
140 :
141 8 : KeySet * copyKs = ksNew (0, KS_END);
142 8 : if (ksCopy (copyKs, ks) == 1)
143 : {
144 8 : compare_keyset (copyKs, ks);
145 8 : compare_keyset (ks, copyKs);
146 : }
147 : else
148 : {
149 0 : yield_error ("ksCopy failed");
150 : }
151 :
152 8 : ksDel (copyKs);
153 8 : keyDel (parentKey);
154 8 : ksDel (ks);
155 8 : closeStoragePlugin (storagePlugin);
156 : }
157 :
158 8 : static void test_ksGetSize (const size_t storagePlugin, const char * tmpFile)
159 : {
160 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
161 8 : open_storage_plugin (storagePlugin);
162 8 : Plugin * plugin = plugins[storagePlugin];
163 :
164 8 : KeySet * ks = simpleTestKeySet ();
165 8 : ssize_t origSize = ksGetSize (ks);
166 8 : succeed_if (origSize > 0, "ks was empty before kdbSet");
167 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
168 :
169 8 : ksDel (ks);
170 8 : ks = ksNew (0, KS_END);
171 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
172 8 : ssize_t returnedSize = ksGetSize (ks);
173 8 : succeed_if (origSize == returnedSize, "ksGetSize before and after kdbSet, kdbGet differ");
174 :
175 8 : keyDel (parentKey);
176 8 : ksDel (ks);
177 8 : closeStoragePlugin (storagePlugin);
178 : }
179 :
180 8 : static void test_double_get (const size_t storagePlugin, const char * tmpFile)
181 : {
182 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
183 8 : open_storage_plugin (storagePlugin);
184 8 : Plugin * plugin = plugins[storagePlugin];
185 :
186 8 : KeySet * ks = simpleTestKeySet ();
187 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
188 :
189 8 : KeySet * first = ksNew (0, KS_END);
190 8 : succeed_if (plugin->kdbGet (plugin, first, parentKey) == 1, "kdbGet was not successful");
191 8 : KeySet * second = ksNew (0, KS_END);
192 8 : succeed_if (plugin->kdbGet (plugin, second, parentKey) == 1, "kdbGet was not successful");
193 8 : succeed_if (first->array != second->array, "ks->array points to same thing");
194 :
195 8 : compare_keyset (first, ks);
196 8 : compare_keyset (ks, first);
197 8 : compare_keyset (second, ks);
198 8 : compare_keyset (ks, second);
199 :
200 8 : ksDel (ks);
201 8 : ks = metaTestKeySet ();
202 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
203 :
204 8 : KeySet * simple = simpleTestKeySet ();
205 8 : compare_keyset (first, simple);
206 8 : compare_keyset (second, simple);
207 8 : ksDel (first);
208 8 : ksDel (second);
209 8 : ksDel (simple);
210 8 : ksDel (ks);
211 8 : keyDel (parentKey);
212 8 : closeStoragePlugin (storagePlugin);
213 : }
214 :
215 8 : static void test_ksAppendKey (const size_t storagePlugin, const char * tmpFile)
216 : {
217 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
218 8 : open_storage_plugin (storagePlugin);
219 8 : Plugin * plugin = plugins[storagePlugin];
220 :
221 8 : KeySet * ks = simpleTestKeySet ();
222 8 : ssize_t origSize = ksGetSize (ks);
223 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
224 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
225 :
226 8 : ssize_t appendSize = 0;
227 8 : Key * toAppend = keyNew (TEST_ROOT_KEY "/my/new/key", KEY_END);
228 :
229 8 : if ((appendSize = ksAppendKey (ks, toAppend)) == -1)
230 : {
231 0 : yield_error ("ksAppendKey failed");
232 : }
233 :
234 8 : succeed_if (appendSize == (origSize + 1), "ksAppendKey after append should be incremented");
235 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
236 8 : ksDel (ks);
237 8 : ks = ksNew (0, KS_END);
238 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
239 8 : ssize_t returnedSize = ksGetSize (ks);
240 :
241 8 : succeed_if (returnedSize == (origSize + 1), "ksGetSize after append should be incremented");
242 :
243 8 : keyDel (parentKey);
244 8 : ksDel (ks);
245 8 : closeStoragePlugin (storagePlugin);
246 : }
247 :
248 8 : static void test_ksAppend (const size_t storagePlugin, const char * tmpFile)
249 : {
250 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
251 8 : open_storage_plugin (storagePlugin);
252 8 : Plugin * plugin = plugins[storagePlugin];
253 :
254 8 : KeySet * ks = simpleTestKeySet ();
255 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
256 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
257 :
258 8 : KeySet * toAppend = ksNew (10, keyNew ("user/tests/storage/zzzz", KEY_VALUE, "root key", KEY_END),
259 : keyNew ("user/tests/storage/simpleKey/c", KEY_VALUE, "c value", KEY_END),
260 : keyNew ("user/tests/storage/simpleKey/d", KEY_VALUE, "d value", KEY_END), KS_END);
261 8 : if (ksAppend (ks, toAppend) == -1)
262 : {
263 0 : yield_error ("ksAppend failed");
264 : }
265 :
266 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
267 8 : ksDel (ks);
268 8 : ks = ksNew (0, KS_END);
269 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
270 :
271 8 : ksDel (toAppend);
272 8 : keyDel (parentKey);
273 8 : ksDel (ks);
274 8 : closeStoragePlugin (storagePlugin);
275 : }
276 :
277 8 : static void test_ksCut (const size_t storagePlugin, const char * tmpFile)
278 : {
279 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
280 8 : open_storage_plugin (storagePlugin);
281 8 : Plugin * plugin = plugins[storagePlugin];
282 :
283 : // create keyset with some folder 'other' that we will then cut
284 8 : KeySet * ks = simpleTestKeySet ();
285 8 : KeySet * other = ksNew (10, keyNew ("user/tests/storage/other", KEY_VALUE, "other key", KEY_END),
286 : keyNew ("user/tests/storage/other/a", KEY_VALUE, "other a value", KEY_END),
287 : keyNew ("user/tests/storage/other/b", KEY_VALUE, "other b value", KEY_END), KS_END);
288 8 : if (ksAppend (ks, other) == -1)
289 : {
290 0 : yield_error ("ksAppend failed");
291 : }
292 :
293 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
294 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
295 :
296 : // now cut the 'other' folder
297 8 : Key * cutKey = keyNew ("user/tests/storage/other", KEY_END);
298 8 : KeySet * returned = ksCut (ks, cutKey);
299 8 : succeed_if (returned, "keyset is empty (does not contain the cut keyset)");
300 :
301 8 : KeySet * simple = simpleTestKeySet ();
302 8 : compare_keyset (simple, ks);
303 8 : compare_keyset (other, returned);
304 :
305 8 : ksDel (other);
306 8 : ksDel (returned);
307 8 : ksDel (simple);
308 8 : keyDel (cutKey);
309 8 : keyDel (parentKey);
310 8 : ksDel (ks);
311 8 : closeStoragePlugin (storagePlugin);
312 : }
313 :
314 8 : static void test_ksPop (const size_t storagePlugin, const char * tmpFile)
315 : {
316 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
317 8 : open_storage_plugin (storagePlugin);
318 8 : Plugin * plugin = plugins[storagePlugin];
319 :
320 8 : KeySet * ks = simpleTestKeySet ();
321 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
322 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
323 :
324 8 : KeySet * poppedKeys = ksNew (0, KS_END);
325 8 : succeed_if (ksAppendKey (poppedKeys, ksPop (ks)) != -1, "ksAppendKey failed");
326 8 : succeed_if (ksAppendKey (poppedKeys, ksPop (ks)) != -1, "ksAppendKey failed");
327 8 : succeed_if (ksGetSize (ks) == 1, "ksGetSize after ksPop should be decremented");
328 8 : succeed_if (ksAppendKey (poppedKeys, ksPop (ks)) != -1, "ksAppendKey failed");
329 8 : succeed_if (ksGetSize (poppedKeys) == 3, "expecting three keys to be in ks");
330 8 : succeed_if (ksPop (ks) == 0, "ks should be empty");
331 8 : succeed_if (ksAppendKey (poppedKeys, ksPop (ks)) == -1, "ks should be empty, but is not");
332 :
333 8 : KeySet * test = simpleTestKeySet ();
334 8 : compare_keyset (poppedKeys, test);
335 8 : ksDel (test);
336 :
337 8 : ksDel (poppedKeys);
338 8 : keyDel (parentKey);
339 8 : ksDel (ks);
340 8 : closeStoragePlugin (storagePlugin);
341 : }
342 :
343 16 : static void test_ksLookup (const size_t storagePlugin, const char * tmpFile, option_t options)
344 : {
345 16 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
346 16 : open_storage_plugin (storagePlugin);
347 16 : Plugin * plugin = plugins[storagePlugin];
348 :
349 16 : KeySet * ks = simpleTestKeySet ();
350 16 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
351 16 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
352 :
353 16 : Key * lookup = keyNew ("user/tests/storage/simpleKey/a", KEY_END);
354 16 : Key * found = ksLookup (ks, lookup, options);
355 16 : succeed_if (found, "did not find key");
356 16 : if (options == KDB_O_POP)
357 : {
358 : // make sure key is really popped
359 8 : keyDel (found);
360 8 : found = ksLookup (ks, lookup, 0);
361 8 : succeed_if (!found, "found key that should not exist");
362 : }
363 16 : keyDel (lookup);
364 :
365 16 : lookup = keyNew ("user/tests/storage/simpleKey/foo", KEY_END);
366 16 : found = ksLookup (ks, lookup, options);
367 16 : succeed_if (!found, "found key that should not exist");
368 16 : keyDel (lookup);
369 :
370 16 : keyDel (parentKey);
371 16 : ksDel (ks);
372 16 : closeStoragePlugin (storagePlugin);
373 : }
374 :
375 16 : static void test_ksLookupByName (const size_t storagePlugin, const char * tmpFile, option_t options)
376 : {
377 16 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
378 16 : open_storage_plugin (storagePlugin);
379 16 : Plugin * plugin = plugins[storagePlugin];
380 :
381 16 : KeySet * ks = simpleTestKeySet ();
382 16 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
383 16 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
384 :
385 16 : const char * name = "user/tests/storage/simpleKey/a";
386 16 : Key * found = ksLookupByName (ks, name, options);
387 16 : succeed_if (found, "did not find key");
388 16 : if (options == KDB_O_POP)
389 : {
390 : // make sure key is really popped
391 8 : keyDel (found);
392 8 : found = ksLookupByName (ks, name, 0);
393 8 : succeed_if (!found, "found key that should not exist");
394 : }
395 :
396 16 : name = "user/tests/storage/simpleKey/foo";
397 16 : found = ksLookupByName (ks, name, options);
398 16 : succeed_if (!found, "found key that should not exist");
399 :
400 16 : keyDel (parentKey);
401 16 : ksDel (ks);
402 16 : closeStoragePlugin (storagePlugin);
403 : }
404 :
405 : /* -- Key API tests --------------------------------------------------------------------------------------------------------------------- */
406 :
407 8 : static void test_keyFlags (const size_t storagePlugin, const char * tmpFile)
408 : {
409 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
410 8 : open_storage_plugin (storagePlugin);
411 8 : Plugin * plugin = plugins[storagePlugin];
412 :
413 8 : KeySet * ks = ksNew (10, keyNew ("user/tests/storage/testKey", KEY_FLAGS, KEY_BINARY, KEY_VALUE, "test key", KEY_END), KS_END);
414 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
415 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
416 :
417 8 : Key * found = ksLookupByName (ks, "user/tests/storage/testKey", 0);
418 8 : succeed_if (found, "did not find key");
419 8 : succeed_if (keyIsBinary (found) == 1, "Key is not binary.");
420 :
421 8 : keyDel (parentKey);
422 8 : ksDel (ks);
423 8 : closeStoragePlugin (storagePlugin);
424 : }
425 :
426 8 : static void test_keyDup (const size_t storagePlugin, const char * tmpFile)
427 : {
428 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
429 8 : open_storage_plugin (storagePlugin);
430 8 : Plugin * plugin = plugins[storagePlugin];
431 :
432 8 : KeySet * ks = metaTestKeySet ();
433 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
434 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
435 :
436 8 : Key * found = ksLookupByName (ks, "user/tests/storage/b", 0);
437 8 : succeed_if (found, "did not find key");
438 :
439 8 : Key * duplicate = keyDup (found);
440 :
441 : // check that keyDup has not changed KeySet
442 8 : KeySet * expected = metaTestKeySet ();
443 8 : compare_keyset (ks, expected);
444 :
445 : // check that KeySet is intact after deleting duplicate Key
446 8 : keyDel (duplicate);
447 8 : compare_keyset (ks, expected);
448 :
449 8 : ksDel (expected);
450 8 : keyDel (parentKey);
451 8 : ksDel (ks);
452 8 : closeStoragePlugin (storagePlugin);
453 : }
454 :
455 8 : static void test_keyCopy_newKey (const size_t storagePlugin, const char * tmpFile)
456 : {
457 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
458 8 : open_storage_plugin (storagePlugin);
459 8 : Plugin * plugin = plugins[storagePlugin];
460 :
461 8 : KeySet * ks = metaTestKeySet ();
462 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
463 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
464 :
465 8 : Key * found = ksLookupByName (ks, "user/tests/storage/b", 0);
466 8 : succeed_if (found, "did not find key");
467 :
468 8 : Key * copy = keyNew (0, KEY_END);
469 8 : succeed_if (keyCopy (copy, found) != -1, "keyCopy failed");
470 :
471 8 : compare_key (found, copy);
472 :
473 : // check that keyCopy has not changed KeySet
474 8 : KeySet * expected = metaTestKeySet ();
475 8 : compare_keyset (ks, expected);
476 :
477 : // check that KeySet is intact after deleting Key copy
478 8 : keyDel (copy);
479 8 : compare_keyset (ks, expected);
480 :
481 8 : ksDel (expected);
482 8 : keyDel (parentKey);
483 8 : ksDel (ks);
484 8 : closeStoragePlugin (storagePlugin);
485 : }
486 :
487 8 : static void test_keyCopy_clearOverwriteKey (const size_t storagePlugin, const char * tmpFile)
488 : {
489 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
490 8 : open_storage_plugin (storagePlugin);
491 8 : Plugin * plugin = plugins[storagePlugin];
492 :
493 8 : KeySet * ks = metaTestKeySet ();
494 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
495 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
496 :
497 8 : Key * toCopy = keyNew ("user/tests/storage/newnewkey", KEY_VALUE, "new key", KEY_END);
498 :
499 8 : Key * found = ksLookupByName (ks, "user/tests/storage/b", KDB_O_POP);
500 8 : succeed_if (found, "did not find key");
501 :
502 : // currently, KDB_O_POP doest not clear the readonly name flag
503 8 : if (test_bit (found->flags, KEY_FLAG_RO_NAME))
504 : {
505 8 : clear_bit (found->flags, KEY_FLAG_RO_NAME);
506 : }
507 :
508 : // overwrite Key
509 8 : succeed_if (keyCopy (found, 0) == 0, "keyCopy: clear destination failed");
510 8 : succeed_if (keyCopy (found, toCopy) == 1, "keyCopy failed");
511 8 : compare_key (found, toCopy);
512 8 : keyDel (toCopy);
513 :
514 : // put key back into place
515 8 : ksAppendKey (ks, found);
516 :
517 : // write KeySet back to storage
518 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
519 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
520 :
521 8 : found = ksLookupByName (ks, "user/tests/storage/newnewkey", 0);
522 8 : succeed_if (found, "did not find key");
523 :
524 8 : keyDel (parentKey);
525 8 : ksDel (ks);
526 8 : closeStoragePlugin (storagePlugin);
527 : }
528 :
529 8 : static void test_keyDel (const size_t storagePlugin, const char * tmpFile)
530 : {
531 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
532 8 : open_storage_plugin (storagePlugin);
533 8 : Plugin * plugin = plugins[storagePlugin];
534 :
535 8 : KeySet * ks = metaTestKeySet ();
536 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
537 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
538 :
539 8 : Key * found = ksLookupByName (ks, "user/tests/storage/b", 0);
540 8 : succeed_if (found, "did not find key");
541 :
542 8 : succeed_if (keyDel (found) > 0, "Key was NULL or free()'d unexpectedly");
543 :
544 : // check that keyDel has not changed KeySet
545 8 : KeySet * expected = metaTestKeySet ();
546 8 : compare_keyset (ks, expected);
547 :
548 8 : ksDel (expected);
549 8 : keyDel (parentKey);
550 8 : ksDel (ks);
551 8 : closeStoragePlugin (storagePlugin);
552 : }
553 :
554 8 : static void test_keyClear (const size_t storagePlugin, const char * tmpFile)
555 : {
556 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
557 8 : open_storage_plugin (storagePlugin);
558 8 : Plugin * plugin = plugins[storagePlugin];
559 :
560 8 : KeySet * ks = metaTestKeySet ();
561 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
562 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
563 :
564 8 : Key * found = ksLookupByName (ks, "user/tests/storage/a", 0);
565 8 : succeed_if (found, "did not find key");
566 :
567 8 : succeed_if (keyClear (found) == 0, "Key was NULL, keyClear failed");
568 :
569 8 : keySetName (found, "user/tests/storage/foo");
570 8 : keySetString (found, "new key value");
571 :
572 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
573 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
574 :
575 8 : keyDel (parentKey);
576 8 : ksDel (ks);
577 8 : closeStoragePlugin (storagePlugin);
578 : }
579 :
580 : /* -- Key name API tests ---------------------------------------------------------------------------------------------------------------- */
581 :
582 8 : static void test_keyName (const size_t storagePlugin, const char * tmpFile)
583 : {
584 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
585 8 : open_storage_plugin (storagePlugin);
586 8 : Plugin * plugin = plugins[storagePlugin];
587 :
588 8 : KeySet * ks = metaTestKeySet ();
589 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
590 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
591 :
592 8 : const char * name = "user/tests/storage/a";
593 8 : Key * found = ksLookupByName (ks, name, 0);
594 8 : succeed_if (found, "did not find key");
595 :
596 8 : ssize_t nameSize = keyGetNameSize (found);
597 8 : succeed_if (elektraStrNCmp (name, keyName (found), nameSize) == 0, "wrong Key name");
598 :
599 8 : keyDel (parentKey);
600 8 : ksDel (ks);
601 8 : closeStoragePlugin (storagePlugin);
602 : }
603 :
604 8 : static void test_keySetName (const size_t storagePlugin, const char * tmpFile)
605 : {
606 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
607 8 : open_storage_plugin (storagePlugin);
608 8 : Plugin * plugin = plugins[storagePlugin];
609 :
610 8 : KeySet * ks = metaTestKeySet ();
611 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
612 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
613 :
614 8 : Key * found = ksLookupByName (ks, "user/tests/storage/b", 0);
615 8 : succeed_if (found, "did not find key");
616 :
617 8 : Key * duplicate = keyDup (found);
618 8 : keySetName (duplicate, "user/tests/storage/z");
619 8 : keySetString (duplicate, "zzz");
620 :
621 8 : KeySet * expected = metaTestKeySet ();
622 8 : compare_keyset (ks, expected);
623 :
624 8 : ksDel (expected);
625 8 : keyDel (duplicate);
626 8 : keyDel (parentKey);
627 8 : ksDel (ks);
628 8 : closeStoragePlugin (storagePlugin);
629 : }
630 :
631 8 : static void test_keyGetFullName (const size_t storagePlugin, const char * tmpFile)
632 : {
633 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
634 8 : open_storage_plugin (storagePlugin);
635 8 : Plugin * plugin = plugins[storagePlugin];
636 :
637 8 : KeySet * ks = metaTestKeySet ();
638 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
639 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
640 :
641 8 : const char * name = "user/tests/storage/a";
642 8 : Key * found = ksLookupByName (ks, name, 0);
643 8 : succeed_if (found, "did not find key");
644 :
645 8 : ssize_t fullNameSize = keyGetFullNameSize (found);
646 8 : char * fullName = elektraMalloc (fullNameSize);
647 8 : ssize_t ret = keyGetFullName (found, fullName, fullNameSize);
648 8 : if (ret < 1)
649 : {
650 0 : yield_error ("Key full name NULL or size error");
651 : }
652 : else
653 : {
654 8 : succeed_if ((size_t) ret >= elektraStrLen (name), "Key full name size too small");
655 : }
656 :
657 8 : elektraFree (fullName);
658 8 : keyDel (parentKey);
659 8 : ksDel (ks);
660 8 : closeStoragePlugin (storagePlugin);
661 : }
662 :
663 8 : static void test_keyGetBaseName (const size_t storagePlugin, const char * tmpFile)
664 : {
665 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
666 8 : open_storage_plugin (storagePlugin);
667 8 : Plugin * plugin = plugins[storagePlugin];
668 :
669 8 : KeySet * ks = metaTestKeySet ();
670 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
671 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
672 :
673 8 : const char * name = "user/tests/storage/a";
674 8 : Key * found = ksLookupByName (ks, name, 0);
675 8 : succeed_if (found, "did not find key");
676 :
677 8 : const char * constBaseName = "a";
678 8 : size_t constBaseNameSize = elektraStrLen (constBaseName);
679 8 : ssize_t baseNameSize = keyGetFullNameSize (found);
680 8 : char * baseName = elektraMalloc (baseNameSize);
681 8 : ssize_t ret = keyGetBaseName (found, baseName, baseNameSize);
682 8 : if (ret < 1)
683 : {
684 0 : yield_error ("Key base name NULL or size error");
685 : }
686 : else
687 : {
688 8 : succeed_if ((size_t) ret == elektraStrLen (constBaseName), "Key base name has wrong size");
689 : }
690 :
691 8 : succeed_if (elektraStrNCmp (constBaseName, baseName, constBaseNameSize) == 0, "Key base name is wrong");
692 :
693 8 : elektraFree (baseName);
694 8 : keyDel (parentKey);
695 8 : ksDel (ks);
696 8 : closeStoragePlugin (storagePlugin);
697 : }
698 :
699 : /* -- Key value API tests --------------------------------------------------------------------------------------------------------------- */
700 :
701 8 : static void test_keyValue (const size_t storagePlugin, const char * tmpFile)
702 : {
703 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
704 8 : open_storage_plugin (storagePlugin);
705 8 : Plugin * plugin = plugins[storagePlugin];
706 :
707 8 : KeySet * ks = metaTestKeySet ();
708 8 : const char * name = "user/tests/storage/specialkey";
709 8 : size_t valueSize = 42;
710 8 : void * value = elektraMalloc (valueSize);
711 8 : memset (value, 42, valueSize);
712 :
713 8 : Key * key = keyNew (name, KEY_END);
714 8 : keySetBinary (key, value, valueSize);
715 8 : ksAppendKey (ks, keyDup (key));
716 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
717 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
718 :
719 8 : Key * found = ksLookupByName (ks, name, 0);
720 8 : succeed_if (found, "did not find key");
721 8 : compare_key (key, found);
722 :
723 8 : elektraFree (value);
724 8 : keyDel (parentKey);
725 8 : ksDel (ks);
726 8 : keyDel (key);
727 8 : closeStoragePlugin (storagePlugin);
728 : }
729 :
730 8 : static void test_keyString (const size_t storagePlugin, const char * tmpFile)
731 : {
732 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
733 8 : open_storage_plugin (storagePlugin);
734 8 : Plugin * plugin = plugins[storagePlugin];
735 :
736 8 : KeySet * ks = metaTestKeySet ();
737 8 : const char * name = "user/tests/storage/specialkey";
738 8 : const char * value = "special value";
739 8 : size_t valueSize = elektraStrLen (value);
740 8 : Key * key = keyNew (name, KEY_VALUE, value, KEY_END);
741 8 : ksAppendKey (ks, key);
742 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
743 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
744 :
745 8 : Key * found = ksLookupByName (ks, name, 0);
746 8 : succeed_if (found, "did not find key");
747 :
748 8 : succeed_if (elektraStrNCmp (value, keyString (found), valueSize) == 0, "Key string value is wrong");
749 :
750 8 : keyDel (parentKey);
751 8 : ksDel (ks);
752 8 : closeStoragePlugin (storagePlugin);
753 : }
754 :
755 8 : static void test_keyGetBinary (const size_t storagePlugin, const char * tmpFile)
756 : {
757 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
758 8 : open_storage_plugin (storagePlugin);
759 8 : Plugin * plugin = plugins[storagePlugin];
760 :
761 8 : KeySet * ks = metaTestKeySet ();
762 8 : const char * name = "user/tests/storage/specialkey";
763 8 : size_t realValueSize = 42;
764 8 : void * value = elektraMalloc (realValueSize);
765 8 : memset (value, 42, realValueSize);
766 :
767 8 : Key * key = keyNew (name, KEY_END);
768 8 : keySetBinary (key, value, realValueSize);
769 8 : ksAppendKey (ks, key);
770 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
771 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
772 :
773 8 : Key * found = ksLookupByName (ks, name, 0);
774 8 : succeed_if (found, "did not find key");
775 :
776 8 : ssize_t apiValueSize = keyGetValueSize (found);
777 8 : char * apiValue = elektraMalloc (apiValueSize);
778 8 : succeed_if (keyGetBinary (found, apiValue, apiValueSize) == (ssize_t) realValueSize, "Key binary has wrong size");
779 :
780 8 : succeed_if (elektraStrNCmp (value, apiValue, realValueSize) == 0, "Key binary value is wrong");
781 :
782 8 : elektraFree (apiValue);
783 8 : elektraFree (value);
784 8 : keyDel (parentKey);
785 8 : ksDel (ks);
786 8 : closeStoragePlugin (storagePlugin);
787 : }
788 :
789 8 : static void test_keyGetString (const size_t storagePlugin, const char * tmpFile)
790 : {
791 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
792 8 : open_storage_plugin (storagePlugin);
793 8 : Plugin * plugin = plugins[storagePlugin];
794 :
795 8 : KeySet * ks = metaTestKeySet ();
796 8 : const char * name = "user/tests/storage/specialkey";
797 8 : const char * value = "special value";
798 8 : size_t realValueSize = elektraStrLen (value);
799 8 : Key * key = keyNew (name, KEY_VALUE, value, KEY_END);
800 8 : ksAppendKey (ks, key);
801 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
802 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
803 :
804 8 : Key * found = ksLookupByName (ks, name, 0);
805 8 : succeed_if (found, "did not find key");
806 :
807 8 : ssize_t apiValueSize = keyGetValueSize (found);
808 8 : char * apiString = elektraMalloc (apiValueSize);
809 8 : succeed_if (keyGetString (found, apiString, apiValueSize) == (ssize_t) realValueSize, "Key string has wrong size");
810 :
811 8 : succeed_if (elektraStrNCmp (value, apiString, realValueSize) == 0, "Key string value is wrong");
812 :
813 8 : elektraFree (apiString);
814 8 : keyDel (parentKey);
815 8 : ksDel (ks);
816 8 : closeStoragePlugin (storagePlugin);
817 : }
818 :
819 8 : static void test_keySetBinary (const size_t storagePlugin, const char * tmpFile)
820 : {
821 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
822 8 : open_storage_plugin (storagePlugin);
823 8 : Plugin * plugin = plugins[storagePlugin];
824 :
825 8 : KeySet * ks = metaTestKeySet ();
826 8 : const char * name = "user/tests/storage/specialkey";
827 8 : size_t realValueSize = 42;
828 8 : void * value = elektraMalloc (realValueSize);
829 8 : memset (value, 42, realValueSize);
830 :
831 8 : Key * key = keyNew (name, KEY_END);
832 8 : keySetBinary (key, value, realValueSize);
833 8 : ksAppendKey (ks, key);
834 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
835 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
836 :
837 8 : Key * found = ksLookupByName (ks, name, KDB_O_POP);
838 8 : succeed_if (found, "did not find key");
839 :
840 : // now set a new key value to the Key _after_ kdbGet
841 8 : size_t newValueSize = 4096;
842 8 : void * newValue = elektraMalloc (newValueSize);
843 8 : memset (newValue, 253, newValueSize);
844 :
845 8 : succeed_if (keySetBinary (found, newValue, newValueSize) == (ssize_t) newValueSize, "Key binary could not be set");
846 :
847 8 : ksAppendKey (ks, found);
848 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
849 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
850 :
851 8 : found = ksLookupByName (ks, name, 0);
852 8 : succeed_if (found, "did not find key");
853 :
854 8 : ssize_t apiValueSize = keyGetValueSize (found);
855 8 : char * apiValue = elektraMalloc (apiValueSize);
856 8 : succeed_if (keyGetBinary (found, apiValue, apiValueSize) == (ssize_t) newValueSize, "Key binary has wrong size");
857 :
858 8 : succeed_if (elektraStrNCmp (value, apiValue, realValueSize) != 0, "Key binary value is wrong");
859 8 : succeed_if (elektraStrNCmp (newValue, apiValue, newValueSize) == 0, "Key binary value is wrong");
860 :
861 8 : elektraFree (newValue);
862 8 : elektraFree (apiValue);
863 8 : elektraFree (value);
864 8 : keyDel (parentKey);
865 8 : ksDel (ks);
866 8 : closeStoragePlugin (storagePlugin);
867 : }
868 :
869 8 : static void test_keySetString (const size_t storagePlugin, const char * tmpFile)
870 : {
871 8 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
872 8 : open_storage_plugin (storagePlugin);
873 8 : Plugin * plugin = plugins[storagePlugin];
874 :
875 8 : KeySet * ks = metaTestKeySet ();
876 8 : const char * name = "user/tests/storage/specialkey";
877 8 : const char * value = "special value";
878 8 : size_t realValueSize = elektraStrLen (value);
879 8 : Key * key = keyNew (name, KEY_VALUE, value, KEY_END);
880 8 : ksAppendKey (ks, key);
881 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
882 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
883 :
884 8 : Key * found = ksLookupByName (ks, name, KDB_O_POP);
885 8 : succeed_if (found, "did not find key");
886 :
887 : // now set a new key string to the Key _after_ kdbGet
888 8 : const char * newValue = "some new special value";
889 8 : size_t newValueSize = elektraStrLen (newValue);
890 :
891 8 : succeed_if (keySetString (found, newValue) == (ssize_t) newValueSize, "Key string could not be set");
892 :
893 8 : ksAppendKey (ks, found);
894 8 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
895 8 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
896 :
897 8 : found = ksLookupByName (ks, name, 0);
898 8 : succeed_if (found, "did not find key");
899 :
900 8 : ssize_t apiValueSize = keyGetValueSize (found);
901 8 : char * apiValue = elektraMalloc (apiValueSize);
902 8 : succeed_if (keyGetString (found, apiValue, apiValueSize) == (ssize_t) newValueSize, "Key string has wrong size");
903 :
904 8 : succeed_if (elektraStrNCmp (value, apiValue, realValueSize) != 0, "Key string value is wrong");
905 8 : succeed_if (elektraStrNCmp (newValue, apiValue, newValueSize) == 0, "Key string value is wrong");
906 :
907 8 : elektraFree (apiValue);
908 8 : keyDel (parentKey);
909 8 : ksDel (ks);
910 8 : closeStoragePlugin (storagePlugin);
911 : }
912 :
913 232 : static void clearStorage (const size_t storagePlugin, const char * tmpFile)
914 : {
915 232 : Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
916 232 : open_storage_plugin (storagePlugin);
917 232 : Plugin * plugin = plugins[storagePlugin];
918 :
919 232 : KeySet * ks = ksNew (0, KS_END);
920 :
921 232 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
922 :
923 232 : keyDel (parentKey);
924 232 : ksDel (ks);
925 :
926 232 : closeStoragePlugin (storagePlugin);
927 : }
928 :
929 : /* -- Main ------------------------------------------------------------------------------------------------------------------------------ */
930 :
931 2 : int main (int argc, char ** argv)
932 : {
933 2 : printf ("STORAGE TESTS\n");
934 2 : printf ("==================\n\n");
935 :
936 2 : init (argc, argv);
937 :
938 2 : initPlugins ();
939 :
940 10 : for (size_t plugin = 0; plugin < numPlugins; ++plugin)
941 : {
942 8 : const char * tmpFile = elektraFilename ();
943 :
944 8 : printf ("Testing plugin %s\n", pluginNames[plugin]);
945 8 : fprintf (stdout, "Tmp-file: %s\n", tmpFile);
946 :
947 : // KeySet API tests
948 8 : clearStorage (plugin, tmpFile);
949 8 : test_ksDupFun (plugin, tmpFile, ksDup);
950 :
951 8 : clearStorage (plugin, tmpFile);
952 8 : test_ksDupFun (plugin, tmpFile, ksDeepDup);
953 :
954 8 : clearStorage (plugin, tmpFile);
955 8 : test_ksCopy (plugin, tmpFile);
956 :
957 8 : clearStorage (plugin, tmpFile);
958 8 : test_ksGetSize (plugin, tmpFile);
959 :
960 8 : clearStorage (plugin, tmpFile);
961 8 : test_double_get (plugin, tmpFile); // regression test
962 :
963 8 : clearStorage (plugin, tmpFile);
964 8 : test_ksAppendKey (plugin, tmpFile);
965 :
966 8 : clearStorage (plugin, tmpFile);
967 8 : test_ksAppend (plugin, tmpFile);
968 :
969 8 : clearStorage (plugin, tmpFile);
970 8 : test_ksCut (plugin, tmpFile);
971 :
972 8 : clearStorage (plugin, tmpFile);
973 8 : test_ksPop (plugin, tmpFile);
974 :
975 8 : clearStorage (plugin, tmpFile);
976 8 : test_ksLookup (plugin, tmpFile, 0);
977 :
978 8 : clearStorage (plugin, tmpFile);
979 8 : test_ksLookup (plugin, tmpFile, KDB_O_POP);
980 :
981 8 : clearStorage (plugin, tmpFile);
982 8 : test_ksLookupByName (plugin, tmpFile, 0);
983 :
984 8 : clearStorage (plugin, tmpFile);
985 8 : test_ksLookupByName (plugin, tmpFile, KDB_O_POP);
986 :
987 : // Key API tests
988 8 : clearStorage (plugin, tmpFile);
989 8 : test_keyFlags (plugin, tmpFile);
990 :
991 8 : clearStorage (plugin, tmpFile);
992 8 : test_keyDup (plugin, tmpFile);
993 :
994 8 : clearStorage (plugin, tmpFile);
995 8 : test_keyCopy_newKey (plugin, tmpFile);
996 :
997 8 : clearStorage (plugin, tmpFile);
998 8 : test_keyCopy_clearOverwriteKey (plugin, tmpFile);
999 :
1000 8 : clearStorage (plugin, tmpFile);
1001 8 : test_keyDel (plugin, tmpFile);
1002 :
1003 8 : clearStorage (plugin, tmpFile);
1004 8 : test_keyClear (plugin, tmpFile);
1005 :
1006 : // Key Name API tests
1007 8 : clearStorage (plugin, tmpFile);
1008 8 : test_keyName (plugin, tmpFile);
1009 :
1010 8 : clearStorage (plugin, tmpFile);
1011 8 : test_keySetName (plugin, tmpFile);
1012 :
1013 8 : clearStorage (plugin, tmpFile);
1014 8 : test_keyGetFullName (plugin, tmpFile);
1015 :
1016 8 : clearStorage (plugin, tmpFile);
1017 8 : test_keyGetBaseName (plugin, tmpFile);
1018 :
1019 : // Key Value API tests
1020 8 : clearStorage (plugin, tmpFile);
1021 8 : test_keyValue (plugin, tmpFile);
1022 :
1023 8 : clearStorage (plugin, tmpFile);
1024 8 : test_keyString (plugin, tmpFile);
1025 :
1026 8 : clearStorage (plugin, tmpFile);
1027 8 : test_keyGetBinary (plugin, tmpFile);
1028 :
1029 8 : clearStorage (plugin, tmpFile);
1030 8 : test_keyGetString (plugin, tmpFile);
1031 :
1032 8 : clearStorage (plugin, tmpFile);
1033 8 : test_keySetBinary (plugin, tmpFile);
1034 :
1035 8 : clearStorage (plugin, tmpFile);
1036 8 : test_keySetString (plugin, tmpFile);
1037 : }
1038 :
1039 2 : printf ("\ntest_storage RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
1040 :
1041 2 : return nbError;
1042 : }
|