LCOV - code coverage report
Current view: top level - test - test-strip-tab-ansi.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 31 35 88.6 %
Date: 2019-08-23 13:36:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 42 42.9 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <stdio.h>
       4                 :            : 
       5                 :            : #include "alloc-util.h"
       6                 :            : #include "pretty-print.h"
       7                 :            : #include "string-util.h"
       8                 :            : #include "terminal-util.h"
       9                 :            : #include "util.h"
      10                 :            : 
      11                 :          4 : int main(int argc, char *argv[]) {
      12                 :          4 :         _cleanup_free_ char *urlified = NULL, *q = NULL, *qq = NULL;
      13                 :            :         char *p, *z;
      14                 :            : 
      15         [ -  + ]:          4 :         assert_se(p = strdup("\tFoobar\tbar\twaldo\t"));
      16         [ -  + ]:          4 :         assert_se(strip_tab_ansi(&p, NULL, NULL));
      17                 :          4 :         fprintf(stdout, "<%s>\n", p);
      18         [ -  + ]:          4 :         assert_se(streq(p, "        Foobar        bar        waldo        "));
      19                 :          4 :         free(p);
      20                 :            : 
      21         [ -  + ]:          4 :         assert_se(p = strdup(ANSI_HIGHLIGHT "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL));
      22         [ -  + ]:          4 :         assert_se(strip_tab_ansi(&p, NULL, NULL));
      23                 :          4 :         fprintf(stdout, "<%s>\n", p);
      24         [ -  + ]:          4 :         assert_se(streq(p, "Hello world!"));
      25                 :          4 :         free(p);
      26                 :            : 
      27         [ -  + ]:          4 :         assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT "\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL));
      28         [ -  + ]:          4 :         assert_se(strip_tab_ansi(&p, NULL, NULL));
      29         [ -  + ]:          4 :         assert_se(streq(p, "\x1B[\x1B[        \x1B[\x1B[Hello world!"));
      30                 :          4 :         free(p);
      31                 :            : 
      32         [ -  + ]:          4 :         assert_se(p = strdup("\x1B[waldo"));
      33         [ -  + ]:          4 :         assert_se(strip_tab_ansi(&p, NULL, NULL));
      34         [ -  + ]:          4 :         assert_se(streq(p, "\x1B[waldo"));
      35                 :          4 :         free(p);
      36                 :            : 
      37         [ -  + ]:          4 :         assert_se(terminal_urlify_path("/etc/fstab", "i am a fabulous link", &urlified) >= 0);
      38         [ -  + ]:          4 :         assert_se(p = strjoin("something ", urlified, " something-else"));
      39         [ -  + ]:          4 :         assert_se(q = strdup(p));
      40                 :          4 :         printf("<%s>\n", p);
      41         [ -  + ]:          4 :         assert_se(strip_tab_ansi(&p, NULL, NULL));
      42                 :          4 :         printf("<%s>\n", p);
      43         [ -  + ]:          4 :         assert_se(streq(p, "something i am a fabulous link something-else"));
      44                 :          4 :         p = mfree(p);
      45                 :            : 
      46                 :            :         /* Truncate the formatted string in the middle of an ANSI sequence (in which case we shouldn't touch the
      47                 :            :          * incomplete sequence) */
      48                 :          4 :         z = strstr(q, "fstab");
      49         [ -  + ]:          4 :         if (z) {
      50                 :          0 :                 *z = 0;
      51         [ #  # ]:          0 :                 assert_se(qq = strdup(q));
      52         [ #  # ]:          0 :                 assert_se(strip_tab_ansi(&q, NULL, NULL));
      53         [ #  # ]:          0 :                 assert_se(streq(q, qq));
      54                 :            :         }
      55                 :            : 
      56                 :          4 :         return 0;
      57                 :            : }

Generated by: LCOV version 1.14