]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-config.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / journal / test-journal-config.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2011 Lennart Poettering
4 ***/
5
6 #include <stdbool.h>
7
8 #include "journald-server.h"
9
10 #define _COMPRESS_PARSE_CHECK(str, enab, thresh, varname) \
11 do { \
12 JournalCompressOptions varname = {true, 111}; \
13 config_parse_compress("", "", 0, "", 0, "", 0, str, \
14 &varname, NULL); \
15 assert_se((enab) == varname.enabled); \
16 if (varname.enabled) \
17 assert_se((thresh) == varname.threshold_bytes); \
18 } while (0)
19
20 #define COMPRESS_PARSE_CHECK(str, enabled, threshold) \
21 _COMPRESS_PARSE_CHECK(str, enabled, threshold, conf##__COUNTER__)
22
23 static void test_config_compress(void) {
24 COMPRESS_PARSE_CHECK("yes", true, 111);
25 COMPRESS_PARSE_CHECK("no", false, 111);
26 COMPRESS_PARSE_CHECK("y", true, 111);
27 COMPRESS_PARSE_CHECK("n", false, 111);
28 COMPRESS_PARSE_CHECK("true", true, 111);
29 COMPRESS_PARSE_CHECK("false", false, 111);
30 COMPRESS_PARSE_CHECK("t", true, 111);
31 COMPRESS_PARSE_CHECK("f", false, 111);
32 COMPRESS_PARSE_CHECK("on", true, 111);
33 COMPRESS_PARSE_CHECK("off", false, 111);
34
35 /* Weird size/bool overlapping case. We preserve backward compatibility instead of assuming these are byte
36 * counts. */
37 COMPRESS_PARSE_CHECK("1", true, 111);
38 COMPRESS_PARSE_CHECK("0", false, 111);
39
40 /* IEC sizing */
41 COMPRESS_PARSE_CHECK("1B", true, 1);
42 COMPRESS_PARSE_CHECK("1K", true, 1024);
43 COMPRESS_PARSE_CHECK("1M", true, 1024 * 1024);
44 COMPRESS_PARSE_CHECK("1G", true, 1024 * 1024 * 1024);
45
46 /* Invalid Case */
47 COMPRESS_PARSE_CHECK("-1", true, 111);
48 COMPRESS_PARSE_CHECK("blah blah", true, 111);
49 COMPRESS_PARSE_CHECK("", true, (uint64_t)-1);
50 }
51
52 int main(int argc, char *argv[]) {
53 test_config_compress();
54
55 return 0;
56 }