tests/test_buffer.c

Fri, 17 Jan 2025 17:55:21 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 17 Jan 2025 17:55:21 +0100
changeset 1131
644f77f903b1
parent 1129
cc60b7d07912
permissions
-rw-r--r--

fix cxBufferAppend() not adjusting position after flush

fixes #565

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 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
35 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_DEFAULT);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
42 CX_TEST_ASSERT(buf.flush == NULL);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 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
45 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
46 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 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
52 cxFree(alloc, space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 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
54 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 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
59 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_AUTO_EXTEND);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
66 CX_TEST_ASSERT(buf.flush == NULL);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 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
69 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
70 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 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
76 cxFree(alloc, space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 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
78 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 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
83 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_FREE_CONTENTS);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
90 CX_TEST_ASSERT(buf.flush == NULL);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 CX_TEST_ASSERT(buf.space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 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
93 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
94 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 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
99 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 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
101 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 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
106 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 cxBufferInit(&buf, NULL, 8, alloc, CX_BUFFER_DEFAULT);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
112 CX_TEST_ASSERT(buf.flush == NULL);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 CX_TEST_ASSERT(buf.space != NULL);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 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
115 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
116 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 CX_TEST_ASSERT(buf.allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 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
121 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 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
123 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 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
128 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 CxBuffer *buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 void *space = cxMalloc(alloc, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 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
135 CX_TEST_ASSERT(buf != NULL);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
136 CX_TEST_ASSERT(buf->flush == NULL);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 CX_TEST_ASSERT(buf->space == space);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 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
139 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
140 CX_TEST_ASSERT(buf->pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 CX_TEST_ASSERT(buf->size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 CX_TEST_ASSERT(buf->capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 CX_TEST_ASSERT(buf->allocator == alloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 cxBufferFree(buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 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
146 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 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
151 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 void *space = cxMalloc(alloc, 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 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
158 memcpy(space, "Testing", 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 buf.size = 8;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 cxBufferMinimumCapacity(&buf, 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 CX_TEST_ASSERT(buf.capacity == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 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
164 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 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
166 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 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
171 CxTestingAllocator talloc;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 cx_testing_allocator_init(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 CxAllocator *alloc = &talloc.base;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 void *space = cxMalloc(alloc, 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 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
178 memcpy(space, "Testing", 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 buf.size = 8;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 cxBufferMinimumCapacity(&buf, 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 CX_TEST_ASSERT(buf.capacity == 16);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 CX_TEST_ASSERT(buf.size == 8);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 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
184 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 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
186 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 cx_testing_allocator_destroy(&talloc);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 CX_TEST(test_buffer_clear) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 char space[16];
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 strcpy(space, "clear test");
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 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
195 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 // 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
198 cxBufferClear(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 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
200 buf.size = 5;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 cxBufferClear(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 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
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 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
210 CX_TEST(test_buffer_clear_copy_on_write) {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
211 char space[16];
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
212 strcpy(space, "clear test");
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
213 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
214 cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
215 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
216 buf.size = 5;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
217 buf.pos = 3;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
218 cxBufferClear(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
219 CX_TEST_ASSERT(0 == memcmp(space, "clear test", 10));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
220 CX_TEST_ASSERT(buf.size == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
221 CX_TEST_ASSERT(buf.pos == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
222 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
223 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
224 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
225
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 CX_TEST(test_buffer_reset) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 char space[16];
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 strcpy(space, "reset test");
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 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
231 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 buf.size = 5;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 cxBufferReset(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 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
236 CX_TEST_ASSERT(buf.size == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 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
243 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 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
245 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 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
249 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 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
256 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 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
258 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261 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
262 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 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
269 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 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
271 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 CX_TEST_DO {
1007
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1006
diff changeset
274 int result = cxBufferSeek(&buf, 7, SEEK_SET);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 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
282 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 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
284 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 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
288 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 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
295 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 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
297 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 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
301 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 CX_TEST_ASSERT(buf.pos == 5);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 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
308 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 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
310 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 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
314 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 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
321 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322 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
323 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 CX_TEST_DO {
1007
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1006
diff changeset
326 int result = cxBufferSeek(&buf, 4, SEEK_CUR);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 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
334 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 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
336 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 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
340 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 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
347 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348 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
349 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 int result = cxBufferSeek(&buf, 0, SEEK_END);
1007
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1006
diff changeset
353 CX_TEST_ASSERT(result == 0);
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1006
diff changeset
354 CX_TEST_ASSERT(buf.pos == 6);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 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
360 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 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
362 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 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
366 CX_TEST_ASSERT(result == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 CX_TEST_ASSERT(buf.pos == 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 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
373 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 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
375 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 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
379 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 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
386 CxBuffer buf;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 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
388 buf.size = 6;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 buf.pos = 3;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 CX_TEST_DO {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 int result = cxBufferSeek(&buf, 2, 9000);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392 CX_TEST_ASSERT(result != 0);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
393 CX_TEST_ASSERT(buf.size == 6);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
394 CX_TEST_ASSERT(buf.pos == 3);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
395 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
396 cxBufferDestroy(&buf);
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
397 }
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
398
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
399 CX_TEST(test_buffer_eof_reached) {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
400 CxBuffer buf;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
401 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
402 buf.size = buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
403 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
404 CX_TEST_ASSERT(cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
405 buf.pos = buf.size - 1;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
406 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
407 cxBufferPut(&buf, 'a');
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
408 CX_TEST_ASSERT(cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
409 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
410 cxBufferDestroy(&buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
411 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
412
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
413 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
414 CxBuffer buf;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
415 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
416 buf.size = 6;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
417 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
418 buf.pos = buf.size - 1;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
419 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
420 buf.pos = 0;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
421 cxBufferWrite("test", 1, 5, &buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
422 CX_TEST_ASSERT(!cxBufferEof(&buf));
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
423 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
424 cxBufferDestroy(&buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
425 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
426
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
427 #define TEST_BUFFER_SHIFT_SETUP(buf) \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
428 CxTestingAllocator talloc; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
429 cx_testing_allocator_init(&talloc); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
430 CxAllocator *alloc = &talloc.base; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
431 CxBuffer buf; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
432 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
433 memcpy(buf.space, "test____XXXXXXXX", 16); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
434 buf.capacity = 8; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
435 buf.pos = 4; \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
436 buf.size = 4
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
437 #define TEST_BUFFER_SHIFT_TEARDOWN(buf) \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
438 cxBufferDestroy(&buf); \
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
439 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
440 cx_testing_allocator_destroy(&talloc)
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
441
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
442
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
443 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
444 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
445 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
446 int ret = cxBufferShiftLeft(&buf, 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
447 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
448 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
449 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
450 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
451 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
452 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
453 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
454
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
455 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
456 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
457 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
458 int ret = cxBufferShift(&buf, -0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
459 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
460 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
461 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
462 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
463 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
464 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
465 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
466
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
467 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
468 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
469 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
470 int ret = cxBufferShiftLeft(&buf, 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
471 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
472 CX_TEST_ASSERT(buf.pos == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
473 CX_TEST_ASSERT(buf.size == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
474 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
475 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
476 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
477 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
478
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
479 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
480 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
481 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
482 int ret = cxBufferShiftLeft(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
483 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
484 CX_TEST_ASSERT(buf.pos == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
485 CX_TEST_ASSERT(buf.size == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
486 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
487 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
488 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
489 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
490
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
491 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
492 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
493 buf.pos = 2;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
494 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
495 int ret = cxBufferShiftLeft(&buf, 3);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
496 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
497 CX_TEST_ASSERT(buf.pos == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
498 CX_TEST_ASSERT(buf.size == 1);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
499 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
500 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
501 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
502 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
503
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
504 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
505 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
506 buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
507 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
508 int ret = cxBufferShift(&buf, -2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
509 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
510 CX_TEST_ASSERT(buf.pos == 1);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
511 CX_TEST_ASSERT(buf.size == 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
512 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
513 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
514 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
515 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
516
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
517 CX_TEST(test_buffer_shift_left_copy_on_write) {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
518 TEST_BUFFER_SHIFT_SETUP(buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
519 buf.flags |= CX_BUFFER_COPY_ON_WRITE;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
520 char *original = buf.space;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
521 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
522 int ret = cxBufferShiftLeft(&buf, 2);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
523 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
524 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
525 CX_TEST_ASSERT(ret == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
526 CX_TEST_ASSERT(buf.pos == 2);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
527 CX_TEST_ASSERT(buf.size == 2);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
528 CX_TEST_ASSERT(memcmp(original, "test____XXXXXXXX", 16) == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
529 CX_TEST_ASSERT(memcmp(buf.space, "st", 2) == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
530 cxFree(buf.allocator, original);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
531 TEST_BUFFER_SHIFT_TEARDOWN(buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
532 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
533 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
534
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
535 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
536 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
537 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
538 int ret = cxBufferShiftRight(&buf, 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
539 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
540 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
541 CX_TEST_ASSERT(buf.size == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
542 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
543 TEST_BUFFER_SHIFT_TEARDOWN(buf);
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
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
547 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
548 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
549 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
550 int ret = cxBufferShift(&buf, +0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
551 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
552 CX_TEST_ASSERT(buf.pos == 4);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
553 CX_TEST_ASSERT(buf.size == 4);
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____XXXXXXXX", 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_standard) {
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 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
562 int ret = cxBufferShiftRight(&buf, 3);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
563 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
564 CX_TEST_ASSERT(buf.pos == 7);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
565 CX_TEST_ASSERT(buf.size == 7);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
566 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
567 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
568 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
569 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
570
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
571 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
572 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
573 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
574 int ret = cxBufferShiftRight(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
575 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
576 CX_TEST_ASSERT(buf.pos == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
577 CX_TEST_ASSERT(buf.size == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
578 CX_TEST_ASSERT(buf.capacity == 8);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
579 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
580 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
581 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
582 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
583
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
584 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
585 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
586 buf.flags |= CX_BUFFER_AUTO_EXTEND;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
587 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
588 int ret = cxBufferShiftRight(&buf, 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
589 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
590 CX_TEST_ASSERT(buf.pos == 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
591 CX_TEST_ASSERT(buf.size == 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
592 CX_TEST_ASSERT(buf.capacity >= 10);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
593 // 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
594 // 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
595 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
596 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
597 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
598 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
599
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
600 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
601 TEST_BUFFER_SHIFT_SETUP(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
602 buf.pos = 3;
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
603 CX_TEST_DO {
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
604 int ret = cxBufferShift(&buf, 2);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
605 CX_TEST_ASSERT(ret == 0);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
606 CX_TEST_ASSERT(buf.pos == 5);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
607 CX_TEST_ASSERT(buf.size == 6);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
608 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
609 TEST_BUFFER_SHIFT_TEARDOWN(buf);
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
610 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
611 }
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
612
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
613 CX_TEST(test_buffer_shift_right_copy_on_write) {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
614 TEST_BUFFER_SHIFT_SETUP(buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
615 buf.flags |= CX_BUFFER_COPY_ON_WRITE;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
616 char *original = buf.space;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
617 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
618 int ret = cxBufferShiftRight(&buf, 3);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
619 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
620 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
621 CX_TEST_ASSERT(ret == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
622 CX_TEST_ASSERT(buf.pos == 7);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
623 CX_TEST_ASSERT(buf.size == 7);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
624 CX_TEST_ASSERT(memcmp(original, "test____XXXXXXXX", 16) == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
625 CX_TEST_ASSERT(memcmp(buf.space, "testest", 7) == 0);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
626 cxFree(buf.allocator, original);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
627 TEST_BUFFER_SHIFT_TEARDOWN(buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
628 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
629 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
630
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
631 static size_t mock_write_limited_rate(
890
54565fd74e74 move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents: 793
diff changeset
632 const void *ptr,
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
633 size_t size,
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
634 cx_attr_unused size_t nitems,
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
635 CxBuffer *buffer
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
636 ) {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
637 return cxBufferWrite(ptr, size, nitems > 2 ? 2 : nitems, buffer);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
638 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
639
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
640 CX_TEST(test_buffer_write_size_one_fit) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
641 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
642 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
643 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
644 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
645 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
646 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
647 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
648 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
649 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
650 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
651 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
652 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
653 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
654 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
655
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
656 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
657 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
658
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
659 CX_TEST(test_buffer_write_size_one_discard) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
660 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
661 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
662 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
663 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
664 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
665 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
666 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
667 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
668 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
669 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
670 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
671 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
672 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
673 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
674 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
675 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
676
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
677 CX_TEST(test_buffer_write_size_one_extend) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
678 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
679 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
680 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
681 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
682 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
683 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
684 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
685 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
686 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
687 CX_TEST_ASSERT(written == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
688 CX_TEST_ASSERT(buf.size == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
689 CX_TEST_ASSERT(buf.pos == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
690 CX_TEST_ASSERT(buf.capacity >= 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
691 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
692 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
693 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
694 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
695
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
696 CX_TEST(test_buffer_write_copy_on_write) {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
697 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
698 char original[16] = "preparedXXXXXXX\0";
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
699 cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
700 buf.capacity = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
701 buf.size = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
702 buf.pos = 0;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
703 const char *data = "testing";
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
704 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
705 size_t written = cxBufferWrite(data, 1, 7, &buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
706 CX_TEST_ASSERT(written == 7);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
707 CX_TEST_ASSERT(buf.size == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
708 CX_TEST_ASSERT(buf.pos == 7);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
709 CX_TEST_ASSERT(buf.capacity == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
710 CX_TEST_ASSERT(0 == memcmp(buf.space, "testingd", 8));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
711 CX_TEST_ASSERT(0 == memcmp(original, "preparedXXXXXXX\0", 16));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
712 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
713 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
714 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
715 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
716 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
717
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
718 CX_TEST(test_buffer_write_multibyte_fit) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
719 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
720 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
721 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
722 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
723 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
724 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
725 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
726 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
727 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
728 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
729 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
730 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
731 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
732 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
733 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
734 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
735
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
736 CX_TEST(test_buffer_write_multibyte_discard) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
737 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
738 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
739 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
740 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
741 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
742 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
743 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
744 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
745 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
746 // 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
747 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
748 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
749 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
750 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
751 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
752 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
753 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
754 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
755
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
756 CX_TEST(test_buffer_write_multibyte_extend) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
757 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
758 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
759 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
760 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
761 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
762 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
763 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
764 const char *data = "tester";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
765 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
766 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
767 // 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
768 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
769 CX_TEST_ASSERT(buf.size == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
770 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
771 CX_TEST_ASSERT(buf.capacity >= 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
772 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
773 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
774 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
775 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
776
1030
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
777 CX_TEST(test_buffer_append) {
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
778 CxBuffer buf;
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
779 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
780 memcpy(buf.space, "prepXXXX\0\0\0\0\0\0\0\0", 16);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
781 buf.capacity = 8;
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
782 buf.size = 6;
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
783 buf.pos = 4;
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
784 CX_TEST_DO {
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
785 size_t written = cxBufferAppend("testing", 1, 7, &buf);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
786 CX_TEST_ASSERT(written == 7);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
787 CX_TEST_ASSERT(buf.size == 13);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
788 CX_TEST_ASSERT(buf.pos == 4);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
789 CX_TEST_ASSERT(buf.capacity >= 13);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
790 CX_TEST_ASSERT(0 == memcmp(buf.space, "prepXXtesting", 13));
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
791 }
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
792 cxBufferDestroy(&buf);
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
793 }
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
794
1131
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
795 CX_TEST(test_buffer_append_flush) {
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
796 CxBuffer buf, target;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
797 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
798 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
799 memcpy(buf.space, "prepXXXX", 8);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
800 buf.capacity = 8;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
801 buf.size = 6;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
802 buf.pos = 4;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
803 CxBufferFlushConfig flush;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
804 flush.threshold = 0;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
805 flush.blksize = 4;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
806 flush.blkmax = 1;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
807 flush.target = &target;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
808 flush.wfunc = cxBufferWriteFunc;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
809 cxBufferEnableFlushing(&buf, flush);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
810 CX_TEST_DO{
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
811 size_t written = cxBufferAppend("testing", 1, 7, &buf);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
812 CX_TEST_ASSERT(written == 7);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
813 CX_TEST_ASSERT(buf.size == 7);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
814 CX_TEST_ASSERTM(buf.pos == 0, "position not correctly reset");
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
815 CX_TEST_ASSERT(buf.capacity == 8);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
816 CX_TEST_ASSERT(target.size == 6);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
817 CX_TEST_ASSERT(target.pos == 6);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
818 CX_TEST_ASSERT(0 == memcmp(buf.space, "testing", 7));
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
819 CX_TEST_ASSERT(0 == memcmp(target.space, "prepXX", 6));
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
820 // second test - position only shifted by one block
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
821 buf.pos = 6;
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
822 written = cxBufferAppend("foo", 1, 3, &buf);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
823 CX_TEST_ASSERT(written == 3);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
824 CX_TEST_ASSERT(buf.size == 6);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
825 CX_TEST_ASSERTM(buf.pos == 2, "position not correctly adjusted");
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
826 CX_TEST_ASSERT(buf.capacity == 8);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
827 CX_TEST_ASSERT(target.size == 10);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
828 CX_TEST_ASSERT(target.pos == 10);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
829 CX_TEST_ASSERT(0 == memcmp(buf.space, "ingfoo", 6));
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
830 CX_TEST_ASSERT(0 == memcmp(target.space, "prepXXtest", 10));
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
831 }
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
832 cxBufferDestroy(&buf);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
833 cxBufferDestroy(&target);
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
834 }
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
835
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
836 CX_TEST(test_buffer_put_fit) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
837 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
838 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
839 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
840 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
841 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
842 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
843 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
844 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
845 CX_TEST_ASSERT(buf.size == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
846 CX_TEST_ASSERT(buf.pos == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
847 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
848 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
849 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
850 cxBufferDestroy(&buf);
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_put_discard) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
854 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
855 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
856 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
857 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
858 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
859 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
860 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
861 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
862 CX_TEST_ASSERT(c == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
863 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
864 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
865 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
866 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
867 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
868 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
869 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
870
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
871 CX_TEST(test_buffer_put_extend) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
872 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
873 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
874 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
875 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
876 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
877 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
878 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
879 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
880 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
881 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
882 CX_TEST_ASSERT(buf.size == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
883 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
884 CX_TEST_ASSERT(buf.capacity >= 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
885 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
886 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
887 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
888 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
889
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
890 CX_TEST(test_buffer_put_copy_on_write) {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
891 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
892 char original[16] = "preparedXXXXXXX\0";
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
893 cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
894 buf.capacity = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
895 buf.size = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
896 buf.pos = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
897 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
898 int c = cxBufferPut(&buf, 0x200 | 'a');
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
899 CX_TEST_ASSERT(c == EOF);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
900 CX_TEST_ASSERT(buf.size == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
901 CX_TEST_ASSERT(buf.pos == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
902 CX_TEST_ASSERT(buf.capacity == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
903 CX_TEST_ASSERT(0 == memcmp(buf.space, "prepared", 8));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
904 // discarded, no write happend!
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
905 CX_TEST_ASSERT(original == buf.space);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
906 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
907 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
908 // now actually write somewhere
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
909 buf.pos = 2;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
910 c = cxBufferPut(&buf, 0x200 | 'a');
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
911 CX_TEST_ASSERT(c == 'a');
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
912 CX_TEST_ASSERT(buf.size == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
913 CX_TEST_ASSERT(buf.pos == 3);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
914 CX_TEST_ASSERT(buf.capacity == 8);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
915 CX_TEST_ASSERT(0 == memcmp(buf.space, "prapared", 8));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
916 CX_TEST_ASSERT(original != buf.space);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
917 CX_TEST_ASSERT(0 == memcmp(original, "preparedXXXXXXX\0", 16));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
918 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
919 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
920 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
921 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
922 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
923
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
924 CX_TEST(test_buffer_put_string_fit) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
925 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
926 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
927 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
928 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
929 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
930 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
931 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
932 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
933 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
934 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
935 CX_TEST_ASSERT(buf.pos == 8);
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(0 == memcmp(buf.space, "preptest", 8));
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
938 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
939 cxBufferDestroy(&buf);
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
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
942 CX_TEST(test_buffer_put_string_discard) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
943 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
944 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
945 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
946 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
947 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
948 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
949 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
950 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
951 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
952 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
953 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
954 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
955 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
956 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
957 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
958 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
959
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
960 CX_TEST(test_buffer_put_string_extend) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
961 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
962 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
963 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
964 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
965 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
966 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
967 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
968 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
969 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
970 CX_TEST_ASSERT(written == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
971 CX_TEST_ASSERT(buf.size == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
972 CX_TEST_ASSERT(buf.pos == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
973 CX_TEST_ASSERT(buf.capacity >= 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
974 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
975 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
976 cxBufferDestroy(&buf);
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
977 }
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
978
1028
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
979 CX_TEST(test_buffer_put_string_copy_on_extend) {
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
980 CxTestingAllocator talloc;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
981 cx_testing_allocator_init(&talloc);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
982 const CxAllocator *alloc = &talloc.base;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
983 CxBuffer buf;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
984 char original[16] = "preparedXXXXXXX\0";
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
985 CX_TEST_DO {
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
986 cxBufferInit(&buf, original, 16, alloc, CX_BUFFER_COPY_ON_EXTEND);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
987 buf.capacity = 8;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
988 buf.size = buf.pos = 4;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
989 size_t written = cxBufferPutString(&buf, "test");
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
990 CX_TEST_ASSERT(written == 4);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
991 CX_TEST_ASSERT(buf.size == 8);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
992 CX_TEST_ASSERT(buf.pos == 8);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
993 CX_TEST_ASSERT(buf.capacity == 8);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
994 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest", 8));
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
995 CX_TEST_ASSERT(original == buf.space);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
996 written = cxBufferPutString(&buf, "ing");
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
997 CX_TEST_ASSERT(written == 3);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
998 CX_TEST_ASSERT(buf.size == 11);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
999 CX_TEST_ASSERT(buf.pos == 11);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1000 CX_TEST_ASSERT(buf.capacity >= 11);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1001 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1002 CX_TEST_ASSERT(original != buf.space);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1003 CX_TEST_ASSERT(0 == memcmp(original, "preptestXXXXXXX\0", 16));
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1004 CX_TEST_ASSERT(!cx_testing_allocator_verify(&talloc));
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1005 cxBufferDestroy(&buf);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1006 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1007 cx_testing_allocator_destroy(&talloc);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1008 }
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1009 }
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1010
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1011 CX_TEST(test_buffer_put_string_copy_on_write) {
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1012 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1013 char original[16] = "preparedXXXXXXX\0";
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1014 cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1015 buf.capacity = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1016 buf.size = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1017 buf.pos = 4;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1018 buf.flags |= CX_BUFFER_AUTO_EXTEND;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1019 const char *data = "testing";
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1020 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1021 size_t written = cxBufferPutString(&buf, data);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1022 CX_TEST_ASSERT(written == 7);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1023 CX_TEST_ASSERT(buf.size == 11);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1024 CX_TEST_ASSERT(buf.pos == 11);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1025 CX_TEST_ASSERT(buf.capacity >= 11);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1026 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptesting", 11));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1027 CX_TEST_ASSERT(original != buf.space);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1028 CX_TEST_ASSERT(0 == memcmp(original, "preparedXXXXXXX\0", 16));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1029 CX_TEST_ASSERT(0 == (buf.flags & CX_BUFFER_COPY_ON_WRITE));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1030 CX_TEST_ASSERT(0 != (buf.flags & CX_BUFFER_FREE_CONTENTS));
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1031 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1032 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1033 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1034
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1035 CX_TEST(test_buffer_terminate) {
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1036 CxBuffer buf;
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1037 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1038 memcpy(buf.space, "prepAAAAAA\0\0\0\0\0\0", 16);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1039 buf.capacity = 8;
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1040 buf.size = buf.pos = 4;
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1041 const char *data = "test";
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1042 CX_TEST_DO {
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1043 size_t written = cxBufferPutString(&buf, data);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1044 CX_TEST_ASSERT(0 != cxBufferTerminate(&buf));
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1045 CX_TEST_ASSERT(written == 4);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1046 CX_TEST_ASSERT(buf.size == 8);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1047 CX_TEST_ASSERT(buf.pos == 8);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1048 CX_TEST_ASSERT(buf.capacity == 8);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1049 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptestAA", 10));
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1050 buf.flags |= CX_BUFFER_AUTO_EXTEND;
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1051 CX_TEST_ASSERT(0 == cxBufferTerminate(&buf));
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1052 CX_TEST_ASSERT(buf.size == 8);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1053 CX_TEST_ASSERT(buf.pos == 8);
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1054 CX_TEST_ASSERT(buf.capacity > 8);
1023
989e144c912a fix out of range access in test on platforms which are actually shrinking the buffer
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1055 CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest\0", 9));
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1056 }
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1057 cxBufferDestroy(&buf);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1058 }
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 CX_TEST(test_buffer_write_size_overflow) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1061 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1062 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
1063 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
1064 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1065 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1066 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1067 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1068 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
1069 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1070 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1071 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1072 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1073 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
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_write_capacity_overflow) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1079 CxBuffer buf;
793
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, "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
1082 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1083 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1084 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1085 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1086 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1087 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
1088 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1089 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1090 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1091 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1092 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
1093 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1094 cxBufferDestroy(&buf);
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
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1097 CX_TEST(test_buffer_write_only_overwrite) {
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1098 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1099 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
1100 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
1101 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1102 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1103 buf.size = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1104 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1105 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1106 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
1107 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1108 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1109 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1110 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1111 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
1112 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1113 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1114 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1115
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1116 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
1117 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1118 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1119 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1120 memset(buf.space, 0, 8);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1121 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1122 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1123 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1124 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1125 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1126 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1127 flush.target = &target;
1112
22dc2163fffd add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents: 1110
diff changeset
1128 flush.wfunc = cxBufferWriteFunc;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1129 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1130 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
1131 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1132 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1133 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1134 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1135 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1136 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1137 CX_TEST_ASSERT(written == 5);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1138 CX_TEST_ASSERT(buf.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1139 CX_TEST_ASSERT(buf.size == 5);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1140 CX_TEST_ASSERT(buf.capacity == 8);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1141 CX_TEST_ASSERT(target.pos == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1142 CX_TEST_ASSERT(target.size == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1143 CX_TEST_ASSERT(0 == memcmp(buf.space, "hello", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1144 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfoo", 7));
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1145 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1146 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1147 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1148 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1149
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1150 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
1151 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1152 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1153 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1154 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1155 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1156 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1157 flush.threshold = 12;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1158 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1159 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1160 flush.target = &target;
1112
22dc2163fffd add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents: 1110
diff changeset
1161 flush.wfunc = cxBufferWriteFunc;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1162 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1163 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
1164 CX_TEST_ASSERT(written == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1165 CX_TEST_ASSERT(buf.pos == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1166 CX_TEST_ASSERT(buf.size == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1167 CX_TEST_ASSERT(buf.capacity >= 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1168 CX_TEST_ASSERT(buf.capacity <= 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1169 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1170 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1171 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1172 CX_TEST_ASSERT(written == 5);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1173 CX_TEST_ASSERT(buf.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1174 CX_TEST_ASSERT(buf.size == 5);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1175 CX_TEST_ASSERT(buf.capacity <= 12);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1176 CX_TEST_ASSERT(target.pos == 10);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1177 CX_TEST_ASSERT(target.size == 10);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1178 CX_TEST_ASSERT(0 == memcmp(buf.space, "hello", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1179 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfoobar", 10));
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1180 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1181 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1182 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1183 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1184
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1185 CX_TEST(test_buffer_write_flush_rate_limited_and_buffer_too_small) {
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1186 // the idea is that the target only accepts two bytes and
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1187 // then gives up... accepts another two bytes, gives up, etc.
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1188 // and at the same time, the written string is too large for
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1189 // the buffer (buffer can take 8, we want to write 13)
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1190 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1191 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1192 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1193 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1194 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1195 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1196 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1197 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1198 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1199 flush.target = &target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1200 flush.wfunc = (cx_write_func)mock_write_limited_rate;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1201 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1202 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
1203 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1204 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1205 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1206 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1207 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1208 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
1209 // " 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
1210 CX_TEST_ASSERT(written == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1211 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1212 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1213 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1214 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
1215 CX_TEST_ASSERT(target.pos == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1216 CX_TEST_ASSERT(target.size == 13);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1217 CX_TEST_ASSERT(target.capacity >= 13);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1218 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
1219 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1220 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1221 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1222 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1223
1129
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1224 CX_TEST(test_buffer_write_flush_multibyte) {
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1225 // this test case tests that flushing works correctly even when the
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1226 // contents in the buffer are currently not aligned with the item size
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1227 CxBuffer buf, target;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1228 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1229 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1230 memset(buf.space, 0, 8);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1231 cxBufferPutString(&buf, "pre");
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1232 CX_TEST_DO {
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1233 CxBufferFlushConfig flush;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1234 flush.threshold = 0;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1235 flush.blksize = 4; // test blksize that is not aligned
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1236 flush.blkmax = 2; // test with two blocks
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1237 flush.target = &target;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1238 flush.wfunc = cxBufferWriteFunc;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1239 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1240 // first case: string fits after flush
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1241 size_t written = cxBufferWrite("foobar", 3, 2, &buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1242 CX_TEST_ASSERT(written == 2);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1243 CX_TEST_ASSERT(buf.pos == 6);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1244 CX_TEST_ASSERT(buf.size == 6);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1245 CX_TEST_ASSERT(target.pos == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1246 CX_TEST_ASSERT(target.size == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1247 CX_TEST_ASSERT(0 == memcmp(buf.space, "foobar", 6));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1248 CX_TEST_ASSERT(0 == memcmp(target.space, "pre", 3));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1249 // second case: string does not fit, data is relayed, but only two blocks!
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1250 written = cxBufferWrite("bazfooBAR", 3, 3, &buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1251 CX_TEST_ASSERT(written == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1252 CX_TEST_ASSERT(buf.pos == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1253 CX_TEST_ASSERT(buf.size == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1254 CX_TEST_ASSERT(target.pos == 15);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1255 CX_TEST_ASSERT(target.size == 15);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1256 CX_TEST_ASSERT(0 == memcmp(buf.space, "BAR", 3));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1257 CX_TEST_ASSERT(0 == memcmp(target.space, "prefoobarbazfoo", 15));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1258 // third case: everything can be relayed, block size is large enough
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1259 buf.flush->blkmax = 3;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1260 written = cxBufferWrite("abcdef012", 3, 3, &buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1261 CX_TEST_ASSERT(written == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1262 CX_TEST_ASSERT(buf.pos == 0);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1263 CX_TEST_ASSERT(buf.size == 0);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1264 CX_TEST_ASSERT(target.pos == 27);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1265 CX_TEST_ASSERT(target.size == 27);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1266 CX_TEST_ASSERT(0 == memcmp(target.space, "prefoobarbazfooBARabcdef012", 27));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1267 }
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1268 cxBufferDestroy(&buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1269 cxBufferDestroy(&target);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1270 }
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1271
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1272 CX_TEST(test_buffer_write_flush_misaligned) {
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1273 // this test case tests that flushing works correctly even when the
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1274 // contents in the buffer are currently not aligned with the item size
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1275 CxBuffer buf, target;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1276 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1277 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1278 memset(buf.space, 0, 8);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1279 cxBufferPutString(&buf, "prep");
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1280 CX_TEST_DO {
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1281 CxBufferFlushConfig flush;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1282 flush.threshold = 0;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1283 flush.blksize = 32;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1284 flush.blkmax = 1;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1285 flush.target = &target;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1286 flush.wfunc = cxBufferWriteFunc;
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1287 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1288 // first case: string fits after flush
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1289 size_t written = cxBufferWrite("foobar", 3, 2, &buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1290 CX_TEST_ASSERT(written == 2);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1291 CX_TEST_ASSERT(buf.pos == 7);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1292 CX_TEST_ASSERT(buf.size == 7);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1293 CX_TEST_ASSERT(target.pos == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1294 CX_TEST_ASSERT(target.size == 3);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1295 CX_TEST_ASSERT(0 == memcmp(buf.space, "pfoobar", 7));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1296 CX_TEST_ASSERT(0 == memcmp(target.space, "pre", 3));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1297 // second case: string does not fit, relaying not possible due to misalignment
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1298 written = cxBufferWrite("bazfoobar", 3, 3, &buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1299 CX_TEST_ASSERT(written == 0);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1300 CX_TEST_ASSERT(buf.pos == 1);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1301 CX_TEST_ASSERT(buf.size == 1);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1302 CX_TEST_ASSERT(target.pos == 9);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1303 CX_TEST_ASSERT(target.size == 9);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1304 CX_TEST_ASSERT(0 == memcmp(buf.space, "r", 1));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1305 CX_TEST_ASSERT(0 == memcmp(target.space, "prepfooba", 9));
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1306 }
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1307 cxBufferDestroy(&buf);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1308 cxBufferDestroy(&target);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1309 }
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1310
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1311 CX_TEST(test_buffer_flush) {
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1312 CxBuffer buf, target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1313 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1314 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1315 cxBufferPutString(&buf, "prepare");
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1316 CX_TEST_DO {
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1317 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1318 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1319 flush.blksize = 2;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1320 flush.blkmax = 2;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1321 flush.target = &target;
1112
22dc2163fffd add convenience macros to avoid a fptr cast for cxBufferRead and cxBufferWrite
Mike Becker <universe@uap-core.de>
parents: 1110
diff changeset
1322 flush.wfunc = cxBufferWriteFunc;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1323 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1324 CX_TEST_ASSERT(buf.size == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1325 buf.pos = 5;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1326 size_t flushed = cxBufferFlush(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1327 CX_TEST_ASSERT(flushed == flush.blkmax * flush.blksize);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1328 CX_TEST_ASSERT(buf.pos == 1);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1329 CX_TEST_ASSERT(buf.size == 3);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1330 CX_TEST_ASSERT(target.pos == 4);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1331 CX_TEST_ASSERT(target.size == 4);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1332 CX_TEST_ASSERT(0 == memcmp(buf.space, "are", 3));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1333 CX_TEST_ASSERT(0 == memcmp(target.space, "prep", 4));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1334 flushed = cxBufferFlush(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1335 CX_TEST_ASSERT(flushed == 1);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1336 CX_TEST_ASSERT(buf.pos == 0);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1337 CX_TEST_ASSERT(buf.size == 2);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1338 CX_TEST_ASSERT(target.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1339 CX_TEST_ASSERT(target.size == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1340 CX_TEST_ASSERT(0 == memcmp(buf.space, "re", 2));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1341 CX_TEST_ASSERT(0 == memcmp(target.space, "prepa", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1342 }
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1343 cxBufferDestroy(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1344 cxBufferDestroy(&target);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1345 }
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1346
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1347 CX_TEST(test_buffer_get) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1348 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1349 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
1350 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
1351 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1352 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1353 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1354 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1355 CX_TEST_ASSERT(cxBufferGet(&buf) == 'm');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1356 CX_TEST_ASSERT(cxBufferGet(&buf) == 'e');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1357 CX_TEST_ASSERT(cxBufferGet(&buf) == ' ');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1358 CX_TEST_ASSERT(cxBufferGet(&buf) == 'd');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1359 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1360 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1361 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1362 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1363
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1364 CX_TEST(test_buffer_get_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1365 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1366 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
1367 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
1368 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1369 buf.pos = buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1370 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1371 CX_TEST_ASSERT(cxBufferGet(&buf) == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1372 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1373 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1374 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1375
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1376 CX_TEST(test_buffer_read) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1377 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1378 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
1379 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
1380 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1381 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1382 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1383 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1384 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1385 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
1386 CX_TEST_ASSERT(read == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1387 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
1388 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1389 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1390 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1391 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1392
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1393 CX_TEST(test_buffer_read_oob) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1394 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1395 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
1396 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
1397 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1398 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1399 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1400 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1401 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1402 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
1403 CX_TEST_ASSERT(read == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1404 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
1405 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1406 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1407 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1408 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1409
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1410 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
1411 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1412 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
1413 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
1414 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1415 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1416 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1417 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1418 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1419 target[2] = '\0';
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1420 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
1421 CX_TEST_ASSERT(read == 1);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1422 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
1423 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1424 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1425 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1426 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1427
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1428 CX_TEST(test_buffer_read_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1429 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1430 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
1431 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
1432 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1433 buf.size = buf.pos = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1434 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1435 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1436 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
1437 CX_TEST_ASSERT(read == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1438 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1439 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1440 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1441 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1442
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1443 CxTestSuite *cx_test_suite_buffer(void) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1444 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
1445
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1446 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
1447 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
1448 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
1449 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
1450 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
1451 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
1452 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
1453 cx_test_register(suite, test_buffer_clear);
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1454 cx_test_register(suite, test_buffer_clear_copy_on_write);
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1455 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
1456 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
1457 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
1458 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
1459 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
1460 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
1461 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
1462 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
1463 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
1464 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
1465 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
1466 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
1467 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
1468 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
1469 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
1470 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
1471 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
1472 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
1473 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
1474 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
1475 cx_test_register(suite, test_buffer_shift_left_offset_interface);
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1476 cx_test_register(suite, test_buffer_shift_left_copy_on_write);
792
3ca984931e1d migrate more buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 789
diff changeset
1477 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
1478 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
1479 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
1480 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
1481 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
1482 cx_test_register(suite, test_buffer_shift_right_offset_interface);
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1483 cx_test_register(suite, test_buffer_shift_right_copy_on_write);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1484 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
1485 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
1486 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
1487 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
1488 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
1489 cx_test_register(suite, test_buffer_write_multibyte_extend);
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1490 cx_test_register(suite, test_buffer_write_copy_on_write);
1030
06091e067bee add cxBufferAppend() - fixes #534
Mike Becker <universe@uap-core.de>
parents: 1028
diff changeset
1491 cx_test_register(suite, test_buffer_append);
1131
644f77f903b1 fix cxBufferAppend() not adjusting position after flush
Mike Becker <universe@uap-core.de>
parents: 1129
diff changeset
1492 cx_test_register(suite, test_buffer_append_flush);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1493 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
1494 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
1495 cx_test_register(suite, test_buffer_put_extend);
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1496 cx_test_register(suite, test_buffer_put_copy_on_write);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1497 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
1498 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
1499 cx_test_register(suite, test_buffer_put_string_extend);
1028
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1500 cx_test_register(suite, test_buffer_put_string_copy_on_extend);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
1501 cx_test_register(suite, test_buffer_put_string_copy_on_write);
1006
8ee818fa29f7 fix stupid initialization of target buffer in tests where no flush target is used
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
1502 cx_test_register(suite, test_buffer_terminate);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1503 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
1504 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
1505 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
1506 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
1507 cx_test_register(suite, test_buffer_write_flush_at_threshold);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1508 cx_test_register(suite, test_buffer_write_flush_rate_limited_and_buffer_too_small);
1129
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1509 cx_test_register(suite, test_buffer_write_flush_multibyte);
cc60b7d07912 fix #566 by changing the spec (pro-move 8)
Mike Becker <universe@uap-core.de>
parents: 1112
diff changeset
1510 cx_test_register(suite, test_buffer_write_flush_misaligned);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1511 cx_test_register(suite, test_buffer_flush);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1512 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
1513 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
1514 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
1515 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
1516 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
1517 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
1518
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1519 return suite;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1520 }

mercurial