]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-match.c
Merge pull request #8461 from keszybz/oss-fuzz-fixes
[thirdparty/systemd.git] / src / journal / test-journal-match.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
cbdca852
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
21#include <stdio.h>
22
07630cea 23#include "sd-journal.h"
cbdca852 24
b5efdb8a 25#include "alloc-util.h"
cbdca852 26#include "journal-internal.h"
cbdca852 27#include "log.h"
07630cea
LP
28#include "string-util.h"
29#include "util.h"
cbdca852
LP
30
31int main(int argc, char *argv[]) {
4afd3348 32 _cleanup_(sd_journal_closep) sd_journal*j = NULL;
7fd1b19b 33 _cleanup_free_ char *t;
cbdca852
LP
34
35 log_set_max_level(LOG_DEBUG);
36
37 assert_se(sd_journal_open(&j, 0) >= 0);
38
39 assert_se(sd_journal_add_match(j, "foobar", 0) < 0);
40 assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0);
41 assert_se(sd_journal_add_match(j, "", 0) < 0);
42 assert_se(sd_journal_add_match(j, "=", 0) < 0);
43 assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
44 assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
45 assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
46 assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
47 assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0);
48 assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
49 assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0);
50 assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0);
51
52 assert_se(sd_journal_add_disjunction(j) >= 0);
53
54 assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0);
55 assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0);
56 assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0);
57
cd34b3c6
HH
58 assert_se(sd_journal_add_conjunction(j) >= 0);
59
60 assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0);
61 assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0);
62 assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0);
63 assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0);
64
65 assert_se(sd_journal_add_disjunction(j) >= 0);
cbdca852 66
cd34b3c6
HH
67 assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0);
68 assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0);
69
70 assert_se(t = journal_make_match_string(j));
cbdca852
LP
71
72 printf("resulting match expression is: %s\n", t);
cbdca852 73
cd34b3c6
HH
74 assert_se(streq(t, "(((L3=ok OR L3=yes) OR ((L4_2=ok OR L4_2=yes) AND (L4_1=ok OR L4_1=yes))) AND ((TWO=two AND (ONE=two OR ONE=one)) OR (PIFF=paff AND (QUUX=yyyyy OR QUUX=xxxxx OR QUUX=mmmm) AND (HALLO= OR HALLO=WALDO))))"));
75
cbdca852
LP
76 return 0;
77}