summaryrefslogtreecommitdiff
path: root/src/journal/test-journal-syslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal/test-journal-syslog.c')
-rw-r--r--src/journal/test-journal-syslog.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
index 33f412956b..84cfcefc3a 100644
--- a/src/journal/test-journal-syslog.c
+++ b/src/journal/test-journal-syslog.c
@@ -5,8 +5,9 @@
#include "macro.h"
#include "string-util.h"
#include "syslog-util.h"
+#include "tests.h"
-static void test_syslog_parse_identifier(const char *str,
+static void test_syslog_parse_identifier_one(const char *str,
const char *ident, const char *pid, const char *rest, int ret) {
const char *buf = str;
_cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
@@ -20,40 +21,50 @@ static void test_syslog_parse_identifier(const char *str,
assert_se(streq(buf, rest));
}
-static void test_syslog_parse_priority(const char *str, int priority, int ret) {
- const char *buf = str;
+static void test_syslog_parse_priority_one(const char *str, bool with_facility, int priority, int ret) {
int priority2 = 0, ret2;
- ret2 = syslog_parse_priority(&buf, &priority2, false);
+ ret2 = syslog_parse_priority(&str, &priority2, with_facility);
assert_se(ret == ret2);
if (ret2 == 1)
assert_se(priority == priority2);
}
-int main(void) {
- 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);
- test_syslog_parse_identifier(" :", "", NULL, "", 2);
- test_syslog_parse_identifier(" pidu:", "pidu", NULL, "", 8);
- 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);
-
- 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 */
-
- return 0;
+TEST(syslog_parse_identifier) {
+ test_syslog_parse_identifier_one("pidu[111]: xxx", "pidu", "111", "xxx", 11);
+ test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL, "xxx", 6);
+ test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL, " xxx", 6);
+ test_syslog_parse_identifier_one("pidu xxx", NULL, NULL, "pidu xxx", 0);
+ test_syslog_parse_identifier_one(" pidu xxx", NULL, NULL, " pidu xxx", 0);
+ test_syslog_parse_identifier_one("", NULL, NULL, "", 0);
+ test_syslog_parse_identifier_one(" ", NULL, NULL, " ", 0);
+ test_syslog_parse_identifier_one(":", "", NULL, "", 1);
+ test_syslog_parse_identifier_one(": ", "", NULL, " ", 2);
+ test_syslog_parse_identifier_one(" :", "", NULL, "", 2);
+ test_syslog_parse_identifier_one(" pidu:", "pidu", NULL, "", 8);
+ test_syslog_parse_identifier_one("pidu:", "pidu", NULL, "", 5);
+ test_syslog_parse_identifier_one("pidu: ", "pidu", NULL, "", 6);
+ test_syslog_parse_identifier_one("pidu : ", NULL, NULL, "pidu : ", 0);
+}
+
+TEST(syslog_parse_priority) {
+ test_syslog_parse_priority_one("", false, 0, 0);
+ test_syslog_parse_priority_one("<>", false, 0, 0);
+ test_syslog_parse_priority_one("<>aaa", false, 0, 0);
+ test_syslog_parse_priority_one("<aaaa>", false, 0, 0);
+ test_syslog_parse_priority_one("<aaaa>aaa", false, 0, 0);
+ test_syslog_parse_priority_one(" <aaaa>", false, 0, 0);
+ test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
+ test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
+ test_syslog_parse_priority_one(" <1>", false, 0, 0);
+ test_syslog_parse_priority_one("<1>", false, 1, 1);
+ test_syslog_parse_priority_one("<7>", false, 7, 1);
+ test_syslog_parse_priority_one("<8>", false, 0, 0);
+ test_syslog_parse_priority_one("<9>", true, 9, 1);
+ test_syslog_parse_priority_one("<22>", true, 22, 1);
+ test_syslog_parse_priority_one("<111>", false, 0, 0);
+ test_syslog_parse_priority_one("<111>", true, 111, 1);
}
+
+DEFINE_TEST_MAIN(LOG_INFO);