]>
git.proxmox.com Git - systemd.git/blob - src/journal/test-catalog.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Lennart Poettering
7 Copyright 2013 Zbigniew Jędrzejewski-Szmek
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #include "sd-messages.h"
34 static const char *catalog_dirs
[] = {
39 static const char *no_catalog_dirs
[] = {
40 "/bin/hopefully/with/no/catalog",
44 static void test_import(Hashmap
*h
, struct strbuf
*sb
,
45 const char* contents
, ssize_t size
, int code
) {
47 char name
[] = "/tmp/test-catalog.XXXXXX";
48 _cleanup_close_
int fd
= mkstemp(name
);
50 assert_se(write(fd
, contents
, size
) == size
);
52 r
= catalog_import_file(h
, sb
, name
);
58 static void test_catalog_importing(void) {
62 assert_se(h
= hashmap_new(catalog_hash_func
, catalog_compare_func
));
63 assert_se(sb
= strbuf_new());
66 test_import(h
, sb
, BUF
, sizeof(BUF
), -EINVAL
);
68 assert(hashmap_isempty(h
));
69 log_debug("----------------------------------------");
72 "-- 0027229ca0644181a76c4e92458afaff dededededededededededededededede\n" \
73 "Subject: message\n" \
76 test_import(h
, sb
, BUF
, sizeof(BUF
), -EINVAL
);
79 log_debug("----------------------------------------");
82 "-- 0027229ca0644181a76c4e92458afaff dededededededededededededededed\n" \
83 "Subject: message\n" \
86 test_import(h
, sb
, BUF
, sizeof(BUF
), 0);
89 assert(hashmap_size(h
) == 1);
91 log_debug("----------------------------------------");
98 static const char* database
= NULL
;
100 static void test_catalog_update(void) {
103 static char name
[] = "/tmp/test-catalog.XXXXXX";
109 /* Test what happens if there are no files. */
110 r
= catalog_update(database
, NULL
, NULL
);
113 /* Test what happens if there are no files in the directory. */
114 r
= catalog_update(database
, NULL
, no_catalog_dirs
);
117 /* Make sure that we at least have some files loaded or the
118 catalog_list below will fail. */
119 r
= catalog_update(database
, NULL
, catalog_dirs
);
123 int main(int argc
, char *argv
[]) {
124 _cleanup_free_
char *text
= NULL
;
127 setlocale(LC_ALL
, "de_DE.UTF-8");
129 log_set_max_level(LOG_DEBUG
);
131 test_catalog_importing();
133 test_catalog_update();
135 r
= catalog_list(stdout
, database
, true);
138 r
= catalog_list(stdout
, database
, false);
141 assert_se(catalog_get(database
, SD_MESSAGE_COREDUMP
, &text
) >= 0);
142 printf(">>>%s<<<\n", text
);