LCOV - code coverage report
Current view: top level - src/plugins/list - testmod_list.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 31 35 88.6 %
Date: 2019-09-12 12:28:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for list plugin
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #include <stdlib.h>
      11             : #include <string.h>
      12             : 
      13             : #include <kdbconfig.h>
      14             : 
      15             : #include <tests_plugin.h>
      16             : 
      17           2 : static void doTest (void)
      18             : {
      19           2 :         KeySet * ks = ksNew (5, keyNew ("user/tests/list/to/be/cut/key1", KEY_END), keyNew ("user/tests/list/to/be/cut/key2", KEY_END),
      20             :                              keyNew ("user/tests/list/to/be/cut/meta1", KEY_END),
      21             :                              keyNew ("user/tests/list/to/be/cut/meta2", KEY_VALUE, "meta?", KEY_META, "convert/metaname", "amimetanow?",
      22             :                                      KEY_META, "convert/append", "previous", KEY_END),
      23             :                              KS_END);
      24           2 :         KeySet * conf = ksNew (20, keyNew ("user/placements", KEY_END), keyNew ("user/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
      25             :                                keyNew ("user/placements/set", KEY_VALUE, "presetstorage", KEY_END), keyNew ("user/plugins", KEY_END),
      26             :                                keyNew ("user/plugins/#0", KEY_VALUE, "rename", KEY_END), keyNew ("user/plugins/#0/config", KEY_END),
      27             :                                // Configure "rename" plugin directly to cut a part of the key name
      28             :                                keyNew ("user/plugins/#0/config/cut", KEY_VALUE, "to/be/cut", KEY_END),
      29             :                                keyNew ("user/plugins/#0/placements", KEY_END),
      30             :                                keyNew ("user/plugins/#0/placements/set", KEY_VALUE, "presetstorage", KEY_END),
      31             :                                keyNew ("user/plugins/#0/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
      32             :                                keyNew ("user/plugins/#1", KEY_VALUE, "keytometa", KEY_END), keyNew ("user/plugins/#1/placements", KEY_END),
      33             :                                keyNew ("user/plugins/#1/placements/set", KEY_VALUE, "presetstorage", KEY_END),
      34             :                                keyNew ("user/plugins/#1/placements/get", KEY_VALUE, "pregetstorage", KEY_END),
      35             :                                // For all plugins, but only used by "rename" plugin
      36             :                                keyNew ("user/config", KEY_END), keyNew ("user/config/toupper", KEY_END), KS_END);
      37           2 :         Key * parentKey = keyNew ("user/tests/list", KEY_END);
      38           2 :         ksAppendKey (ks, parentKey);
      39           2 :         PLUGIN_OPEN ("list");
      40             : 
      41           2 :         Plugin * check = elektraPluginOpen ("keytometa", modules, ksNew (5, KS_END), parentKey);
      42           2 :         if (!check)
      43             :         {
      44           0 :                 printf ("Abort test case, keytometa is missing");
      45           0 :                 goto end;
      46             :         }
      47           2 :         elektraPluginClose (check, 0);
      48             : 
      49           2 :         check = elektraPluginOpen ("rename", modules, ksNew (5, KS_END), parentKey);
      50           2 :         if (!check)
      51             :         {
      52           0 :                 printf ("Abort test case, rename is missing");
      53           0 :                 goto end;
      54             :         }
      55           2 :         elektraPluginClose (check, 0);
      56             : 
      57           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
      58           2 :         const Key * key = ksLookupByName (ks, "user/tests/list/META1", 0);
      59           2 :         succeed_if (key, "key not found");
      60           2 :         const Key * meta = keyGetMeta (key, "amimetanow?");
      61           2 :         succeed_if (meta, "metakey not found");
      62           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 0, "kdbset failed");
      63           2 :         key = ksLookupByName (ks, "user/tests/list/to/be/cut/meta1", 0);
      64           2 :         succeed_if (key, "key not found");
      65             : 
      66             : end:
      67           2 :         PLUGIN_CLOSE ();
      68           2 :         keyDel (parentKey);
      69           2 :         ksDel (ks);
      70           2 : }
      71             : 
      72           2 : int main (int argc, char ** argv)
      73             : {
      74           2 :         printf ("LIST     TESTS\n");
      75           2 :         printf ("==================\n\n");
      76             : 
      77           2 :         init (argc, argv);
      78             : 
      79           2 :         doTest ();
      80             : 
      81           2 :         print_result ("testmod_list");
      82             : 
      83           2 :         return nbError;
      84             : }

Generated by: LCOV version 1.13