LCOV - code coverage report
Current view: top level - src/plugins/lineendings - testmod_lineendings.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 42 42 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 lineendings 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 : void testvalid (const char * file)
      18             : {
      19           2 :         Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
      20           2 :         KeySet * conf = 0;
      21           2 :         PLUGIN_OPEN ("lineendings");
      22           2 :         KeySet * ks = ksNew (0, KS_END);
      23           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
      24           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbset failed");
      25           2 :         ksDel (ks);
      26           2 :         keyDel (parentKey);
      27           2 :         PLUGIN_CLOSE ();
      28           2 : }
      29             : 
      30           2 : void testinconsistent (const char * file)
      31             : {
      32           2 :         Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
      33           2 :         KeySet * conf = 0;
      34           2 :         PLUGIN_OPEN ("lineendings");
      35           2 :         KeySet * ks = ksNew (0, KS_END);
      36           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == (-1), "should have failed");
      37           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "should have failed");
      38           2 :         ksDel (ks);
      39           2 :         keyDel (parentKey);
      40           2 :         PLUGIN_CLOSE ();
      41           2 : }
      42             : 
      43           2 : void testinvalid (const char * file)
      44             : {
      45           2 :         Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
      46           2 :         KeySet * conf = ksNew (20, keyNew ("system/valid", KEY_VALUE, "CRLF", KEY_END), KS_END);
      47           2 :         PLUGIN_OPEN ("lineendings");
      48           2 :         KeySet * ks = ksNew (0, KS_END);
      49           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
      50           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "should have failed");
      51           2 :         ksDel (ks);
      52           2 :         keyDel (parentKey);
      53           2 :         PLUGIN_CLOSE ();
      54           2 : }
      55             : 
      56             : 
      57           2 : int main (int argc, char ** argv)
      58             : {
      59           2 :         printf ("LINEENDINGS     TESTS\n");
      60           2 :         printf ("==================\n\n");
      61             : 
      62           2 :         init (argc, argv);
      63             : 
      64           2 :         testvalid ("lineendings/valid1");
      65           2 :         testinconsistent ("lineendings/inconsistent");
      66           2 :         testinvalid ("lineendings/invalid");
      67           2 :         print_result ("testmod_lineendings");
      68             : 
      69           2 :         return nbError;
      70             : }

Generated by: LCOV version 1.13