LCOV - code coverage report
Current view: top level - tests/ctest - test_utility.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 64 64 100.0 %
Date: 2019-09-12 12:28:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Test suite for Libease functions accessing key name data.
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <kdbutility.h>
      10             : 
      11             : #include "tests.h"
      12             : 
      13             : #define MAX_LENGTH 100
      14             : 
      15           2 : static void test_elektraLskip (void)
      16             : {
      17           2 :         printf ("Test elektraLskip\n");
      18             : 
      19           2 :         succeed_if_same_string (elektraLskip (""), "");
      20           2 :         succeed_if_same_string (elektraLskip ("No Leading Whitespace"), "No Leading Whitespace");
      21           2 :         succeed_if_same_string (elektraLskip ("\tLeading Tab"), "Leading Tab");
      22           2 :         succeed_if_same_string (elektraLskip (" Leading Space"), "Leading Space");
      23           2 :         succeed_if_same_string (elektraLskip (" \tLeading And Trailing Whitespace\t\n "), "Leading And Trailing Whitespace\t\n ");
      24           2 : }
      25             : 
      26           2 : static void test_elektraRstrip (void)
      27             : {
      28           2 :         printf ("Test elektraRstrip\n");
      29             : 
      30             :         char text[MAX_LENGTH];
      31           2 :         char * last = NULL;
      32             : 
      33           2 :         strncpy (text, "", MAX_LENGTH);
      34           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "");
      35           2 :         elektraRstrip (text, &last);
      36           2 :         succeed_if_same_string (last, text);
      37             : 
      38           2 :         strncpy (text, "No Trailing Whitespace", MAX_LENGTH);
      39           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "No Trailing Whitespace");
      40           2 :         last = NULL;
      41           2 :         elektraRstrip (text, &last);
      42           2 :         succeed_if_same_string (last, "e");
      43             : 
      44           2 :         strncpy (text, "\t\nLeading Whitespace", MAX_LENGTH);
      45           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "\t\nLeading Whitespace");
      46           2 :         last = NULL;
      47           2 :         elektraRstrip (text, &last);
      48           2 :         succeed_if_same_string (last, "e");
      49             : 
      50           2 :         strncpy (text, "Trailing Tab\t", MAX_LENGTH);
      51           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "Trailing Tab");
      52           2 :         strncpy (text, "Trailing Tab\t", MAX_LENGTH);
      53           2 :         last = NULL;
      54           2 :         elektraRstrip (text, &last);
      55           2 :         succeed_if_same_string (last, "b");
      56             : 
      57           2 :         strncpy (text, "Trailing Whitespace\n\r\t  ", MAX_LENGTH);
      58           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "Trailing Whitespace");
      59           2 :         strncpy (text, "Trailing Whitespace\n\r\t  ", MAX_LENGTH);
      60           2 :         last = NULL;
      61           2 :         elektraRstrip (text, &last);
      62           2 :         succeed_if_same_string (last, "e");
      63             : 
      64           2 :         strncpy (text, "\r  \t\nLeading And Trailing Whitespace\n  \r\n\t", MAX_LENGTH);
      65           2 :         succeed_if_same_string (elektraRstrip (text, NULL), "\r  \t\nLeading And Trailing Whitespace");
      66           2 :         strncpy (text, "\r  \t\nLeading And Trailing Whitespace\n  \r\n\t", MAX_LENGTH);
      67           2 :         last = NULL;
      68           2 :         elektraRstrip (text, &last);
      69           2 :         succeed_if_same_string (last, "e");
      70             : 
      71           2 :         strncpy (text, "\r\t\nLeading And Trailing Whitespace\n  \r\n\t", MAX_LENGTH);
      72           2 :         last = text + 10;
      73           2 :         succeed_if_same_string (elektraRstrip (text, &last), "\r\t\nLeading");
      74           2 :         succeed_if_same_string (last, "g");
      75           2 : }
      76             : 
      77           2 : static void test_elektraStrip (void)
      78             : {
      79           2 :         printf ("Test elektraStrip\n");
      80             :         char text[MAX_LENGTH];
      81             : 
      82           2 :         strncpy (text, "", MAX_LENGTH);
      83           2 :         succeed_if_same_string (elektraStrip (text), "");
      84             : 
      85           2 :         strncpy (text, "\t \nLeading And Trailing Whitespace\n\tSecond Line\n ", MAX_LENGTH);
      86           2 :         succeed_if_same_string (elektraStrip (text), "Leading And Trailing Whitespace\n\tSecond Line");
      87           2 : }
      88             : 
      89             : 
      90           2 : int main (int argc, char ** argv)
      91             : {
      92           2 :         printf ("Utility Tests\n");
      93           2 :         printf ("=============\n\n");
      94             : 
      95           2 :         init (argc, argv);
      96             : 
      97           2 :         test_elektraLskip ();
      98           2 :         test_elektraRstrip ();
      99           2 :         test_elektraStrip ();
     100             : 
     101           2 :         printf ("\nResults: %d Test%s done — %d Error%s.\n", nbTest, nbTest == 1 ? "" : "s", nbError, nbError == 1 ? "" : "s");
     102             : 
     103           2 :         return nbError;
     104             : }

Generated by: LCOV version 1.13