test/test_buffer.cpp

Fri, 27 May 2022 14:02:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 May 2022 14:02:14 +0200
changeset 559
8603709932b9
parent 548
459bca1cdf8d
child 565
d756746ea94f
permissions
-rw-r--r--

corrects documentation of iterator behavior

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

mercurial