test/buffer_tests.c

changeset 140
15f871f50bfd
parent 134
4d320dc3a7af
child 147
1aa598f36872
     1.1 --- a/test/buffer_tests.c	Mon Aug 12 14:43:22 2013 +0200
     1.2 +++ b/test/buffer_tests.c	Tue Aug 13 14:20:12 2013 +0200
     1.3 @@ -27,6 +27,7 @@
     1.4   */
     1.5  
     1.6  #include "buffer_tests.h"
     1.7 +#include "ucx/utils.h"
     1.8  
     1.9  UCX_TEST(test_ucx_buffer_seektell) {
    1.10      UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
    1.11 @@ -292,7 +293,7 @@
    1.12      ucx_buffer_free(src);
    1.13  }
    1.14  
    1.15 -UCX_TEST(test_ucx_buffer_generic_copy) {
    1.16 +UCX_TEST(test_ucx_stream_copy) {
    1.17      UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT);
    1.18      UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
    1.19      
    1.20 @@ -303,7 +304,7 @@
    1.21      UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1");
    1.22      ucx_buffer_seek(b1, 0, SEEK_SET);
    1.23      
    1.24 -    size_t ncp = ucx_buffer_copy(b1, b2, ucx_buffer_read, ucx_buffer_write);
    1.25 +    size_t ncp = ucx_stream_hcopy(b1, b2, ucx_buffer_read, ucx_buffer_write);
    1.26      UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes");
    1.27      UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size");
    1.28      UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
    1.29 @@ -317,19 +318,25 @@
    1.30      FILE *file = tmpfile();
    1.31      UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted");
    1.32      
    1.33 -    ncp = ucx_buffer_copy(b1, file, ucx_buffer_read, fwrite);
    1.34 +    ncp = ucx_stream_hcopy(b1, file, ucx_buffer_read, fwrite);
    1.35      UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file");
    1.36      
    1.37      fseek(file, 0, SEEK_SET);
    1.38      
    1.39 -    ncp = ucx_buffer_copy(file, b2, fread, ucx_buffer_write);
    1.40 +    ncp = ucx_stream_hcopy(file, b2, fread, ucx_buffer_write);
    1.41      UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file");
    1.42      
    1.43      UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
    1.44              "b1 and b2 content mismatch");
    1.45      
    1.46      fclose(file);
    1.47 -    
    1.48 +
    1.49 +    ucx_buffer_clear(b1);
    1.50 +    ucx_buffer_seek(b2, 0, SEEK_SET);
    1.51 +    ncp = ucx_stream_ncopy(b2, b1, ucx_buffer_read, ucx_buffer_write, 8);
    1.52 +    UCX_TEST_ASSERT(ncp == 8, "copied wrong number of bytes with ncopy");
    1.53 +    UCX_TEST_ASSERT(memcmp(b1->space, "01234567\0\0\0\0\0\0\0\0", 16) == 0,
    1.54 +        "content wrong after ncopy");
    1.55      
    1.56      UCX_TEST_END
    1.57      

mercurial