tests/test_buffer.c

Tue, 10 Dec 2024 00:09:55 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 10 Dec 2024 00:09:55 +0100
changeset 1006
8ee818fa29f7
parent 985
68754c7de906
child 1007
81b2986d2b04
permissions
-rw-r--r--

fix stupid initialization of target buffer in tests where no flush target is used

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

mercurial