]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-syslog.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
4 #include "journald-syslog.h"
6 #include "string-util.h"
7 #include "syslog-util.h"
9 static void test_syslog_parse_identifier(const char *str
,
10 const char *ident
, const char *pid
, const char *rest
, int ret
) {
11 const char *buf
= str
;
12 _cleanup_free_
char *ident2
= NULL
, *pid2
= NULL
;
15 ret2
= syslog_parse_identifier(&buf
, &ident2
, &pid2
);
17 assert_se(ret
== ret2
);
18 assert_se(ident
== ident2
|| streq_ptr(ident
, ident2
));
19 assert_se(pid
== pid2
|| streq_ptr(pid
, pid2
));
20 assert_se(streq(buf
, rest
));
23 static void test_syslog_parse_priority(const char *str
, int priority
, int ret
) {
24 const char *buf
= str
;
25 int priority2
= 0, ret2
;
27 ret2
= syslog_parse_priority(&buf
, &priority2
, false);
29 assert_se(ret
== ret2
);
31 assert_se(priority
== priority2
);
35 test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
36 test_syslog_parse_identifier("pidu: xxx", "pidu", NULL
, "xxx", 6);
37 test_syslog_parse_identifier("pidu: xxx", "pidu", NULL
, " xxx", 6);
38 test_syslog_parse_identifier("pidu xxx", NULL
, NULL
, "pidu xxx", 0);
39 test_syslog_parse_identifier(" pidu xxx", NULL
, NULL
, " pidu xxx", 0);
40 test_syslog_parse_identifier("", NULL
, NULL
, "", 0);
41 test_syslog_parse_identifier(" ", NULL
, NULL
, " ", 0);
42 test_syslog_parse_identifier(":", "", NULL
, "", 1);
43 test_syslog_parse_identifier(": ", "", NULL
, " ", 2);
44 test_syslog_parse_identifier(" :", "", NULL
, "", 2);
45 test_syslog_parse_identifier(" pidu:", "pidu", NULL
, "", 8);
46 test_syslog_parse_identifier("pidu:", "pidu", NULL
, "", 5);
47 test_syslog_parse_identifier("pidu: ", "pidu", NULL
, "", 6);
48 test_syslog_parse_identifier("pidu : ", NULL
, NULL
, "pidu : ", 0);
50 test_syslog_parse_priority("<>", 0, 0);
51 test_syslog_parse_priority("<>aaa", 0, 0);
52 test_syslog_parse_priority("<aaaa>", 0, 0);
53 test_syslog_parse_priority("<aaaa>aaa", 0, 0);
54 test_syslog_parse_priority(" <aaaa>", 0, 0);
55 test_syslog_parse_priority(" <aaaa>aaa", 0, 0);
56 /* TODO: add test cases of valid priorities */