test/buffer_tests.c

changeset 64
16590c9c497c
parent 63
1d3500806565
child 69
fb59270b1de3
equal deleted inserted replaced
63:1d3500806565 64:16590c9c497c
143 143
144 ucx_buffer_free(b); 144 ucx_buffer_free(b);
145 free(buffer); 145 free(buffer);
146 } 146 }
147 147
148 UCX_TEST_IMPLEMENT(test_ucx_buffer_write_ax) {
149 char *buffer = malloc(4);
150
151 UcxBuffer *b = ucx_buffer_new(buffer, 16,
152 UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE);
153 int r;
154
155 UCX_TEST_BEGIN
156
157 char* teststring = "this is way too much";
158 r = ucx_buffer_write(teststring, 1, 20, b);
159 buffer = b->space; /* autoextend is enabled, so we MUST retrieve pointer */
160 UCX_TEST_ASSERT(r == 20, "not all characters written");
161 UCX_TEST_ASSERT(b->size == 32, "buffer not properly extended");
162 UCX_TEST_ASSERT(b->pos == 20, "position incorrect");
163 UCX_TEST_ASSERT(memcmp(buffer,
164 "this is way too much\0\0\0\0\0\0\0\0\0\0\0\0", 32) == 0,
165 "incorrect buffer content");
166
167 UCX_TEST_END
168
169 ucx_buffer_free(b);
170 }
171
148 UCX_TEST_IMPLEMENT(test_ucx_buffer_read) { 172 UCX_TEST_IMPLEMENT(test_ucx_buffer_read) {
149 char *buffer = malloc(16); 173 char *buffer = malloc(16);
150 memset(buffer, 56, 8); 174 memset(buffer, 56, 8);
151 for (int i = 8; i < 16 ; i++) { 175 for (int i = 8; i < 16 ; i++) {
152 buffer[i] = 40+i; 176 buffer[i] = 40+i;

mercurial