test/buffer_tests.c

Thu, 08 Sep 2016 16:39:45 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 08 Sep 2016 16:39:45 +0200
changeset 226
669136d4e3af
parent 225
a1a068c2c4ef
child 227
740fbd7bab71
permissions
-rw-r--r--

adds web documentation to project

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 *
225
a1a068c2c4ef updates documenting comments
Mike Becker <universe@uap-core.de>
parents: 219
diff changeset
4 * Copyright 2016 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"
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
30
166
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
31 UCX_TEST(test_ucx_buffer_new) {
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
32 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
33 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
34 UCX_TEST_BEGIN
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
35
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
36 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
37 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
38
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
39 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
40 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
41
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
42 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
43 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
44
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
45 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
46 "wrong flags for autoextending buffer");
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
47 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
48 "wrong flags for default bufer");
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
49
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
50 UCX_TEST_END
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
51 ucx_buffer_free(b2);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
52 ucx_buffer_free(b);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
53 }
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 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
56 char* test = (char*) malloc(16);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
57 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
58 UCX_TEST_BEGIN
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
59
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
60 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
61 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
62 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
63
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
64 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
65
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
66 UCX_TEST_END
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
67 free(test);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
68 ucx_buffer_free(b);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
69 }
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
70
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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 }
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
83
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 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
85 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
86 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
87 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
88
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 UCX_TEST_BEGIN
218
b20d6088795c fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
90 const size_t sizemax = (size_t)-1;
b20d6088795c fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
91 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
92 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
93 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
94 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
95 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
96 "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
97
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 b->pos = 0;
218
b20d6088795c fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
99 b->size = sizemax / 2 + 32;
b20d6088795c fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
100 off_t bigoff = sizemax / 2 - 16;
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
101 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
102 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
103 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
104 "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
105
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
106 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
107
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_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
109 }
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
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 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
112 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
113 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
114 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
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 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
117 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
118 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
119 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
120 "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
121 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
122
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 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
124 }
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
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 UCX_TEST(test_ucx_buffer_seek_oob) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
127 UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
128 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
129 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
130 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
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_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
133
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
134 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
135 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
136 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
137 "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
138
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 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
140 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
141 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
142 "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
143
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 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
145 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
146 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
147 "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
148
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 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
150 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
151 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
152 "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
153
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 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
155 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
156 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
157 "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
158
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 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
160 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
161 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
162 "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
163
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 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
165
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_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
167 }
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
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 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
170 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
171 b->size = 16;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
176 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
177 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
178 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
179
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
180
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
181 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
182 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
183 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
184
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 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
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 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
188 }
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189
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
190 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
191 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
192 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
193 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
194
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
195 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
196
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 b->pos = 7;
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
198 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
199 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
200 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
201
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 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
203
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
204 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
205 }
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206
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
207 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
208 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
209 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
210 int r;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211
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
212 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
213
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
214 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
215 UCX_TEST_ASSERT(r == 0, "seek END-5 failed");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
216 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
217
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
221 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
224 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
225 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
226 memset(buffer, 32, 16);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
228 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
229 b->size = b->capacity;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232
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
233 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
234 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
235 "putc shall return (arg & 0xFF)");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
236 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
237 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
238
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
239 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
240 ucx_buffer_seek(b, 10, SEEK_CUR);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
241
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
242 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
243 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
244 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
245
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
246 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
247
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
248 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
249 "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
250 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
251 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
252 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
253 }
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
254
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
255 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
256 UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
257
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
258 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
259 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
260 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
261
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 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
263 "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
264 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
265 "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
266
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
269 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271
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
272
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
273 UCX_TEST(test_ucx_buffer_putc_ae) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
274 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
275 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
276 ucx_buffer_putc(b, '1');
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
277
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
278 UCX_TEST_BEGIN
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
279
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
280 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
281 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
282 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
283 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
284
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
285 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
286
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_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
288 }
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
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 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
291 UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
292 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
293 ucx_buffer_putc(b, '1');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
294
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
295 UCX_TEST_BEGIN
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
296
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
297 ucx_buffer_putc(b, 'a');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
298
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
299 UCX_TEST_ASSERT(b->pos == 3, "pos wrong after put");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
300 UCX_TEST_ASSERT(b->capacity == 4, "buffer not properly extended");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
301 UCX_TEST_ASSERT(b->size == 3, "wrong buffer size");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
302
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
303 UCX_TEST_ASSERT(!memcmp(b->space,"01a\0", 4), "wrong content");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
304
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
305 UCX_TEST_END
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
306
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
307 ucx_buffer_free(b);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
308 }
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
309
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
310 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
311 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
312
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
313 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
314
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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324
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_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
326
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_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
328 }
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
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
330 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
331 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
332 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 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
334 buffer[i] = 40+i;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
337 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
338 b->size = b->capacity;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 UCX_TEST_BEGIN
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 char rb[16];
95
ecfdc1c4a552 added gnu++11 support
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
343 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
344 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
345 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
346 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
347 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348 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
349 "read data incorrect");
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
350
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
351 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
352 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
353
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
354 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
355 "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
356 UCX_TEST_ASSERT(b->pos == 16, "wrong position after out of bounds read");
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_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
360 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
364 UCX_TEST(test_ucx_buffer_write) {
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
365 char *buffer = (char*) malloc(32);
169
279dd3ca7a77 fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents: 168
diff changeset
366 memset(buffer, 0, 32);
279dd3ca7a77 fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents: 168
diff changeset
367
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 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
370 buffer[i] = 40+i;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
373 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
374 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 UCX_TEST_BEGIN
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
377 b->pos = 4;
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
378 r = ucx_buffer_write("test string", 1, 11, b);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
379 UCX_TEST_ASSERT(r == 11, "returned incorrect number of written bytes");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
380 UCX_TEST_ASSERT(b->pos == 15, "incorrect position");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
381 UCX_TEST_ASSERT(memcmp(buffer, " test string7\0\0", 18) == 0,
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
382 "incorrect buffer content (test string)");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
383
219
2df780a4482b fixed misaligned memory access in test_ucx_buffer_write
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
384 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
385 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
386 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
387
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
388 int32_t testarr[4] = {0x09abcdef, 0x05fedcba, 0x01abefcd, 0x3cd07ab};
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
389 r = ucx_buffer_write(testarr, 4, 4, b);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
390 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
391 UCX_TEST_ASSERT(b->pos == 32, "incorrect position");
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
392
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
393 char cmp[32];
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
394 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
395 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
396 int32_t *ptr = (int32_t*) (cmp+16);
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
397 ptr[0] = testarr[0];
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
398 ptr[1] = testarr[1];
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
399 ptr[2] = testarr[2];
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
400 ptr[3] = testarr[3];
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
401 UCX_TEST_ASSERT(memcmp(buffer, cmp, 32) == 0,
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
402 "incorrect buffer content (int array)");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
403
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
404 UCX_TEST_END
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
405
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
406 ucx_buffer_free(b);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
407 free(buffer);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
408 }
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
409
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
410 UCX_TEST(test_ucx_buffer_write_oob) {
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
411 char *buffer = (char*) malloc(32);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
412 memset(buffer, 0, 32);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
413
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
414 UcxBuffer *b = ucx_buffer_new(buffer, 15, UCX_BUFFER_DEFAULT);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
415 int r;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
416
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
417 UCX_TEST_BEGIN
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
418 r = ucx_buffer_write("a very long string", 1, 18, b);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
419 UCX_TEST_ASSERT(r == 15, "incorrect number of written bytes");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
420 UCX_TEST_ASSERT(memcmp(buffer, "a very long str\0\0\0", 18) == 0,
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
421 "invalid buffer content (test string)");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
422
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
423 b->size = b->pos = 0;
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
424 int32_t intarr[4] = {0,-1,0,-1};
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
425 memset(buffer, 0, 32);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
426
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
427 r = ucx_buffer_write(intarr, 4, 4, b);
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
428 UCX_TEST_ASSERT(r == 3, "incorrect number of written elements");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
429 UCX_TEST_ASSERT(memcmp(buffer,
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
430 "\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0", 16) == 0,
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
431 "invalid buffer content (test string)");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
432
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
433 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
434
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
435 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
436 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
437 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
438
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
439 UCX_TEST(test_ucx_buffer_write_ax) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
440 char *buffer = (char*) malloc(16);
169
279dd3ca7a77 fixed issues revealed by buffer tests
Mike Becker <universe@uap-core.de>
parents: 168
diff changeset
441 memset(buffer, 0, 16);
64
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
442
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
443 UcxBuffer *b = ucx_buffer_new(buffer, 16,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
444 UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
445 int r;
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
446
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
447 UCX_TEST_BEGIN
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
448
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
449 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
450 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
451 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
452 UCX_TEST_ASSERT(r == 20, "not all characters written");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
453 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
454 UCX_TEST_ASSERT(b->pos == 20, "position incorrect");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
455 UCX_TEST_ASSERT(memcmp(buffer,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
456 "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
457 "incorrect buffer content");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
458
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
459 UCX_TEST_END
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
460
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
461 ucx_buffer_free(b);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
462 }
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
463
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
464 UCX_TEST(test_ucx_buffer_read) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
465 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
466 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
467 b->pos = 0;
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
468
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
469 char buf[32];
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
470 memset(buf, 'X', 32);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
471 int r;
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
472
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
473 UCX_TEST_BEGIN
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
474
166
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
475 ucx_buffer_seek(b, 2, SEEK_SET);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
476 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
477 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
478 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
479 "buffer incorrect after read");
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
480 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
481
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
482 UCX_TEST_END
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
483
166
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
484 ucx_buffer_free(b);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
485 }
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
486
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
487 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
488 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
489 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
490
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
491 char buf[32];
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
492 memset(buf, 'X', 32);
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
493 int r;
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
494
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
495 UCX_TEST_BEGIN
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
496
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
497 b->pos = 2;
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
498 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
499 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
500 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
501 "buffer incorrect after read");
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
502 UCX_TEST_ASSERT(b->pos == 8,
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
503 "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
504
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
505 b->pos = 0;
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
506 memset(buf, 'X', 32);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
507
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
508 r = ucx_buffer_read(buf, 3, 3, b);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
509
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
510 UCX_TEST_ASSERT(r == 2, "wrong number of blocks read");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
511 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
512 "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
513
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
514 r = ucx_buffer_read(buf+6, 1, 5, b);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
515
166
350a0e3898bd improved more buffer tests + some doc fixes
Mike Becker <universe@uap-core.de>
parents: 164
diff changeset
516 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
517 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
518 "buffer incorrect after remaining byte read");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
519
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
520 UCX_TEST_END
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
521
147
1aa598f36872 added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
522 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
523 }
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
524
134
4d320dc3a7af documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents: 103
diff changeset
525 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
526 char *buffer = (char*) malloc(16);
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
527 strcpy(buffer, "this is a test!");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
528
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
529 UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE);
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
530 src->size = 16;
167
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
531 UcxBuffer *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_AUTOEXTEND);
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
532
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
533 UCX_TEST_BEGIN
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
534 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
535 UCX_TEST_ASSERT(dst->flags == (UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE),
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
536 "autofree flag shall be enforced");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
537 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
538 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
539 UCX_TEST_ASSERT(dst->pos == 0, "wrong position for new buffer");
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
540 char rb[5];
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
541 ucx_buffer_read(rb, 1, 5, dst);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
542 UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
543 "new buffer has incorrect content");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
544
167
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
545 UCX_TEST_END
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
546
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
547 ucx_buffer_free(dst);
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
548 ucx_buffer_free(src);
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
549 }
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
550
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
551 UCX_TEST(test_ucx_buffer_extract_oob) {
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
552 char *buffer = (char*) malloc(16);
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
553 strcpy(buffer, "this is a test!");
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
554
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
555 UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE);
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
556 src->size = 16;
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
557
167
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
558 UCX_TEST_BEGIN
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
559
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
560 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
561 "extract shall fail on zero length");
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
562 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
563 "extract shall fail on invalid bounds (size exceeds limits)");
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
564 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
565 "extract shall fail on invalid bounds (start exceeds limits)");
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
566
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
567 UCX_TEST_END
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
568
167
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_overflow) {
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
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
577 src->size = 16;
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
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, (size_t)-4,
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
582 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
583
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
584 UCX_TEST_END
aed60ba37acf ucx_buffer_extract tests
Mike Becker <universe@uap-core.de>
parents: 166
diff changeset
585
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
586 ucx_buffer_free(src);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
587 }
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
588
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
589 UCX_TEST(test_ucx_buffer_extend) {
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
590
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
591 UcxBuffer *b = ucx_buffer_new(NULL, 10, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
592
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
593 UCX_TEST_BEGIN
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
594
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
595 UCX_TEST_ASSERT(ucx_buffer_extend(b, 15) == 0, "shall return 0 on success");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
596 UCX_TEST_ASSERT(b->capacity = 40, "wrong capacity");
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
597 UCX_TEST_ASSERT((b->size == 0 && b->pos == 0),
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
598 "pos and size shall remain unchanged");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
599
218
b20d6088795c fixed further usages of SIZE_MAX
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
600 UCX_TEST_ASSERT(ucx_buffer_extend(b, (size_t) - 61) != 0,
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
601 "shall fail and return a non-zero value on overflow");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
602
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
603 UCX_TEST_END
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
604
168
24a012440dee completed buffer tests
Mike Becker <universe@uap-core.de>
parents: 167
diff changeset
605 ucx_buffer_free(b);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
606 }

mercurial