test/buffer_tests.c

changeset 140
15f871f50bfd
parent 134
4d320dc3a7af
child 147
1aa598f36872
--- a/test/buffer_tests.c	Mon Aug 12 14:43:22 2013 +0200
+++ b/test/buffer_tests.c	Tue Aug 13 14:20:12 2013 +0200
@@ -27,6 +27,7 @@
  */
 
 #include "buffer_tests.h"
+#include "ucx/utils.h"
 
 UCX_TEST(test_ucx_buffer_seektell) {
     UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
@@ -292,7 +293,7 @@
     ucx_buffer_free(src);
 }
 
-UCX_TEST(test_ucx_buffer_generic_copy) {
+UCX_TEST(test_ucx_stream_copy) {
     UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT);
     UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
     
@@ -303,7 +304,7 @@
     UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1");
     ucx_buffer_seek(b1, 0, SEEK_SET);
     
-    size_t ncp = ucx_buffer_copy(b1, b2, ucx_buffer_read, ucx_buffer_write);
+    size_t ncp = ucx_stream_hcopy(b1, b2, ucx_buffer_read, ucx_buffer_write);
     UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes");
     UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size");
     UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
@@ -317,19 +318,25 @@
     FILE *file = tmpfile();
     UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted");
     
-    ncp = ucx_buffer_copy(b1, file, ucx_buffer_read, fwrite);
+    ncp = ucx_stream_hcopy(b1, file, ucx_buffer_read, fwrite);
     UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file");
     
     fseek(file, 0, SEEK_SET);
     
-    ncp = ucx_buffer_copy(file, b2, fread, ucx_buffer_write);
+    ncp = ucx_stream_hcopy(file, b2, fread, ucx_buffer_write);
     UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file");
     
     UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
             "b1 and b2 content mismatch");
     
     fclose(file);
-    
+
+    ucx_buffer_clear(b1);
+    ucx_buffer_seek(b2, 0, SEEK_SET);
+    ncp = ucx_stream_ncopy(b2, b1, ucx_buffer_read, ucx_buffer_write, 8);
+    UCX_TEST_ASSERT(ncp == 8, "copied wrong number of bytes with ncopy");
+    UCX_TEST_ASSERT(memcmp(b1->space, "01234567\0\0\0\0\0\0\0\0", 16) == 0,
+        "content wrong after ncopy");
     
     UCX_TEST_END
     

mercurial