LCOV - code coverage report
Current view: top level - journal - test-journal-syslog.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 38 39 97.4 %
Date: 2019-08-23 13:36:53 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 18 55.6 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include "alloc-util.h"
       4                 :            : #include "journald-syslog.h"
       5                 :            : #include "macro.h"
       6                 :            : #include "string-util.h"
       7                 :            : #include "syslog-util.h"
       8                 :            : 
       9                 :         56 : static void test_syslog_parse_identifier(const char *str,
      10                 :            :                                          const char *ident, const char *pid, const char *rest, int ret) {
      11                 :         56 :         const char *buf = str;
      12                 :         56 :         _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
      13                 :            :         int ret2;
      14                 :            : 
      15                 :         56 :         ret2 = syslog_parse_identifier(&buf, &ident2, &pid2);
      16                 :            : 
      17         [ -  + ]:         56 :         assert_se(ret == ret2);
      18   [ +  +  -  + ]:         56 :         assert_se(ident == ident2 || streq_ptr(ident, ident2));
      19   [ +  +  -  + ]:         56 :         assert_se(pid == pid2 || streq_ptr(pid, pid2));
      20         [ -  + ]:         56 :         assert_se(streq(buf, rest));
      21                 :         56 : }
      22                 :            : 
      23                 :         24 : static void test_syslog_parse_priority(const char *str, int priority, int ret) {
      24                 :         24 :         const char *buf = str;
      25                 :         24 :         int priority2 = 0, ret2;
      26                 :            : 
      27                 :         24 :         ret2 = syslog_parse_priority(&buf, &priority2, false);
      28                 :            : 
      29         [ -  + ]:         24 :         assert_se(ret == ret2);
      30         [ -  + ]:         24 :         if (ret2 == 1)
      31         [ #  # ]:          0 :                 assert_se(priority == priority2);
      32                 :         24 : }
      33                 :            : 
      34                 :          4 : int main(void) {
      35                 :          4 :         test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
      36                 :          4 :         test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
      37                 :          4 :         test_syslog_parse_identifier("pidu:  xxx", "pidu", NULL, " xxx", 6);
      38                 :          4 :         test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
      39                 :          4 :         test_syslog_parse_identifier("   pidu xxx", NULL, NULL, "   pidu xxx", 0);
      40                 :          4 :         test_syslog_parse_identifier("", NULL, NULL, "", 0);
      41                 :          4 :         test_syslog_parse_identifier("  ", NULL, NULL, "  ", 0);
      42                 :          4 :         test_syslog_parse_identifier(":", "", NULL, "", 1);
      43                 :          4 :         test_syslog_parse_identifier(":  ", "", NULL, " ", 2);
      44                 :          4 :         test_syslog_parse_identifier(" :", "", NULL, "", 2);
      45                 :          4 :         test_syslog_parse_identifier("   pidu:", "pidu", NULL, "", 8);
      46                 :          4 :         test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
      47                 :          4 :         test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
      48                 :          4 :         test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
      49                 :            : 
      50                 :          4 :         test_syslog_parse_priority("<>", 0, 0);
      51                 :          4 :         test_syslog_parse_priority("<>aaa", 0, 0);
      52                 :          4 :         test_syslog_parse_priority("<aaaa>", 0, 0);
      53                 :          4 :         test_syslog_parse_priority("<aaaa>aaa", 0, 0);
      54                 :          4 :         test_syslog_parse_priority(" <aaaa>", 0, 0);
      55                 :          4 :         test_syslog_parse_priority(" <aaaa>aaa", 0, 0);
      56                 :            :         /* TODO: add test cases of valid priorities */
      57                 :            : 
      58                 :          4 :         return 0;
      59                 :            : }

Generated by: LCOV version 1.14