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