LCOV - code coverage report
Current view: top level - src/plugins/process - testmod_process.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 65 65 100.0 %
Date: 2019-09-12 12:28:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for process 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 test_basics (void)
      18             : {
      19           2 :         printf ("test basics\n");
      20             : 
      21           2 :         const char * tmpFile = elektraFilename ();
      22             : 
      23           2 :         Key * parentKey = keyNew ("user/tests/process", KEY_VALUE, tmpFile, KEY_END);
      24           2 :         KeySet * conf = ksNew (0, KS_END);
      25             :         // We can safely assume dump exists as without it the processplugin wouldn't work
      26             :         // We don't test any other plugin here since we can't make any guarantees about their existence
      27           2 :         Key * pluginKey = keyNew ("/plugin", KEY_VALUE, "dump", KEY_END);
      28           2 :         ksAppendKey (conf, pluginKey);
      29           2 :         PLUGIN_OPEN ("process");
      30             : 
      31           2 :         KeySet * ks = ksNew (0, KS_END);
      32             : 
      33           2 :         succeed_if (plugin->kdbOpen (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbOpen was not successful");
      34             : 
      35           2 :         Key * contractKey = keyNew ("system/elektra/modules/process", KEY_END);
      36           2 :         KeySet * contractSet = ksNew (0, KS_END);
      37             : 
      38           2 :         succeed_if (plugin->kdbGet (plugin, contractSet, contractKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS,
      39             :                     "call to kdbGet for the contract was not successful");
      40             : 
      41           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
      42           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
      43           2 :         succeed_if (plugin->kdbError (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbError was not successful");
      44           2 :         succeed_if (plugin->kdbClose (plugin, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbClose was not successful");
      45             : 
      46           2 :         keyDel (contractKey);
      47           2 :         ksDel (contractSet);
      48           2 :         keyDel (parentKey);
      49           2 :         ksDel (ks);
      50           2 :         PLUGIN_CLOSE ();
      51           2 :         elektraUnlink (tmpFile);
      52           2 : }
      53             : 
      54           2 : static void test_no_plugin_key (void)
      55             : {
      56           2 :         printf ("test no plugin key \n");
      57             : 
      58           2 :         Key * parentKey = keyNew ("user/tests/process", KEY_END);
      59           2 :         KeySet * conf = ksNew (0, KS_END);
      60             :         // No plugin key, should fail
      61           2 :         KeySet * modules = ksNew (0, KS_END);
      62           2 :         elektraModulesInit (modules, 0);
      63           2 :         Key * errorKey = keyNew ("", KEY_END);
      64           2 :         Plugin * plugin = elektraPluginOpen ("process", modules, conf, errorKey);
      65           2 :         succeed_if (!output_warnings (errorKey), "no warnings in kdbOpen for plugin process");
      66           2 :         succeed_if (output_error (errorKey), "error in kdbOpen for plugin process");
      67             : 
      68           2 :         keyDel (errorKey);
      69           2 :         keyDel (parentKey);
      70           2 :         succeed_if (plugin != 0, "could not open process plugin");
      71           2 :         PLUGIN_CLOSE ();
      72           2 : }
      73             : 
      74           2 : static void test_invalid_plugin_key (void)
      75             : {
      76           2 :         printf ("test invalid plugin key\n");
      77             : 
      78           2 :         Key * parentKey = keyNew ("user/tests/process", KEY_END);
      79           2 :         KeySet * conf = ksNew (0, KS_END);
      80           2 :         Key * pluginKey = keyNew ("/plugin", KEY_VALUE, "non_existent_plugin", KEY_END);
      81           2 :         ksAppendKey (conf, pluginKey);
      82             : 
      83             :         // Non-existent plugin, should fail
      84           2 :         KeySet * modules = ksNew (0, KS_END);
      85           2 :         elektraModulesInit (modules, 0);
      86           2 :         Key * errorKey = keyNew ("", KEY_END);
      87           2 :         Plugin * plugin = elektraPluginOpen ("process", modules, conf, errorKey);
      88           2 :         succeed_if (!output_warnings (errorKey), "no warnings in kdbOpen for plugin process");
      89           2 :         succeed_if (!output_error (errorKey), "no error in kdbOpen for plugin process");
      90             : 
      91           2 :         keyDel (errorKey);
      92           2 :         keyDel (parentKey);
      93           2 :         succeed_if (plugin == 0, "could open process plugin");
      94           2 :         PLUGIN_CLOSE ();
      95           2 : }
      96             : 
      97           2 : int main (int argc, char ** argv)
      98             : {
      99           2 :         printf ("PROCESS     TESTS\n");
     100           2 :         printf ("==================\n\n");
     101             : 
     102           2 :         init (argc, argv);
     103             : 
     104           2 :         test_basics ();
     105           2 :         test_no_plugin_key ();
     106           2 :         test_invalid_plugin_key ();
     107             : 
     108           2 :         print_result ("testmod_process");
     109             : 
     110           2 :         return nbError;
     111             : }

Generated by: LCOV version 1.13