LCOV - code coverage report
Current view: top level - src/plugins/dump - testmod_dump.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 6 10 60.0 %
Date: 2019-09-12 12:28:41 Functions: 1 2 50.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             : #ifdef HAVE_KDBCONFIG_H
      10             : #include "kdbconfig.h"
      11             : #endif
      12             : 
      13             : #include <stdio.h>
      14             : #ifdef HAVE_STDLIB_H
      15             : #include <stdlib.h>
      16             : #endif
      17             : #ifdef HAVE_STRING_H
      18             : #include <string.h>
      19             : #endif
      20             : 
      21             : #include <tests.h>
      22             : 
      23           0 : KeySet * get_dump (void)
      24             : {
      25             :         Key *k1, *k2;
      26             :         // clang-format off
      27           0 :         KeySet *ks = ksNew(10,
      28             :                         k1 = keyNew("user/tests/dump",
      29             :                                KEY_VALUE, "root key",
      30             :                                KEY_META, "a", "b",
      31             :                                KEY_END),
      32             :                         k2 = keyNew("user/tests/dump/a",
      33             :                                KEY_VALUE, "a value",
      34             :                                KEY_META, "ab", "cd",
      35             :                                KEY_END),
      36             :                         keyNew("user/tests/dump/b",
      37             :                                KEY_VALUE, "b value",
      38             :                                KEY_META, "longer val", "here some even more with ugly €@\\1¹²³¼ chars",
      39             :                                KEY_END),
      40             :                         KS_END
      41             :                 );
      42             :         // clang-format on
      43           0 :         keyCopyMeta (k1, k2, "ab");
      44             : 
      45           0 :         return ks;
      46             : }
      47             : 
      48             : #if 0
      49             : 
      50             : void test_writedump(const char *file)
      51             : {
      52             :         KDB *kdb = kdbOpen();
      53             :         Key *mnt;
      54             :         KeySet *conf;
      55             :         KeySet *ks = get_dump();
      56             : 
      57             :         printf("Test write dump\n");
      58             : 
      59             :         succeed_if (kdbMount(kdb,mnt=keyNew("user/tests/dump",KEY_VALUE,"dump", KEY_END),
      60             :                 conf=ksNew (2,keyNew("system/path", KEY_VALUE, file, KEY_END), KS_END)) == 0,
      61             :                 "could not mount dump");
      62             :         succeed_if (kdbSet(kdb,ks,keyNew("user/tests/dump",KEY_END),KDB_O_DEL) >= 0, "could not set keys");
      63             :         ksDel (conf);
      64             :         keyDel(mnt);
      65             : 
      66             :         ksDel (ks);
      67             :         kdbClose (kdb);
      68             : }
      69             : 
      70             : void test_readdump(const char *file)
      71             : {
      72             :         KDB *kdb = kdbOpen();
      73             :         Key *mnt;
      74             :         KeySet *conf;
      75             :         KeySet *ks = get_dump();
      76             :         KeySet *read = ksNew(0, KS_END);
      77             :         Key *k1, *k2;
      78             : 
      79             :         printf("Test read dump\n");
      80             : 
      81             :         succeed_if (kdbMount(kdb,mnt=keyNew("user/tests/dump",KEY_VALUE,"dump", KEY_END),
      82             :                 conf=ksNew (2,keyNew("system/path", KEY_VALUE, file, KEY_END), KS_END)) == 0,
      83             :                 "could not mount dump");
      84             :         succeed_if (kdbGet(kdb,read,keyNew("user/tests/dump",KEY_END),KDB_O_DEL) >= 0, "could not get keys");
      85             :         ksDel (conf);
      86             :         keyDel(mnt);
      87             : 
      88             :         compare_keyset (read, ks, 0, 0);
      89             : 
      90             :         k1 = ksLookupByName(ks, "user/tests/dump", 0);
      91             :         succeed_if (k1 != 0, "did not find key");
      92             :         k2 = ksLookupByName(ks, "user/tests/dump/a", 0);
      93             :         succeed_if (k2 != 0, "did not find key");
      94             : 
      95             :         succeed_if (!strcmp(keyValue(keyGetMeta(k1, "ab")), "cd"), "metavalue not correct");
      96             :         succeed_if (!strcmp(keyValue(keyGetMeta(k2, "ab")), "cd"), "metavalue not correct");
      97             :         succeed_if (keyGetMeta(k1, "ab") == keyGetMeta(k2, "ab"), "does not point to the same storage");
      98             : 
      99             :         // ksOutput (read, stdout, KEY_VALUE);
     100             : 
     101             :         ksDel (ks);
     102             :         ksDel (read);
     103             :         kdbClose (kdb);
     104             : }
     105             : 
     106             : #endif
     107             : 
     108           2 : int main (int argc, char ** argv)
     109             : {
     110           2 :         printf ("MOUNT       TESTS\n");
     111           2 :         printf ("==================\n\n");
     112             : 
     113           2 :         init (argc, argv);
     114             : 
     115             :         /*
     116             :         test_writedump("dump_mount_test.edf");
     117             :         test_readdump("dump_mount_test.edf");
     118             :         */
     119             : 
     120           2 :         print_result ("test_mount");
     121             : 
     122           2 :         return nbError;
     123             : }

Generated by: LCOV version 1.13