tests/test_utils.cpp

changeset 674
dc514a5d42a5
parent 654
c9d008861178
--- a/tests/test_utils.cpp	Mon Apr 03 19:09:31 2023 +0200
+++ b/tests/test_utils.cpp	Mon Apr 03 19:20:30 2023 +0200
@@ -28,8 +28,70 @@
 
 #include "cx/utils.h"
 
+#include "cx/buffer.h"
+
 #include <gtest/gtest.h>
 
+TEST(Utils, cx_stream_bncopy) {
+    CxBuffer source, target;
+    char sbuf[32], tbuf[32];
+    memset(tbuf, 0, 32);
+    cxBufferInit(&source, sbuf, 32, nullptr, 0);
+    cxBufferInit(&target, tbuf, 32, nullptr, 0);
+    cxBufferPutString(&source, "This is a stream copy test.");
+    cxBufferSeek(&source, 0, SEEK_SET);
+
+    char tmp[4];
+    size_t result = cx_stream_bncopy(&source, &target,
+                                     (cx_read_func) cxBufferRead,
+                                     (cx_write_func) cxBufferWrite,
+                                     tmp, 4, 20);
+    EXPECT_EQ(20, result);
+    EXPECT_EQ(20, target.size);
+    EXPECT_STREQ("This is a stream cop\0", tbuf);
+
+    result = cx_stream_bcopy(&source, &target,
+                             (cx_read_func) cxBufferRead,
+                             (cx_write_func) cxBufferWrite,
+                             nullptr, 16);
+
+    EXPECT_EQ(7, result);
+    EXPECT_EQ(27, target.size);
+    EXPECT_STREQ("This is a stream copy test.\0", tbuf);
+
+    cxBufferDestroy(&source);
+    cxBufferDestroy(&target);
+}
+
+TEST(Utils, cx_stream_ncopy) {
+    CxBuffer source, target;
+    char sbuf[32], tbuf[32];
+    memset(tbuf, 0, 32);
+    cxBufferInit(&source, sbuf, 32, nullptr, 0);
+    cxBufferInit(&target, tbuf, 32, nullptr, 0);
+    cxBufferPutString(&source, "This is a stream copy test.");
+    cxBufferSeek(&source, 0, SEEK_SET);
+
+    size_t result = cx_stream_ncopy(&source, &target,
+                                    (cx_read_func) cxBufferRead,
+                                    (cx_write_func) cxBufferWrite,
+                                    20);
+    EXPECT_EQ(20, result);
+    EXPECT_EQ(20, target.size);
+    EXPECT_STREQ("This is a stream cop\0", tbuf);
+
+    result = cx_stream_copy(&source, &target,
+                            (cx_read_func) cxBufferRead,
+                            (cx_write_func) cxBufferWrite);
+
+    EXPECT_EQ(7, result);
+    EXPECT_EQ(27, target.size);
+    EXPECT_STREQ("This is a stream copy test.\0", tbuf);
+
+    cxBufferDestroy(&source);
+    cxBufferDestroy(&target);
+}
+
 TEST(Utils, ForN) {
     unsigned j;
     j = 0;
@@ -106,7 +168,7 @@
 struct Utils_szmul_impl : ::testing::Test {
 #undef CX_SZMUL_BUILTIN
 
-#include "../src/utils.c"
+#include "../src/szmul.c"
 
 #define CX_SZMUL_BUILTIN
 };

mercurial