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