tests/test_buffer.cpp

Mon, 01 Jan 2024 16:43:18 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 01 Jan 2024 16:43:18 +0100
changeset 790
42877968260c
parent 789
9b2f5661bebd
child 792
3ca984931e1d
permissions
-rw-r--r--

some text replacements to prepare migration of list 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
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 {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
37 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
548
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
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
49 class BufferShiftFixture : public ::testing::Test {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
50 protected:
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
51 void SetUp() override {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
52 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
53 cxBufferInit(&buf, NULL, 16, &alloc, CX_BUFFER_DEFAULT);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
54 memcpy(buf.space, "test____________", 16);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
55 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
56 buf.pos = 4;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
57 buf.size = 4;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
58 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
59
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
60 void TearDown() override {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
61 cxBufferDestroy(&buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
62 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
63 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
64
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
65 CxTestingAllocator alloc;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
66 CxBuffer buf{};
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 class BufferShiftLeft : public BufferShiftFixture {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
70 };
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
71
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
72 TEST_F(BufferShiftLeft, Zero) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
73 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
74 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
75 int ret = cxBufferShiftLeft(&buf, 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
76 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
77 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
78 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
79 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
80 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
81
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
82 TEST_F(BufferShiftLeft, ZeroOffsetInterface) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
83 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
84 CX_TEST_ASSERT(buf.size == 4);
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
85 int ret = cxBufferShift(&buf, -0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
86 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
87 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
88 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
89 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
90 }
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
91
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
92 TEST_F(BufferShiftLeft, Standard) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
93 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
94 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
95 int ret = cxBufferShiftLeft(&buf, 2);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
96 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
97 CX_TEST_ASSERT(buf.pos == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
98 CX_TEST_ASSERT(buf.size == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
99 CX_TEST_ASSERT(memcmp(buf.space, "stst________", 8) == 0);
535
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
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
102 TEST_F(BufferShiftLeft, Overshift) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
103 ASSERT_LT(buf.pos, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
104 ASSERT_LT(buf.size, 6);
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
105 int ret = cxBufferShiftLeft(&buf, 6);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
106 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
107 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
108 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
109 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
110 }
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 TEST_F(BufferShiftLeft, OvershiftPosOnly) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
113 buf.pos = 2;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
114 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
115 int ret = cxBufferShiftLeft(&buf, 3);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
116 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
117 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
118 CX_TEST_ASSERT(buf.size == 1);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
119 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
120 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
121
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
122 TEST_F(BufferShiftLeft, OffsetInterface) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
123 buf.pos = 3;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
124 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
125 int ret = cxBufferShift(&buf, -2);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
126 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
127 CX_TEST_ASSERT(buf.pos == 1);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
128 CX_TEST_ASSERT(buf.size == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
129 CX_TEST_ASSERT(memcmp(buf.space, "stst________", 8) == 0);
530
e866516cac17 #170 first buffer tests
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 }
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
131
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
132 TEST_F(BufferShiftRight, Zero) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
133 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
134 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
135 int ret = cxBufferShiftRight(&buf, 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
136 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
137 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
138 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
139 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
535
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
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
142 TEST_F(BufferShiftRight, ZeroOffsetInterface) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
143 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
144 CX_TEST_ASSERT(buf.size == 4);
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
145 int ret = cxBufferShift(&buf, +0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
146 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
147 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
148 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
149 CX_TEST_ASSERT(memcmp(buf.space, "test________", 8) == 0);
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
150 }
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
151
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
152 TEST_F(BufferShiftRight, Standard) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
153 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
154 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
155 int ret = cxBufferShiftRight(&buf, 3);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
156 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
157 CX_TEST_ASSERT(buf.pos == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
158 CX_TEST_ASSERT(buf.size == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
159 CX_TEST_ASSERT(memcmp(buf.space, "testest_____", 8) == 0);
535
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
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
162 TEST_F(BufferShiftRight, OvershiftDiscard) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
163 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
164 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
165 CX_TEST_ASSERT(buf.capacity == 8);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
166 int ret = cxBufferShiftRight(&buf, 6);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
167 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
168 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
169 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
170 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
171 CX_TEST_ASSERT(memcmp(buf.space, "test__te____", 8) == 0);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
172 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
173
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
174 TEST_F(BufferShiftRight, OvershiftExtend) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
175 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
176 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
177 CX_TEST_ASSERT(buf.capacity == 8);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
178 buf.flags |= CX_BUFFER_AUTO_EXTEND;
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
179 int ret = cxBufferShiftRight(&buf, 6);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
180 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
181 CX_TEST_ASSERT(buf.pos == 10);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
182 CX_TEST_ASSERT(buf.size == 10);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
183 EXPECT_GE(buf.capacity, 10);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
184 CX_TEST_ASSERT(memcmp(buf.space, "test__test__", 8) == 0);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
185 }
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
186
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
187 TEST_F(BufferShiftRight, OffsetInterface) {
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
188 buf.pos = 3;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
189 CX_TEST_ASSERT(buf.size == 4);
535
2ff6e9184468 #170 add several more buffer tests
Mike Becker <universe@uap-core.de>
parents: 530
diff changeset
190 int ret = cxBufferShift(&buf, 2);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
191 CX_TEST_ASSERT(ret == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
192 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
193 CX_TEST_ASSERT(buf.size == 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
194 CX_TEST_ASSERT(memcmp(buf.space, "tetest______", 8) == 0);
761
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 683
diff changeset
195 }
61d5197d612b add cxBufferReset() - resolves #338
Mike Becker <universe@uap-core.de>
parents: 683
diff changeset
196
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
197 class BufferWrite : public ::testing::Test {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
198 protected:
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
199 CxBuffer buf{}, target{};
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
200
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
201 void SetUp() override {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
202 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
203 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
204 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
205 memset(buf.space, 0, 16);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
206 memcpy(buf.space, "prep", 4);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
207 buf.size = buf.pos = 4;
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
208 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
209
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
210 void TearDown() override {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
211 cxBufferDestroy(&buf);
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
212 cxBufferDestroy(&target);
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
213 }
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
214
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
215 void enableFlushing() {
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
216 buf.flush_target = &target;
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
217 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
218 buf.flush_blkmax = 1;
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
219 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
220 };
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
221
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
222 static size_t mock_write_limited_rate(
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
223 void const *ptr,
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
224 size_t size,
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
225 __attribute__((unused)) size_t nitems,
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
226 CxBuffer *buffer
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
227 ) {
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
228 // simulate limited target drain capacity
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
229 static bool full = false;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
230 if (full) {
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
231 full = false;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
232 return 0;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
233 } else {
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
234 full = true;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
235 return cxBufferWrite(ptr, size, nitems > 2 ? 2 : nitems, buffer);
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
236 }
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
237 }
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
238
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
239 TEST_F(BufferWrite, SizeOneFit) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
240 const char *data = "test";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
241 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
242 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
243 CX_TEST_ASSERT(buf.size == 4);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
244 size_t written = cxBufferWrite(data, 1, 4, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
245 CX_TEST_ASSERT(written == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
246 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
247 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
248 CX_TEST_ASSERT(buf.capacity == 8);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
249 EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
250 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
251
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
252 TEST_F(BufferWrite, SizeOneDiscard) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
253 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
254 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
255 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
256 CX_TEST_ASSERT(buf.size == 4);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
257 size_t written = cxBufferWrite(data, 1, 7, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
258 CX_TEST_ASSERT(written == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
259 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
260 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
261 CX_TEST_ASSERT(buf.capacity == 8);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
262 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
263 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
264
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
265 TEST_F(BufferWrite, SizeOneExtend) {
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
266 buf.flags |= CX_BUFFER_AUTO_EXTEND;
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
267 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
268 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
269 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
270 CX_TEST_ASSERT(buf.size == 4);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
271 size_t written = cxBufferWrite(data, 1, 7, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
272 CX_TEST_ASSERT(written == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
273 CX_TEST_ASSERT(buf.size == 11);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
274 CX_TEST_ASSERT(buf.pos == 11);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
275 EXPECT_GE(buf.capacity, 11);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
276 EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0);
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
277 }
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 TEST_F(BufferWrite, MultibyteFit) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
280 const char *data = "test";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
281 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
282 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
283 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
284 size_t written = cxBufferWrite(data, 2, 2, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
285 CX_TEST_ASSERT(written == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
286 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
287 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
288 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
289 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
290 }
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 TEST_F(BufferWrite, MultibyteDiscard) {
542
45bcfd152f85 #170 no bug never existed
Mike Becker <universe@uap-core.de>
parents: 541
diff changeset
293 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
294 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
295 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
296 buf.pos = 3;
542
45bcfd152f85 #170 no bug never existed
Mike Becker <universe@uap-core.de>
parents: 541
diff changeset
297 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
298 // remember: whole elements are discarded if they do not fit
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
299 CX_TEST_ASSERT(written == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
300 CX_TEST_ASSERT(buf.size == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
301 CX_TEST_ASSERT(buf.pos == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
302 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
303 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
304 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
305
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
306 TEST_F(BufferWrite, MultibyteExtend) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
307 buf.flags |= CX_BUFFER_AUTO_EXTEND;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
308 const char *data = "tester";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
309 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
310 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
311 buf.pos = 3;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
312 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
313 // remember: whole elements are discarded if they do not fit
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
314 CX_TEST_ASSERT(written == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
315 CX_TEST_ASSERT(buf.size == 9);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
316 CX_TEST_ASSERT(buf.pos == 9);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
317 EXPECT_GE(buf.capacity, 9);
566
d3100c987a39 fix two tests reading one byte too much
Mike Becker <universe@uap-core.de>
parents: 565
diff changeset
318 EXPECT_EQ(memcmp(buf.space, "pretester", 9), 0);
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
319 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
320
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
321 TEST_F(BufferWrite, PutcWrapperFit) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
322 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
323 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
324 CX_TEST_ASSERT(buf.size == 4);
565
d756746ea94f fix putc tests to make more sense of the bitwise or
Mike Becker <universe@uap-core.de>
parents: 548
diff changeset
325 int c = cxBufferPut(&buf, 0x200 | 'a');
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
326 CX_TEST_ASSERT(c == 'a');
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
327 CX_TEST_ASSERT(buf.size == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
328 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
329 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
330 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
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 TEST_F(BufferWrite, PutcWrapperDiscard) {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
334 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
335 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
336 buf.pos = 8;
565
d756746ea94f fix putc tests to make more sense of the bitwise or
Mike Becker <universe@uap-core.de>
parents: 548
diff changeset
337 int c = cxBufferPut(&buf, 0x200 | 'a');
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
338 CX_TEST_ASSERT(c == EOF);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
339 CX_TEST_ASSERT(buf.size == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
340 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
341 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
342 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
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 TEST_F(BufferWrite, PutcWrapperExtend) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
346 buf.flags |= CX_BUFFER_AUTO_EXTEND;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
347 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
348 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
349 buf.pos = 8;
565
d756746ea94f fix putc tests to make more sense of the bitwise or
Mike Becker <universe@uap-core.de>
parents: 548
diff changeset
350 int c = cxBufferPut(&buf, 0x200 | 'a');
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
351 CX_TEST_ASSERT(c == 'a');
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
352 CX_TEST_ASSERT(buf.size == 9);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
353 CX_TEST_ASSERT(buf.pos == 9);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
354 EXPECT_GE(buf.capacity, 9);
566
d3100c987a39 fix two tests reading one byte too much
Mike Becker <universe@uap-core.de>
parents: 565
diff changeset
355 EXPECT_EQ(memcmp(buf.space, "prep\0\0\0\0a", 9), 0);
538
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, PutStringWrapperFit) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
359 const char *data = "test";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
360 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
361 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
362 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
363 size_t written = cxBufferPutString(&buf, data);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
364 CX_TEST_ASSERT(written == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
365 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
366 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
367 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
368 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
369 }
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
370
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
371 TEST_F(BufferWrite, PutStringWrapperDiscard) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
372 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
373 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
374 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
375 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
376 size_t written = cxBufferPutString(&buf, data);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
377 CX_TEST_ASSERT(written == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
378 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
379 CX_TEST_ASSERT(buf.pos == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
380 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
381 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
382 }
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 TEST_F(BufferWrite, PutStringWrapperExtend) {
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
385 buf.flags |= CX_BUFFER_AUTO_EXTEND;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
386 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
387 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
388 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
389 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
390 size_t written = cxBufferPutString(&buf, data);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
391 CX_TEST_ASSERT(written == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
392 CX_TEST_ASSERT(buf.size == 11);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
393 CX_TEST_ASSERT(buf.pos == 11);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
394 EXPECT_GE(buf.capacity, 11);
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
395 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
396 }
538
2cfbcbe86a7c #170 first basic write tests
Mike Becker <universe@uap-core.de>
parents: 536
diff changeset
397
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
398 TEST_F(BufferWrite, MultOverflow) {
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
399 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
400 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
401 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
402 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
403 size_t written = cxBufferWrite(data, 8, SIZE_MAX / 4, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
404 CX_TEST_ASSERT(written == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
405 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
406 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
407 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
408 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
409 }
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
410
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
411 TEST_F(BufferWrite, MaxCapaOverflow) {
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
412 buf.flags |= CX_BUFFER_AUTO_EXTEND;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
413 const char *data = "testing";
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
414 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
415 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
416 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
417 size_t written = cxBufferWrite(data, 1, SIZE_MAX - 2, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
418 CX_TEST_ASSERT(written == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
419 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
420 CX_TEST_ASSERT(buf.pos == 4);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
421 CX_TEST_ASSERT(buf.size == 4);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
422 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
423 }
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
424
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
425 TEST_F(BufferWrite, OnlyOverwrite) {
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
426 buf.flags |= CX_BUFFER_AUTO_EXTEND;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
427 CX_TEST_ASSERT(buf.capacity == 8);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
428 memcpy(buf.space, "preptest", 8);
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
429 buf.pos = 3;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
430 buf.size = 8;
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
431 size_t written = cxBufferWrite("XXX", 2, 2, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
432 CX_TEST_ASSERT(written == 2);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
433 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
434 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
435 CX_TEST_ASSERT(buf.pos == 7);
541
67e078518935 #170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents: 539
diff changeset
436 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
437 }
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
438
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
439 TEST_F(BufferWrite, FlushAtCapacity) {
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
440 enableFlushing();
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
441 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
442 CX_TEST_ASSERT(buf.pos == 4);
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
443 size_t written = cxBufferWrite("foo", 1, 3, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
444 CX_TEST_ASSERT(written == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
445 CX_TEST_ASSERT(buf.pos == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
446 CX_TEST_ASSERT(buf.size == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
447 CX_TEST_ASSERT(target.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
448 CX_TEST_ASSERT(target.size == 0);
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
449 written = cxBufferWrite("hello", 1, 5, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
450 CX_TEST_ASSERT(written == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
451 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
452 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
453 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
454 CX_TEST_ASSERT(target.pos == 12);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
455 CX_TEST_ASSERT(target.size == 12);
545
3700ac4bd9a3 #184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents: 542
diff changeset
456 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
457 }
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
458
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
459 TEST_F(BufferWrite, FlushAtThreshold) {
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
460 enableFlushing();
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
461 buf.flush_threshold = 12;
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
462 buf.flags |= CX_BUFFER_AUTO_EXTEND;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
463 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
464 CX_TEST_ASSERT(buf.pos == 4);
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
465 size_t written = cxBufferWrite("foobar", 1, 6, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
466 CX_TEST_ASSERT(written == 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
467 CX_TEST_ASSERT(buf.pos == 10);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
468 CX_TEST_ASSERT(buf.size == 10);
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
469 ASSERT_GE(buf.capacity, 10);
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
470 ASSERT_LE(buf.capacity, 12);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
471 CX_TEST_ASSERT(target.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
472 CX_TEST_ASSERT(target.size == 0);
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
473 written = cxBufferWrite("hello", 1, 5, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
474 CX_TEST_ASSERT(written == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
475 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
476 CX_TEST_ASSERT(buf.size == 0);
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
477 EXPECT_LE(buf.capacity, 12);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
478 CX_TEST_ASSERT(target.pos == 15);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
479 CX_TEST_ASSERT(target.size == 15);
546
900795d59d03 #184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents: 545
diff changeset
480 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
481 }
547
9e933920dcf9 #170 test buffer seek
Mike Becker <universe@uap-core.de>
parents: 546
diff changeset
482
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
483 TEST_F(BufferWrite, FlushRateLimited) {
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
484 enableFlushing();
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
485 // limit the rate of the flush function and the capacity of the target
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
486 target.capacity = 16;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
487 target.flags &= ~CX_BUFFER_AUTO_EXTEND;
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
488 buf.flush_func = (cx_write_func) mock_write_limited_rate;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
489 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
490 CX_TEST_ASSERT(buf.pos == 4);
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
491 size_t written = cxBufferWrite("foo", 1, 3, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
492 CX_TEST_ASSERT(written == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
493 CX_TEST_ASSERT(buf.pos == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
494 CX_TEST_ASSERT(buf.size == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
495 CX_TEST_ASSERT(target.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
496 CX_TEST_ASSERT(target.size == 0);
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
497 written = cxBufferWrite("hello, world!", 1, 13, &buf);
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
498 // " world!" fits into this buffer, the remaining stuff is flushed out
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
499 CX_TEST_ASSERT(written == 13);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
500 CX_TEST_ASSERT(buf.pos == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
501 CX_TEST_ASSERT(buf.size == 7);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
502 CX_TEST_ASSERT(buf.capacity == 8);
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
503 EXPECT_EQ(memcmp(buf.space, " world!", 7), 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
504 CX_TEST_ASSERT(target.pos == 13);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
505 CX_TEST_ASSERT(target.size == 13);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
506 CX_TEST_ASSERT(target.capacity == 16);
567
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
507 EXPECT_EQ(memcmp(target.space, "prepfoohello,", 13), 0);
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
508 }
f90a7cfe2480 #184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents: 566
diff changeset
509
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
510
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
511 TEST_F(BufferEof, Reached) {
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
512 buf.pos = buf.size;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
513 CX_TEST_ASSERT(cxBufferEof(&buf));
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
514 buf.pos = buf.size - 1;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
515 CX_TEST_ASSERT(!cxBufferEof(&buf));
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
516 cxBufferPut(&buf, 'a');
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
517 CX_TEST_ASSERT(cxBufferEof(&buf));
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
518 }
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
519
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
520 TEST_F(BufferEof, NotReached) {
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
521 buf.pos = buf.size - 1;
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
522 CX_TEST_ASSERT(!cxBufferEof(&buf));
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
523 buf.pos = 0;
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
524 cxBufferWrite("test", 1, 5, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
525 CX_TEST_ASSERT(!cxBufferEof(&buf));
548
459bca1cdf8d #170 test buffer eof
Mike Becker <universe@uap-core.de>
parents: 547
diff changeset
526 }
568
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
527
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
528 class BufferRead : public ::testing::Test {
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
529 protected:
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
530 CxBuffer buf{};
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
531
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
532 void SetUp() override {
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
533 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
568
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
534 buf.capacity = 8; // artificially reduce capacity to check OOB writes
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
535 memset(buf.space, 0, 16);
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
536 memcpy(buf.space, "some data", 9);
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
537 buf.size = 9;
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
538 }
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
539
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
540 void TearDown() override {
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
541 cxBufferDestroy(&buf);
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
542 }
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
543 };
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
544
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
545 TEST_F(BufferRead, GetByte) {
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
546 buf.pos = 2;
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
547 EXPECT_EQ(cxBufferGet(&buf), 'm');
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
548 EXPECT_EQ(cxBufferGet(&buf), 'e');
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
549 EXPECT_EQ(cxBufferGet(&buf), ' ');
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
550 EXPECT_EQ(cxBufferGet(&buf), 'd');
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
551 CX_TEST_ASSERT(buf.pos == 6);
568
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
552 }
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
553
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
554 TEST_F(BufferRead, GetEof) {
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
555 buf.pos = buf.size;
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
556 EXPECT_EQ(cxBufferGet(&buf), EOF);
8eda32d09e3d #170 test cxBufferGet
Mike Becker <universe@uap-core.de>
parents: 567
diff changeset
557 }
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
558
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
559 TEST_F(BufferRead, ReadWithinBounds) {
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
560 buf.pos = 2;
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
561 char target[4];
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
562 auto read = cxBufferRead(&target, 1, 4, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
563 CX_TEST_ASSERT(read == 4);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
564 EXPECT_EQ(memcmp(&target, "me d", 4), 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
565 CX_TEST_ASSERT(buf.pos == 6);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
566 }
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
567
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
568 TEST_F(BufferRead, ReadOutOfBounds) {
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
569 buf.pos = 6;
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
570 char target[4];
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
571 auto read = cxBufferRead(&target, 1, 4, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
572 CX_TEST_ASSERT(read == 3);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
573 EXPECT_EQ(memcmp(&target, "ata", 3), 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
574 CX_TEST_ASSERT(buf.pos == 9);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
575 }
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
576
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
577 TEST_F(BufferRead, ReadOutOfBoundsMultibyte) {
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
578 buf.pos = 6;
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
579 char target[4];
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
580 target[2] = '\0';
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
581 auto read = cxBufferRead(&target, 2, 2, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
582 CX_TEST_ASSERT(read == 1);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
583 EXPECT_EQ(memcmp(&target, "at\0", 3), 0);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
584 CX_TEST_ASSERT(buf.pos == 8);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
585 }
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
586
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
587 TEST_F(BufferRead, ReadEof) {
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
588 buf.pos = 9;
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
589 char target[4];
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
590 auto read = cxBufferRead(&target, 1, 1, &buf);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
591 CX_TEST_ASSERT(read == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 761
diff changeset
592 CX_TEST_ASSERT(buf.pos == 9);
569
cb63f3d1236a #170 test cxBufferRead
Mike Becker <universe@uap-core.de>
parents: 568
diff changeset
593 }

mercurial