Wed, 10 Oct 2012 13:58:51 +0200
discarded fascism from buffer
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | */ |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
5 | #include "buffer_tests.h" |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
7 | UCX_TEST_IMPLEMENT(test_ucx_buffer_seektell) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | memset(buffer, 32, 7); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | buffer[7] = 0; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
12 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
17 | r = ucx_buffer_seek(b, 5, SEEK_SET); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | UCX_TEST_ASSERT(r == 0, "seek SET+5 failed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
19 | UCX_TEST_ASSERT(b->pos == 5, "seek SET+5 set wrong position"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
21 | r = ucx_buffer_seek(b, 20, SEEK_SET); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | UCX_TEST_ASSERT(r != 0, "seek beyond bounds shall fail"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
23 | UCX_TEST_ASSERT(b->pos == 5, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | "failed seek shall leave pos unchanged"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
26 | r = ucx_buffer_seek(b, 5, SEEK_CUR); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | UCX_TEST_ASSERT(r == 0, "seek CUR+5 failed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
28 | UCX_TEST_ASSERT(b->pos == 10, "seek CUR+5 set wrong position"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
30 | r = ucx_buffer_seek(b, 10, SEEK_CUR); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | UCX_TEST_ASSERT(r != 0, "seek CUR beyond bounds shall fail"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
32 | UCX_TEST_ASSERT(b->pos == 10, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | "failed seek shall leave pos unchanged"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
35 | r = ucx_buffer_seek(b, -5, SEEK_END); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | UCX_TEST_ASSERT(r == 0, "seek END-5 failed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
37 | UCX_TEST_ASSERT(b->pos == 2, "seek END-5 set wrong position"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
39 | r = ucx_buffer_seek(b, -10, SEEK_END); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | UCX_TEST_ASSERT(r != 0, "seek END beyond bounds shall fail"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
41 | UCX_TEST_ASSERT(b->pos == 2, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | "failed seek shall leave pos unchanged"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
46 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
50 | UCX_TEST_IMPLEMENT(test_ucx_buffer_putc) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | memset(buffer, 32, 16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
54 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
59 | ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
60 | UCX_TEST_ASSERT(b->pos == 3, "pos wrong after first 3 puts"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
61 | ucx_buffer_seek(b, 10, SEEK_CUR); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
62 | ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
63 | UCX_TEST_ASSERT(b->pos == 16, "pos wrong after last 3 puts"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
64 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof not set"); |
62 | 65 | UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF, |
66 | "put shall return EOF when buffer is full"); | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | UCX_TEST_ASSERT(memcmp(buffer, "000 000", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | "buffer contains incorrect content"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
72 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
76 | UCX_TEST_IMPLEMENT(test_ucx_buffer_getc) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | for (int i = 8; i < 16 ; i++) { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
83 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | char rb[16]; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | for (int i = 0 ; i < 16 ; i++) { |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
90 | UCX_TEST_ASSERT(b->pos == i, "pos wrong during read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
91 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | "EOF shall not be set during read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
93 | rb[i] = ucx_buffer_getc(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | } |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
95 | UCX_TEST_ASSERT(b->pos == 16, "pos wrong after read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
96 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "EOF not set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | UCX_TEST_ASSERT(memcmp(rb, " 01234567", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | "read data incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
102 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
106 | UCX_TEST_IMPLEMENT(test_ucx_buffer_write) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | for (int i = 8; i < 16 ; i++) { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
113 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | char* teststring = "this is way too much"; |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
119 | r = ucx_buffer_write(teststring, 1, 20, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | UCX_TEST_ASSERT(r == 16, "string not correctly trimed"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | UCX_TEST_ASSERT(memcmp(buffer, teststring, 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | "buffer data incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
123 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof shall be set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
125 | ucx_buffer_seek(b, 8, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
126 | r = ucx_buffer_write("not", 1, 3, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | UCX_TEST_ASSERT(r == 3, "three bytes should be replace"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | UCX_TEST_ASSERT(memcmp(buffer, "this is not too much", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | "modified buffer is incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | char* threebytestring = " t h r e e "; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | memset(buffer, 49, 16); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
133 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
134 | r = ucx_buffer_write(threebytestring, 3, 6, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | UCX_TEST_ASSERT(r == 15, "three byte string not correctly trimed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
136 | UCX_TEST_ASSERT(b->pos == 15, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | "position after write of three byte string incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
138 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), "eof shall not be set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | UCX_TEST_ASSERT(memcmp(buffer, " t h r e e1", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | "bufer is incorrect after three byte string has been written"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
144 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
148 | UCX_TEST_IMPLEMENT(test_ucx_buffer_read) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | memset(buffer, 56, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | for (int i = 8; i < 16 ; i++) { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
155 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | char rb[16]; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | memset(rb, 32, 16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
163 | ucx_buffer_seek(b, 8, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
164 | r = ucx_buffer_read(rb, 1, 16, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | UCX_TEST_ASSERT(r == 8, "read did not stop at buffer end"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | UCX_TEST_ASSERT(memcmp(rb, "01234567 ", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | "buffer incorrect after first read"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
168 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof shall be set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
170 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
171 | r = ucx_buffer_read(rb+8, 1, 8, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | UCX_TEST_ASSERT(r == 8, "read did not read the specified amount of bytes"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | UCX_TEST_ASSERT(memcmp(rb, "0123456788888888", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | "buffer incorrect after second read"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
176 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
177 | r = ucx_buffer_read(rb, 3, 6, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | UCX_TEST_ASSERT(r == 15, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | "three byte read did not read the desired amount of bytes"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | UCX_TEST_ASSERT(memcmp(rb, "8888888801234568", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | "buffer incorrect after three byte read"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
185 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | } |
62 | 188 | |
189 | UCX_TEST_IMPLEMENT(test_ucx_buffer_extract) { | |
190 | char *buffer = malloc(16); | |
191 | strcpy(buffer, "this is a test!"); | |
192 | ||
193 | UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE), | |
194 | *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_DEFAULT); | |
195 | ||
196 | UCX_TEST_BEGIN | |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
197 | UCX_TEST_ASSERT((dst->flags & UCX_BUFFER_AUTOFREE) == UCX_BUFFER_AUTOFREE, |
62 | 198 | "autofree flag shall be enforced"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
199 | UCX_TEST_ASSERT(dst->size == 5, "wrong size for new buffer"); |
62 | 200 | char rb[5]; |
201 | ucx_buffer_read(rb, 1, 5, dst); | |
202 | UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0, | |
203 | "new buffer has incorrect content"); | |
204 | ||
205 | UCX_TEST_ASSERT(ucx_buffer_extract(dst, 3, 3, UCX_BUFFER_DEFAULT) == NULL, | |
206 | "extract shall fail on invalid bounds"); | |
207 | ||
208 | UCX_TEST_END | |
209 | ||
210 | ucx_buffer_free(dst); | |
211 | ucx_buffer_free(src); | |
212 | } |