--- a/test/buffer_tests.c Wed Oct 10 10:04:01 2012 +0200 +++ b/test/buffer_tests.c Wed Oct 10 10:46:20 2012 +0200 @@ -62,7 +62,8 @@ ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); UCX_TEST_ASSERT(ucx_buffer_tell(b) == 16, "pos wrong after last 3 puts"); UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof not set"); - UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF, "put shall return EOF on memof"); + UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF, + "put shall return EOF when buffer is full"); UCX_TEST_ASSERT(memcmp(buffer, "000 000", 16) == 0, "buffer contains incorrect content"); @@ -184,3 +185,28 @@ ucx_buffer_free(b); free(buffer); } + +UCX_TEST_IMPLEMENT(test_ucx_buffer_extract) { + char *buffer = malloc(16); + strcpy(buffer, "this is a test!"); + + UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE), + *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_DEFAULT); + + UCX_TEST_BEGIN + UCX_TEST_ASSERT(ucx_buffer_testflags(dst, UCX_BUFFER_AUTOFREE), + "autofree flag shall be enforced"); + UCX_TEST_ASSERT(ucx_buffer_size(dst) == 5, "wrong size for new buffer"); + char rb[5]; + ucx_buffer_read(rb, 1, 5, dst); + UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0, + "new buffer has incorrect content"); + + UCX_TEST_ASSERT(ucx_buffer_extract(dst, 3, 3, UCX_BUFFER_DEFAULT) == NULL, + "extract shall fail on invalid bounds"); + + UCX_TEST_END + + ucx_buffer_free(dst); + ucx_buffer_free(src); +}