]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-send.c
2 This file is part of systemd.
4 Copyright 2011 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "sd-journal.h"
28 int main(int argc
, char *argv
[]) {
31 /* utf-8 and non-utf-8, message-less and message-ful iovecs */
32 struct iovec graph1
[] = {
33 {(char*) "GRAPH=graph", strlen("GRAPH=graph")}
35 struct iovec graph2
[] = {
36 {(char*) "GRAPH=graph\n", strlen("GRAPH=graph\n")}
38 struct iovec message1
[] = {
39 {(char*) "MESSAGE=graph", strlen("MESSAGE=graph")}
41 struct iovec message2
[] = {
42 {(char*) "MESSAGE=graph\n", strlen("MESSAGE=graph\n")}
45 assert_se(sd_journal_print(LOG_INFO
, "piepapo") == 0);
47 assert_se(sd_journal_send("MESSAGE=foobar",
52 assert_se(sd_journal_perror("Foobar") == 0);
54 assert_se(sd_journal_perror("") == 0);
56 memset(huge
, 'x', sizeof(huge
));
57 memcpy(huge
, "HUGE=", 5);
60 assert_se(sd_journal_send("MESSAGE=Huge field attached",
64 assert_se(sd_journal_send("MESSAGE=uiui",
71 "WITH_BINARY=this is a binary value \a",
74 syslog(LOG_NOTICE
, "Hello World!");
76 assert_se(sd_journal_print(LOG_NOTICE
, "Hello World") == 0);
78 assert_se(sd_journal_send("MESSAGE=Hello World!",
79 "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
81 "HOME=%s", getenv("HOME"),
82 "TERM=%s", getenv("TERM"),
83 "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE
),
84 "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN
),
87 assert_se(sd_journal_sendv(graph1
, 1) == 0);
88 assert_se(sd_journal_sendv(graph2
, 1) == 0);
89 assert_se(sd_journal_sendv(message1
, 1) == 0);
90 assert_se(sd_journal_sendv(message2
, 1) == 0);
92 /* test without location fields */
93 #undef sd_journal_sendv
94 assert_se(sd_journal_sendv(graph1
, 1) == 0);
95 assert_se(sd_journal_sendv(graph2
, 1) == 0);
96 assert_se(sd_journal_sendv(message1
, 1) == 0);
97 assert_se(sd_journal_sendv(message2
, 1) == 0);