Mon, 16 May 2022 19:15:44 +0200
#170 test buffer seek
530 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include "cx/buffer.h" | |
30 | ||
31 | #include <gtest/gtest.h> | |
32 | #include "util_allocator.h" | |
33 | ||
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
34 | static void expect_default_flush_config(CxBuffer *buf) { |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
35 | EXPECT_EQ(buf->flush_blkmax, 0); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
36 | EXPECT_EQ(buf->flush_blksize, 4096); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
37 | EXPECT_EQ(buf->flush_threshold, SIZE_MAX); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
38 | EXPECT_EQ(buf->flush_func, nullptr); |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
39 | EXPECT_EQ(buf->flush_target, nullptr); |
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
40 | } |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
41 | |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
42 | TEST(BufferInit, WrapSpace) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
43 | CxTestingAllocator alloc; |
530 | 44 | CxBuffer buf; |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
45 | void *space = cxMalloc(&alloc, 16); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
46 | cxBufferInit(&buf, space, 16, &alloc, CX_BUFFER_DEFAULT); |
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
47 | expect_default_flush_config(&buf); |
530 | 48 | EXPECT_EQ(buf.space, space); |
49 | EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, 0); | |
50 | EXPECT_EQ(buf.flags & CX_BUFFER_FREE_CONTENTS, 0); | |
51 | EXPECT_EQ(buf.pos, 0); | |
52 | EXPECT_EQ(buf.size, 0); | |
53 | EXPECT_EQ(buf.capacity, 16); | |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
54 | EXPECT_EQ(buf.allocator, &alloc); |
530 | 55 | cxBufferDestroy(&buf); |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
56 | EXPECT_FALSE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
57 | cxFree(&alloc, space); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
58 | EXPECT_TRUE(alloc.verify()); |
530 | 59 | } |
60 | ||
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
61 | TEST(BufferInit, WrapSpaceAutoExtend) { |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
62 | CxTestingAllocator alloc; |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
63 | CxBuffer buf; |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
64 | void *space = cxMalloc(&alloc, 16); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
65 | cxBufferInit(&buf, space, 16, &alloc, CX_BUFFER_AUTO_EXTEND); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
66 | expect_default_flush_config(&buf); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
67 | EXPECT_EQ(buf.space, space); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
68 | EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, CX_BUFFER_AUTO_EXTEND); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
69 | EXPECT_EQ(buf.flags & CX_BUFFER_FREE_CONTENTS, 0); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
70 | EXPECT_EQ(buf.pos, 0); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
71 | EXPECT_EQ(buf.size, 0); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
72 | EXPECT_EQ(buf.capacity, 16); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
73 | EXPECT_EQ(buf.allocator, &alloc); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
74 | cxBufferDestroy(&buf); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
75 | EXPECT_FALSE(alloc.verify()); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
76 | cxFree(&alloc, space); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
77 | EXPECT_TRUE(alloc.verify()); |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
78 | } |
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
79 | |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
80 | TEST(BufferInit, WrapSpaceAutoFree) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
81 | CxTestingAllocator alloc; |
530 | 82 | CxBuffer buf; |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
83 | void *space = cxMalloc(&alloc, 16); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
84 | cxBufferInit(&buf, space, 16, &alloc, CX_BUFFER_FREE_CONTENTS); |
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
85 | expect_default_flush_config(&buf); |
530 | 86 | EXPECT_EQ(buf.space, space); |
87 | EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, 0); | |
88 | EXPECT_EQ(buf.flags & CX_BUFFER_FREE_CONTENTS, CX_BUFFER_FREE_CONTENTS); | |
89 | EXPECT_EQ(buf.pos, 0); | |
90 | EXPECT_EQ(buf.size, 0); | |
91 | EXPECT_EQ(buf.capacity, 16); | |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
92 | EXPECT_EQ(buf.allocator, &alloc); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
93 | EXPECT_FALSE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
94 | cxBufferDestroy(&buf); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
95 | EXPECT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
96 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
97 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
98 | TEST(BufferInit, FreshSpace) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
99 | CxTestingAllocator alloc; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
100 | CxBuffer buf; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
101 | cxBufferInit(&buf, nullptr, 8, &alloc, CX_BUFFER_DEFAULT); |
539
9cd98da9ee17
#184 start implementation of the flush feature
Mike Becker <universe@uap-core.de>
parents:
538
diff
changeset
|
102 | expect_default_flush_config(&buf); |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
103 | EXPECT_NE(buf.space, nullptr); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
104 | EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
105 | EXPECT_EQ(buf.flags & CX_BUFFER_FREE_CONTENTS, CX_BUFFER_FREE_CONTENTS); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
106 | EXPECT_EQ(buf.pos, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
107 | EXPECT_EQ(buf.size, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
108 | EXPECT_EQ(buf.capacity, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
109 | EXPECT_EQ(buf.allocator, &alloc); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
110 | EXPECT_FALSE(alloc.verify()); // space is still allocated |
530 | 111 | cxBufferDestroy(&buf); |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
112 | EXPECT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
113 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
114 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
115 | class BufferShiftFixture : public ::testing::Test { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
116 | protected: |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
117 | void SetUp() override { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
118 | ASSERT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
119 | cxBufferInit(&buf, nullptr, 16, &alloc, CX_BUFFER_DEFAULT); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
120 | memcpy(buf.space, "test____________", 16); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
121 | buf.capacity = 8; // purposely pretend that the buffer has less capacity s.t. we can test beyond the range |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
122 | buf.pos = 4; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
123 | buf.size = 4; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
124 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
125 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
126 | void TearDown() override { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
127 | cxBufferDestroy(&buf); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
128 | EXPECT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
129 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
130 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
131 | CxTestingAllocator alloc; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
132 | CxBuffer buf{}; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
133 | }; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
134 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
135 | class BufferShiftLeft : public BufferShiftFixture { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
136 | }; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
137 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
138 | TEST_F(BufferShiftLeft, Zero) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
139 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
140 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
141 | int ret = cxBufferShiftLeft(&buf, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
142 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
143 | EXPECT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
144 | EXPECT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
145 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
146 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
147 | |
547 | 148 | TEST_F(BufferShiftLeft, ZeroOffsetInterface) { |
149 | ASSERT_EQ(buf.pos, 4); | |
150 | ASSERT_EQ(buf.size, 4); | |
151 | int ret = cxBufferShift(&buf, -0); | |
152 | EXPECT_EQ(ret, 0); | |
153 | EXPECT_EQ(buf.pos, 4); | |
154 | EXPECT_EQ(buf.size, 4); | |
155 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); | |
156 | } | |
157 | ||
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
158 | TEST_F(BufferShiftLeft, Standard) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
159 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
160 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
161 | int ret = cxBufferShiftLeft(&buf, 2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
162 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
163 | EXPECT_EQ(buf.pos, 2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
164 | EXPECT_EQ(buf.size, 2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
165 | EXPECT_TRUE(memcmp(buf.space, "stst________", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
166 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
167 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
168 | TEST_F(BufferShiftLeft, Overshift) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
169 | ASSERT_LT(buf.pos, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
170 | ASSERT_LT(buf.size, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
171 | int ret = cxBufferShiftLeft(&buf, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
172 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
173 | EXPECT_EQ(buf.pos, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
174 | EXPECT_EQ(buf.size, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
175 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
176 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
177 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
178 | TEST_F(BufferShiftLeft, OvershiftPosOnly) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
179 | buf.pos = 2; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
180 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
181 | int ret = cxBufferShiftLeft(&buf, 3); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
182 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
183 | EXPECT_EQ(buf.pos, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
184 | EXPECT_EQ(buf.size, 1); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
185 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
186 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
187 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
188 | TEST_F(BufferShiftLeft, OffsetInterface) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
189 | buf.pos = 3; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
190 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
191 | int ret = cxBufferShift(&buf, -2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
192 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
193 | EXPECT_EQ(buf.pos, 1); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
194 | EXPECT_EQ(buf.size, 2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
195 | EXPECT_TRUE(memcmp(buf.space, "stst________", 8) == 0); |
530 | 196 | } |
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
197 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
198 | class BufferShiftRight : public BufferShiftFixture { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
199 | }; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
200 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
201 | TEST_F(BufferShiftRight, Zero) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
202 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
203 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
204 | int ret = cxBufferShiftRight(&buf, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
205 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
206 | EXPECT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
207 | EXPECT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
208 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
209 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
210 | |
547 | 211 | TEST_F(BufferShiftRight, ZeroOffsetInterface) { |
212 | ASSERT_EQ(buf.pos, 4); | |
213 | ASSERT_EQ(buf.size, 4); | |
214 | int ret = cxBufferShift(&buf, +0); | |
215 | EXPECT_EQ(ret, 0); | |
216 | EXPECT_EQ(buf.pos, 4); | |
217 | EXPECT_EQ(buf.size, 4); | |
218 | EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0); | |
219 | } | |
220 | ||
535
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
221 | TEST_F(BufferShiftRight, Standard) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
222 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
223 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
224 | int ret = cxBufferShiftRight(&buf, 3); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
225 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
226 | EXPECT_EQ(buf.pos, 7); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
227 | EXPECT_EQ(buf.size, 7); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
228 | EXPECT_TRUE(memcmp(buf.space, "testest_____", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
229 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
230 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
231 | TEST_F(BufferShiftRight, OvershiftDiscard) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
232 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
233 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
234 | ASSERT_EQ(buf.capacity, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
235 | int ret = cxBufferShiftRight(&buf, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
236 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
237 | EXPECT_EQ(buf.pos, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
238 | EXPECT_EQ(buf.size, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
239 | EXPECT_EQ(buf.capacity, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
240 | EXPECT_TRUE(memcmp(buf.space, "test__te____", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
241 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
242 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
243 | TEST_F(BufferShiftRight, OvershiftExtend) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
244 | ASSERT_EQ(buf.pos, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
245 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
246 | ASSERT_EQ(buf.capacity, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
247 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
248 | int ret = cxBufferShiftRight(&buf, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
249 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
250 | EXPECT_EQ(buf.pos, 10); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
251 | EXPECT_EQ(buf.size, 10); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
252 | EXPECT_GE(buf.capacity, 10); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
253 | EXPECT_TRUE(memcmp(buf.space, "test__test__", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
254 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
255 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
256 | TEST_F(BufferShiftRight, OffsetInterface) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
257 | buf.pos = 3; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
258 | ASSERT_EQ(buf.size, 4); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
259 | int ret = cxBufferShift(&buf, 2); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
260 | EXPECT_EQ(ret, 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
261 | EXPECT_EQ(buf.pos, 5); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
262 | EXPECT_EQ(buf.size, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
263 | EXPECT_TRUE(memcmp(buf.space, "tetest______", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
264 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
265 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
266 | TEST(BufferMinimumCapacity, Sufficient) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
267 | CxTestingAllocator alloc; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
268 | auto space = cxMalloc(&alloc, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
269 | CxBuffer buf; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
270 | cxBufferInit(&buf, space, 8, &alloc, CX_BUFFER_FREE_CONTENTS); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
271 | memcpy(space, "Testing", 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
272 | buf.size = 8; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
273 | cxBufferMinimumCapacity(&buf, 6); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
274 | EXPECT_EQ(buf.capacity, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
275 | EXPECT_EQ(buf.size, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
276 | EXPECT_TRUE(memcmp(buf.space, "Testing", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
277 | cxBufferDestroy(&buf); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
278 | EXPECT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
279 | } |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
280 | |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
281 | TEST(BufferMinimumCapacity, Extend) { |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
282 | CxTestingAllocator alloc; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
283 | auto space = cxMalloc(&alloc, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
284 | CxBuffer buf; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
285 | cxBufferInit(&buf, space, 8, &alloc, CX_BUFFER_FREE_CONTENTS); // NO auto extend! |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
286 | memcpy(space, "Testing", 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
287 | buf.size = 8; |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
288 | cxBufferMinimumCapacity(&buf, 16); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
289 | EXPECT_EQ(buf.capacity, 16); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
290 | EXPECT_EQ(buf.size, 8); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
291 | EXPECT_TRUE(memcmp(buf.space, "Testing", 8) == 0); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
292 | cxBufferDestroy(&buf); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
293 | EXPECT_TRUE(alloc.verify()); |
2ff6e9184468
#170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents:
530
diff
changeset
|
294 | } |
536
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
295 | |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
296 | TEST(BufferClear, Test) { |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
297 | char space[16]; |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
298 | strcpy(space, "clear test"); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
299 | CxBuffer buf; |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
300 | cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
301 | ASSERT_EQ(buf.size, 0); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
302 | // only clear the used part of the buffer |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
303 | cxBufferClear(&buf); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
304 | EXPECT_EQ(memcmp(space, "clear test", 10), 0); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
305 | buf.size = 5; |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
306 | buf.pos = 3; |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
307 | cxBufferClear(&buf); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
308 | EXPECT_EQ(memcmp(space, "\0\0\0\0\0 test", 10), 0); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
309 | EXPECT_EQ(buf.size, 0); |
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
310 | EXPECT_EQ(buf.pos, 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
311 | cxBufferDestroy(&buf); |
536
cb9b9739055e
#170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents:
535
diff
changeset
|
312 | } |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
313 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
314 | class BufferWrite : public ::testing::Test { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
315 | protected: |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
316 | CxBuffer buf{}, target{}; |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
317 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
318 | void SetUp() override { |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
319 | cxBufferInit(&target, nullptr, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
320 | cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
321 | buf.capacity = 8; // artificially reduce capacity to check OOB writes |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
322 | memset(buf.space, 0, 16); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
323 | memcpy(buf.space, "prep", 4); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
324 | buf.size = buf.pos = 4; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
325 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
326 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
327 | void TearDown() override { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
328 | cxBufferDestroy(&buf); |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
329 | cxBufferDestroy(&target); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
330 | } |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
331 | |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
332 | void enableFlushing() { |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
333 | buf.flush_target = ⌖ |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
334 | buf.flush_func = reinterpret_cast<cx_write_func>(cxBufferWrite); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
335 | buf.flush_blkmax = 1; |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
336 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
337 | }; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
338 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
339 | TEST_F(BufferWrite, SizeOneFit) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
340 | const char *data = "test"; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
341 | ASSERT_EQ(buf.capacity, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
342 | ASSERT_EQ(buf.pos, 4); |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
343 | ASSERT_EQ(buf.size, 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
344 | size_t written = cxBufferWrite(data, 1, 4, &buf); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
345 | EXPECT_EQ(written, 4); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
346 | EXPECT_EQ(buf.size, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
347 | EXPECT_EQ(buf.pos, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
348 | EXPECT_EQ(buf.capacity, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
349 | EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
350 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
351 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
352 | TEST_F(BufferWrite, SizeOneDiscard) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
353 | const char *data = "testing"; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
354 | ASSERT_EQ(buf.capacity, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
355 | ASSERT_EQ(buf.pos, 4); |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
356 | ASSERT_EQ(buf.size, 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
357 | size_t written = cxBufferWrite(data, 1, 7, &buf); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
358 | EXPECT_EQ(written, 4); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
359 | EXPECT_EQ(buf.size, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
360 | EXPECT_EQ(buf.pos, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
361 | EXPECT_EQ(buf.capacity, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
362 | EXPECT_EQ(memcmp(buf.space, "preptest\0", 9), 0); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
363 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
364 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
365 | TEST_F(BufferWrite, SizeOneExtend) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
366 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
367 | const char *data = "testing"; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
368 | ASSERT_EQ(buf.capacity, 8); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
369 | ASSERT_EQ(buf.pos, 4); |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
370 | ASSERT_EQ(buf.size, 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
371 | size_t written = cxBufferWrite(data, 1, 7, &buf); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
372 | EXPECT_EQ(written, 7); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
373 | EXPECT_EQ(buf.size, 11); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
374 | EXPECT_EQ(buf.pos, 11); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
375 | EXPECT_GE(buf.capacity, 11); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
376 | EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
377 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
378 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
379 | TEST_F(BufferWrite, MultibyteFit) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
380 | const char *data = "test"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
381 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
382 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
383 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
384 | size_t written = cxBufferWrite(data, 2, 2, &buf); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
385 | EXPECT_EQ(written, 2); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
386 | EXPECT_EQ(buf.size, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
387 | EXPECT_EQ(buf.pos, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
388 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
389 | EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
390 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
391 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
392 | TEST_F(BufferWrite, MultibyteDiscard) { |
542
45bcfd152f85
#170 no bug never existed
Mike Becker <universe@uap-core.de>
parents:
541
diff
changeset
|
393 | const char *data = "testing"; |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
394 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
395 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
396 | buf.pos = 3; |
542
45bcfd152f85
#170 no bug never existed
Mike Becker <universe@uap-core.de>
parents:
541
diff
changeset
|
397 | size_t written = cxBufferWrite(data, 2, 4, &buf); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
398 | // remember: whole elements are discarded if they do not fit |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
399 | EXPECT_EQ(written, 2); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
400 | EXPECT_EQ(buf.size, 7); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
401 | EXPECT_EQ(buf.pos, 7); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
402 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
403 | EXPECT_EQ(memcmp(buf.space, "pretest\0", 8), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
404 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
405 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
406 | TEST_F(BufferWrite, MultibyteExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
407 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
408 | const char *data = "tester"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
409 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
410 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
411 | buf.pos = 3; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
412 | size_t written = cxBufferWrite(data, 2, 3, &buf); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
413 | // remember: whole elements are discarded if they do not fit |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
414 | EXPECT_EQ(written, 3); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
415 | EXPECT_EQ(buf.size, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
416 | EXPECT_EQ(buf.pos, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
417 | EXPECT_GE(buf.capacity, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
418 | EXPECT_EQ(memcmp(buf.space, "pretester\0", 10), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
419 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
420 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
421 | TEST_F(BufferWrite, PutcWrapperFit) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
422 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
423 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
424 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
425 | int c = cxBufferPut(&buf, 0x20 | 'a'); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
426 | EXPECT_EQ(c, 'a'); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
427 | EXPECT_EQ(buf.size, 5); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
428 | EXPECT_EQ(buf.pos, 5); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
429 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
430 | EXPECT_EQ(memcmp(buf.space, "prepa\0", 6), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
431 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
432 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
433 | TEST_F(BufferWrite, PutcWrapperDiscard) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
434 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
435 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
436 | buf.pos = 8; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
437 | int c = cxBufferPut(&buf, 0x20 | 'a'); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
438 | EXPECT_EQ(c, EOF); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
439 | EXPECT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
440 | EXPECT_EQ(buf.pos, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
441 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
442 | EXPECT_EQ(memcmp(buf.space, "prep\0\0\0\0\0", 9), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
443 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
444 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
445 | TEST_F(BufferWrite, PutcWrapperExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
446 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
447 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
448 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
449 | buf.pos = 8; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
450 | int c = cxBufferPut(&buf, 0x20 | 'a'); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
451 | EXPECT_EQ(c, 'a'); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
452 | EXPECT_EQ(buf.size, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
453 | EXPECT_EQ(buf.pos, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
454 | EXPECT_GE(buf.capacity, 9); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
455 | EXPECT_EQ(memcmp(buf.space, "prep\0\0\0\0a\0", 10), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
456 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
457 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
458 | TEST_F(BufferWrite, PutStringWrapperFit) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
459 | const char *data = "test"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
460 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
461 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
462 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
463 | size_t written = cxBufferPutString(&buf, data); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
464 | EXPECT_EQ(written, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
465 | EXPECT_EQ(buf.size, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
466 | EXPECT_EQ(buf.pos, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
467 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
468 | EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
469 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
470 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
471 | TEST_F(BufferWrite, PutStringWrapperDiscard) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
472 | const char *data = "testing"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
473 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
474 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
475 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
476 | size_t written = cxBufferPutString(&buf, data); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
477 | EXPECT_EQ(written, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
478 | EXPECT_EQ(buf.size, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
479 | EXPECT_EQ(buf.pos, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
480 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
481 | EXPECT_EQ(memcmp(buf.space, "preptest\0", 9), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
482 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
483 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
484 | TEST_F(BufferWrite, PutStringWrapperExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
485 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
486 | const char *data = "testing"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
487 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
488 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
489 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
490 | size_t written = cxBufferPutString(&buf, data); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
491 | EXPECT_EQ(written, 7); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
492 | EXPECT_EQ(buf.size, 11); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
493 | EXPECT_EQ(buf.pos, 11); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
494 | EXPECT_GE(buf.capacity, 11); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
495 | EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
496 | } |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
497 | |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
498 | TEST_F(BufferWrite, MultOverflow) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
499 | const char *data = "testing"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
500 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
501 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
502 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
503 | size_t written = cxBufferWrite(data, 8, SIZE_MAX / 4, &buf); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
504 | EXPECT_EQ(written, 0); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
505 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
506 | EXPECT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
507 | EXPECT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
508 | EXPECT_EQ(memcmp(buf.space, "prep\0", 5), 0); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
509 | } |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
510 | |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
511 | TEST_F(BufferWrite, MaxCapaOverflow) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
512 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
513 | const char *data = "testing"; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
514 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
515 | ASSERT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
516 | ASSERT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
517 | size_t written = cxBufferWrite(data, 1, SIZE_MAX - 2, &buf); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
518 | EXPECT_EQ(written, 0); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
519 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
520 | EXPECT_EQ(buf.pos, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
521 | EXPECT_EQ(buf.size, 4); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
522 | EXPECT_EQ(memcmp(buf.space, "prep\0", 5), 0); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
523 | } |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
524 | |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
525 | TEST_F(BufferWrite, OnlyOverwrite) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
526 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
527 | ASSERT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
528 | memcpy(buf.space, "preptest", 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
529 | buf.pos = 3; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
530 | buf.size = 8; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
531 | size_t written = cxBufferWrite("XXX", 2, 2, &buf); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
532 | EXPECT_EQ(written, 2); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
533 | EXPECT_EQ(buf.capacity, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
534 | EXPECT_EQ(buf.size, 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
535 | EXPECT_EQ(buf.pos, 7); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
536 | EXPECT_EQ(memcmp(buf.space, "preXXX\0t", 8), 0); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
537 | } |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
538 | |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
539 | TEST_F(BufferWrite, FlushAtCapacity) { |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
540 | enableFlushing(); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
541 | ASSERT_EQ(buf.capacity, 8); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
542 | ASSERT_EQ(buf.pos, 4); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
543 | size_t written = cxBufferWrite("foo", 1, 3, &buf); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
544 | EXPECT_EQ(written, 3); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
545 | ASSERT_EQ(buf.pos, 7); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
546 | ASSERT_EQ(buf.size, 7); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
547 | ASSERT_EQ(target.pos, 0); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
548 | ASSERT_EQ(target.size, 0); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
549 | written = cxBufferWrite("hello", 1, 5, &buf); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
550 | EXPECT_EQ(written, 5); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
551 | EXPECT_EQ(buf.pos, 0); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
552 | EXPECT_EQ(buf.size, 0); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
553 | EXPECT_EQ(buf.capacity, 8); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
554 | EXPECT_EQ(target.pos, 12); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
555 | ASSERT_EQ(target.size, 12); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
556 | EXPECT_EQ(memcmp(target.space, "prepfoohello", 12), 0); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
557 | } |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
558 | |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
559 | TEST_F(BufferWrite, FlushAtThreshold) { |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
560 | enableFlushing(); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
561 | buf.flush_threshold = 12; |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
562 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
563 | ASSERT_EQ(buf.capacity, 8); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
564 | ASSERT_EQ(buf.pos, 4); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
565 | size_t written = cxBufferWrite("foobar", 1, 6, &buf); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
566 | EXPECT_EQ(written, 6); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
567 | ASSERT_EQ(buf.pos, 10); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
568 | ASSERT_EQ(buf.size, 10); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
569 | ASSERT_GE(buf.capacity, 10); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
570 | ASSERT_LE(buf.capacity, 12); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
571 | ASSERT_EQ(target.pos, 0); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
572 | ASSERT_EQ(target.size, 0); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
573 | written = cxBufferWrite("hello", 1, 5, &buf); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
574 | EXPECT_EQ(written, 5); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
575 | EXPECT_EQ(buf.pos, 0); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
576 | EXPECT_EQ(buf.size, 0); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
577 | EXPECT_LE(buf.capacity, 12); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
578 | EXPECT_EQ(target.pos, 15); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
579 | ASSERT_EQ(target.size, 15); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
580 | EXPECT_EQ(memcmp(target.space, "prepfoobarhello", 15), 0); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
581 | } |
547 | 582 | |
583 | class BufferSeek : public ::testing::Test { | |
584 | protected: | |
585 | void SetUp() override { | |
586 | cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); | |
587 | buf.size = 6; | |
588 | buf.pos = 3; | |
589 | } | |
590 | ||
591 | void TearDown() override { | |
592 | cxBufferDestroy(&buf); | |
593 | } | |
594 | ||
595 | CxBuffer buf{}; | |
596 | }; | |
597 | ||
598 | TEST_F(BufferSeek, SetZero) { | |
599 | int result = cxBufferSeek(&buf, 0, SEEK_SET); | |
600 | EXPECT_EQ(result, 0); | |
601 | EXPECT_EQ(buf.pos, 0); | |
602 | } | |
603 | ||
604 | TEST_F(BufferSeek, SetValid) { | |
605 | int result = cxBufferSeek(&buf, 5, SEEK_SET); | |
606 | EXPECT_EQ(result, 0); | |
607 | EXPECT_EQ(buf.pos, 5); | |
608 | } | |
609 | ||
610 | TEST_F(BufferSeek, SetInvalid) { | |
611 | ASSERT_EQ(buf.pos, 3); | |
612 | int result = cxBufferSeek(&buf, 6, SEEK_SET); | |
613 | EXPECT_NE(result, 0); | |
614 | EXPECT_EQ(buf.pos, 3); | |
615 | } | |
616 | ||
617 | TEST_F(BufferSeek, CurZero) { | |
618 | ASSERT_EQ(buf.pos, 3); | |
619 | int result = cxBufferSeek(&buf, 0, SEEK_CUR); | |
620 | EXPECT_EQ(result, 0); | |
621 | EXPECT_EQ(buf.pos, 3); | |
622 | } | |
623 | ||
624 | TEST_F(BufferSeek, CurValidPositive) { | |
625 | ASSERT_EQ(buf.pos, 3); | |
626 | int result = cxBufferSeek(&buf, 2, SEEK_CUR); | |
627 | EXPECT_EQ(result, 0); | |
628 | EXPECT_EQ(buf.pos, 5); | |
629 | } | |
630 | ||
631 | TEST_F(BufferSeek, CurValidNegative) { | |
632 | ASSERT_EQ(buf.pos, 3); | |
633 | int result = cxBufferSeek(&buf, -3, SEEK_CUR); | |
634 | EXPECT_EQ(result, 0); | |
635 | EXPECT_EQ(buf.pos, 0); | |
636 | } | |
637 | ||
638 | TEST_F(BufferSeek, CurInvalidPositive) { | |
639 | ASSERT_EQ(buf.pos, 3); | |
640 | int result = cxBufferSeek(&buf, 3, SEEK_CUR); | |
641 | EXPECT_NE(result, 0); | |
642 | EXPECT_EQ(buf.pos, 3); | |
643 | } | |
644 | ||
645 | TEST_F(BufferSeek, CurInvalidNegative) { | |
646 | ASSERT_EQ(buf.pos, 3); | |
647 | int result = cxBufferSeek(&buf, -4, SEEK_CUR); | |
648 | EXPECT_NE(result, 0); | |
649 | EXPECT_EQ(buf.pos, 3); | |
650 | } | |
651 | ||
652 | TEST_F(BufferSeek, EndZero) { | |
653 | ASSERT_EQ(buf.size, 6); | |
654 | int result = cxBufferSeek(&buf, 0, SEEK_END); | |
655 | // the (past-the-)end position is always invalid | |
656 | EXPECT_NE(result, 0); | |
657 | EXPECT_EQ(buf.pos, 3); | |
658 | } | |
659 | ||
660 | TEST_F(BufferSeek, EndValid) { | |
661 | ASSERT_EQ(buf.size, 6); | |
662 | int result = cxBufferSeek(&buf, -6, SEEK_END); | |
663 | EXPECT_EQ(result, 0); | |
664 | EXPECT_EQ(buf.pos, 0); | |
665 | } | |
666 | ||
667 | TEST_F(BufferSeek, EndInvalid) { | |
668 | ASSERT_EQ(buf.size, 6); | |
669 | int result = cxBufferSeek(&buf, 1, SEEK_END); | |
670 | EXPECT_NE(result, 0); | |
671 | EXPECT_EQ(buf.pos, 3); | |
672 | } | |
673 | ||
674 | TEST_F(BufferSeek, WhenceInvalid) { | |
675 | ASSERT_EQ(buf.size, 6); | |
676 | ASSERT_EQ(buf.pos, 3); | |
677 | int result = cxBufferSeek(&buf, 2, 9000); | |
678 | EXPECT_NE(result, 0); | |
679 | EXPECT_EQ(buf.size, 6); | |
680 | EXPECT_EQ(buf.pos, 3); | |
681 | } |