test-journal.c revision 6eb7a9a0010d035e5bdbbf70227088ce02b2120e
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering This file is part of systemd.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Copyright 2011 Lennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is free software; you can redistribute it and/or modify it
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering under the terms of the GNU Lesser General Public License as published by
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (at your option) any later version.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is distributed in the hope that it will be useful, but
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Lesser General Public License for more details.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering You should have received a copy of the GNU Lesser General Public License
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstatic bool arg_keep = false;
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversstatic void test_non_empty(void) {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering static const char test[] = "TEST1=1", test2[] = "TEST2=2";
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, true, NULL, NULL, NULL, &f) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry(f, NULL, 0, DIRECTION_DOWN, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry(f, o, p, DIRECTION_DOWN, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry(f, o, p, DIRECTION_DOWN, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry(f, o, p, DIRECTION_DOWN, &o, &p) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry(f, NULL, 0, DIRECTION_DOWN, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_skip_entry(f, o, p, 2, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_skip_entry(f, o, p, -2, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_skip_entry(f, o, p, -2, &o, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_find_data_object(f, test, strlen(test), NULL, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_DOWN, &o, NULL) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_UP, &o, NULL) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_find_data_object(f, test2, strlen(test2), NULL, &p) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_UP, &o, NULL) == 1);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert(journal_file_next_entry_for_data(f, NULL, 0, p, DIRECTION_DOWN, &o, NULL) == 1);
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek assert(journal_file_find_data_object(f, "quux", 4, NULL, &p) == 0);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers assert(journal_file_move_to_entry_by_seqnum(f, 1, DIRECTION_DOWN, &o, NULL) == 1);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers assert(journal_file_move_to_entry_by_seqnum(f, 3, DIRECTION_DOWN, &o, NULL) == 1);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers assert(journal_file_move_to_entry_by_seqnum(f, 2, DIRECTION_DOWN, &o, NULL) == 1);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers assert(journal_file_move_to_entry_by_seqnum(f, 10, DIRECTION_DOWN, &o, NULL) == 0);
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers journal_file_rotate(&f, true, true);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering journal_directory_vacuum(".", 3000000, 0, 0, NULL);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering puts("------------------------------------------------------------");
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieversstatic void test_empty(void) {
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers char t[] = "/tmp/journal-XXXXXX";
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, false, false, NULL, NULL, NULL, &f1) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_open("test-compress.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &f2) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(journal_file_open("test-seal.journal", O_RDWR|O_CREAT, 0666, false, true, NULL, NULL, NULL, &f3) == 0);
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers assert_se(journal_file_open("test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, true, NULL, NULL, NULL, &f4) == 0);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering journal_directory_vacuum(".", 3000000, 0, 0, NULL);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering assert_se(rm_rf_dangerous(t, false, true, false) >= 0);