test-journal-stream.c revision cbdca8525b4f36297cb9e5cb090a9648763ed1bf
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <fcntl.h>
#include <systemd/sd-journal.h>
#include "journal-file.h"
#include "journal-internal.h"
#include "util.h"
#include "log.h"
#define N_ENTRIES 200
unsigned i;
assert(j);
i = 0;
SD_JOURNAL_FOREACH(j) {
const void *d;
char *k;
size_t l;
unsigned u;
assert_se(sd_journal_get_cursor(j, &k) >= 0);
printf("cursor: %s\n", k);
free(k);
printf("\t%.*s\n", (int) l, (const char*) d);
printf("\t%s\n", k);
if (skip > 0) {
assert_se(i == u);
i += skip;
}
free(k);
}
if (skip > 0)
}
char t[] = "/tmp/journal-stream-XXXXXX";
unsigned i;
sd_journal *j;
char *z;
for (i = 0; i < N_ENTRIES; i++) {
char *p, *q;
if (i % 10 == 0)
else {
if (i % 3 == 0)
}
free(p);
free(q);
}
assert_se(sd_journal_open_directory(&j, t, 0) >= 0);
const void *d;
size_t l;
printf("\t%.*s\n", (int) l, (const char*) d);
}
SD_JOURNAL_FOREACH(j) {
const void *d;
size_t l;
printf("\t%.*s\n", (int) l, (const char*) d);
}
verify_contents(j, 1);
printf("NEXT TEST\n");
assert_se(z = journal_make_match_string(j));
printf("resulting match expression is: %s\n", z);
free(z);
verify_contents(j, 5);
printf("NEXT TEST\n");
assert_se(z = journal_make_match_string(j));
printf("resulting match expression is: %s\n", z);
free(z);
verify_contents(j, 0);
sd_journal_close(j);
return 0;
}