tests/test_buffer.c

Mon, 22 Jan 2024 19:34:38 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 22 Jan 2024 19:34:38 +0100
changeset 816
425234b05dff
parent 793
db1c8dfe403a
child 890
54565fd74e74
permissions
-rw-r--r--

add first basic low level tree functions

relates to #165 tested by issue #167

789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
9b2f5661bebd begin migration of buffer tests - relates to #342
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
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/test.h"
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include "util_allocator.h"
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include "cx/buffer.h"
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 static CX_TEST_SUBROUTINE(expect_default_flush_config, CxBuffer *buf) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 CX_TEST_ASSERT(buf->flush_blkmax == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 CX_TEST_ASSERT(buf->flush_blksize == 4096);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 CX_TEST_ASSERT(buf->flush_threshold == SIZE_MAX);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 CX_TEST_ASSERT(buf->flush_func == NULL);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 CX_TEST_ASSERT(buf->flush_target == NULL);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 CX_TEST(test_buffer_init_wrap_space) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 CX_TEST_CALL_SUBROUTINE(expect_default_flush_config, &buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 cxFree(alloc, space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 CX_TEST(test_buffer_init_wrap_space_auto_extend) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_AUTO_EXTEND);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 CX_TEST_CALL_SUBROUTINE(expect_default_flush_config, &buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == CX_BUFFER_AUTO_EXTEND);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 cxFree(alloc, space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 CX_TEST(test_buffer_init_wrap_space_auto_free) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 CX_TEST_CALL_SUBROUTINE(expect_default_flush_config, &buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 CX_TEST(test_buffer_init_fresh_space) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 cxBufferInit(&buf, NULL, 8, alloc, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 CX_TEST_CALL_SUBROUTINE(expect_default_flush_config, &buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 CX_TEST_ASSERT(buf.space != NULL);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc)); // space is still allocated
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 CX_TEST(test_buffer_init_on_heap) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 CxBuffer *buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 buf = cxBufferCreate(space, 16, alloc, CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 CX_TEST_ASSERT(buf != NULL);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 CX_TEST_CALL_SUBROUTINE(expect_default_flush_config, buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 CX_TEST_ASSERT(buf->space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 CX_TEST_ASSERT((buf->flags & CX_BUFFER_AUTO_EXTEND) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 CX_TEST_ASSERT((buf->flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 CX_TEST_ASSERT(buf->pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 CX_TEST_ASSERT(buf->size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 CX_TEST_ASSERT(buf->capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 CX_TEST_ASSERT(buf->allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 cxBufferFree(buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 CX_TEST(test_buffer_minimum_capacity_sufficient) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 void *space = cxMalloc(alloc, 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 cxBufferInit(&buf, space, 8, alloc, CX_BUFFER_FREE_CONTENTS);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 memcpy(space, "Testing", 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 buf.size = 8;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 cxBufferMinimumCapacity(&buf, 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 CX_TEST(test_buffer_minimum_capacity_extend) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 void *space = cxMalloc(alloc, 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 cxBufferInit(&buf, space, 8, alloc, CX_BUFFER_FREE_CONTENTS); // NO auto extend!
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 memcpy(space, "Testing", 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 buf.size = 8;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 cxBufferMinimumCapacity(&buf, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 CX_TEST(test_buffer_clear) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 char space[16];
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 strcpy(space, "clear test");
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 // only clear the used part of the buffer
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 cxBufferClear(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 CX_TEST_ASSERT(0 == memcmp(space, "clear test", 10));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 buf.size = 5;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 cxBufferClear(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 CX_TEST_ASSERT(0 == memcmp(space, "\0\0\0\0\0 test", 10));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 CX_TEST(test_buffer_reset) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 char space[16];
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 strcpy(space, "reset test");
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 buf.size = 5;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 cxBufferReset(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 CX_TEST_ASSERT(0 == memcmp(space, "reset test", 10));
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 CX_TEST(test_buffer_seek_set_zero) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 int result = cxBufferSeek(&buf, 0, SEEK_SET);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 CX_TEST(test_buffer_seek_set_valid) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 int result = cxBufferSeek(&buf, 5, SEEK_SET);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 CX_TEST(test_buffer_seek_set_invalid) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 int result = cxBufferSeek(&buf, 6, SEEK_SET);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 CX_TEST(test_buffer_seek_cur_zero) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 int result = cxBufferSeek(&buf, 0, SEEK_CUR);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 CX_TEST(test_buffer_seek_cur_valid_positive) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 int result = cxBufferSeek(&buf, 2, SEEK_CUR);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 CX_TEST(test_buffer_seek_cur_valid_negative) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 int result = cxBufferSeek(&buf, -3, SEEK_CUR);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 CX_TEST(test_buffer_seek_cur_invalid_positive) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 int result = cxBufferSeek(&buf, 3, SEEK_CUR);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 CX_TEST(test_buffer_seek_cur_invalid_negative) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331 int result = cxBufferSeek(&buf, -4, SEEK_CUR);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 CX_TEST(test_buffer_seek_end_zero) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 int result = cxBufferSeek(&buf, 0, SEEK_END);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 // the (past-the-)end position is always invalid
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
349 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 CX_TEST(test_buffer_seek_end_valid) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 int result = cxBufferSeek(&buf, -6, SEEK_END);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 CX_TEST(test_buffer_seek_end_invalid) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 int result = cxBufferSeek(&buf, 1, SEEK_END);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 CX_TEST(test_buffer_seek_whence_invalid) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384 int result = cxBufferSeek(&buf, 2, 9000);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 CX_TEST_ASSERT(buf.size == 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
392 CX_TEST(test_buffer_eof_reached) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
393 CxBuffer buf;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
394 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
395 buf.size = buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
396 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
397 CX_TEST_ASSERT(cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
398 buf.pos = buf.size - 1;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
399 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
400 cxBufferPut(&buf, 'a');
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
401 CX_TEST_ASSERT(cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
402 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
403 cxBufferDestroy(&buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
404 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
405
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
406 CX_TEST(test_buffer_eof_not_reached) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
407 CxBuffer buf;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
408 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
409 buf.size = 6;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
410 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
411 buf.pos = buf.size - 1;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
412 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
413 buf.pos = 0;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
414 cxBufferWrite("test", 1, 5, &buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
415 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
416 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
417 cxBufferDestroy(&buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
418 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
419
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
420 #define TEST_BUFFER_SHIFT_SETUP(buf) \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
421 CxTestingAllocator talloc; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
422 cx_testing_allocator_init(&talloc); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
423 CxAllocator *alloc = &talloc.base; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
424 CxBuffer buf; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
425 cxBufferInit(&buf, NULL, 16, alloc, CX_BUFFER_DEFAULT); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
426 memcpy(buf.space, "test____XXXXXXXX", 16); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
427 buf.capacity = 8; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
428 buf.pos = 4; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
429 buf.size = 4
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
430 #define TEST_BUFFER_SHIFT_TEARDOWN(buf) \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
431 cxBufferDestroy(&buf); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
432 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); \
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
433 cx_testing_allocator_destroy(&talloc)
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
434
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
435
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
436 CX_TEST(test_buffer_shift_left_zero) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
437 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
438 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
439 int ret = cxBufferShiftLeft(&buf, 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
440 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
441 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
442 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
443 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
444 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
445 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
446 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
447
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
448 CX_TEST(test_buffer_shift_left_zero_offset_interface) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
449 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
450 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
451 int ret = cxBufferShift(&buf, -0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
452 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
453 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
454 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
455 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
456 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
457 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
458 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
459
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
460 CX_TEST(test_buffer_shift_left_standard) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
461 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
462 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
463 int ret = cxBufferShiftLeft(&buf, 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
464 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
465 CX_TEST_ASSERT(buf.pos == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
466 CX_TEST_ASSERT(buf.size == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
467 CX_TEST_ASSERT(memcmp(buf.space, "stst____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
468 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
469 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
470 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
471
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
472 CX_TEST(test_buffer_shift_left_overshift) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
473 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
474 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
475 int ret = cxBufferShiftLeft(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
476 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
477 CX_TEST_ASSERT(buf.pos == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
478 CX_TEST_ASSERT(buf.size == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
479 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
480 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
481 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
482 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
483
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
484 CX_TEST(test_buffer_shift_left_overshift_pos_only) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
485 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
486 buf.pos = 2;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
487 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
488 int ret = cxBufferShiftLeft(&buf, 3);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
489 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
490 CX_TEST_ASSERT(buf.pos == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
491 CX_TEST_ASSERT(buf.size == 1);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
492 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
493 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
494 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
495 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
496
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
497 CX_TEST(test_buffer_shift_left_offset_interface) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
498 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
499 buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
500 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
501 int ret = cxBufferShift(&buf, -2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
502 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
503 CX_TEST_ASSERT(buf.pos == 1);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
504 CX_TEST_ASSERT(buf.size == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
505 CX_TEST_ASSERT(memcmp(buf.space, "stst____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
506 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
507 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
508 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
509
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
510 CX_TEST(test_buffer_shift_right_zero) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
511 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
512 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
513 int ret = cxBufferShiftRight(&buf, 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
514 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
515 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
516 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
517 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
518 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
519 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
520 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
521
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
522 CX_TEST(test_buffer_shift_right_zero_offset_interface) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
523 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
524 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
525 int ret = cxBufferShift(&buf, +0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
526 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
527 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
528 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
529 CX_TEST_ASSERT(memcmp(buf.space, "test____XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
530 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
531 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
532 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
533
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
534 CX_TEST(test_buffer_shift_right_standard) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
535 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
536 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
537 int ret = cxBufferShiftRight(&buf, 3);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
538 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
539 CX_TEST_ASSERT(buf.pos == 7);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
540 CX_TEST_ASSERT(buf.size == 7);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
541 CX_TEST_ASSERT(memcmp(buf.space, "testest_XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
542 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
543 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
544 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
545
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
546 CX_TEST(test_buffer_shift_right_overshift_discard) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
547 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
548 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
549 int ret = cxBufferShiftRight(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
550 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
551 CX_TEST_ASSERT(buf.pos == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
552 CX_TEST_ASSERT(buf.size == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
553 CX_TEST_ASSERT(buf.capacity == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
554 CX_TEST_ASSERT(memcmp(buf.space, "test__teXXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
555 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
556 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
557 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
558
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
559 CX_TEST(test_buffer_shift_right_overshift_extend) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
560 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
561 buf.flags |= CX_BUFFER_AUTO_EXTEND;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
562 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
563 int ret = cxBufferShiftRight(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
564 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
565 CX_TEST_ASSERT(buf.pos == 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
566 CX_TEST_ASSERT(buf.size == 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
567 CX_TEST_ASSERT(buf.capacity >= 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
568 // cannot assert more than 10 bytes because
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
569 // the buffer was required to reallocate the space
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
570 CX_TEST_ASSERT(memcmp(buf.space, "test__test", 10) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
571 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
572 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
573 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
574
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
575 CX_TEST(test_buffer_shift_right_offset_interface) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
576 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
577 buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
578 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
579 int ret = cxBufferShift(&buf, 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
580 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
581 CX_TEST_ASSERT(buf.pos == 5);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
582 CX_TEST_ASSERT(buf.size == 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
583 CX_TEST_ASSERT(memcmp(buf.space, "tetest__XXXXXXXX", 16) == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
584 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
585 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
586 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
587
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
588 static size_t mock_write_limited_rate(
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
589 void const *ptr,
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
590 size_t size,
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
591 __attribute__((unused)) size_t nitems,
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
592 CxBuffer *buffer
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
593 ) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
594 // simulate limited target drain capacity
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
595 static bool full = false;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
596 if (full) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
597 full = false;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
598 return 0;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
599 } else {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
600 full = true;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
601 return cxBufferWrite(ptr, size, nitems > 2 ? 2 : nitems, buffer);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
602 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
603 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
604
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
605 CX_TEST(test_buffer_write_size_one_fit) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
606 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
607 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
608 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
609 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
610 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
611 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
612 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
613 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
614 size_t written = cxBufferWrite(data, 1, 4, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
615 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
616 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
617 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
618 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
619 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
620 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
621
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
622 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
623 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
624 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
625
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
626 CX_TEST(test_buffer_write_size_one_discard) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
627 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
628 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
629 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
630 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
631 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
632 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
633 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
634 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
635 size_t written = cxBufferWrite(data, 1, 7, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
636 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
637 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
638 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
639 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
640 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest\0", 9));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
641 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
642 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
643 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
644 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
645
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
646 CX_TEST(test_buffer_write_size_one_extend) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
647 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
648 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
649 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
650 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
651 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
652 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
653 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
654 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
655 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
656 size_t written = cxBufferWrite(data, 1, 7, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
657 CX_TEST_ASSERT(written == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
658 CX_TEST_ASSERT(buf.size == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
659 CX_TEST_ASSERT(buf.pos == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
660 CX_TEST_ASSERT(buf.capacity >= 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
661 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
662 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
663 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
664 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
665 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
666
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
667 CX_TEST(test_buffer_write_multibyte_fit) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
668 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
669 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
670 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
671 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
672 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
673 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
674 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
675 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
676 size_t written = cxBufferWrite(data, 2, 2, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
677 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
678 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
679 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
680 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
681 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
682 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
683 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
684 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
685 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
686
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
687 CX_TEST(test_buffer_write_multibyte_discard) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
688 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
689 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
690 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
691 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
692 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
693 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
694 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
695 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
696 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
697 size_t written = cxBufferWrite(data, 2, 4, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
698 // remember: whole elements are discarded if they do not fit
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
699 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
700 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
701 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
702 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
703 CX_TEST_ASSERT(0 == memcmp(buf.space, "pretest\0", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
704 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
705 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
706 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
707 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
708
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
709 CX_TEST(test_buffer_write_multibyte_extend) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
710 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
711 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
712 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
713 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
714 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
715 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
716 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
717 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
718 const char *data = "tester";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
719 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
720 size_t written = cxBufferWrite(data, 2, 3, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
721 // remember: whole elements are discarded if they do not fit
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
722 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
723 CX_TEST_ASSERT(buf.size == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
724 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
725 CX_TEST_ASSERT(buf.capacity >= 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
726 CX_TEST_ASSERT(0 == memcmp(buf.space, "pretester", 9));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
727 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
728 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
729 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
730 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
731
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
732 CX_TEST(test_buffer_put_fit) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
733 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
734 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
735 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
736 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
737 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
738 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
739 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
740 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
741 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
742 CX_TEST_ASSERT(buf.size == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
743 CX_TEST_ASSERT(buf.pos == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
744 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
745 CX_TEST_ASSERT(0 == memcmp(buf.space, "prepa\0", 6));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
746 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
747 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
748 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
749 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
750
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
751 CX_TEST(test_buffer_put_discard) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
752 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
753 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
754 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
755 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
756 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
757 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
758 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
759 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
760 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
761 CX_TEST_ASSERT(c == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
762 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
763 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
764 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
765 CX_TEST_ASSERT(0 == memcmp(buf.space, "prep\0\0\0\0\0", 9));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
766 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
767 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
768 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
769 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
770
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
771 CX_TEST(test_buffer_put_extend) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
772 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
773 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
774 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
775 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
776 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
777 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
778 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
779 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
780 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
781 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
782 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
783 CX_TEST_ASSERT(buf.size == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
784 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
785 CX_TEST_ASSERT(buf.capacity >= 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
786 CX_TEST_ASSERT(0 == memcmp(buf.space, "prep\0\0\0\0a", 9));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
787 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
788 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
789 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
790 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
791
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
792 CX_TEST(test_buffer_put_string_fit) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
793 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
794 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
795 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
796 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
797 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
798 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
799 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
800 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
801 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
802 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
803 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
804 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
805 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
806 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
807 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
808 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
809 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
810 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
811
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
812 CX_TEST(test_buffer_put_string_discard) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
813 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
814 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
815 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
816 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
817 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
818 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
819 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
820 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
821 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
822 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
823 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
824 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
825 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
826 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest\0", 9));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
827 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
828 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
829 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
830 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
831
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
832 CX_TEST(test_buffer_put_string_extend) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
833 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
834 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
835 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
836 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
837 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
838 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
839 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
840 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
841 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
842 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
843 CX_TEST_ASSERT(written == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
844 CX_TEST_ASSERT(buf.size == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
845 CX_TEST_ASSERT(buf.pos == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
846 CX_TEST_ASSERT(buf.capacity >= 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
847 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
848 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
849 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
850 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
851 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
852
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
853 CX_TEST(test_buffer_write_size_overflow) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
854 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
855 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
856 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
857 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
858 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
859 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
860 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
861 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
862 size_t written = cxBufferWrite(data, 8, SIZE_MAX / 4, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
863 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
864 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
865 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
866 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
867 CX_TEST_ASSERT(0 == memcmp(buf.space, "prep\0", 5));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
868 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
869 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
870 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
871 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
872
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
873 CX_TEST(test_buffer_write_capacity_overflow) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
874 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
875 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
876 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
877 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
878 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
879 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
880 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
881 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
882 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
883 size_t written = cxBufferWrite(data, 1, SIZE_MAX - 2, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
884 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
885 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
886 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
887 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
888 CX_TEST_ASSERT(0 == memcmp(buf.space, "prep\0", 5));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
889 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
890 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
891 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
892 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
893
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
894 CX_TEST(test_buffer_write_only_overwrite) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
895 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
896 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
897 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
898 memcpy(buf.space, "preptest\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
899 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
900 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
901 buf.size = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
902 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
903 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
904 size_t written = cxBufferWrite("XXX", 2, 2, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
905 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
906 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
907 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
908 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
909 CX_TEST_ASSERT(0 == memcmp(buf.space, "preXXX\0t", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
910 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
911 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
912 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
913 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
914
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
915 CX_TEST(test_buffer_write_flush_at_capacity) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
916 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
917 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
918 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
919 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
920 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
921 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
922 buf.flush_target = &target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
923 buf.flush_func = (cx_write_func)cxBufferWrite;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
924 buf.flush_blkmax = 1;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
925 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
926 size_t written = cxBufferWrite("foo", 1, 3, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
927 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
928 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
929 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
930 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
931 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
932 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
933 CX_TEST_ASSERT(written == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
934 CX_TEST_ASSERT(buf.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
935 CX_TEST_ASSERT(buf.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
936 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
937 CX_TEST_ASSERT(target.pos == 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
938 CX_TEST_ASSERT(target.size == 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
939 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfoohello", 12));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
940 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
941 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
942 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
943 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
944
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
945 CX_TEST(test_buffer_write_flush_at_threshold) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
946 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
947 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
948 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
949 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
950 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
951 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
952 buf.flush_target = &target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
953 buf.flush_func = (cx_write_func)cxBufferWrite;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
954 buf.flush_blkmax = 1;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
955 buf.flush_threshold = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
956 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
957 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
958 size_t written = cxBufferWrite("foobar", 1, 6, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
959 CX_TEST_ASSERT(written == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
960 CX_TEST_ASSERT(buf.pos == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
961 CX_TEST_ASSERT(buf.size == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
962 CX_TEST_ASSERT(buf.capacity >= 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
963 CX_TEST_ASSERT(buf.capacity <= 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
964 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
965 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
966 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
967 CX_TEST_ASSERT(written == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
968 CX_TEST_ASSERT(buf.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
969 CX_TEST_ASSERT(buf.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
970 CX_TEST_ASSERT(buf.capacity <= 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
971 CX_TEST_ASSERT(target.pos == 15);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
972 CX_TEST_ASSERT(target.size == 15);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
973 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfoobarhello", 15));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
974 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
975 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
976 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
977 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
978
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
979 CX_TEST(test_buffer_write_flush_rate_limited) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
980 CxBuffer buf, target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
981 cxBufferInit(&target, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
982 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
983 memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
984 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
985 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
986 buf.flush_target = &target;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
987 buf.flush_blkmax = 1;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
988 // limit the rate of the flush function and the capacity of the target
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
989 buf.flush_func = (cx_write_func) mock_write_limited_rate;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
990 target.capacity = 16;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
991 target.flags &= ~CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
992 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
993 size_t written = cxBufferWrite("foo", 1, 3, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
994 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
995 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
996 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
997 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
998 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
999 written = cxBufferWrite("hello, world!", 1, 13, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1000 // " world!" fits into this buffer, the remaining stuff is flushed out
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1001 CX_TEST_ASSERT(written == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1002 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1003 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1004 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1005 CX_TEST_ASSERT(0 == memcmp(buf.space, " world!", 7));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1006 CX_TEST_ASSERT(target.pos == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1007 CX_TEST_ASSERT(target.size == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1008 CX_TEST_ASSERT(target.capacity == 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1009 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfoohello,", 13));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1010 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1011 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1012 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1013 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1014
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1015 CX_TEST(test_buffer_get) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1016 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1017 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1018 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1019 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1020 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1021 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1022 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1023 CX_TEST_ASSERT(cxBufferGet(&buf) == 'm');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1024 CX_TEST_ASSERT(cxBufferGet(&buf) == 'e');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1025 CX_TEST_ASSERT(cxBufferGet(&buf) == ' ');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1026 CX_TEST_ASSERT(cxBufferGet(&buf) == 'd');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1027 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1028 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1029 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1030 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1031
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1032 CX_TEST(test_buffer_get_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1033 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1034 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1035 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1036 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1037 buf.pos = buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1038 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1039 CX_TEST_ASSERT(cxBufferGet(&buf) == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1040 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1041 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1042 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1043
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1044 CX_TEST(test_buffer_read) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1045 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1046 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1047 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1048 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1049 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1050 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1051 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1052 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1053 size_t read = cxBufferRead(&target, 1, 4, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1054 CX_TEST_ASSERT(read == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1055 CX_TEST_ASSERT(0 == memcmp(&target, "me d", 4));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1056 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1057 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1058 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1059 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1060
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1061 CX_TEST(test_buffer_read_oob) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1062 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1063 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1064 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1065 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1066 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1067 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1068 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1069 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1070 size_t read = cxBufferRead(&target, 1, 4, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1071 CX_TEST_ASSERT(read == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1072 CX_TEST_ASSERT(0 == memcmp(&target, "ata", 3));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1073 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1074 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1075 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1076 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1077
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1078 CX_TEST(test_buffer_read_oob_multibyte) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1079 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1080 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1081 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1082 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1083 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1084 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1085 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1086 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1087 target[2] = '\0';
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1088 size_t read = cxBufferRead(&target, 2, 2, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1089 CX_TEST_ASSERT(read == 1);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1090 CX_TEST_ASSERT(0 == memcmp(&target, "at\0", 3));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1091 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1092 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1093 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1094 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1095
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1096 CX_TEST(test_buffer_read_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1097 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1098 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1099 memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1100 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1101 buf.size = buf.pos = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1102 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1103 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1104 size_t read = cxBufferRead(&target, 1, 1, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1105 CX_TEST_ASSERT(read == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1106 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1107 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1108 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1109 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1110
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1111 CxTestSuite *cx_test_suite_buffer(void) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1112 CxTestSuite *suite = cx_test_suite_new("buffer");
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1113
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1114 cx_test_register(suite, test_buffer_init_wrap_space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1115 cx_test_register(suite, test_buffer_init_wrap_space_auto_extend);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1116 cx_test_register(suite, test_buffer_init_wrap_space_auto_free);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1117 cx_test_register(suite, test_buffer_init_fresh_space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1118 cx_test_register(suite, test_buffer_init_on_heap);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1119 cx_test_register(suite, test_buffer_minimum_capacity_sufficient);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1120 cx_test_register(suite, test_buffer_minimum_capacity_extend);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1121 cx_test_register(suite, test_buffer_clear);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1122 cx_test_register(suite, test_buffer_reset);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1123 cx_test_register(suite, test_buffer_seek_set_zero);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1124 cx_test_register(suite, test_buffer_seek_set_valid);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1125 cx_test_register(suite, test_buffer_seek_set_invalid);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1126 cx_test_register(suite, test_buffer_seek_cur_zero);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1127 cx_test_register(suite, test_buffer_seek_cur_valid_positive);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1128 cx_test_register(suite, test_buffer_seek_cur_valid_negative);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1129 cx_test_register(suite, test_buffer_seek_cur_invalid_positive);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1130 cx_test_register(suite, test_buffer_seek_cur_invalid_negative);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1131 cx_test_register(suite, test_buffer_seek_end_zero);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1132 cx_test_register(suite, test_buffer_seek_end_valid);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1133 cx_test_register(suite, test_buffer_seek_end_invalid);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1134 cx_test_register(suite, test_buffer_seek_whence_invalid);
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1135 cx_test_register(suite, test_buffer_eof_reached);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1136 cx_test_register(suite, test_buffer_eof_not_reached);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1137 cx_test_register(suite, test_buffer_shift_left_zero);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1138 cx_test_register(suite, test_buffer_shift_left_zero_offset_interface);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1139 cx_test_register(suite, test_buffer_shift_left_standard);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1140 cx_test_register(suite, test_buffer_shift_left_overshift);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1141 cx_test_register(suite, test_buffer_shift_left_overshift_pos_only);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1142 cx_test_register(suite, test_buffer_shift_left_offset_interface);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1143 cx_test_register(suite, test_buffer_shift_right_zero);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1144 cx_test_register(suite, test_buffer_shift_right_zero_offset_interface);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1145 cx_test_register(suite, test_buffer_shift_right_standard);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1146 cx_test_register(suite, test_buffer_shift_right_overshift_discard);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1147 cx_test_register(suite, test_buffer_shift_right_overshift_extend);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1148 cx_test_register(suite, test_buffer_shift_right_offset_interface);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1149 cx_test_register(suite, test_buffer_write_size_one_fit);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1150 cx_test_register(suite, test_buffer_write_size_one_discard);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1151 cx_test_register(suite, test_buffer_write_size_one_extend);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1152 cx_test_register(suite, test_buffer_write_multibyte_fit);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1153 cx_test_register(suite, test_buffer_write_multibyte_discard);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1154 cx_test_register(suite, test_buffer_write_multibyte_extend);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1155 cx_test_register(suite, test_buffer_put_fit);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1156 cx_test_register(suite, test_buffer_put_discard);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1157 cx_test_register(suite, test_buffer_put_extend);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1158 cx_test_register(suite, test_buffer_put_string_fit);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1159 cx_test_register(suite, test_buffer_put_string_discard);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1160 cx_test_register(suite, test_buffer_put_string_extend);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1161 cx_test_register(suite, test_buffer_write_size_overflow);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1162 cx_test_register(suite, test_buffer_write_capacity_overflow);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1163 cx_test_register(suite, test_buffer_write_only_overwrite);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1164 cx_test_register(suite, test_buffer_write_flush_at_capacity);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1165 cx_test_register(suite, test_buffer_write_flush_at_threshold);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1166 cx_test_register(suite, test_buffer_write_flush_rate_limited);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1167 cx_test_register(suite, test_buffer_get);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1168 cx_test_register(suite, test_buffer_get_eof);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1169 cx_test_register(suite, test_buffer_read);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1170 cx_test_register(suite, test_buffer_read_oob);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1171 cx_test_register(suite, test_buffer_read_oob_multibyte);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1172 cx_test_register(suite, test_buffer_read_eof);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1173
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1174 return suite;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1175 }

mercurial