Wed, 16 May 2018 19:27:45 +0200
adds scstr_t to modules.md + fixes parenthesis bug in sstrsplit_a macro
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
259 | 4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
5 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
8 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
11 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
15 | * |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
29 | #include "buffer_tests.h" |
230
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
30 | #include <stdint.h> |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
31 | |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
32 | UCX_TEST(test_ucx_buffer_new) { |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
33 | UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
34 | UcxBuffer *b2 = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
35 | UCX_TEST_BEGIN |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
36 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
37 | UCX_TEST_ASSERT(b->capacity==16, "wrong capacity"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
38 | UCX_TEST_ASSERT(b2->capacity==32, "wrong capacity"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
39 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
40 | UCX_TEST_ASSERT(b->size==0, "wrong size"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
41 | UCX_TEST_ASSERT(b2->size==0, "wrong size"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
42 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
43 | UCX_TEST_ASSERT(b->pos==0, "wrong position"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
44 | UCX_TEST_ASSERT(b2->pos==0, "wrong position"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
45 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
46 | UCX_TEST_ASSERT(b->flags==(UCX_BUFFER_AUTOEXTEND|UCX_BUFFER_AUTOFREE), |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
47 | "wrong flags for autoextending buffer"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
48 | UCX_TEST_ASSERT(b2->flags==UCX_BUFFER_AUTOFREE, |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
49 | "wrong flags for default bufer"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
50 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
51 | UCX_TEST_END |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
52 | ucx_buffer_free(b2); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
53 | ucx_buffer_free(b); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
54 | } |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
55 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
56 | UCX_TEST(test_ucx_buffer_new_prealloc) { |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
57 | char* test = (char*) malloc(16); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
58 | UcxBuffer *b = ucx_buffer_new(test, 16, UCX_BUFFER_DEFAULT); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
59 | UCX_TEST_BEGIN |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
60 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
61 | UCX_TEST_ASSERT(b->capacity==16, "wrong capacity"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
62 | UCX_TEST_ASSERT(b->size==0, "wrong size"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
63 | UCX_TEST_ASSERT(b->pos==0, "wrong position"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
64 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
65 | UCX_TEST_ASSERT(b->flags==0, "wrong flags - all should be cleared"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
66 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
67 | UCX_TEST_END |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
68 | free(test); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
69 | ucx_buffer_free(b); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
70 | } |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
71 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
72 | UCX_TEST(test_ucx_buffer_eof) { |
185
a48428642b4e
added stack implementation + added g++ config and added some fixes for C++
Mike Becker <universe@uap-core.de>
parents:
177
diff
changeset
|
73 | char *test = (char*)"0123456789ABCDEF"; |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
74 | UcxBuffer *b = ucx_buffer_new(test, 16, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
75 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
76 | b->pos = 9; b->size = 10; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
77 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), "false positive"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
78 | b->pos = 10; b->size = 10; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
79 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "pos == size should be EOF"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
80 | b->pos = 11; b->size = 10; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
81 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "false negative"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
82 | UCX_TEST_END |
227
740fbd7bab71
fixes memory leak in test_ucx_buffer_eof
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
83 | ucx_buffer_free(b); |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
84 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
85 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
86 | UCX_TEST(test_ucx_buffer_seek_overflow) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
87 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
88 | b->size = 32; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
89 | int r; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
90 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
91 | UCX_TEST_BEGIN |
218
b20d6088795c
fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
92 | const size_t sizemax = (size_t)-1; |
b20d6088795c
fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
93 | size_t bigpos = sizemax - 5000; |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
94 | b->pos = bigpos; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
95 | r = ucx_buffer_seek(b, 5016, SEEK_CUR); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
96 | UCX_TEST_ASSERT(r != 0, "seek cur overflow"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
97 | UCX_TEST_ASSERT(b->pos == bigpos, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
98 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
99 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
100 | b->pos = 0; |
230
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
101 | b->size = (sizemax >> 1) + 32; |
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
102 | |
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
103 | // we don't want to risk overflows in implicit constant casts |
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
104 | const size_t bigoff_comp = (sizemax >> 1) - 16; |
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
105 | off_t bigoff = (off_t)bigoff_comp; |
4044131874f9
adds missing stdint.h include for int32_t + fixes possible implicit const cast overflow + adds support for DESTDIR variable in Makefile
Mike Becker <universe@uap-core.de>
parents:
227
diff
changeset
|
106 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
107 | r = ucx_buffer_seek(b, -bigoff, SEEK_CUR); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
108 | UCX_TEST_ASSERT(r != 0, "seek cur underflow"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
109 | UCX_TEST_ASSERT(b->pos == 0, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
110 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
111 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
112 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
113 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
114 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
115 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
116 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
117 | UCX_TEST(test_ucx_buffer_seek_invalid) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
118 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
119 | b->pos = 7; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
120 | int r; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
121 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
122 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
123 | r = ucx_buffer_seek(b, 0, ~(SEEK_SET|SEEK_CUR|SEEK_END)); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
124 | UCX_TEST_ASSERT(r != 0, "invalid whence shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
125 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
126 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
127 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
128 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
129 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
130 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
131 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
132 | UCX_TEST(test_ucx_buffer_seek_oob) { |
76 | 133 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
134 | b->size = 16; // less than capacity | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
135 | b->pos = 7; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
136 | int r; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
137 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
138 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
139 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
140 | r = ucx_buffer_seek(b, -1, SEEK_SET); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
141 | UCX_TEST_ASSERT(r != 0, "seek SET below bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
142 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
143 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
144 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
145 | r = ucx_buffer_seek(b, 16, SEEK_SET); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
146 | UCX_TEST_ASSERT(r != 0, "seek SET above bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
147 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
148 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
149 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
150 | r = ucx_buffer_seek(b, -8, SEEK_CUR); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
151 | UCX_TEST_ASSERT(r != 0, "seek CUR below bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
152 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
153 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
154 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
155 | r = ucx_buffer_seek(b, 9, SEEK_CUR); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
156 | UCX_TEST_ASSERT(r != 0, "seek CUR above bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
157 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
158 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
159 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
160 | r = ucx_buffer_seek(b, -17, SEEK_END); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
161 | UCX_TEST_ASSERT(r != 0, "seek END below bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
162 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
163 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
164 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
165 | r = ucx_buffer_seek(b, 1, SEEK_END); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
166 | UCX_TEST_ASSERT(r != 0, "seek END above bounds shall fail"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
167 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
168 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
169 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
170 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
171 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
172 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
173 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
174 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
175 | UCX_TEST(test_ucx_buffer_seek_set) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
176 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
177 | b->size = 16; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
182 | r = ucx_buffer_seek(b, 5, SEEK_SET); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | UCX_TEST_ASSERT(r == 0, "seek SET+5 failed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
184 | UCX_TEST_ASSERT(b->pos == 5, "seek SET+5 set wrong position"); |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
185 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
186 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
187 | r = ucx_buffer_seek(b, 10, SEEK_SET); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
188 | UCX_TEST_ASSERT(r == 0, "seek SET+10 failed"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
189 | UCX_TEST_ASSERT(b->pos == 10, "seek SET+10 set wrong position"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
191 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
192 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
193 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
194 | } |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
196 | UCX_TEST(test_ucx_buffer_seek_cur) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
197 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
198 | b->size = 16; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
199 | int r; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
200 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
201 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
202 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
203 | b->pos = 7; |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
204 | r = ucx_buffer_seek(b, 5, SEEK_CUR); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | UCX_TEST_ASSERT(r == 0, "seek CUR+5 failed"); |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
206 | UCX_TEST_ASSERT(b->pos == 12, "seek CUR+5 set wrong position"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
207 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
208 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
209 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
210 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
211 | } |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
213 | UCX_TEST(test_ucx_buffer_seek_end) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
214 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
215 | b->size = 16; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
216 | int r; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
218 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
219 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
220 | r = ucx_buffer_seek(b, -5, SEEK_END); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | UCX_TEST_ASSERT(r == 0, "seek END-5 failed"); |
76 | 222 | UCX_TEST_ASSERT(b->pos == 11, "seek END-5 set wrong position"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
227 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
230 | UCX_TEST(test_ucx_buffer_putc) { |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
231 | char *buffer = (char*) malloc(16); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | memset(buffer, 32, 16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
234 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
76 | 235 | b->size = b->capacity; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
239 | ucx_buffer_seek(b, 0, SEEK_SET); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
240 | UCX_TEST_ASSERT(ucx_buffer_putc(b, '0'|~0xFF) == '0', |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
241 | "putc shall return (arg & 0xFF)"); |
76 | 242 | ucx_buffer_putc(b, '0'); |
243 | ucx_buffer_putc(b, '0'); | |
244 | ||
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
245 | UCX_TEST_ASSERT(b->pos == 3, "pos wrong after first 3 puts"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
246 | ucx_buffer_seek(b, 10, SEEK_CUR); |
76 | 247 | |
248 | ucx_buffer_putc(b, '0'); | |
249 | ucx_buffer_putc(b, '0'); | |
250 | ucx_buffer_putc(b, '0'); | |
251 | ||
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
252 | UCX_TEST_ASSERT(b->pos == 16, "pos wrong after last 3 puts"); |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
253 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
254 | UCX_TEST_ASSERT(!memcmp(b->space, "000 000", 16), |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
255 | "buffer content wrong") |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
256 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
257 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
258 | free(buffer); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
259 | } |
76 | 260 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
261 | UCX_TEST(test_ucx_buffer_putc_oob) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
262 | UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_DEFAULT); |
76 | 263 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
264 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
265 | b->pos = b->size = b->capacity = 1; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
266 | b->space[1] = 'X'; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
267 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
268 | UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF, "put shall return EOF " |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
269 | "when buffer is full and auto extend is disabled"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
270 | UCX_TEST_ASSERT(!memcmp(b->space, "\0X", 2), |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
271 | "wrong buffer content after failed putc"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
275 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
278 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
279 | UCX_TEST(test_ucx_buffer_putc_ae) { |
76 | 280 | UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); |
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
281 | ucx_buffer_putc(b, '0'); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
282 | ucx_buffer_putc(b, '1'); |
76 | 283 | |
284 | UCX_TEST_BEGIN | |
285 | ||
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
286 | UCX_TEST_ASSERT(b->pos == 2, "pos wrong after first 2 puts"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
287 | UCX_TEST_ASSERT(b->size == 2, "size wrong after first 2 puts"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
288 | UCX_TEST_ASSERT(b->capacity == 2, "buffer erroneously extended"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
289 | UCX_TEST_ASSERT(!memcmp(b->space,"01", 2), "wrong content"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
290 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
291 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
292 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
293 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
294 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
295 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
296 | UCX_TEST(test_ucx_buffer_putc_oobae) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
297 | UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); |
76 | 298 | ucx_buffer_putc(b, '0'); |
299 | ucx_buffer_putc(b, '1'); | |
300 | ||
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
301 | UCX_TEST_BEGIN |
76 | 302 | |
303 | ucx_buffer_putc(b, 'a'); | |
304 | ||
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
305 | UCX_TEST_ASSERT(b->pos == 3, "pos wrong after put"); |
76 | 306 | UCX_TEST_ASSERT(b->capacity == 4, "buffer not properly extended"); |
307 | UCX_TEST_ASSERT(b->size == 3, "wrong buffer size"); | |
308 | ||
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
309 | UCX_TEST_ASSERT(!memcmp(b->space,"01a\0", 4), "wrong content"); |
76 | 310 | |
311 | UCX_TEST_END | |
312 | ||
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
313 | ucx_buffer_free(b); |
76 | 314 | } |
315 | ||
164
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
316 | UCX_TEST(test_ucx_buffer_putc_size) { |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
317 | UcxBuffer *b = ucx_buffer_new(NULL, 4, UCX_BUFFER_DEFAULT); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
318 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
319 | UCX_TEST_BEGIN |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
320 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
321 | UCX_TEST_ASSERT(b->size == 0, "wrong initial size"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
322 | ucx_buffer_putc(b, 'a'); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
323 | ucx_buffer_putc(b, 'b'); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
324 | ucx_buffer_putc(b, 'c'); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
325 | UCX_TEST_ASSERT(b->size == 3, "size does not increase"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
326 | ucx_buffer_seek(b, 1, SEEK_SET); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
327 | ucx_buffer_putc(b, 'd'); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
328 | UCX_TEST_ASSERT(b->size == 3, "size shall not decrease"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
329 | UCX_TEST_ASSERT(b->pos == 2, "wrong position after seek and putc"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
330 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
331 | UCX_TEST_END |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
332 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
333 | ucx_buffer_free(b); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
334 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
335 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
336 | UCX_TEST(test_ucx_buffer_getc) { |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
337 | char *buffer = (char*) malloc(16); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | for (int i = 8; i < 16 ; i++) { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
340 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
343 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
76 | 344 | b->size = b->capacity; |
269
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
345 | |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
346 | unsigned char ubuffer[] = {127, 128, 129, 130}; |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
347 | UcxBuffer *ub = ucx_buffer_new(ubuffer, 4, UCX_BUFFER_DEFAULT); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
348 | ub->size = 4; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
352 | char rb[16]; |
95 | 353 | for (size_t i = 0 ; i < 16 ; i++) { |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
354 | UCX_TEST_ASSERT(b->pos == i, "wrong position"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
355 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), "EOF false positive"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
356 | rb[i] = ucx_buffer_getc(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | UCX_TEST_ASSERT(memcmp(rb, " 01234567", 16) == 0, |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
359 | "read data incorrect"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
360 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
361 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "EOF not set after last possible read"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
362 | UCX_TEST_ASSERT(b->pos == 16, "wrong position after EOF"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
363 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
364 | UCX_TEST_ASSERT(ucx_buffer_getc(b) == EOF, |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
365 | "out of bounds read does not return EOF"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
366 | UCX_TEST_ASSERT(b->pos == 16, "wrong position after out of bounds read"); |
269
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
367 | |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
368 | int uc[5]; |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
369 | for(int i=0;i<5;i++) { |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
370 | uc[i] = ucx_buffer_getc(ub); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
371 | } |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
372 | UCX_TEST_ASSERT(uc[0] == 127, "wrong unsigned value(0)"); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
373 | UCX_TEST_ASSERT(uc[1] == 128, "wrong unsigned value(0)"); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
374 | UCX_TEST_ASSERT(uc[2] == 129, "wrong unsigned value(0)"); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
375 | UCX_TEST_ASSERT(uc[3] == 130, "wrong unsigned value(0)"); |
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
376 | UCX_TEST_ASSERT(uc[4] == EOF, "EOF not set after last ub read"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
377 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
378 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
379 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
380 | ucx_buffer_free(b); |
269
591473851c95
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
259
diff
changeset
|
381 | ucx_buffer_free(ub); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
382 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
383 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
384 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
385 | UCX_TEST(test_ucx_buffer_write) { |
168 | 386 | char *buffer = (char*) malloc(32); |
169
279dd3ca7a77
fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
387 | memset(buffer, 0, 32); |
279dd3ca7a77
fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
388 | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
389 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
390 | for (int i = 8; i < 16 ; i++) { |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
391 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
392 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
393 | |
168 | 394 | UcxBuffer *b = ucx_buffer_new(buffer, 32, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
395 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
396 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
397 | UCX_TEST_BEGIN |
168 | 398 | b->pos = 4; |
399 | r = ucx_buffer_write("test string", 1, 11, b); | |
400 | UCX_TEST_ASSERT(r == 11, "returned incorrect number of written bytes"); | |
401 | UCX_TEST_ASSERT(b->pos == 15, "incorrect position"); | |
402 | UCX_TEST_ASSERT(memcmp(buffer, " test string7\0\0", 18) == 0, | |
403 | "incorrect buffer content (test string)"); | |
404 | ||
219
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
405 | r = ucx_buffer_write(".", 1, 1, b); |
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
406 | UCX_TEST_ASSERT(r == 1, "returned incorrect number of written elements"); |
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
407 | UCX_TEST_ASSERT(b->pos == 16, "incorrect position"); |
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
408 | |
168 | 409 | int32_t testarr[4] = {0x09abcdef, 0x05fedcba, 0x01abefcd, 0x3cd07ab}; |
410 | r = ucx_buffer_write(testarr, 4, 4, b); | |
411 | UCX_TEST_ASSERT(r = 4, "returned incorrect number of written elements"); | |
219
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
412 | UCX_TEST_ASSERT(b->pos == 32, "incorrect position"); |
168 | 413 | |
414 | char cmp[32]; | |
415 | memset(cmp, 0, 32); | |
219
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
416 | memcpy(cmp, " test string.", 16); |
2df780a4482b
fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
218
diff
changeset
|
417 | int32_t *ptr = (int32_t*) (cmp+16); |
168 | 418 | ptr[0] = testarr[0]; |
419 | ptr[1] = testarr[1]; | |
420 | ptr[2] = testarr[2]; | |
421 | ptr[3] = testarr[3]; | |
422 | UCX_TEST_ASSERT(memcmp(buffer, cmp, 32) == 0, | |
423 | "incorrect buffer content (int array)"); | |
424 | ||
425 | UCX_TEST_END | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
426 | |
168 | 427 | ucx_buffer_free(b); |
428 | free(buffer); | |
429 | } | |
430 | ||
431 | UCX_TEST(test_ucx_buffer_write_oob) { | |
432 | char *buffer = (char*) malloc(32); | |
433 | memset(buffer, 0, 32); | |
434 | ||
435 | UcxBuffer *b = ucx_buffer_new(buffer, 15, UCX_BUFFER_DEFAULT); | |
436 | int r; | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
437 | |
168 | 438 | UCX_TEST_BEGIN |
439 | r = ucx_buffer_write("a very long string", 1, 18, b); | |
440 | UCX_TEST_ASSERT(r == 15, "incorrect number of written bytes"); | |
441 | UCX_TEST_ASSERT(memcmp(buffer, "a very long str\0\0\0", 18) == 0, | |
442 | "invalid buffer content (test string)"); | |
443 | ||
444 | b->size = b->pos = 0; | |
445 | int32_t intarr[4] = {0,-1,0,-1}; | |
446 | memset(buffer, 0, 32); | |
447 | ||
448 | r = ucx_buffer_write(intarr, 4, 4, b); | |
449 | UCX_TEST_ASSERT(r == 3, "incorrect number of written elements"); | |
450 | UCX_TEST_ASSERT(memcmp(buffer, | |
451 | "\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0", 16) == 0, | |
452 | "invalid buffer content (test string)"); | |
453 | ||
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
454 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
455 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
456 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
457 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
458 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
459 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
460 | UCX_TEST(test_ucx_buffer_write_ax) { |
76 | 461 | char *buffer = (char*) malloc(16); |
169
279dd3ca7a77
fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
462 | memset(buffer, 0, 16); |
64
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
463 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
464 | UcxBuffer *b = ucx_buffer_new(buffer, 16, |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
465 | UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
466 | int r; |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
467 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
468 | UCX_TEST_BEGIN |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
469 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
470 | const char* teststring = "this is way too much"; |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
471 | r = ucx_buffer_write((void*)teststring, 1, 20, b); |
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
472 | buffer = (char*) b->space; /*autoextend enabled, we MUST retrieve pointer*/ |
64
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
473 | UCX_TEST_ASSERT(r == 20, "not all characters written"); |
76 | 474 | UCX_TEST_ASSERT(b->capacity == 32, "buffer not properly extended"); |
64
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
475 | UCX_TEST_ASSERT(b->pos == 20, "position incorrect"); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
476 | UCX_TEST_ASSERT(memcmp(buffer, |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
477 | "this is way too much\0\0\0\0\0\0\0\0\0\0\0\0", 32) == 0, |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
478 | "incorrect buffer content"); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
479 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
480 | UCX_TEST_END |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
481 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
482 | ucx_buffer_free(b); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
483 | } |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
484 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
485 | UCX_TEST(test_ucx_buffer_read) { |
76 | 486 | UcxBuffer *b = ucx_buffer_new(NULL, 8, UCX_BUFFER_AUTOFREE); |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
487 | ucx_buffer_write("01234567", 1, 8, b); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
488 | b->pos = 0; |
76 | 489 | |
490 | char buf[32]; | |
491 | memset(buf, 'X', 32); | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
492 | int r; |
76 | 493 | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
494 | UCX_TEST_BEGIN |
76 | 495 | |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
496 | ucx_buffer_seek(b, 2, SEEK_SET); |
76 | 497 | r = ucx_buffer_read(buf, 1, 2, b); |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
498 | UCX_TEST_ASSERT(r == 2, "wrong number of bytes read (2 items)"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
499 | UCX_TEST_ASSERT(buf[0] == '2' && buf[1] == '3' && buf[2] == 'X', |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
500 | "buffer incorrect after read"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
501 | UCX_TEST_ASSERT(b->pos == 4, "wrong position after read (2 items)"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
502 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
503 | UCX_TEST_END |
76 | 504 | |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
505 | ucx_buffer_free(b); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
506 | } |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
507 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
508 | UCX_TEST(test_ucx_buffer_read_oob) { |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
509 | UcxBuffer *b = ucx_buffer_new(NULL, 8, UCX_BUFFER_AUTOFREE); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
510 | ucx_buffer_write("01234567", 1, 8, b); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
511 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
512 | char buf[32]; |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
513 | memset(buf, 'X', 32); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
514 | int r; |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
515 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
516 | UCX_TEST_BEGIN |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
517 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
518 | b->pos = 2; |
76 | 519 | r = ucx_buffer_read(buf + 2, 1, 8, b); |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
520 | UCX_TEST_ASSERT(r == 6, "wrong number of bytes read (8 items)"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
521 | UCX_TEST_ASSERT(memcmp(buf, "XX234567XX", 10) == 0, |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
522 | "buffer incorrect after read"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
523 | UCX_TEST_ASSERT(b->pos == 8, |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
524 | "wrong position after read (8 items out of bound)"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
525 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
526 | b->pos = 0; |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
527 | memset(buf, 'X', 32); |
76 | 528 | |
529 | r = ucx_buffer_read(buf, 3, 3, b); | |
530 | ||
531 | UCX_TEST_ASSERT(r == 2, "wrong number of blocks read"); | |
532 | UCX_TEST_ASSERT(memcmp(buf, "012345XX", 8) == 0, | |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
533 | "buffer incorrect after block out of bounds read"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
534 | |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
535 | r = ucx_buffer_read(buf+6, 1, 5, b); |
76 | 536 | |
166
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
537 | UCX_TEST_ASSERT(r == 2, "wrong number of remaining bytes read"); |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
538 | UCX_TEST_ASSERT(memcmp(buf, "01234567XX", 10) == 0, |
350a0e3898bd
improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents:
164
diff
changeset
|
539 | "buffer incorrect after remaining byte read"); |
76 | 540 | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
541 | UCX_TEST_END |
76 | 542 | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
543 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
544 | } |
62 | 545 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
546 | UCX_TEST(test_ucx_buffer_extract) { |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
547 | char *buffer = (char*) malloc(16); |
62 | 548 | strcpy(buffer, "this is a test!"); |
549 | ||
76 | 550 | UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE); |
168 | 551 | src->size = 16; |
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
552 | UcxBuffer *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_AUTOEXTEND); |
62 | 553 | |
554 | UCX_TEST_BEGIN | |
76 | 555 | UCX_TEST_ASSERT(dst != NULL, "ucx_buffer_extract returned NULL"); |
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
556 | UCX_TEST_ASSERT(dst->flags == (UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE), |
62 | 557 | "autofree flag shall be enforced"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
558 | UCX_TEST_ASSERT(dst->size == 5, "wrong size for new buffer"); |
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
559 | UCX_TEST_ASSERT(dst->capacity == 5, "wrong capacity for new buffer"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
560 | UCX_TEST_ASSERT(dst->pos == 0, "wrong position for new buffer"); |
62 | 561 | char rb[5]; |
562 | ucx_buffer_read(rb, 1, 5, dst); | |
563 | UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0, | |
564 | "new buffer has incorrect content"); | |
565 | ||
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
566 | UCX_TEST_END |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
567 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
568 | ucx_buffer_free(dst); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
569 | ucx_buffer_free(src); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
570 | } |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
571 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
572 | UCX_TEST(test_ucx_buffer_extract_oob) { |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
573 | char *buffer = (char*) malloc(16); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
574 | strcpy(buffer, "this is a test!"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
575 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
576 | UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE); |
168 | 577 | src->size = 16; |
578 | ||
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
579 | UCX_TEST_BEGIN |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
580 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
581 | UCX_TEST_ASSERT(ucx_buffer_extract(src, 5, 0, UCX_BUFFER_DEFAULT) == NULL, |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
582 | "extract shall fail on zero length"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
583 | UCX_TEST_ASSERT(ucx_buffer_extract(src, 10, 10, UCX_BUFFER_DEFAULT) == NULL, |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
584 | "extract shall fail on invalid bounds (size exceeds limits)"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
585 | UCX_TEST_ASSERT(ucx_buffer_extract(src, 20, -7, UCX_BUFFER_DEFAULT) == NULL, |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
586 | "extract shall fail on invalid bounds (start exceeds limits)"); |
62 | 587 | |
588 | UCX_TEST_END | |
589 | ||
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
590 | ucx_buffer_free(src); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
591 | } |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
592 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
593 | UCX_TEST(test_ucx_buffer_extract_overflow) { |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
594 | char *buffer = (char*) malloc(16); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
595 | strcpy(buffer, "this is a test!"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
596 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
597 | UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE); |
168 | 598 | src->size = 16; |
599 | ||
167
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
600 | UCX_TEST_BEGIN |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
601 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
602 | UCX_TEST_ASSERT(ucx_buffer_extract(src, 5, (size_t)-4, |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
603 | UCX_BUFFER_DEFAULT) == NULL, "extract shall fail on integer overflow"); |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
604 | |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
605 | UCX_TEST_END |
aed60ba37acf
ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
606 | |
62 | 607 | ucx_buffer_free(src); |
608 | } | |
76 | 609 | |
168 | 610 | UCX_TEST(test_ucx_buffer_extend) { |
611 | ||
612 | UcxBuffer *b = ucx_buffer_new(NULL, 10, UCX_BUFFER_DEFAULT); | |
76 | 613 | |
614 | UCX_TEST_BEGIN | |
615 | ||
168 | 616 | UCX_TEST_ASSERT(ucx_buffer_extend(b, 15) == 0, "shall return 0 on success"); |
617 | UCX_TEST_ASSERT(b->capacity = 40, "wrong capacity"); | |
618 | UCX_TEST_ASSERT((b->size == 0 && b->pos == 0), | |
619 | "pos and size shall remain unchanged"); | |
76 | 620 | |
218
b20d6088795c
fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents:
192
diff
changeset
|
621 | UCX_TEST_ASSERT(ucx_buffer_extend(b, (size_t) - 61) != 0, |
168 | 622 | "shall fail and return a non-zero value on overflow"); |
76 | 623 | |
624 | UCX_TEST_END | |
625 | ||
168 | 626 | ucx_buffer_free(b); |
76 | 627 | } |
290
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
628 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
629 | UCX_TEST(test_ucx_buffer_shl) { |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
630 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
631 | const char* hw = "Shift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
632 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
633 | UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_DEFAULT); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
634 | ucx_buffer_puts(b, hw); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
635 | b->pos = 5; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
636 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
637 | UCX_TEST_BEGIN |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
638 | char* expected; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
639 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
640 | ucx_buffer_shift_left(b, 2); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
641 | expected = "ift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
642 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
643 | UCX_TEST_ASSERT(b->pos == 3, "position after normal shl wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
644 | UCX_TEST_ASSERT(b->size == strlen(expected), "size after normal shl wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
645 | UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
646 | "contents after normal shl wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
647 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
648 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
649 | ucx_buffer_shift_left(b, 5); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
650 | expected = "he World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
651 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
652 | UCX_TEST_ASSERT(b->pos == 0, "position after overshift left wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
653 | UCX_TEST_ASSERT(b->size == strlen(expected), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
654 | "size after overshift left wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
655 | UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
656 | "contents after overshift left wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
657 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
658 | ucx_buffer_shift_left(b, 10); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
659 | UCX_TEST_ASSERT(b->pos == 0, "position after 'shl everything away' wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
660 | UCX_TEST_ASSERT(b->size == 0, "size after 'shl everything away' wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
661 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
662 | UCX_TEST_END |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
663 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
664 | ucx_buffer_free(b); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
665 | } |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
666 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
667 | UCX_TEST(test_ucx_buffer_shr) { |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
668 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
669 | const char* hw = "Shift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
670 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
671 | UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_DEFAULT); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
672 | ucx_buffer_puts(b, hw); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
673 | b->pos = 12; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
674 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
675 | UCX_TEST_BEGIN |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
676 | char* expected; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
677 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
678 | ucx_buffer_shift_right(b, 2); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
679 | expected = "ShShift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
680 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
681 | UCX_TEST_ASSERT(b->pos == 14, "position after normal shr wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
682 | UCX_TEST_ASSERT(b->size == strlen(expected), "size after normal shr wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
683 | UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
684 | "contents after normal shr wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
685 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
686 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
687 | ucx_buffer_shift_right(b, 5); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
688 | expected = "ShShiShShift the Wor"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
689 | UCX_TEST_ASSERT(strlen(expected) == b->capacity, |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
690 | "Test data is wrong, please fix the test."); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
691 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
692 | UCX_TEST_ASSERT(b->pos == 19, |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
693 | "position after overshift right w/o auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
694 | UCX_TEST_ASSERT(b->size == 20, |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
695 | "size after overshift right w/o auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
696 | UCX_TEST_ASSERT(b->capacity == 20, |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
697 | "capacity after overshift right w/o auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
698 | UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
699 | "contents after overshift right w/o auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
700 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
701 | ucx_buffer_shift_right(b, 15); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
702 | UCX_TEST_ASSERT(b->pos == b->capacity, "position after 'shr to eof' wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
703 | UCX_TEST_ASSERT(b->size == b->capacity, "size after 'shr to eof' wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
704 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "buffer not eof after 'shr to eof'"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
705 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
706 | UCX_TEST_END |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
707 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
708 | ucx_buffer_free(b); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
709 | } |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
710 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
711 | UCX_TEST(test_ucx_buffer_shr_ax) { |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
712 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
713 | const char* hw = "Shift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
714 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
715 | UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_AUTOEXTEND); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
716 | ucx_buffer_puts(b, hw); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
717 | b->pos = 12; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
718 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
719 | UCX_TEST_BEGIN |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
720 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
721 | const char* expected = "Shift the Shift the World!"; |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
722 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
723 | ucx_buffer_shift_right(b, 10); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
724 | UCX_TEST_ASSERT(b->pos == 22, "position after shr w/ auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
725 | UCX_TEST_ASSERT(b->size == strlen(expected), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
726 | "size after shr w/ auto-extend wrong"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
727 | UCX_TEST_ASSERT(b->capacity >= b->size, |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
728 | "auto-extension of capacity after shr w/ auto-extend failed"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
729 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
730 | "buffer should not be eof after shr w/ auto-extend"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
731 | UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size), |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
732 | "contents wrong after shr w/ auto-extend"); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
733 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
734 | UCX_TEST_END |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
735 | |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
736 | ucx_buffer_free(b); |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
737 | } |
d5d6ab809ad3
adds new shift operations for UcxBuffer (including tests and a usage example in modules.md)
Mike Becker <universe@uap-core.de>
parents:
269
diff
changeset
|
738 |