cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering/***
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering This file is part of systemd.
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering Copyright 2012 Lennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering systemd is free software; you can redistribute it and/or modify it
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering under the terms of the GNU Lesser General Public License as published by
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering (at your option) any later version.
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering systemd is distributed in the hope that it will be useful, but
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering Lesser General Public License for more details.
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering You should have received a copy of the GNU Lesser General Public License
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering***/
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering#include <stdio.h>
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "sd-journal.h"
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering#include "journal-internal.h"
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering#include "log.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "util.h"
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poetteringint main(int argc, char *argv[]) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_journal_closep) sd_journal*j = NULL;
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer _cleanup_free_ char *t;
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering log_set_max_level(LOG_DEBUG);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_open(&j, 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "foobar", 0) < 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "", 0) < 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "=", 0) < 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_disjunction(j) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_conjunction(j) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_disjunction(j) >= 0);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0);
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer assert_se(t = journal_make_match_string(j));
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering printf("resulting match expression is: %s\n", t);
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer 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))))"));
cd34b3c6670df8a3fd49179131fe762b2dd86b01Harald Hoyer
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering return 0;
cbdca8525b4f36297cb9e5cb090a9648763ed1bfLennart Poettering}