Mercurial > dovecot > core-2.2
annotate src/lib/test-istream-base64-decoder.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:
20639
diff
changeset
|
1 /* Copyright (c) 2010-2017 Dovecot authors, see the included COPYING file */ |
14845 | 2 |
3 #include "test-lib.h" | |
4 #include "str.h" | |
5 #include "istream-private.h" | |
6 #include "istream-base64.h" | |
7 | |
8 struct { | |
9 const char *input; | |
10 const char *output; | |
11 } tests[] = { | |
12 { "aGVsbG8gd29ybGQ=", "hello world" }, | |
13 { "\naGVs\nbG8g\nd29y\nbGQ=\n", "hello world" }, | |
14 { " aGVs \r\n bG8g \r\n d29y \t \r\n bGQ= \r\n\r\n", "hello world" }, | |
15 }; | |
16 | |
17 static void | |
18 decode_test(const char *base64_input, const char *output, bool broken_input) | |
19 { | |
20 unsigned int base64_input_len = strlen(base64_input); | |
21 struct istream *input_data, *input; | |
22 const unsigned char *data; | |
23 size_t i, size; | |
24 int ret = 0; | |
25 | |
26 input_data = test_istream_create_data(base64_input, base64_input_len); | |
27 test_istream_set_allow_eof(input_data, FALSE); | |
28 input = i_stream_create_base64_decoder(input_data); | |
29 | |
30 for (i = 1; i <= base64_input_len; i++) { | |
31 test_istream_set_size(input_data, i); | |
32 while ((ret = i_stream_read(input)) > 0) ; | |
33 if (ret == -1 && broken_input) | |
34 break; | |
35 test_assert(ret == 0); | |
36 } | |
37 if (ret == 0) { | |
38 test_istream_set_allow_eof(input_data, TRUE); | |
39 while ((ret = i_stream_read(input)) > 0) ; | |
40 } | |
41 test_assert(ret == -1); | |
42 test_assert((input->stream_errno == 0 && !broken_input) || | |
43 (input->stream_errno == EINVAL && broken_input)); | |
44 | |
45 data = i_stream_get_data(input, &size); | |
20639
d6124d30333c
lib,lib-test: stop calling memcmp and memcpy with NULL in tests
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents:
19552
diff
changeset
|
46 test_assert(size == strlen(output)); |
d6124d30333c
lib,lib-test: stop calling memcmp and memcpy with NULL in tests
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents:
19552
diff
changeset
|
47 if (size > 0) |
d6124d30333c
lib,lib-test: stop calling memcmp and memcpy with NULL in tests
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents:
19552
diff
changeset
|
48 test_assert(memcmp(data, output, size) == 0); |
14845 | 49 i_stream_unref(&input); |
50 i_stream_unref(&input_data); | |
51 } | |
52 | |
53 void test_istream_base64_decoder(void) | |
54 { | |
55 unsigned int i; | |
56 | |
57 for (i = 0; i < N_ELEMENTS(tests); i++) { | |
58 test_begin(t_strdup_printf("istream base64 decoder %u", i+1)); | |
59 decode_test(tests[i].input, tests[i].output, FALSE); | |
60 test_end(); | |
61 } | |
62 test_begin("istream base64 decoder error"); | |
63 decode_test("foo", "", TRUE); | |
64 decode_test("Zm9vC", "foo", TRUE); | |
65 decode_test("Zm9v!", "foo", TRUE); | |
66 decode_test("Zm9!v", "", TRUE); | |
67 decode_test("Zm9 v", "", TRUE); | |
68 decode_test("Zm 9v", "", TRUE); | |
69 decode_test("Z m9v", "", TRUE); | |
70 test_end(); | |
71 } |