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

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for camel plugin
       5             :  *
       6             :  * @copyright BSD License (see doc/LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : /* -- Imports --------------------------------------------------------------------------------------------------------------------------- */
      11             : 
      12             : #include <stdlib.h>
      13             : #include <string.h>
      14             : 
      15             : #include <kdbconfig.h>
      16             : 
      17             : #include <tests_plugin.h>
      18             : 
      19             : /* -- Macros ---------------------------------------------------------------------------------------------------------------------------- */
      20             : 
      21             : #define MAX_LENGTH_TEXT 500
      22             : 
      23             : /* -- Functions ------------------------------------------------------------------------------------------------------------------------- */
      24             : 
      25           2 : static void test_basics (void)
      26             : {
      27           2 :         printf ("• Test basic functionality of plugin\n");
      28             : 
      29           2 :         Key * parentKey = keyNew ("system/elektra/modules/camel", KEY_END);
      30           2 :         KeySet * conf = ksNew (0, KS_END);
      31           2 :         PLUGIN_OPEN ("camel");
      32             : 
      33           2 :         KeySet * ks = ksNew (0, KS_END);
      34             : 
      35           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "Could not retrieve plugin contract");
      36             : 
      37           2 :         keyDel (parentKey);
      38           2 :         ksDel (ks);
      39           2 :         PLUGIN_CLOSE ();
      40           2 : }
      41             : 
      42           2 : static void test_get (void)
      43             : {
      44           2 :         char const * const fileName = "camel/simple.yaml";
      45           2 :         printf ("• Parse file “%s”\n", fileName);
      46             : 
      47           2 :         char const * const prefix = "user/camel/tests/read";
      48           2 :         Key * parentKey = keyNew (prefix, KEY_VALUE, srcdir_file (fileName), KEY_END);
      49           2 :         KeySet * conf = ksNew (0, KS_END);
      50           2 :         PLUGIN_OPEN ("camel");
      51             : 
      52           2 :         KeySet * keySet = ksNew (0, KS_END);
      53             : 
      54           2 :         int status = plugin->kdbGet (plugin, keySet, parentKey);
      55             : 
      56           2 :         succeed_if (status == ELEKTRA_PLUGIN_STATUS_SUCCESS || status == ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "Unable to open or parse file");
      57           2 :         succeed_if (output_error (parentKey), "Received unexpected error while reading the configuration");
      58             : 
      59           2 :         char keyValues[][2][50] = {
      60             :                 { "hello", "world" },
      61             :         };
      62             : 
      63             :         Key * key;
      64             :         char text[MAX_LENGTH_TEXT];
      65           4 :         for (size_t pair = 0; pair < sizeof (keyValues) / sizeof (keyValues[0]); pair++)
      66             :         {
      67           2 :                 char * name = keyValues[pair][0];
      68           2 :                 char * value = keyValues[pair][1];
      69           2 :                 snprintf (text, MAX_LENGTH_TEXT, "%s/%s", prefix, name);
      70           2 :                 key = ksLookupByName (keySet, text, KDB_O_NONE);
      71             : 
      72           2 :                 snprintf (text, MAX_LENGTH_TEXT, "Key “%s” not found", name);
      73           2 :                 exit_if_fail (key, text);
      74             : 
      75           2 :                 succeed_if_same_string (keyString (key), value);
      76             :         }
      77             : 
      78           2 :         keyDel (parentKey);
      79           2 :         ksDel (keySet);
      80           2 :         PLUGIN_CLOSE ();
      81           2 : }
      82             : 
      83             : // ========
      84             : // = Main =
      85             : // ========
      86             : 
      87           2 : int main (int argc, char ** argv)
      88             : {
      89           2 :         printf ("🐪 Camel Tests\n");
      90           2 :         printf ("===============\n\n");
      91             : 
      92           2 :         init (argc, argv);
      93             : 
      94           2 :         test_basics ();
      95           2 :         test_get ();
      96             : 
      97           2 :         print_result ("testmod_camel");
      98             : 
      99           2 :         return nbError;
     100             : }

Generated by: LCOV version 1.13