]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-syslog.c
update TODO
[thirdparty/systemd.git] / src / journal / test-journal-syslog.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e88baee8 2
b5efdb8a 3#include "alloc-util.h"
e88baee8
ZJS
4#include "journald-syslog.h"
5#include "macro.h"
07630cea 6#include "string-util.h"
a5ee33b9 7#include "syslog-util.h"
e88baee8 8
a6aadf4a 9static void test_syslog_parse_identifier(const char *str,
8595102d 10 const char *ident, const char *pid, const char *rest, int ret) {
e88baee8 11 const char *buf = str;
7fd1b19b 12 _cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
e88baee8
ZJS
13 int ret2;
14
15 ret2 = syslog_parse_identifier(&buf, &ident2, &pid2);
16
787784c4
RC
17 assert_se(ret == ret2);
18 assert_se(ident == ident2 || streq_ptr(ident, ident2));
19 assert_se(pid == pid2 || streq_ptr(pid, pid2));
8595102d 20 assert_se(streq(buf, rest));
e88baee8
ZJS
21}
22
a5ee33b9
YW
23static void test_syslog_parse_priority(const char *str, int priority, int ret) {
24 const char *buf = str;
6f488159 25 int priority2 = 0, ret2;
a5ee33b9
YW
26
27 ret2 = syslog_parse_priority(&buf, &priority2, false);
28
29 assert_se(ret == ret2);
30 if (ret2 == 1)
31 assert_se(priority == priority2);
32}
33
e88baee8 34int main(void) {
8595102d
YW
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);
937b1171
EV
44 test_syslog_parse_identifier(" :", "", NULL, "", 2);
45 test_syslog_parse_identifier(" pidu:", "pidu", NULL, "", 8);
8595102d
YW
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);
e88baee8 49
a5ee33b9
YW
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 */
57
e88baee8
ZJS
58 return 0;
59}