test/test_buffer.cpp

Sat, 30 Apr 2022 09:03:17 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 30 Apr 2022 09:03:17 +0200
changeset 538
2cfbcbe86a7c
parent 536
cb9b9739055e
child 539
9cd98da9ee17
permissions
-rw-r--r--

#170 first basic write tests

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
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
34 TEST(BufferInit, WrapSpace) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
35 CxTestingAllocator alloc;
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 CxBuffer buf;
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
37 void *space = cxMalloc(&alloc, 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
38 cxBufferInit(&buf, space, 16, &alloc, CX_BUFFER_DEFAULT);
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 EXPECT_EQ(buf.space, space);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 EXPECT_EQ(buf.flags & CX_BUFFER_FREE_CONTENTS, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 EXPECT_EQ(buf.pos, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 EXPECT_EQ(buf.size, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 EXPECT_EQ(buf.capacity, 16);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
45 EXPECT_EQ(buf.allocator, &alloc);
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 cxBufferDestroy(&buf);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
47 EXPECT_FALSE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
48 cxFree(&alloc, space);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
49 EXPECT_TRUE(alloc.verify());
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 }
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
52 TEST(BufferInit, WrapSpaceAutoFree) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
53 CxTestingAllocator alloc;
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 CxBuffer buf;
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
55 void *space = cxMalloc(&alloc, 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
56 cxBufferInit(&buf, space, 16, &alloc, CX_BUFFER_FREE_CONTENTS);
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 EXPECT_EQ(buf.space, space);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 EXPECT_EQ(buf.flags & CX_BUFFER_AUTO_EXTEND, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 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
60 EXPECT_EQ(buf.pos, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 EXPECT_EQ(buf.size, 0);
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 EXPECT_EQ(buf.capacity, 16);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
63 EXPECT_EQ(buf.allocator, &alloc);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
64 EXPECT_FALSE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
65 cxBufferDestroy(&buf);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
66 EXPECT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
67 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
68
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
69 TEST(BufferInit, FreshSpace) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
70 CxTestingAllocator alloc;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
71 CxBuffer buf;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
72 cxBufferInit(&buf, nullptr, 8, &alloc, CX_BUFFER_DEFAULT);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
73 EXPECT_NE(buf.space, nullptr);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
74 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
75 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
76 EXPECT_EQ(buf.pos, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
77 EXPECT_EQ(buf.size, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
78 EXPECT_EQ(buf.capacity, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
79 EXPECT_EQ(buf.allocator, &alloc);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
80 EXPECT_FALSE(alloc.verify()); // space is still allocated
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 cxBufferDestroy(&buf);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
82 EXPECT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
83 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
84
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
85 class BufferShiftFixture : public ::testing::Test {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
86 protected:
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
87 void SetUp() override {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
88 ASSERT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
89 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
90 memcpy(buf.space, "test____________", 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
91 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
92 buf.pos = 4;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
93 buf.size = 4;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
94 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
95
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
96 void TearDown() override {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
97 cxBufferDestroy(&buf);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
98 EXPECT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
99 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
100
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
101 CxTestingAllocator alloc;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
102 CxBuffer buf{};
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
103 };
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
104
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
105 class BufferShiftLeft : public BufferShiftFixture {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
106 };
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
107
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
108 TEST_F(BufferShiftLeft, Zero) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
109 ASSERT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
110 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
111 int ret = cxBufferShiftLeft(&buf, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
112 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
113 EXPECT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
114 EXPECT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
115 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
116 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
117
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
118 TEST_F(BufferShiftLeft, Standard) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
119 ASSERT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
120 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
121 int ret = cxBufferShiftLeft(&buf, 2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
122 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
123 EXPECT_EQ(buf.pos, 2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
124 EXPECT_EQ(buf.size, 2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
125 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
126 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
127
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
128 TEST_F(BufferShiftLeft, Overshift) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
129 ASSERT_LT(buf.pos, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
130 ASSERT_LT(buf.size, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
131 int ret = cxBufferShiftLeft(&buf, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
132 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
133 EXPECT_EQ(buf.pos, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
134 EXPECT_EQ(buf.size, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
135 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
136 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
137
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
138 TEST_F(BufferShiftLeft, OvershiftPosOnly) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
139 buf.pos = 2;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
140 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
141 int ret = cxBufferShiftLeft(&buf, 3);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
142 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
143 EXPECT_EQ(buf.pos, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
144 EXPECT_EQ(buf.size, 1);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
145 EXPECT_TRUE(memcmp(buf.space, "test________", 8) == 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
146 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
147
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
148 TEST_F(BufferShiftLeft, OffsetInterface) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
149 buf.pos = 3;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
150 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
151 int ret = cxBufferShift(&buf, -2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
152 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
153 EXPECT_EQ(buf.pos, 1);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
154 EXPECT_EQ(buf.size, 2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
155 EXPECT_TRUE(memcmp(buf.space, "stst________", 8) == 0);
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 }
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
157
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
158 class BufferShiftRight : public BufferShiftFixture {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
159 };
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
160
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
161 TEST_F(BufferShiftRight, Zero) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
162 ASSERT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
163 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
164 int ret = cxBufferShiftRight(&buf, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
165 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
166 EXPECT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
167 EXPECT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
168 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
169 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
170
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
171 TEST_F(BufferShiftRight, Standard) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
172 ASSERT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
173 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
174 int ret = cxBufferShiftRight(&buf, 3);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
175 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
176 EXPECT_EQ(buf.pos, 7);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
177 EXPECT_EQ(buf.size, 7);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
178 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
179 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
180
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
181 TEST_F(BufferShiftRight, OvershiftDiscard) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
182 ASSERT_EQ(buf.pos, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
183 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
184 ASSERT_EQ(buf.capacity, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
185 int ret = cxBufferShiftRight(&buf, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
186 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
187 EXPECT_EQ(buf.pos, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
188 EXPECT_EQ(buf.size, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
189 EXPECT_EQ(buf.capacity, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
190 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
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(BufferShiftRight, OvershiftExtend) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
194 ASSERT_EQ(buf.pos, 4);
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 ASSERT_EQ(buf.capacity, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
197 buf.flags |= CX_BUFFER_AUTO_EXTEND;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
198 int ret = cxBufferShiftRight(&buf, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
199 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
200 EXPECT_EQ(buf.pos, 10);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
201 EXPECT_EQ(buf.size, 10);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
202 EXPECT_GE(buf.capacity, 10);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
203 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
204 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
205
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
206 TEST_F(BufferShiftRight, OffsetInterface) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
207 buf.pos = 3;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
208 ASSERT_EQ(buf.size, 4);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
209 int ret = cxBufferShift(&buf, 2);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
210 EXPECT_EQ(ret, 0);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
211 EXPECT_EQ(buf.pos, 5);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
212 EXPECT_EQ(buf.size, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
213 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
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(BufferMinimumCapacity, Sufficient) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
217 CxTestingAllocator alloc;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
218 auto space = cxMalloc(&alloc, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
219 CxBuffer buf;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
220 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
221 memcpy(space, "Testing", 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
222 buf.size = 8;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
223 cxBufferMinimumCapacity(&buf, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
224 EXPECT_EQ(buf.capacity, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
225 EXPECT_EQ(buf.size, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
226 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
227 cxBufferDestroy(&buf);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
228 EXPECT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
229 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
230
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
231 TEST(BufferMinimumCapacity, Extend) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
232 CxTestingAllocator alloc;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
233 auto space = cxMalloc(&alloc, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
234 CxBuffer buf;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
235 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
236 memcpy(space, "Testing", 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
237 buf.size = 8;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
238 cxBufferMinimumCapacity(&buf, 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
239 EXPECT_EQ(buf.capacity, 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
240 EXPECT_EQ(buf.size, 8);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
241 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
242 cxBufferDestroy(&buf);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
243 EXPECT_TRUE(alloc.verify());
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
244 }
536
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
245
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
246 TEST(BufferClear, Test) {
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
247 char space[16];
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
248 strcpy(space, "clear test");
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
249 CxBuffer buf;
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
250 cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
251 ASSERT_EQ(buf.size, 0);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
252 // only clear the used part of the buffer
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
253 cxBufferClear(&buf);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
254 EXPECT_EQ(memcmp(space, "clear test", 10), 0);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
255 buf.size = 5;
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
256 buf.pos = 3;
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
257 cxBufferClear(&buf);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
258 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
259 EXPECT_EQ(buf.size, 0);
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
260 EXPECT_EQ(buf.pos, 0);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
261 cxBufferDestroy(&buf);
536
cb9b9739055e #170 add cxBufferClear test
Mike Becker <universe@uap-core.de>
parents: 535
diff changeset
262 }
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
263
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
264 class BufferWrite : public ::testing::Test {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
265 protected:
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
266 CxBuffer buf{};
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
267
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
268 void SetUp() override {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
269 cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
270 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
271 memset(buf.space, 0, 16);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
272 memcpy(buf.space, "prep", 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
273 buf.size = buf.pos = 4;
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
274 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
275
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
276 void TearDown() override {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
277 cxBufferDestroy(&buf);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
278 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
279 };
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
280
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
281 TEST_F(BufferWrite, SizeOneFit) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
282 const char *data = "test";
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
283 ASSERT_EQ(buf.capacity, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
284 ASSERT_EQ(buf.pos, 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
285 size_t written = cxBufferWrite(data, 1, 4, &buf);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
286 EXPECT_EQ(written, 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
287 EXPECT_EQ(buf.size, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
288 EXPECT_EQ(buf.pos, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
289 EXPECT_EQ(buf.capacity, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
290 EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
291 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
292
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
293 TEST_F(BufferWrite, SizeOneOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
294
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
295 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
296
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
297 TEST_F(BufferWrite, SizeOnePartialOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
298
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
299 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
300
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
301 TEST_F(BufferWrite, SizeOneDiscard) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
302 const char *data = "testing";
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
303 ASSERT_EQ(buf.capacity, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
304 ASSERT_EQ(buf.pos, 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
305 size_t written = cxBufferWrite(data, 1, 7, &buf);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
306 EXPECT_EQ(written, 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
307 EXPECT_EQ(buf.size, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
308 EXPECT_EQ(buf.pos, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
309 EXPECT_EQ(buf.capacity, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
310 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
311 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
312
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
313 TEST_F(BufferWrite, SizeOneExtend) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
314 buf.flags |= CX_BUFFER_AUTO_EXTEND;
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
315 const char *data = "testing";
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
316 ASSERT_EQ(buf.capacity, 8);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
317 ASSERT_EQ(buf.pos, 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
318 size_t written = cxBufferWrite(data, 1, 7, &buf);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
319 EXPECT_EQ(written, 7);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
320 EXPECT_EQ(buf.size, 11);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
321 EXPECT_EQ(buf.pos, 11);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
322 EXPECT_GE(buf.capacity, 11);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
323 EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
324 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
325
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
326 TEST_F(BufferWrite, MultibyteOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
327
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
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
330 TEST_F(BufferWrite, MultibytePartialOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
331
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
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
334 TEST_F(BufferWrite, MultibyteFit) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
335
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
336 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
337
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
338 TEST_F(BufferWrite, MultibyteDiscard) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
339 // remember: whole elements are discarded if they do not fit
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 TEST_F(BufferWrite, MultibyteExtend) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
343
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
344 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
345
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
346 TEST_F(BufferWrite, PutcWrapperFit) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
347
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
348 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
349
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
350 TEST_F(BufferWrite, PutcWrapperOverwrite) {
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, PutcWrapperPartialOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
355
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
356 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
357
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
358 TEST_F(BufferWrite, PutcWrapperDiscard) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
359
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
360 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
361
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
362 TEST_F(BufferWrite, PutcWrapperExtend) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
363
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
364 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
365
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
366 TEST_F(BufferWrite, PutStringWrapperFit) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
367
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
368 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
369
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
370 TEST_F(BufferWrite, PutStringWrapperOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
371
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
372 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
373
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
374 TEST_F(BufferWrite, PutStringWrapperPartialOverwrite) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
375
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
376 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
377
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
378 TEST_F(BufferWrite, PutStringWrapperDiscard) {
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 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
381
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
382 TEST_F(BufferWrite, PutStringWrapperExtend) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
383
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
384 }

mercurial