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