2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2012-10-13 11:31:54 +02:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2012-10-13 11:31:54 +02:00
|
|
|
#include "journald-syslog.h"
|
|
|
|
#include "macro.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2018-08-08 11:27:15 +02:00
|
|
|
#include "syslog-util.h"
|
2012-10-13 11:31:54 +02:00
|
|
|
|
2018-08-08 08:06:36 +02:00
|
|
|
static void test_syslog_parse_identifier(const char *str,
|
2018-08-10 04:07:54 +02:00
|
|
|
const char *ident, const char *pid, const char *rest, int ret) {
|
2012-10-13 11:31:54 +02:00
|
|
|
const char *buf = str;
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
|
2012-10-13 11:31:54 +02:00
|
|
|
int ret2;
|
|
|
|
|
|
|
|
ret2 = syslog_parse_identifier(&buf, &ident2, &pid2);
|
|
|
|
|
2014-11-30 02:16:19 +01:00
|
|
|
assert_se(ret == ret2);
|
|
|
|
assert_se(ident == ident2 || streq_ptr(ident, ident2));
|
|
|
|
assert_se(pid == pid2 || streq_ptr(pid, pid2));
|
2018-08-10 04:07:54 +02:00
|
|
|
assert_se(streq(buf, rest));
|
2012-10-13 11:31:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-08 11:27:15 +02:00
|
|
|
static void test_syslog_parse_priority(const char *str, int priority, int ret) {
|
|
|
|
const char *buf = str;
|
2018-09-25 11:34:52 +02:00
|
|
|
int priority2 = 0, ret2;
|
2018-08-08 11:27:15 +02:00
|
|
|
|
|
|
|
ret2 = syslog_parse_priority(&buf, &priority2, false);
|
|
|
|
|
|
|
|
assert_se(ret == ret2);
|
|
|
|
if (ret2 == 1)
|
|
|
|
assert_se(priority == priority2);
|
|
|
|
}
|
|
|
|
|
2012-10-13 11:31:54 +02:00
|
|
|
int main(void) {
|
2018-08-10 04:07:54 +02:00
|
|
|
test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
|
|
|
|
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
|
|
|
|
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, " xxx", 6);
|
|
|
|
test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
|
|
|
|
test_syslog_parse_identifier(" pidu xxx", NULL, NULL, " pidu xxx", 0);
|
|
|
|
test_syslog_parse_identifier("", NULL, NULL, "", 0);
|
|
|
|
test_syslog_parse_identifier(" ", NULL, NULL, " ", 0);
|
|
|
|
test_syslog_parse_identifier(":", "", NULL, "", 1);
|
|
|
|
test_syslog_parse_identifier(": ", "", NULL, " ", 2);
|
2018-08-10 14:55:09 +02:00
|
|
|
test_syslog_parse_identifier(" :", "", NULL, "", 2);
|
|
|
|
test_syslog_parse_identifier(" pidu:", "pidu", NULL, "", 8);
|
2018-08-10 04:07:54 +02:00
|
|
|
test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
|
|
|
|
test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
|
|
|
|
test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
|
2012-10-13 11:31:54 +02:00
|
|
|
|
2018-08-08 11:27:15 +02:00
|
|
|
test_syslog_parse_priority("<>", 0, 0);
|
|
|
|
test_syslog_parse_priority("<>aaa", 0, 0);
|
|
|
|
test_syslog_parse_priority("<aaaa>", 0, 0);
|
|
|
|
test_syslog_parse_priority("<aaaa>aaa", 0, 0);
|
|
|
|
test_syslog_parse_priority(" <aaaa>", 0, 0);
|
|
|
|
test_syslog_parse_priority(" <aaaa>aaa", 0, 0);
|
|
|
|
/* TODO: add test cases of valid priorities */
|
|
|
|
|
2012-10-13 11:31:54 +02:00
|
|
|
return 0;
|
|
|
|
}
|