tests/test_buffer.c

Sun, 05 Jan 2025 18:19:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 05 Jan 2025 18:19:42 +0100
changeset 1110
a0e9be7ed131
parent 1030
06091e067bee
child 1112
22dc2163fffd
permissions
-rw-r--r--

re-implement flushing

fixes #542 fixes #543

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
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
795 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
796 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
797 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
798 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
799 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
800 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
801 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
802 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
803 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
804 CX_TEST_ASSERT(buf.size == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
805 CX_TEST_ASSERT(buf.pos == 5);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
806 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
807 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
808 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
809 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
810 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
811
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
812 CX_TEST(test_buffer_put_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
813 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
814 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
815 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
816 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
817 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
818 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
819 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
820 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
821 CX_TEST_ASSERT(c == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
822 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
823 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
824 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
825 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
826 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
827 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
828 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
829
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
830 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
831 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
832 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
833 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
834 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
835 buf.size = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
836 buf.pos = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
837 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
838 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
839 int c = cxBufferPut(&buf, 0x200 | 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
840 CX_TEST_ASSERT(c == 'a');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
841 CX_TEST_ASSERT(buf.size == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
842 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
843 CX_TEST_ASSERT(buf.capacity >= 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
844 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
845 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
846 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
847 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
848
1024
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
849 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
850 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
851 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
852 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
853 buf.capacity = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
854 buf.size = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
855 buf.pos = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
856 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
857 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
858 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
859 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
860 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
861 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
862 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
863 // 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
864 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
865 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
866 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
867 // 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
868 buf.pos = 2;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
869 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
870 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
871 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
872 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
873 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
874 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
875 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
876 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
877 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
878 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
879 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
880 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
881 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
882
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
883 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
884 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
885 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
886 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
887 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
888 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
889 const char *data = "test";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
890 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
891 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
892 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
893 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
894 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
895 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
896 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
897 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
898 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
899 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
900
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
901 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
902 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
903 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
904 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
905 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
906 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
907 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
908 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
909 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
910 CX_TEST_ASSERT(written == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
911 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
912 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
913 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
914 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
915 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
916 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
917 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
918
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
919 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
920 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
921 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
922 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
923 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
924 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
925 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
926 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
927 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
928 size_t written = cxBufferPutString(&buf, data);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
929 CX_TEST_ASSERT(written == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
930 CX_TEST_ASSERT(buf.size == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
931 CX_TEST_ASSERT(buf.pos == 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
932 CX_TEST_ASSERT(buf.capacity >= 11);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
933 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
934 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
935 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
936 }
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
937
1028
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
938 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
939 CxTestingAllocator talloc;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
940 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
941 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
942 CxBuffer buf;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
943 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
944 CX_TEST_DO {
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
945 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
946 buf.capacity = 8;
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
947 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
948 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
949 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
950 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
951 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
952 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
953 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
954 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
955 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
956 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
957 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
958 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
959 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
960 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
961 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
962 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
963 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
964 cxBufferDestroy(&buf);
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
965 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
966 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
967 }
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
968 }
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
969
3e4905241838 add copy-on-extend feature to UCX buffer - fixes #533
Mike Becker <universe@uap-core.de>
parents: 1026
diff changeset
970 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
971 CxBuffer buf;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
972 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
973 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
974 buf.capacity = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
975 buf.size = 8;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
976 buf.pos = 4;
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
977 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
978 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
979 CX_TEST_DO {
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
980 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
981 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
982 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
983 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
984 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
985 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
986 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
987 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
988 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
989 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
990 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
991 cxBufferDestroy(&buf);
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
992 }
8f99f6c28bd3 add copy-on-write feature to UCX buffer - fixes #531
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
993
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
994 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
995 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
996 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
997 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
998 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
999 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
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 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
1014 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
1015 }
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
1016 cxBufferDestroy(&buf);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1017 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1018
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1019 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
1020 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1021 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
1022 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
1023 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1024 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1025 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1026 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1027 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
1028 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1029 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1030 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1031 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1032 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
1033 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1034 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1035 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1036
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1037 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
1038 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1039 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
1040 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
1041 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1042 buf.size = buf.pos = 4;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1043 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1044 const char *data = "testing";
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1045 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1046 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
1047 CX_TEST_ASSERT(written == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1048 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1049 CX_TEST_ASSERT(buf.pos == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1050 CX_TEST_ASSERT(buf.size == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1051 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
1052 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1053 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1054 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1055
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1056 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
1057 CxBuffer buf;
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1058 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
1059 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
1060 buf.capacity = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1061 buf.pos = 3;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1062 buf.size = 8;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1063 buf.flags |= CX_BUFFER_AUTO_EXTEND;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1064 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1065 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
1066 CX_TEST_ASSERT(written == 2);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1067 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1068 CX_TEST_ASSERT(buf.size == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1069 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1070 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
1071 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1072 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1073 }
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 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
1076 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1077 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1078 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1079 memset(buf.space, 0, 8);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1080 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1081 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1082 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1083 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1084 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1085 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1086 flush.target = &target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1087 flush.wfunc = (cx_write_func)cxBufferWrite;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1088 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
1089 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
1090 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1091 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1092 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1093 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1094 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1095 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1096 CX_TEST_ASSERT(written == 5);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1097 CX_TEST_ASSERT(buf.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1098 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
1099 CX_TEST_ASSERT(buf.capacity == 8);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1100 CX_TEST_ASSERT(target.pos == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1101 CX_TEST_ASSERT(target.size == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1102 CX_TEST_ASSERT(0 == memcmp(buf.space, "hello", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1103 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
1104 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1105 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1106 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1107 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1108
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1109 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
1110 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1111 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1112 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1113 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1114 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1115 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1116 flush.threshold = 12;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1117 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1118 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1119 flush.target = &target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1120 flush.wfunc = (cx_write_func)cxBufferWrite;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1121 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
1122 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
1123 CX_TEST_ASSERT(written == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1124 CX_TEST_ASSERT(buf.pos == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1125 CX_TEST_ASSERT(buf.size == 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1126 CX_TEST_ASSERT(buf.capacity >= 10);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1127 CX_TEST_ASSERT(buf.capacity <= 12);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1128 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1129 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1130 written = cxBufferWrite("hello", 1, 5, &buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1131 CX_TEST_ASSERT(written == 5);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1132 CX_TEST_ASSERT(buf.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1133 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
1134 CX_TEST_ASSERT(buf.capacity <= 12);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1135 CX_TEST_ASSERT(target.pos == 10);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1136 CX_TEST_ASSERT(target.size == 10);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1137 CX_TEST_ASSERT(0 == memcmp(buf.space, "hello", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1138 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
1139 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1140 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1141 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1142 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1143
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1144 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
1145 // 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
1146 // then gives up... accepts another two bytes, gives up, etc.
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1147 // 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
1148 // 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
1149 CxBuffer buf, target;
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1150 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1151 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1152 cxBufferPutString(&buf, "prep");
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1153 CX_TEST_DO {
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1154 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1155 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1156 flush.blksize = 32;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1157 flush.blkmax = 1;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1158 flush.target = &target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1159 flush.wfunc = (cx_write_func)mock_write_limited_rate;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1160 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
1161 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
1162 CX_TEST_ASSERT(written == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1163 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1164 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1165 CX_TEST_ASSERT(target.pos == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1166 CX_TEST_ASSERT(target.size == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1167 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
1168 // " 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
1169 CX_TEST_ASSERT(written == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1170 CX_TEST_ASSERT(buf.pos == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1171 CX_TEST_ASSERT(buf.size == 7);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1172 CX_TEST_ASSERT(buf.capacity == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1173 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
1174 CX_TEST_ASSERT(target.pos == 13);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1175 CX_TEST_ASSERT(target.size == 13);
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1176 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
1177 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
1178 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1179 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1180 cxBufferDestroy(&target);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1181 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1182
1110
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1183 CX_TEST(test_buffer_flush) {
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1184 CxBuffer buf, target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1185 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1186 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1187 cxBufferPutString(&buf, "prepare");
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1188 CX_TEST_DO {
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1189 CxBufferFlushConfig flush;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1190 flush.threshold = 0;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1191 flush.blksize = 2;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1192 flush.blkmax = 2;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1193 flush.target = &target;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1194 flush.wfunc = (cx_write_func)cxBufferWrite;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1195 CX_TEST_ASSERT(0 == cxBufferEnableFlushing(&buf, flush));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1196 CX_TEST_ASSERT(buf.size == 7);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1197 buf.pos = 5;
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1198 size_t flushed = cxBufferFlush(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1199 CX_TEST_ASSERT(flushed == flush.blkmax * flush.blksize);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1200 CX_TEST_ASSERT(buf.pos == 1);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1201 CX_TEST_ASSERT(buf.size == 3);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1202 CX_TEST_ASSERT(target.pos == 4);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1203 CX_TEST_ASSERT(target.size == 4);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1204 CX_TEST_ASSERT(0 == memcmp(buf.space, "are", 3));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1205 CX_TEST_ASSERT(0 == memcmp(target.space, "prep", 4));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1206 flushed = cxBufferFlush(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1207 CX_TEST_ASSERT(flushed == 1);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1208 CX_TEST_ASSERT(buf.pos == 0);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1209 CX_TEST_ASSERT(buf.size == 2);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1210 CX_TEST_ASSERT(target.pos == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1211 CX_TEST_ASSERT(target.size == 5);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1212 CX_TEST_ASSERT(0 == memcmp(buf.space, "re", 2));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1213 CX_TEST_ASSERT(0 == memcmp(target.space, "prepa", 5));
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1214 }
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1215 cxBufferDestroy(&buf);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1216 cxBufferDestroy(&target);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1217 }
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1218
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1219 CX_TEST(test_buffer_get) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1220 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1221 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
1222 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
1223 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1224 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1225 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1226 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1227 CX_TEST_ASSERT(cxBufferGet(&buf) == 'm');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1228 CX_TEST_ASSERT(cxBufferGet(&buf) == 'e');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1229 CX_TEST_ASSERT(cxBufferGet(&buf) == ' ');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1230 CX_TEST_ASSERT(cxBufferGet(&buf) == 'd');
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1231 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1232 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1233 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1234 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1235
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1236 CX_TEST(test_buffer_get_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1237 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1238 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
1239 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
1240 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1241 buf.pos = buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1242 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1243 CX_TEST_ASSERT(cxBufferGet(&buf) == EOF);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1244 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1245 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1246 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1247
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1248 CX_TEST(test_buffer_read) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1249 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1250 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
1251 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
1252 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1253 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1254 buf.pos = 2;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1255 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1256 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1257 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
1258 CX_TEST_ASSERT(read == 4);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1259 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
1260 CX_TEST_ASSERT(buf.pos == 6);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1261 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1262 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1263 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1264
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1265 CX_TEST(test_buffer_read_oob) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1266 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1267 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
1268 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
1269 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1270 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1271 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1272 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1273 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1274 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
1275 CX_TEST_ASSERT(read == 3);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1276 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
1277 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1278 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1279 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1280 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1281
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1282 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
1283 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1284 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
1285 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
1286 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1287 buf.size = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1288 buf.pos = 6;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1289 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1290 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1291 target[2] = '\0';
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1292 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
1293 CX_TEST_ASSERT(read == 1);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1294 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
1295 CX_TEST_ASSERT(buf.pos == 8);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1296 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1297 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1298 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1299
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1300 CX_TEST(test_buffer_read_eof) {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1301 CxBuffer buf;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1302 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
1303 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
1304 buf.capacity = 12;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1305 buf.size = buf.pos = 9;
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1306 CX_TEST_DO {
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1307 char target[4];
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1308 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
1309 CX_TEST_ASSERT(read == 0);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1310 CX_TEST_ASSERT(buf.pos == 9);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1311 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1312 cxBufferDestroy(&buf);
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1313 }
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1314
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1315 CxTestSuite *cx_test_suite_buffer(void) {
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1316 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
1317
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1318 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
1319 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
1320 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
1321 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
1322 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
1323 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
1324 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
1325 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
1326 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
1327 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
1328 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
1329 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
1330 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
1331 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
1332 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
1333 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
1334 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
1335 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341 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
1342 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
1343 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
1344 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
1345 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
1346 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
1347 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
1348 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
1349 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
1350 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
1351 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
1352 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
1353 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
1354 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
1355 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
1356 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
1357 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
1358 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
1359 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
1360 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
1361 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
1362 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
1363 cx_test_register(suite, test_buffer_append);
793
db1c8dfe403a migrate remaining buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents: 792
diff changeset
1364 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
1365 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
1366 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
1367 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
1368 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
1369 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
1370 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
1371 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
1372 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
1373 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
1374 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
1375 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
1376 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
1377 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
1378 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
1379 cx_test_register(suite, test_buffer_write_flush_rate_limited_and_buffer_too_small);
a0e9be7ed131 re-implement flushing
Mike Becker <universe@uap-core.de>
parents: 1030
diff changeset
1380 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
1381 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
1382 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
1383 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
1384 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
1385 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
1386 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
1387
789
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1388 return suite;
9b2f5661bebd begin migration of buffer tests - relates to #342
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1389 }

mercurial