LCOV - code coverage report
Current view: top level - examples - cascading.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 0 35 0.0 %
Date: 2019-09-12 12:28:41 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <kdb.h>
      10             : 
      11             : #include <stdio.h>
      12             : 
      13           0 : void printError (char * what, Key const * parentKey)
      14             : {
      15           0 :         printf ("%s \"%s\" returned error: %s and reason %s\n", what, keyName (parentKey),
      16             :                 keyString (keyGetMeta (parentKey, "error/number")), keyString (keyGetMeta (parentKey, "error/reason")));
      17           0 : }
      18             : 
      19           0 : int main (void)
      20             : {
      21           0 :         Key * parentKey = keyNew ("", KEY_CASCADING_NAME, KEY_END);
      22           0 :         KDB * kdb = kdbOpen (parentKey);
      23           0 :         KeySet * ks = ksNew (0, KS_END);
      24           0 :         if (kdbGet (kdb, ks, parentKey) == -1)
      25             :         {
      26           0 :                 printError ("kdbGet", parentKey);
      27             :         }
      28           0 :         keyDel (parentKey);
      29           0 :         parentKey = keyNew ("meta", KEY_META_NAME, KEY_END);
      30           0 :         if (kdbGet (kdb, ks, parentKey) == -1)
      31             :         {
      32           0 :                 printError ("kdbGet", parentKey);
      33             :         }
      34           0 :         keyDel (parentKey);
      35           0 :         parentKey = keyNew ("/test/shell/somewhere", KEY_CASCADING_NAME, KEY_END);
      36           0 :         if (kdbGet (kdb, ks, parentKey) == -1)
      37             :         {
      38           0 :                 printError ("kdbGet", parentKey);
      39             :         }
      40           0 :         keyDel (parentKey);
      41             : 
      42           0 :         ksRewind (ks);
      43             :         Key * k;
      44           0 :         while ((k = ksNext (ks)))
      45             :         {
      46           0 :                 printf ("%s = %s\n", keyName (k), keyString (k));
      47             :         }
      48             : 
      49             :         /*
      50             :         k = keyNew("user/test/shell/somewhere/key", KEY_VALUE, "value", KEY_END);
      51             :         ksAppendKey(ks, k);
      52             :         keyDel(k);
      53             :         */
      54             : 
      55           0 :         parentKey = keyNew ("/", KEY_CASCADING_NAME, KEY_END);
      56           0 :         if (kdbSet (kdb, ks, parentKey) == -1)
      57             :         {
      58           0 :                 printError ("kdbSet", parentKey);
      59             :         }
      60           0 :         keyDel (parentKey);
      61           0 :         parentKey = keyNew ("meta", KEY_META_NAME, KEY_END);
      62           0 :         if (kdbSet (kdb, ks, parentKey) == -1)
      63             :         {
      64           0 :                 printError ("kdbSet", parentKey);
      65             :         }
      66           0 :         keyDel (parentKey);
      67           0 :         parentKey = keyNew ("/test/shell/somewhere", KEY_CASCADING_NAME, KEY_END);
      68           0 :         if (kdbSet (kdb, ks, parentKey) == -1)
      69             :         {
      70           0 :                 printError ("kdbSet", parentKey);
      71             :         }
      72             : 
      73           0 :         ksDel (ks);
      74           0 :         kdbClose (kdb, 0);
      75           0 :         keyDel (parentKey);
      76             : }

Generated by: LCOV version 1.13