2017-11-18 17:09:20 +01:00
/* SPDX-License-Identifier: LGPL-2.1+ */
2012-07-13 00:29:26 +02:00
# include <stdio.h>
2015-10-24 22:58:24 +02:00
# include "sd-journal.h"
2012-07-13 00:29:26 +02:00
2015-10-27 03:01:06 +01:00
# include "alloc-util.h"
2012-07-13 00:29:26 +02:00
# include "journal-internal.h"
# include "log.h"
2015-10-24 22:58:24 +02:00
# include "string-util.h"
2018-09-13 14:31:13 +02:00
# include "tests.h"
2015-10-24 22:58:24 +02:00
# include "util.h"
2012-07-13 00:29:26 +02:00
int main ( int argc , char * argv [ ] ) {
2018-12-04 09:29:54 +01:00
_cleanup_ ( sd_journal_closep ) sd_journal * j = NULL ;
2013-04-18 09:11:22 +02:00
_cleanup_free_ char * t ;
2012-07-13 00:29:26 +02:00
2018-09-13 14:31:13 +02:00
test_setup_logging ( LOG_DEBUG ) ;
2012-07-13 00:29:26 +02:00
assert_se ( sd_journal_open ( & j , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " foobar " , 0 ) < 0 ) ;
assert_se ( sd_journal_add_match ( j , " foobar=waldo " , 0 ) < 0 ) ;
assert_se ( sd_journal_add_match ( j , " " , 0 ) < 0 ) ;
assert_se ( sd_journal_add_match ( j , " = " , 0 ) < 0 ) ;
assert_se ( sd_journal_add_match ( j , " =xxxxx " , 0 ) < 0 ) ;
2018-10-12 14:17:04 +02:00
assert_se ( sd_journal_add_match ( j , ( uint8_t [ 4 ] ) { ' A ' , ' = ' , ' \1 ' , ' \2 ' } , 4 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , ( uint8_t [ 5 ] ) { ' B ' , ' = ' , ' C ' , ' \0 ' , ' D ' } , 5 ) > = 0 ) ;
2012-07-13 00:29:26 +02:00
assert_se ( sd_journal_add_match ( j , " HALLO=WALDO " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " QUUX=mmmm " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " QUUX=xxxxx " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " HALLO= " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " QUUX=xxxxx " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " QUUX=yyyyy " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " PIFF=paff " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_disjunction ( j ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " ONE=one " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " ONE=two " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " TWO=two " , 0 ) > = 0 ) ;
2013-04-11 15:27:55 +02:00
assert_se ( sd_journal_add_conjunction ( j ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " L4_1=yes " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " L4_1=ok " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " L4_2=yes " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " L4_2=ok " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_disjunction ( j ) > = 0 ) ;
2012-07-13 00:29:26 +02:00
2013-04-11 15:27:55 +02:00
assert_se ( sd_journal_add_match ( j , " L3=yes " , 0 ) > = 0 ) ;
assert_se ( sd_journal_add_match ( j , " L3=ok " , 0 ) > = 0 ) ;
assert_se ( t = journal_make_match_string ( j ) ) ;
2012-07-13 00:29:26 +02:00
printf ( " resulting match expression is: %s \n " , t ) ;
2018-10-12 14:17:04 +02:00
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))) " ) ) ;
2013-04-11 15:27:55 +02:00
2012-07-13 00:29:26 +02:00
return 0 ;
}