Mercurial > dovecot > core-2.2
annotate src/lib/test-istream-concat.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 | 81a4cf22408f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19639
diff
changeset
|
1 /* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */ |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "test-lib.h" |
13529
cf77e448295c
Renamed lib/*-internal.h files to lib/*-private.h for consistency.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
4 #include "istream-private.h" |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "istream-concat.h" |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include <fcntl.h> |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include <unistd.h> |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
17125
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
10 #define TEST_MAX_ISTREAM_COUNT 10 |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
11 #define TEST_MAX_ISTREAM_SIZE 1024 |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
12 #define TEST_MAX_BUFFER_SIZE 128 |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
13 |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 static void test_istream_concat_one(unsigned int buffer_size) |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 static const char *input_string = "xyz"; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #define STREAM_COUNT 5 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #define STREAM_BYTES 3 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 struct istream *streams[STREAM_COUNT+1]; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 struct istream *input; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 const unsigned char *data; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 size_t size; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 unsigned int i, j; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 for (i = 0; i < STREAM_COUNT; i++) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 streams[i] = test_istream_create(input_string); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 test_istream_set_allow_eof(streams[i], TRUE); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 test_istream_set_size(streams[i], 0); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 streams[i] = NULL; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 input = i_stream_create_concat(streams); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 for (i = 0; i/STREAM_BYTES < STREAM_COUNT; i++) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 test_istream_set_size(streams[i/STREAM_BYTES], (i%STREAM_BYTES) + 1); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 test_assert(i_stream_read(input) == 1); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 if (i < buffer_size) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 data = i_stream_get_data(input, &size); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 test_assert(size == i+1); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 } else { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 i_stream_skip(input, 1); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 data = i_stream_get_data(input, &size); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 test_assert(size == buffer_size); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 for (j = 0; j < size; j++) { |
10887 | 45 test_assert((char)data[j] == input_string[(input->v_offset + j) % STREAM_BYTES]); |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 } |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
48 test_assert(i_stream_read(input) == -1); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
49 i_stream_skip(input, i_stream_get_data_size(input)); |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 i_stream_unref(&input); |
17778
e5028f632d1c
lib: test-istream-concat - clean up our test-istreams
Phil Carmody <phil@dovecot.fi>
parents:
17616
diff
changeset
|
51 |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
52 for (i = 0; i < STREAM_COUNT; i++) { |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
53 test_assert(i_stream_is_eof(streams[i])); |
17778
e5028f632d1c
lib: test-istream-concat - clean up our test-istreams
Phil Carmody <phil@dovecot.fi>
parents:
17616
diff
changeset
|
54 i_stream_unref(&streams[i]); |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
55 } |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
17526
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
58 static bool test_istream_concat_random(void) |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 { |
17616
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
60 struct istream **streams, *concat, **limits = NULL; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 const unsigned char *data; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 unsigned char *w_data; |
10206
86110f830311
test-istream-concat: Don't use uninitialized variable.
Timo Sirainen <tss@iki.fi>
parents:
10186
diff
changeset
|
63 size_t size = 0; |
17616
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
64 unsigned int i, j, offset, stream_count, data_len, simult; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 |
17125
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
66 stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 streams = t_new(struct istream *, stream_count + 1); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 for (i = 0, offset = 0; i < stream_count; i++) { |
17125
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
69 data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 w_data = t_malloc(data_len); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 for (j = 0; j < data_len; j++) |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 w_data[j] = offset++; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 streams[i] = test_istream_create_data(w_data, data_len); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 test_istream_set_allow_eof(streams[i], TRUE); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 streams[i] = NULL; |
11074
c32f55615055
Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents:
10887
diff
changeset
|
77 i_assert(offset > 0); |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 |
17616
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
79 concat = i_stream_create_concat(streams); |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
80 i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE); |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
81 |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
82 simult = rand() % TEST_MAX_ISTREAM_COUNT; |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
83 if (simult > 0) { |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
84 limits = t_new(struct istream *, simult); |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
85 for (i = 0; i < simult; i++) |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
86 limits[i] = i_stream_create_limit(concat, (uoff_t)-1); |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
87 } |
17125
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
88 |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
89 for (i = 0; i < 1000; i++) { |
17616
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
90 struct istream *input = (simult == 0) ? concat : limits[rand() % simult]; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 if (rand() % 3 == 0) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 i_stream_seek(input, rand() % offset); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 } else { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 ssize_t ret = i_stream_read(input); |
17125
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
95 size = i_stream_get_data_size(input); |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
96 if (ret == -2) { |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
97 test_assert(size >= TEST_MAX_BUFFER_SIZE); |
e1db4af9e2c1
test-istream-concat unit test improved.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
98 } else if (input->v_offset + size != offset) { |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 test_assert(ret > 0); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 test_assert(input->v_offset + ret <= offset); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 i_stream_skip(input, rand() % ret); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 data = i_stream_get_data(input, &size); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 for (j = 0; j < size; j++) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 test_assert(data[j] == (input->v_offset + j) % 256); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 } |
17526
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
109 if (test_has_failed()) |
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
110 break; |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 for (i = 0; i < stream_count; i++) |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 i_stream_unref(&streams[i]); |
17616
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
114 for (i = 0; i < simult; i++) |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
115 i_stream_unref(&limits[i]); |
4583a0c2e368
lib: test-istream-concat - add simultanious limit streams back into the mix
Phil Carmody <phil@dovecot.fi>
parents:
17615
diff
changeset
|
116 i_stream_unref(&concat); |
17526
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
117 return !test_has_failed(); |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 |
22055
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
120 static void test_istream_concat_seek_end(void) |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
121 { |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
122 test_begin("istream concat seek end"); |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
123 |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
124 struct istream *streams[] = { |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
125 test_istream_create("s1"), |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
126 test_istream_create("s2"), |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
127 NULL |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
128 }; |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
129 struct istream *input = i_stream_create_concat(streams); |
22056
81a4cf22408f
lib: Fix memory leak in test-istream-concat
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22055
diff
changeset
|
130 i_stream_unref(&streams[0]); |
81a4cf22408f
lib: Fix memory leak in test-istream-concat
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22055
diff
changeset
|
131 i_stream_unref(&streams[1]); |
81a4cf22408f
lib: Fix memory leak in test-istream-concat
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22055
diff
changeset
|
132 |
22055
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
133 i_stream_seek(input, 4); |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
134 test_assert(i_stream_read(input) == -1); |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
135 i_stream_unref(&input); |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
136 |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
137 test_end(); |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
138 } |
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
139 |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
140 static void test_istream_concat_early_end(void) |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
141 { |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
142 struct istream *input, *streams[2]; |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
143 |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
144 test_begin("istream concat early end"); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
145 |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
146 streams[0] = test_istream_create("stream"); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
147 test_istream_set_size(streams[0], 3); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
148 test_istream_set_allow_eof(streams[0], FALSE); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
149 streams[1] = NULL; |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
150 |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
151 input = i_stream_create_concat(streams); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
152 test_assert(i_stream_read(input) == 3); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
153 test_istream_set_size(streams[0], 5); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
154 test_assert(i_stream_read(input) == 2); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
155 i_stream_skip(input, 5); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
156 i_stream_unref(&input); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
157 |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
158 test_assert(streams[0]->v_offset == 5); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
159 i_stream_unref(&streams[0]); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
160 |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
161 test_end(); |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
162 } |
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
163 |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 void test_istream_concat(void) |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 unsigned int i; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 test_begin("istream concat"); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 for (i = 1; i < STREAM_BYTES*STREAM_COUNT; i++) { |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 test_istream_concat_one(i); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 } |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 test_end(); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 test_begin("istream concat random"); |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 for (i = 0; i < 100; i++) T_BEGIN { |
17526
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
176 if(!test_istream_concat_random()) |
77f21248d29e
lib: test-istream-concat - early abort test loop on failure
Phil Carmody <phil@dovecot.fi>
parents:
17130
diff
changeset
|
177 i = 101; /* don't break a T_BEGIN */ |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 } T_END; |
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 test_end(); |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
180 |
22055
4ae88bb10a94
lib: Fix crash when seeking istream-concat to EOF and trying to read it
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
181 test_istream_concat_seek_end(); |
19639
e583f67b241e
lib: istream-concat now seeks parent streams to correct offset.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
182 test_istream_concat_early_end(); |
10186
49599bbfc900
Added unit tests for istream-seekable istream-concat.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } |