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 void test_import(Hashmap *h, struct strbuf *sb,
35 const char* contents, ssize_t size, int code) {
37 char name[] = "/tmp/test-catalog.XXXXXX";
38 int _cleanup_close_ fd = mkstemp(name);
40 assert_se(write(fd, contents, size) == size);
42 r = catalog_import_file(h, sb, name);
48 static void test_catalog_importing(void) {
52 assert_se(h = hashmap_new(catalog_hash_func, catalog_compare_func));
53 assert_se(sb = strbuf_new());
56 test_import(h, sb, BUF, sizeof(BUF), -EINVAL);
58 assert(hashmap_isempty(h));
59 log_debug("----------------------------------------");
62 "-- 0027229ca0644181a76c4e92458afaff dededededededededededededededede\n" \
63 "Subject: message\n" \
66 test_import(h, sb, BUF, sizeof(BUF), -EINVAL);
69 log_debug("----------------------------------------");
72 "-- 0027229ca0644181a76c4e92458afaff dededededededededededededededed\n" \
73 "Subject: message\n" \
76 test_import(h, sb, BUF, sizeof(BUF), 0);
79 assert(hashmap_size(h) == 1);
81 log_debug("----------------------------------------");
88 static const char* database = NULL;
90 static void test_catalog_update(void) {
92 char _cleanup_free_ *path = NULL;
94 static char name[] = "/tmp/test-catalog.XXXXXX";
100 /* Test what happens if there are no files. */
101 r = catalog_update(database, NULL, NULL);
104 /* Note: this might actually not find anything, if systemd was
105 * not installed before. That should be fine too. */
106 r = catalog_update(database, NULL, catalog_file_dirs);
110 int main(int argc, char *argv[]) {
111 _cleanup_free_ char *text = NULL;
114 setlocale(LC_ALL, "de_DE.UTF-8");
116 log_set_max_level(LOG_DEBUG);
118 test_catalog_importing();
120 test_catalog_update();
122 r = catalog_list(stdout, database, true);
125 r = catalog_list(stdout, database, false);
128 assert_se(catalog_get(database, SD_MESSAGE_COREDUMP, &text) >= 0);
129 printf(">>>%s<<<\n", text);