]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-syslog.c
84cfcefc3a2a0b37603f7f3bff322b07a16f2efe
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "alloc-util.h"
4 #include "journald-syslog.h"
6 #include "string-util.h"
7 #include "syslog-util.h"
10 static void test_syslog_parse_identifier_one(const char *str
,
11 const char *ident
, const char *pid
, const char *rest
, int ret
) {
12 const char *buf
= str
;
13 _cleanup_free_
char *ident2
= NULL
, *pid2
= NULL
;
16 ret2
= syslog_parse_identifier(&buf
, &ident2
, &pid2
);
18 assert_se(ret
== ret2
);
19 assert_se(ident
== ident2
|| streq_ptr(ident
, ident2
));
20 assert_se(pid
== pid2
|| streq_ptr(pid
, pid2
));
21 assert_se(streq(buf
, rest
));
24 static void test_syslog_parse_priority_one(const char *str
, bool with_facility
, int priority
, int ret
) {
25 int priority2
= 0, ret2
;
27 ret2
= syslog_parse_priority(&str
, &priority2
, with_facility
);
29 assert_se(ret
== ret2
);
31 assert_se(priority
== priority2
);
34 TEST(syslog_parse_identifier
) {
35 test_syslog_parse_identifier_one("pidu[111]: xxx", "pidu", "111", "xxx", 11);
36 test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL
, "xxx", 6);
37 test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL
, " xxx", 6);
38 test_syslog_parse_identifier_one("pidu xxx", NULL
, NULL
, "pidu xxx", 0);
39 test_syslog_parse_identifier_one(" pidu xxx", NULL
, NULL
, " pidu xxx", 0);
40 test_syslog_parse_identifier_one("", NULL
, NULL
, "", 0);
41 test_syslog_parse_identifier_one(" ", NULL
, NULL
, " ", 0);
42 test_syslog_parse_identifier_one(":", "", NULL
, "", 1);
43 test_syslog_parse_identifier_one(": ", "", NULL
, " ", 2);
44 test_syslog_parse_identifier_one(" :", "", NULL
, "", 2);
45 test_syslog_parse_identifier_one(" pidu:", "pidu", NULL
, "", 8);
46 test_syslog_parse_identifier_one("pidu:", "pidu", NULL
, "", 5);
47 test_syslog_parse_identifier_one("pidu: ", "pidu", NULL
, "", 6);
48 test_syslog_parse_identifier_one("pidu : ", NULL
, NULL
, "pidu : ", 0);
51 TEST(syslog_parse_priority
) {
52 test_syslog_parse_priority_one("", false, 0, 0);
53 test_syslog_parse_priority_one("<>", false, 0, 0);
54 test_syslog_parse_priority_one("<>aaa", false, 0, 0);
55 test_syslog_parse_priority_one("<aaaa>", false, 0, 0);
56 test_syslog_parse_priority_one("<aaaa>aaa", false, 0, 0);
57 test_syslog_parse_priority_one(" <aaaa>", false, 0, 0);
58 test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
59 test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
60 test_syslog_parse_priority_one(" <1>", false, 0, 0);
61 test_syslog_parse_priority_one("<1>", false, 1, 1);
62 test_syslog_parse_priority_one("<7>", false, 7, 1);
63 test_syslog_parse_priority_one("<8>", false, 0, 0);
64 test_syslog_parse_priority_one("<9>", true, 9, 1);
65 test_syslog_parse_priority_one("<22>", true, 22, 1);
66 test_syslog_parse_priority_one("<111>", false, 0, 0);
67 test_syslog_parse_priority_one("<111>", true, 111, 1);
70 DEFINE_TEST_MAIN(LOG_INFO
);