tests/test_utils.cpp

changeset 674
dc514a5d42a5
parent 654
c9d008861178
equal deleted inserted replaced
673:60fb6aec157d 674:dc514a5d42a5
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "cx/utils.h" 29 #include "cx/utils.h"
30 30
31 #include "cx/buffer.h"
32
31 #include <gtest/gtest.h> 33 #include <gtest/gtest.h>
34
35 TEST(Utils, cx_stream_bncopy) {
36 CxBuffer source, target;
37 char sbuf[32], tbuf[32];
38 memset(tbuf, 0, 32);
39 cxBufferInit(&source, sbuf, 32, nullptr, 0);
40 cxBufferInit(&target, tbuf, 32, nullptr, 0);
41 cxBufferPutString(&source, "This is a stream copy test.");
42 cxBufferSeek(&source, 0, SEEK_SET);
43
44 char tmp[4];
45 size_t result = cx_stream_bncopy(&source, &target,
46 (cx_read_func) cxBufferRead,
47 (cx_write_func) cxBufferWrite,
48 tmp, 4, 20);
49 EXPECT_EQ(20, result);
50 EXPECT_EQ(20, target.size);
51 EXPECT_STREQ("This is a stream cop\0", tbuf);
52
53 result = cx_stream_bcopy(&source, &target,
54 (cx_read_func) cxBufferRead,
55 (cx_write_func) cxBufferWrite,
56 nullptr, 16);
57
58 EXPECT_EQ(7, result);
59 EXPECT_EQ(27, target.size);
60 EXPECT_STREQ("This is a stream copy test.\0", tbuf);
61
62 cxBufferDestroy(&source);
63 cxBufferDestroy(&target);
64 }
65
66 TEST(Utils, cx_stream_ncopy) {
67 CxBuffer source, target;
68 char sbuf[32], tbuf[32];
69 memset(tbuf, 0, 32);
70 cxBufferInit(&source, sbuf, 32, nullptr, 0);
71 cxBufferInit(&target, tbuf, 32, nullptr, 0);
72 cxBufferPutString(&source, "This is a stream copy test.");
73 cxBufferSeek(&source, 0, SEEK_SET);
74
75 size_t result = cx_stream_ncopy(&source, &target,
76 (cx_read_func) cxBufferRead,
77 (cx_write_func) cxBufferWrite,
78 20);
79 EXPECT_EQ(20, result);
80 EXPECT_EQ(20, target.size);
81 EXPECT_STREQ("This is a stream cop\0", tbuf);
82
83 result = cx_stream_copy(&source, &target,
84 (cx_read_func) cxBufferRead,
85 (cx_write_func) cxBufferWrite);
86
87 EXPECT_EQ(7, result);
88 EXPECT_EQ(27, target.size);
89 EXPECT_STREQ("This is a stream copy test.\0", tbuf);
90
91 cxBufferDestroy(&source);
92 cxBufferDestroy(&target);
93 }
32 94
33 TEST(Utils, ForN) { 95 TEST(Utils, ForN) {
34 unsigned j; 96 unsigned j;
35 j = 0; 97 j = 0;
36 cx_for_n(i, 50) { 98 cx_for_n(i, 50) {
104 166
105 // also test the custom implementation 167 // also test the custom implementation
106 struct Utils_szmul_impl : ::testing::Test { 168 struct Utils_szmul_impl : ::testing::Test {
107 #undef CX_SZMUL_BUILTIN 169 #undef CX_SZMUL_BUILTIN
108 170
109 #include "../src/utils.c" 171 #include "../src/szmul.c"
110 172
111 #define CX_SZMUL_BUILTIN 173 #define CX_SZMUL_BUILTIN
112 }; 174 };
113 175
114 TEST_F(Utils_szmul_impl, Test) { 176 TEST_F(Utils_szmul_impl, Test) {

mercurial