Wed, 03 Jan 2024 22:17:40 +0100
migrate more buffer tests - relates to #342
only read and write tests are remaining now
530 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include "cx/buffer.h" | |
30 | ||
31 | #include <gtest/gtest.h> | |
32 | #include "util_allocator.h" | |
33 | ||
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
34 | class BufferWrite : public ::testing::Test { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
35 | protected: |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
36 | CxBuffer buf{}, target{}; |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
37 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
38 | void SetUp() override { |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
39 | 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
|
40 | 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
|
41 | 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
|
42 | memset(buf.space, 0, 16); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
43 | memcpy(buf.space, "prep", 4); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
44 | buf.size = buf.pos = 4; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
45 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
46 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
47 | void TearDown() override { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
48 | cxBufferDestroy(&buf); |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
49 | cxBufferDestroy(&target); |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
50 | } |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
51 | |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
52 | void enableFlushing() { |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
53 | buf.flush_target = ⌖ |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
54 | 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
|
55 | buf.flush_blkmax = 1; |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
56 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
57 | }; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
58 | |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
59 | static size_t mock_write_limited_rate( |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
60 | void const *ptr, |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
61 | size_t size, |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
62 | __attribute__((unused)) size_t nitems, |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
63 | CxBuffer *buffer |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
64 | ) { |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
65 | // simulate limited target drain capacity |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
66 | static bool full = false; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
67 | if (full) { |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
68 | full = false; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
69 | return 0; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
70 | } else { |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
71 | full = true; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
72 | 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
|
73 | } |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
74 | } |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
75 | |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
76 | TEST_F(BufferWrite, SizeOneFit) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
77 | const char *data = "test"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
78 | 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
|
79 | 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
|
80 | CX_TEST_ASSERT(buf.size == 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
81 | 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
|
82 | CX_TEST_ASSERT(written == 4); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
83 | 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
|
84 | 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
|
85 | CX_TEST_ASSERT(buf.capacity == 8); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
86 | EXPECT_EQ(memcmp(buf.space, "preptest", 8), 0); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
87 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
88 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
89 | TEST_F(BufferWrite, SizeOneDiscard) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
90 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
91 | 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
|
92 | 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
|
93 | CX_TEST_ASSERT(buf.size == 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
94 | 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
|
95 | CX_TEST_ASSERT(written == 4); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
96 | 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
|
97 | 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
|
98 | CX_TEST_ASSERT(buf.capacity == 8); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
99 | 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
|
100 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
101 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
102 | TEST_F(BufferWrite, SizeOneExtend) { |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
103 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
104 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
105 | 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
|
106 | 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
|
107 | CX_TEST_ASSERT(buf.size == 4); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
108 | 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
|
109 | CX_TEST_ASSERT(written == 7); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
110 | 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
|
111 | CX_TEST_ASSERT(buf.pos == 11); |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
112 | EXPECT_GE(buf.capacity, 11); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
113 | EXPECT_EQ(memcmp(buf.space, "preptesting", 11), 0); |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
114 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
115 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
116 | TEST_F(BufferWrite, MultibyteFit) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
117 | const char *data = "test"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
118 | 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
|
119 | 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
|
120 | 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
|
121 | 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
|
122 | CX_TEST_ASSERT(written == 2); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
128 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
129 | TEST_F(BufferWrite, MultibyteDiscard) { |
542
45bcfd152f85
#170 no bug never existed
Mike Becker <universe@uap-core.de>
parents:
541
diff
changeset
|
130 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
131 | 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
|
132 | 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
|
133 | buf.pos = 3; |
542
45bcfd152f85
#170 no bug never existed
Mike Becker <universe@uap-core.de>
parents:
541
diff
changeset
|
134 | 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
|
135 | // 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
|
136 | CX_TEST_ASSERT(written == 2); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
137 | 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
|
138 | 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
|
139 | 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
|
140 | 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
|
141 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
142 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
143 | TEST_F(BufferWrite, MultibyteExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
144 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
145 | const char *data = "tester"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
146 | 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
|
147 | 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
|
148 | buf.pos = 3; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
149 | 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
|
150 | // 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
|
151 | CX_TEST_ASSERT(written == 3); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | 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
|
156 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
157 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
158 | TEST_F(BufferWrite, PutcWrapperFit) { |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
159 | 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
|
160 | 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
|
161 | 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
|
162 | 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
|
163 | CX_TEST_ASSERT(c == 'a'); |
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 == 5); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
165 | 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
|
166 | 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
|
167 | 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
|
168 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
169 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
170 | TEST_F(BufferWrite, PutcWrapperDiscard) { |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
171 | 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
|
172 | 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
|
173 | 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
|
174 | 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
|
175 | CX_TEST_ASSERT(c == EOF); |
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.pos == 8); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
178 | 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
|
179 | 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
|
180 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
181 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
182 | TEST_F(BufferWrite, PutcWrapperExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
183 | 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
|
184 | 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
|
185 | 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
|
186 | 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
|
187 | 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
|
188 | CX_TEST_ASSERT(c == 'a'); |
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 == 9); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
190 | 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
|
191 | 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
|
192 | 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
|
193 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
194 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
195 | TEST_F(BufferWrite, PutStringWrapperFit) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
196 | const char *data = "test"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
197 | 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
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | CX_TEST_ASSERT(written == 4); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | 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
|
206 | } |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
207 | |
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
208 | TEST_F(BufferWrite, PutStringWrapperDiscard) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
209 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | CX_TEST_ASSERT(written == 4); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
215 | 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
|
216 | 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
|
217 | 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
|
218 | 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
|
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 | TEST_F(BufferWrite, PutStringWrapperExtend) { |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
222 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
223 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | CX_TEST_ASSERT(written == 7); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
229 | 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
|
230 | 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
|
231 | EXPECT_GE(buf.capacity, 11); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
232 | 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
|
233 | } |
538
2cfbcbe86a7c
#170 first basic write tests
Mike Becker <universe@uap-core.de>
parents:
536
diff
changeset
|
234 | |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
235 | TEST_F(BufferWrite, MultOverflow) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
236 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
237 | 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
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | CX_TEST_ASSERT(written == 0); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
242 | 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
|
243 | 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
|
244 | 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
|
245 | 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
|
246 | } |
541
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
247 | |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
248 | TEST_F(BufferWrite, MaxCapaOverflow) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
249 | buf.flags |= CX_BUFFER_AUTO_EXTEND; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
250 | const char *data = "testing"; |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
251 | 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
|
252 | 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
|
253 | 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
|
254 | 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
|
255 | CX_TEST_ASSERT(written == 0); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
256 | 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
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | } |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
261 | |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
262 | TEST_F(BufferWrite, OnlyOverwrite) { |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
263 | 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
|
264 | 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
|
265 | memcpy(buf.space, "preptest", 8); |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
266 | buf.pos = 3; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
267 | buf.size = 8; |
67e078518935
#170 complete write tests for status quo
Mike Becker <universe@uap-core.de>
parents:
539
diff
changeset
|
268 | 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
|
269 | CX_TEST_ASSERT(written == 2); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | 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
|
274 | } |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
275 | |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
276 | TEST_F(BufferWrite, FlushAtCapacity) { |
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
277 | enableFlushing(); |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
278 | 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
|
279 | CX_TEST_ASSERT(buf.pos == 4); |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
280 | 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
|
281 | CX_TEST_ASSERT(written == 3); |
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 == 7); |
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 == 7); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
284 | 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
|
285 | CX_TEST_ASSERT(target.size == 0); |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
286 | 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
|
287 | CX_TEST_ASSERT(written == 5); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | CX_TEST_ASSERT(target.size == 12); |
545
3700ac4bd9a3
#184 #170 first basic flush test
Mike Becker <universe@uap-core.de>
parents:
542
diff
changeset
|
293 | 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
|
294 | } |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
295 | |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
296 | TEST_F(BufferWrite, FlushAtThreshold) { |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
297 | enableFlushing(); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
298 | buf.flush_threshold = 12; |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
299 | 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
|
300 | 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
|
301 | CX_TEST_ASSERT(buf.pos == 4); |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
302 | 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
|
303 | CX_TEST_ASSERT(written == 6); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
304 | 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
|
305 | CX_TEST_ASSERT(buf.size == 10); |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
306 | ASSERT_GE(buf.capacity, 10); |
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
307 | 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
|
308 | 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
|
309 | CX_TEST_ASSERT(target.size == 0); |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
310 | 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
|
311 | CX_TEST_ASSERT(written == 5); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
312 | 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
|
313 | CX_TEST_ASSERT(buf.size == 0); |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
314 | 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
|
315 | 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
|
316 | CX_TEST_ASSERT(target.size == 15); |
546
900795d59d03
#184 #170 flush at threshold test
Mike Becker <universe@uap-core.de>
parents:
545
diff
changeset
|
317 | 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
|
318 | } |
547 | 319 | |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
320 | TEST_F(BufferWrite, FlushRateLimited) { |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
321 | enableFlushing(); |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
322 | // 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
|
323 | target.capacity = 16; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
324 | target.flags &= ~CX_BUFFER_AUTO_EXTEND; |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
325 | 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
|
326 | 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
|
327 | CX_TEST_ASSERT(buf.pos == 4); |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
328 | 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
|
329 | CX_TEST_ASSERT(written == 3); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
330 | 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
|
331 | 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
|
332 | 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
|
333 | CX_TEST_ASSERT(target.size == 0); |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
334 | written = cxBufferWrite("hello, world!", 1, 13, &buf); |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
335 | // " 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
|
336 | CX_TEST_ASSERT(written == 13); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
337 | 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
|
338 | 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
|
339 | CX_TEST_ASSERT(buf.capacity == 8); |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
340 | 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
|
341 | 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
|
342 | 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
|
343 | CX_TEST_ASSERT(target.capacity == 16); |
567
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
344 | 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
|
345 | } |
f90a7cfe2480
#184 #170 more thorough flush testing
Mike Becker <universe@uap-core.de>
parents:
566
diff
changeset
|
346 | |
568 | 347 | class BufferRead : public ::testing::Test { |
348 | protected: | |
349 | CxBuffer buf{}; | |
350 | ||
351 | void SetUp() override { | |
789
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
352 | cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); |
568 | 353 | buf.capacity = 8; // artificially reduce capacity to check OOB writes |
354 | memset(buf.space, 0, 16); | |
355 | memcpy(buf.space, "some data", 9); | |
356 | buf.size = 9; | |
357 | } | |
358 | ||
359 | void TearDown() override { | |
360 | cxBufferDestroy(&buf); | |
361 | } | |
362 | }; | |
363 | ||
364 | TEST_F(BufferRead, GetByte) { | |
365 | buf.pos = 2; | |
366 | EXPECT_EQ(cxBufferGet(&buf), 'm'); | |
367 | EXPECT_EQ(cxBufferGet(&buf), 'e'); | |
368 | EXPECT_EQ(cxBufferGet(&buf), ' '); | |
369 | 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
|
370 | CX_TEST_ASSERT(buf.pos == 6); |
568 | 371 | } |
372 | ||
373 | TEST_F(BufferRead, GetEof) { | |
374 | buf.pos = buf.size; | |
375 | EXPECT_EQ(cxBufferGet(&buf), EOF); | |
376 | } | |
569 | 377 | |
378 | TEST_F(BufferRead, ReadWithinBounds) { | |
379 | buf.pos = 2; | |
380 | char target[4]; | |
381 | 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
|
382 | CX_TEST_ASSERT(read == 4); |
569 | 383 | 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
|
384 | CX_TEST_ASSERT(buf.pos == 6); |
569 | 385 | } |
386 | ||
387 | TEST_F(BufferRead, ReadOutOfBounds) { | |
388 | buf.pos = 6; | |
389 | char target[4]; | |
390 | 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
|
391 | CX_TEST_ASSERT(read == 3); |
569 | 392 | 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
|
393 | CX_TEST_ASSERT(buf.pos == 9); |
569 | 394 | } |
395 | ||
396 | TEST_F(BufferRead, ReadOutOfBoundsMultibyte) { | |
397 | buf.pos = 6; | |
398 | char target[4]; | |
399 | target[2] = '\0'; | |
400 | 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
|
401 | CX_TEST_ASSERT(read == 1); |
569 | 402 | 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
|
403 | CX_TEST_ASSERT(buf.pos == 8); |
569 | 404 | } |
405 | ||
406 | TEST_F(BufferRead, ReadEof) { | |
407 | buf.pos = 9; | |
408 | char target[4]; | |
409 | 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
|
410 | CX_TEST_ASSERT(read == 0); |
9b2f5661bebd
begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
761
diff
changeset
|
411 | CX_TEST_ASSERT(buf.pos == 9); |
569 | 412 | } |