Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : :
3 : : #include <stdio.h>
4 : :
5 : : #include "sd-journal.h"
6 : :
7 : : #include "alloc-util.h"
8 : : #include "journal-internal.h"
9 : : #include "log.h"
10 : : #include "string-util.h"
11 : : #include "tests.h"
12 : : #include "util.h"
13 : :
14 : 4 : int main(int argc, char *argv[]) {
15 : 4 : _cleanup_(sd_journal_closep) sd_journal *j = NULL;
16 : 4 : _cleanup_free_ char *t;
17 : :
18 : 4 : test_setup_logging(LOG_DEBUG);
19 : :
20 [ - + ]: 4 : assert_se(sd_journal_open(&j, 0) >= 0);
21 : :
22 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "foobar", 0) < 0);
23 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0);
24 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "", 0) < 0);
25 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "=", 0) < 0);
26 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
27 [ - + ]: 4 : assert_se(sd_journal_add_match(j, (uint8_t[4]){'A', '=', '\1', '\2'}, 4) >= 0);
28 [ - + ]: 4 : assert_se(sd_journal_add_match(j, (uint8_t[5]){'B', '=', 'C', '\0', 'D'}, 5) >= 0);
29 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
30 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
31 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
32 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0);
33 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
34 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0);
35 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0);
36 : :
37 [ - + ]: 4 : assert_se(sd_journal_add_disjunction(j) >= 0);
38 : :
39 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0);
40 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0);
41 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0);
42 : :
43 [ - + ]: 4 : assert_se(sd_journal_add_conjunction(j) >= 0);
44 : :
45 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0);
46 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0);
47 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0);
48 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0);
49 : :
50 [ - + ]: 4 : assert_se(sd_journal_add_disjunction(j) >= 0);
51 : :
52 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0);
53 [ - + ]: 4 : assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0);
54 : :
55 [ - + ]: 4 : assert_se(t = journal_make_match_string(j));
56 : :
57 : 4 : printf("resulting match expression is: %s\n", t);
58 : :
59 [ - + ]: 4 : 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) AND B=C\\000D AND A=\\001\\002)))"));
60 : :
61 : 4 : return 0;
62 : : }
|