LCOV - code coverage report
Current view: top level - journal - test-journal-syslog.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 38 39 97.4 %
Date: 2019-08-22 15:41:25 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14