LCOV - code coverage report
Current view: top level - src/plugins/specload - testapp.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 31 32 96.9 %
Date: 2019-09-12 12:28:41 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for specload 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 <kdbinvoke.h>
      14             : #include <kdbmodule.h>
      15             : 
      16             : #include "testdata.h"
      17             : 
      18             : // keep #ifdef in sync with kdb export
      19             : #ifdef _WIN32
      20             : #define STDOUT_FILENAME ("CON")
      21             : #else
      22             : #define STDOUT_FILENAME ("/dev/stdout")
      23             : #endif
      24             : 
      25          46 : static int outputKeySet (KeySet * ks, int noparent)
      26             : {
      27          46 :         Key * parentKey = keyNew (PARENT_KEY, KEY_END);
      28             : 
      29          46 :         if (noparent)
      30             :         {
      31           2 :                 keySetMeta (parentKey, "system/elektra/quickdump/noparent", "");
      32             :         }
      33             : 
      34          46 :         KeySet * specloadConf = ksNew (1, keyNew ("system/sendspec", KEY_END), KS_END);
      35          46 :         ElektraInvokeHandle * specload = elektraInvokeOpen ("specload", specloadConf, parentKey);
      36             : 
      37          46 :         int result = elektraInvoke2Args (specload, "sendspec", ks, parentKey);
      38             : 
      39          46 :         elektraInvokeClose (specload, parentKey);
      40          46 :         keyDel (parentKey);
      41          46 :         ksDel (specloadConf);
      42             : 
      43          46 :         return result == ELEKTRA_PLUGIN_STATUS_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
      44             : }
      45             : 
      46          44 : static int outputDefaultSpec (void)
      47             : {
      48          44 :         KeySet * ks = DEFAULT_SPEC;
      49          44 :         int result = outputKeySet (ks, 0);
      50          44 :         ksDel (ks);
      51          44 :         return result;
      52             : }
      53             : 
      54           2 : static int outputNoParentSpec (void)
      55             : {
      56           2 :         KeySet * ks = NOPARENT_SPEC;
      57           2 :         int result = outputKeySet (ks, 1);
      58           2 :         ksDel (ks);
      59           2 :         return result;
      60             : }
      61             : 
      62           2 : static int outputSpec (const char * name)
      63             : {
      64           2 :         if (strcmp (name, "default") == 0)
      65             :         {
      66           0 :                 return outputDefaultSpec ();
      67             :         }
      68             : 
      69           2 :         if (strcmp (name, "noparent") == 0)
      70             :         {
      71           2 :                 return outputNoParentSpec ();
      72             :         }
      73             : 
      74             :         return EXIT_FAILURE;
      75             : }
      76             : 
      77          46 : int main (int argc, const char ** argv)
      78             : {
      79          46 :         if (argc != 2 && argc != 3)
      80             :         {
      81             :                 return EXIT_FAILURE;
      82             :         }
      83             : 
      84          46 :         if (strcmp (argv[1], "--elektra-spec") == 0)
      85             :         {
      86          44 :                 return outputDefaultSpec ();
      87             :         }
      88           2 :         else if (strcmp (argv[1], "spec") == 0 && argc == 3)
      89             :         {
      90           2 :                 return outputSpec (argv[2]);
      91             :         }
      92             : 
      93             :         return EXIT_FAILURE;
      94             : }

Generated by: LCOV version 1.13