Mercurial > dovecot > core-2.2
annotate src/lib/test-str-sanitize.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 | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
1 /* Copyright (c) 2007-2017 Dovecot authors, see the included COPYING file */ |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "test-lib.h" |
18206
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
4 #include "str.h" |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "str-sanitize.h" |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
17657
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
7 struct str_sanitize_test { |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 const char *str; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 unsigned int max_len; |
17657
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
10 const char *sanitized; /* NULL for no change */ |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 }; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 void test_str_sanitize(void) |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 { |
17657
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
15 static struct str_sanitize_test tests[] = { |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
16 { NULL, 2, NULL }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
17 { "", 2, NULL }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
18 { "a", 2, NULL }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
19 { "ab", 2, NULL }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
20 { "abc", 2, "..." }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
21 { "abcd", 3, "..." }, |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
22 { "abcde", 4, "a..." }, |
18206
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
23 { "\xD1\x81", 1, "..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
24 { "\xD1\x81", 2, "\xD1\x81" }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
25 { "\xD1\x81", 3, NULL }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
26 { "\xC3\xA4\xC3\xA4zyxa", 1, "..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
27 { "\xC3\xA4\xC3\xA4zyxa", 2, "..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
28 { "\xC3\xA4\xC3\xA4zyxa", 3, "..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
29 { "\xC3\xA4\xC3\xA4zyxa", 4, "..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
30 { "\xC3\xA4\xC3\xA4zyxa", 5, "\xC3\xA4..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
31 { "\xC3\xA4\xC3\xA4zyxa", 6, "\xC3\xA4..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
32 { "\xC3\xA4\xC3\xA4zyxa", 7, "\xC3\xA4\xC3\xA4..." }, |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
33 { "\xC3\xA4\xC3\xA4zyxa", 8, "\xC3\xA4\xC3\xA4zyxa" }, |
17657
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
34 { "\001x\x1fy\x81", 10, "?x?y?" } |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 }; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 const char *str; |
18206
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
37 string_t *str2; |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 unsigned int i; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
10212
f68c2cc1b32b
str_sanitize(): Don't break UTF-8 input.
Timo Sirainen <tss@iki.fi>
parents:
9425
diff
changeset
|
40 test_begin("str_sanitize"); |
17657
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
41 for (i = 0; i < N_ELEMENTS(tests); i++) { |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
42 str = str_sanitize(tests[i].str, tests[i].max_len); |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
43 if (tests[i].sanitized != NULL) |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
44 test_assert_idx(null_strcmp(str, tests[i].sanitized) == 0, i); |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
45 else |
e5157203e96d
lib: test-str-sanitize - tighten tests
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
46 test_assert_idx(str == tests[i].str, i); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 } |
10212
f68c2cc1b32b
str_sanitize(): Don't break UTF-8 input.
Timo Sirainen <tss@iki.fi>
parents:
9425
diff
changeset
|
48 test_end(); |
18206
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
49 |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
50 test_begin("str_sanitize_append"); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
51 str2 = t_str_new(128); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
52 for (i = 0; i < N_ELEMENTS(tests); i++) { |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
53 if (tests[i].str == NULL) |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
54 continue; |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
55 str_truncate(str2, 0); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
56 str_append(str2, "1234567890"); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
57 str_sanitize_append(str2, tests[i].str, tests[i].max_len); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
58 |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
59 test_assert_idx(strncmp(str_c(str2), "1234567890", 10) == 0, i); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
60 if (tests[i].sanitized != NULL) |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
61 test_assert_idx(strcmp(str_c(str2)+10, tests[i].sanitized) == 0, i); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
62 else |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
63 test_assert_idx(strcmp(str_c(str2)+10, tests[i].str) == 0, i); |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
64 } |
ee12ce691bd3
lib: Various fixes to str_sanitize*()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
65 test_end(); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 } |