Mercurial > dovecot > core-2.2
annotate src/lib/test-var-expand.c @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | 47f3f4d58b17 |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21063
diff
changeset
|
1 /* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */ |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "test-lib.h" |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "str.h" |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "env-util.h" |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "hostpid.h" |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "var-expand.h" |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
8 #include "var-expand-private.h" |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 struct var_expand_test { |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 const char *in; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 const char *out; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 }; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
14339
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
15 struct var_get_key_range_test { |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
16 const char *in; |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
17 unsigned int idx, size; |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
18 }; |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
19 |
17160
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
20 static void test_var_expand_ranges(void) |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
21 { |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
22 static struct var_expand_test tests[] = { |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
23 { "%v", "value1234" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
24 { "%3v", "val" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
25 { "%3.2v", "ue" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
26 { "%3.-2v", "ue12" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
27 { "%-3.2v", "23" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
28 { "%0.-1v", "value123" }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
29 { "%-4.-1v", "123" } |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
30 }; |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
31 static struct var_expand_table table[] = { |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
32 { 'v', "value1234", NULL }, |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
33 { '\0', NULL, NULL } |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
34 }; |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
35 string_t *str = t_str_new(128); |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
36 unsigned int i; |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
37 |
17819
8a969c11e1af
lib: test-var-expand - disambiguate tests
Phil Carmody <phil@dovecot.fi>
parents:
17550
diff
changeset
|
38 test_begin("var_expand - ranges"); |
17160
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
39 for (i = 0; i < N_ELEMENTS(tests); i++) { |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
40 str_truncate(str, 0); |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
41 var_expand(str, tests[i].in, table); |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
42 test_assert(strcmp(tests[i].out, str_c(str)) == 0); |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
43 } |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
44 test_end(); |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
45 } |
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
46 |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 static void test_var_expand_builtin(void) |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 { |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 static struct var_expand_test tests[] = { |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 { "%{hostname}", NULL }, |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 { "%{pid}", NULL }, |
16474
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
52 { "a%{env:FOO}b", "abaRb" }, |
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
53 { "%50Hv", "1f" }, |
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
54 { "%50Hw", "2e" }, |
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
55 { "%50Nv", "25" }, |
20053
2a83fcc09a68
lib: var_expand() now expands %{nonexistent} to UNSUPPORTED_VARIABLE_nonexistent
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
56 { "%50Nw", "e" }, |
2a83fcc09a68
lib: var_expand() now expands %{nonexistent} to UNSUPPORTED_VARIABLE_nonexistent
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
57 |
2a83fcc09a68
lib: var_expand() now expands %{nonexistent} to UNSUPPORTED_VARIABLE_nonexistent
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
58 { "%{nonexistent}", "UNSUPPORTED_VARIABLE_nonexistent" }, |
2a83fcc09a68
lib: var_expand() now expands %{nonexistent} to UNSUPPORTED_VARIABLE_nonexistent
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
59 { "%{nonexistent:default}", "UNSUPPORTED_VARIABLE_nonexistent" }, |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 }; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 static struct var_expand_table table[] = { |
16474
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
62 { 'v', "value", NULL }, |
561f36451dc2
var_expand*(): Added small unit tests for %H and %N
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
63 { 'w', "value2", NULL }, |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 { '\0', NULL, NULL } |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 }; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 string_t *str = t_str_new(128); |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 unsigned int i; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 tests[0].out = my_hostname; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 tests[1].out = my_pid; |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 env_put("FOO=baR"); |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 |
17819
8a969c11e1af
lib: test-var-expand - disambiguate tests
Phil Carmody <phil@dovecot.fi>
parents:
17550
diff
changeset
|
73 test_begin("var_expand - builtin"); |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 for (i = 0; i < N_ELEMENTS(tests); i++) { |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 str_truncate(str, 0); |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 var_expand(str, tests[i].in, table); |
17550
1278fed4f2c9
lib: test-var-expand - use test_assert_idx() inside loops
Phil Carmody <phil@dovecot.fi>
parents:
17160
diff
changeset
|
77 test_assert_idx(strcmp(tests[i].out, str_c(str)) == 0, i); |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 } |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 test_end(); |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 } |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
14339
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
82 static void test_var_get_key_range(void) |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
83 { |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
84 static struct var_get_key_range_test tests[] = { |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
85 { "", 0, 0 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
86 { "{", 1, 0 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
87 { "k", 0, 1 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
88 { "{key}", 1, 3 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
89 { "5.5Rk", 4, 1 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
90 { "5.5R{key}", 5, 3 }, |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
91 { "{key", 1, 3 } |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
92 }; |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
93 unsigned int i, idx, size; |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
94 |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
95 test_begin("var_get_key_range"); |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
96 for (i = 0; i < N_ELEMENTS(tests); i++) { |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
97 var_get_key_range(tests[i].in, &idx, &size); |
17550
1278fed4f2c9
lib: test-var-expand - use test_assert_idx() inside loops
Phil Carmody <phil@dovecot.fi>
parents:
17160
diff
changeset
|
98 test_assert_idx(tests[i].idx == idx, i); |
1278fed4f2c9
lib: test-var-expand - use test_assert_idx() inside loops
Phil Carmody <phil@dovecot.fi>
parents:
17160
diff
changeset
|
99 test_assert_idx(tests[i].size == size, i); |
14339
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
100 |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
101 if (tests[i].size == 1) |
17550
1278fed4f2c9
lib: test-var-expand - use test_assert_idx() inside loops
Phil Carmody <phil@dovecot.fi>
parents:
17160
diff
changeset
|
102 test_assert_idx(tests[i].in[idx] == var_get_key(tests[i].in), i); |
14339
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
103 } |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
104 test_end(); |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
105 } |
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
106 |
19030
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
107 static const char *test_var_expand_func1(const char *data, void *context) |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
108 { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
109 test_assert(*(int *)context == 0xabcdef); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
110 return t_strdup_printf("<%s>", data); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
111 } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
112 |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
113 static const char *test_var_expand_func2(const char *data ATTR_UNUSED, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
114 void *context ATTR_UNUSED) |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
115 { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
116 return ""; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
117 } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
118 |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
119 static const char *test_var_expand_func3(const char *data ATTR_UNUSED, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
120 void *context ATTR_UNUSED) |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
121 { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
122 return NULL; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
123 } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
124 |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
125 static void test_var_expand_with_funcs(void) |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
126 { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
127 static struct var_expand_test tests[] = { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
128 { "%{func1}", "<>" }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
129 { "%{func1:foo}", "<foo>" }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
130 { "%{func2}", "" }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
131 { "%{func3}", "" } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
132 }; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
133 static struct var_expand_table table[] = { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
134 { '\0', NULL, NULL } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
135 }; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
136 static const struct var_expand_func_table func_table[] = { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
137 { "func1", test_var_expand_func1 }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
138 { "func2", test_var_expand_func2 }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
139 { "func3", test_var_expand_func3 }, |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
140 { NULL, NULL } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
141 }; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
142 string_t *str = t_str_new(128); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
143 unsigned int i; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
144 int ctx = 0xabcdef; |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
145 |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
146 test_begin("var_expand_with_funcs"); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
147 for (i = 0; i < N_ELEMENTS(tests); i++) { |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
148 str_truncate(str, 0); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
149 var_expand_with_funcs(str, tests[i].in, table, func_table, &ctx); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
150 test_assert_idx(strcmp(tests[i].out, str_c(str)) == 0, i); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
151 } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
152 test_end(); |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
153 } |
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
154 |
20550
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
155 static void test_var_get_key(void) |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
156 { |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
157 static struct { |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
158 const char *str; |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
159 char key; |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
160 } tests[] = { |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
161 { "x", 'x' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
162 { "2.5Mx", 'x' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
163 { "200MDx", 'x' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
164 { "200MD{foo}", '{' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
165 { "{foo}", '{' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
166 { "", '\0' }, |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
167 }; |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
168 |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
169 test_begin("var_get_key"); |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
170 for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
171 test_assert_idx(var_get_key(tests[i].str) == tests[i].key, i); |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
172 test_end(); |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
173 } |
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
174 |
20551
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
175 static void test_var_has_key(void) |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
176 { |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
177 static struct { |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
178 const char *str; |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
179 char key; |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
180 const char *long_key; |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
181 bool result; |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
182 } tests[] = { |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
183 { "%x%y", 'x', NULL, TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
184 { "%x%y", 'y', NULL, TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
185 { "%x%y", 'z', NULL, FALSE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
186 { "%{foo}", 'f', NULL, FALSE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
187 { "%{foo}", 'o', NULL, FALSE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
188 { "%{foo}", '\0', "foo", TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
189 { "%{foo}", 'o', "foo", TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
190 { "%2.5Mx%y", 'x', NULL, TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
191 { "%2.5M{foo}", '\0', "foo", TRUE }, |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
192 }; |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
193 |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
194 test_begin("var_has_key"); |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
195 for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
196 test_assert_idx(var_has_key(tests[i].str, tests[i].key, tests[i].long_key) == tests[i].result, i); |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
197 test_end(); |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
198 } |
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
199 |
21063
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
200 static const char *test_var_expand_hashing_func1(const char *data, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
201 void *context ATTR_UNUSED) |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
202 { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
203 return data; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
204 } |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
205 |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
206 static int test_var_expand_bad_func(struct var_expand_context *ctx ATTR_UNUSED, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
207 const char *key, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
208 const char *field ATTR_UNUSED, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
209 const char **result_r ATTR_UNUSED, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
210 const char **error_r) |
21063
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
211 { |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
212 if (strcmp(key, "notfound") == 0) return 0; |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
213 *error_r = "Bad parameters"; |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
214 return -1; |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
215 } |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
216 |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
217 static const struct var_expand_extension_func_table test_extension_funcs[] = { |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
218 { "notfound", test_var_expand_bad_func }, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
219 { "badparam", test_var_expand_bad_func }, |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
220 { NULL, NULL } |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
221 }; |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
222 |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
223 static void test_var_expand_extensions(void) |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
224 { |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
225 test_begin("var_expand_extensions"); |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
226 |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
227 var_expand_register_func_array(test_extension_funcs); |
21063
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
228 |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
229 static struct var_expand_table table[] = { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
230 {'\0', "example", "value" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
231 {'\0', "other-example", "other-value" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
232 {'\0', NULL, NULL} |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
233 }; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
234 |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
235 static struct { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
236 const char *in; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
237 const char *out; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
238 } tests[] = { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
239 { "md5: %M{value} %{md5:value}", "md5: 1a79a4d60de6718e8e5b326e338ae533 1a79a4d60de6718e8e5b326e338ae533" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
240 { "sha1: %{sha1:value}", "sha1: c3499c2729730a7f807efb8676a92dcb6f8a3f8f" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
241 { "sha1: %{sha1:func1:example}", "sha1: c3499c2729730a7f807efb8676a92dcb6f8a3f8f" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
242 { "truncate: %{sha1;truncate=12:value}", "truncate: 0c34" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
243 { "truncate: %{sha1;truncate=16:value}", "truncate: c349" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
244 { "rounds,salt: %{sha1;rounds=1000,salt=seawater:value}", "rounds,salt: b515c85884f6b82dc7588279f3643a73e55d2289" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
245 { "rounds,salt,expand: %{sha1;rounds=1000,salt=%{other-value}:value} %{other-value}", "rounds,salt,expand: 49a598ee110af615e175f2e4511cc5d7ccff96ab other-example" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
246 { "format: %4.8{sha1:value}", "format: 9c272973" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
247 { "base64: %{sha1;format=base64:value}", "base64: w0mcJylzCn+AfvuGdqkty2+KP48=" }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
248 }; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
249 |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
250 static const struct var_expand_func_table func_table[] = { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
251 { "func1", test_var_expand_hashing_func1 }, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
252 { NULL, NULL } |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
253 }; |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
254 |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
255 string_t *str = t_str_new(128); |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
256 |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
257 for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) { |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
258 str_truncate(str, 0); |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
259 var_expand_with_funcs(str, tests[i].in, table, |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
260 func_table, NULL); |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
261 test_assert_idx(strcmp(str_c(str), tests[i].out) == 0, i); |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
262 } |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
263 |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
264 var_expand_with_funcs(str, "notfound: %{notfound:field}", |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
265 table, func_table, NULL); |
21864
69257c124bd3
test-var-expand: Expect error
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21860
diff
changeset
|
266 /* expect error */ |
69257c124bd3
test-var-expand: Expect error
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21860
diff
changeset
|
267 test_expect_errors(1); |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
268 var_expand_with_funcs(str, "notfound: %{badparam:field}", |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
269 table, func_table, NULL); |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
270 |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
271 var_expand_unregister_func_array(test_extension_funcs); |
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
272 |
21063
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
273 test_end(); |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
274 } |
ee699e66a993
lib: Add tests for hashed var-expand
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20551
diff
changeset
|
275 |
22540
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
276 static void test_var_expand_if(void) |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
277 { |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
278 static const struct var_expand_table table[] = { |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
279 { 'a', "alpha", "alpha" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
280 { 'b', "beta", "beta" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
281 { 'o', "1", "one" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
282 { 't', "2", "two" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
283 { '\0', ";:", "evil1" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
284 { '\0', ";test;", "evil2" }, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
285 { '\0', NULL, NULL } |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
286 }; |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
287 string_t *dest = t_str_new(64); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
288 test_begin("var_expand_if"); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
289 |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
290 static const struct var_expand_test tests[] = { |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
291 /* basic numeric operand test */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
292 { "%{if;1;==;1;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
293 { "%{if;1;==;2;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
294 { "%{if;1;<;1;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
295 { "%{if;1;<;2;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
296 { "%{if;1;<=;1;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
297 { "%{if;1;<=;2;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
298 { "%{if;1;>;1;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
299 { "%{if;1;>;2;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
300 { "%{if;1;>=;1;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
301 { "%{if;1;>=;2;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
302 { "%{if;1;!=;1;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
303 { "%{if;1;!=;2;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
304 /* basic string operand test */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
305 { "%{if;a;eq;a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
306 { "%{if;a;eq;b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
307 { "%{if;a;lt;a;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
308 { "%{if;a;lt;b;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
309 { "%{if;a;le;a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
310 { "%{if;a;le;b;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
311 { "%{if;a;gt;a;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
312 { "%{if;a;gt;b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
313 { "%{if;a;ge;a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
314 { "%{if;a;ge;b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
315 { "%{if;a;ne;a;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
316 { "%{if;a;ne;b;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
317 { "%{if;a;*;a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
318 { "%{if;a;*;b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
319 { "%{if;a;*;*a*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
320 { "%{if;a;*;*b*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
321 { "%{if;a;*;*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
322 { "%{if;a;!*;a;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
323 { "%{if;a;!*;b;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
324 { "%{if;a;!*;*a*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
325 { "%{if;a;!*;*b*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
326 { "%{if;a;!*;*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
327 { "%{if;a;~;a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
328 { "%{if;a;~;b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
329 { "%{if;a;~;.*a.*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
330 { "%{if;a;~;.*b.*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
331 { "%{if;a;~;.*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
332 { "%{if;a;!~;a;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
333 { "%{if;a;!~;b;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
334 { "%{if;a;!~;.*a.*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
335 { "%{if;a;!~;.*b.*;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
336 { "%{if;a;!~;.*;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
337 { "%{if;this is test;~;^test;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
338 { "%{if;this is test;~;.*test;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
339 /* variable expansion */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
340 { "%{if;%a;eq;%a;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
341 { "%{if;%a;eq;%b;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
342 { "%{if;%{alpha};eq;%{alpha};yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
343 { "%{if;%{alpha};eq;%{beta};yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
344 { "%{if;%o;eq;%o;yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
345 { "%{if;%o;eq;%t;yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
346 { "%{if;%{one};eq;%{one};yes;no}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
347 { "%{if;%{one};eq;%{two};yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
348 { "%{if;%{one};eq;%{one};%{one};%{two}}", "1"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
349 { "%{if;%{one};gt;%{two};%{one};%{two}}", "2"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
350 { "%{if;%{evil1};eq;\\;\\:;%{evil2};no}", ";test;"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
351 /* inner if */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
352 { "%{if;%{if;%{one};eq;1;1;0};eq;%{if;%{two};eq;2;2;3};yes;no}", "no"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
353 /* no false */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
354 { "%{if;1;==;1;yes}", "yes"}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
355 { "%{if;1;==;2;yes}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
356 /* invalid input */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
357 { "%{if;}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
358 { "%{if;1;}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
359 { "%{if;1;==;}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
360 { "%{if;1;==;2;}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
361 { "%{if;1;fu;2;yes;no}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
362 /* missing variables */ |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
363 { "%{if;%{missing1};==;%{missing2};yes;no}", ""}, |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
364 }; |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
365 |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
366 test_expect_errors(6); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
367 |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
368 for(size_t i = 0; i < N_ELEMENTS(tests); i++) { |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
369 str_truncate(dest, 0); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
370 var_expand(dest, tests[i].in, table); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
371 test_assert_idx(strcmp(tests[i].out, str_c(dest)) == 0, i); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
372 } |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
373 |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
374 test_expect_no_more_errors(); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
375 |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
376 test_end(); |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
377 } |
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
378 |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 void test_var_expand(void) |
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 { |
17160
cb2607ffa93a
test-var-expand: Added more unit tests for %variable offsets/lengths.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
381 test_var_expand_ranges(); |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 test_var_expand_builtin(); |
14339
13d4c4f91622
liblib: Added var_get_key_range()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
383 test_var_get_key_range(); |
19030
061c21b5c5e4
lib: If var_expand_with_funcs() function returns NULL, it should be treated the same as ""
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
384 test_var_expand_with_funcs(); |
20550
ba37ec73c6aa
lib: var_get_key() didn't handle %{long_variables} correctly
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20053
diff
changeset
|
385 test_var_get_key(); |
20551
64f547f5bd86
lib: var_has_key() properly ignores key=='\0' now.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20550
diff
changeset
|
386 test_var_has_key(); |
21860
f7cfff192280
lib: Add tests for extensions
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21390
diff
changeset
|
387 test_var_expand_extensions(); |
22540
47f3f4d58b17
var-expand: Add tests for var_expand conditionals
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21864
diff
changeset
|
388 test_var_expand_if(); |
10526
e1b725d02c30
var_expand(): Added support for built-in host, pid and env:* variables.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 } |