test-journal-match.c revision 7fd1b19bc9e9f5574f2877936b8ac267c7706947
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen/***
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen This file is part of systemd.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen Copyright 2012 Lennart Poettering
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen systemd is free software; you can redistribute it and/or modify it
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen under the terms of the GNU Lesser General Public License as published by
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen (at your option) any later version.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen systemd is distributed in the hope that it will be useful, but
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen Lesser General Public License for more details.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen You should have received a copy of the GNU Lesser General Public License
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen***/
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen#include <stdio.h>
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen#include <systemd/sd-journal.h>
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen#include "journal-internal.h"
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersen#include "util.h"
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen#include "log.h"
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersenint main(int argc, char *argv[]) {
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen _cleanup_journal_close_ sd_journal*j;
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen _cleanup_free_ char *t;
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen log_set_max_level(LOG_DEBUG);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_open(&j, 0) >= 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "foobar", 0) < 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen assert_se(sd_journal_add_match(j, "", 0) < 0);
3dbcf5795730047478079da6243fbcab9fe22842Susant Sahani assert_se(sd_journal_add_match(j, "=", 0) < 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0);
85a8eeee36b57c1ab382b0225fa9a87525bbeee9Susant Sahani assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0);
cffacc741cb79f63999720525ceaa65aae01a542Susant Sahani
cffacc741cb79f63999720525ceaa65aae01a542Susant Sahani assert_se(sd_journal_add_disjunction(j) >= 0);
cffacc741cb79f63999720525ceaa65aae01a542Susant Sahani
ea84fd5cb327508ae2b4e9ab8ebf3c09f7471d27Susant Sahani assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0);
aa9f11405829fd4755fef28602a7167dba3ddc89Tom Gundersen assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0);
3be1d7e0c5bf60658d34eb6311d4e77c6803578cTom Gundersen
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_conjunction(j) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_disjunction(j) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0);
a94d64d256d1a2b73c578116f341824eb5d0fab1Susant Sahani assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0);
assert_se(t = journal_make_match_string(j));
printf("resulting match expression is: %s\n", t);
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))))"));
return 0;
}