1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/* Copyright (c) 2021 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
static void test_event_strlist(void)
{
test_begin("event strlist");
struct event *e1 = event_create(NULL);
event_strlist_append(e1, "key", "s1");
event_strlist_append(e1, "key", "s2");
struct event *e2 = event_create(e1);
event_strlist_append(e2, "key", "s3");
event_strlist_append(e2, "key", "s2");
test_assert_strcmp(event_find_field_recursive_str(e1, "key"), "s1,s2");
test_assert_strcmp(event_find_field_recursive_str(e2, "key"), "s3,s2,s1");
const char *new_strlist[] = { "new1", "new2", "new2", "s2" };
event_strlist_replace(e2, "key", new_strlist, N_ELEMENTS(new_strlist));
test_assert_strcmp(event_find_field_recursive_str(e2, "key"), "new1,new2,s2,s1");
struct event *e3 = event_create(NULL);
event_strlist_copy_recursive(e3, e2, "key");
test_assert_strcmp(event_find_field_recursive_str(e3, "key"), "new1,new2,s2,s1");
event_unref(&e3);
event_unref(&e1);
event_unref(&e2);
test_end();
}
static void test_lib_event_reason_code(void)
{
test_begin("event reason codes");
test_assert_strcmp(event_reason_code("foo", "bar"), "foo:bar");
test_assert_strcmp(event_reason_code("foo", "B A-r"), "foo:b_a_r");
test_assert_strcmp(event_reason_code_prefix("foo", "x", "bar"), "foo:xbar");
test_assert_strcmp(event_reason_code_prefix("foo", "", "bar"), "foo:bar");
test_end();
}
void test_lib_event(void)
{
test_event_strlist();
test_lib_event_reason_code();
}
enum fatal_test_state fatal_lib_event(unsigned int stage)
{
switch (stage) {
case 0:
test_begin("event reason codes - asserts");
/* module: uppercase */
test_expect_fatal_string("Invalid module");
(void)event_reason_code("FOO", "bar");
return FATAL_TEST_FAILURE;
case 1:
/* module: space */
test_expect_fatal_string("Invalid module");
(void)event_reason_code("f oo", "bar");
return FATAL_TEST_FAILURE;
case 2:
/* module: - */
test_expect_fatal_string("Invalid module");
(void)event_reason_code("f-oo", "bar");
return FATAL_TEST_FAILURE;
case 3:
/* module: empty */
test_expect_fatal_string("module[0] != '\\0'");
(void)event_reason_code("", "bar");
return FATAL_TEST_FAILURE;
case 4:
/* name_prefix: uppercase */
test_expect_fatal_string("Invalid name_prefix");
(void)event_reason_code_prefix("module", "FOO", "bar");
return FATAL_TEST_FAILURE;
case 5:
/* name_prefix: space */
test_expect_fatal_string("Invalid name_prefix");
(void)event_reason_code_prefix("module", "f oo", "bar");
return FATAL_TEST_FAILURE;
case 6:
/* name_prefix: - */
test_expect_fatal_string("Invalid name_prefix");
(void)event_reason_code_prefix("module", "f-oo", "bar");
return FATAL_TEST_FAILURE;
case 7:
/* name: empty */
test_expect_fatal_string("(name[0] != '\\0')");
(void)event_reason_code("foo:", "");
return FATAL_TEST_FAILURE;
default:
test_end();
return FATAL_TEST_FINISHED;
}
}
|