Mon, 05 May 2014 14:52:40 +0200
hotfix for ucx_buffer_seek documentation
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 | * |
103
08018864fb91
added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
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" |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
30 | #include "ucx/utils.h" |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | |
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
|
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
|
33 | * TODO: refactor tests |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
34 | * |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
35 | * ucx_buffer_extend |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
36 | * ucx_buffer_extract |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
37 | * ucx_buffer_free |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
38 | * ucx_buffer_getc |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
39 | * ucx_buffer_new |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
40 | * ucx_buffer_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
|
41 | * ucx_buffer_read |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
42 | * ucx_buffer_write |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
43 | * |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
44 | */ |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
45 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
46 | UCX_TEST(test_ucx_buffer_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
|
47 | char *test = "0123456789ABCDEF"; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
48 | 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
|
49 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | 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
|
56 | 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
|
57 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
58 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
59 | 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
|
60 | 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
|
61 | 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
|
62 | 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
|
63 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
64 | 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
|
65 | size_t bigpos = SIZE_MAX - 5000; |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
66 | 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
|
67 | 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
|
68 | 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
|
69 | 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
|
70 | "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
|
71 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
72 | 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
|
73 | b->size = SIZE_MAX / 2 + 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
|
74 | off_t bigoff = SIZE_MAX / 2 - 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
|
75 | 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
|
76 | 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
|
77 | 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
|
78 | "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
|
79 | |
1fa3f13f774c
added allocator 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_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
|
81 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
82 | ucx_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
|
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 | |
1fa3f13f774c
added allocator 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 | 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
|
86 | 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
|
87 | 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
|
88 | 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
|
89 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
90 | 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
|
91 | 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
|
92 | 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
|
93 | 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
|
94 | "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
|
95 | 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
|
96 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
97 | ucx_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
|
98 | } |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
99 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
100 | UCX_TEST(test_ucx_buffer_seek_oob) { |
76 | 101 | UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); |
102 | 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
|
103 | 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
|
104 | 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
|
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_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
|
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 | 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
|
109 | 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
|
110 | 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
|
111 | "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
|
112 | |
1fa3f13f774c
added allocator 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 | 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
|
114 | 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
|
115 | 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
|
116 | "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
|
117 | |
1fa3f13f774c
added allocator 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 | 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
|
119 | 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
|
120 | 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
|
121 | "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
|
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 | 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
|
124 | 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
|
125 | UCX_TEST_ASSERT(b->pos == 7, |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
126 | "failed seek shall leave pos unchanged"); |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
127 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
128 | 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
|
129 | 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
|
130 | 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
|
131 | "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
|
132 | |
1fa3f13f774c
added allocator 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 | 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
|
134 | 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
|
135 | 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
|
136 | "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
|
137 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
138 | UCX_TEST_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
|
139 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
140 | 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
|
141 | } |
1fa3f13f774c
added allocator 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 | |
1fa3f13f774c
added allocator 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 | 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
|
144 | 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
|
145 | b->size = 16; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
150 | 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
|
151 | 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
|
152 | 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
|
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 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
155 | r = ucx_buffer_seek(b, 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
|
156 | 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
|
157 | 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
|
158 | |
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
|
159 | 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
|
160 | |
1fa3f13f774c
added allocator 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_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
|
162 | } |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | |
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
|
164 | 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
|
165 | 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
|
166 | 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
|
167 | 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
|
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_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
|
170 | |
1fa3f13f774c
added allocator 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->pos = 7; |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
172 | 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
|
173 | 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
|
174 | 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
|
175 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
176 | 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
|
177 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
178 | 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
|
179 | } |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | |
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
|
181 | 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
|
182 | 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
|
183 | 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
|
184 | int r; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | |
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
|
186 | 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
|
187 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
188 | 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
|
189 | UCX_TEST_ASSERT(r == 0, "seek END-5 failed"); |
76 | 190 | 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
|
191 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
195 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
198 | 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
|
199 | 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
|
200 | memset(buffer, 32, 16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
202 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
76 | 203 | b->size = b->capacity; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | UCX_TEST_BEGIN |
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_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
|
208 | 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
|
209 | "putc shall return (arg & 0xFF)"); |
76 | 210 | ucx_buffer_putc(b, '0'); |
211 | ucx_buffer_putc(b, '0'); | |
212 | ||
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
213 | 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
|
214 | ucx_buffer_seek(b, 10, SEEK_CUR); |
76 | 215 | |
216 | ucx_buffer_putc(b, '0'); | |
217 | ucx_buffer_putc(b, '0'); | |
218 | ucx_buffer_putc(b, '0'); | |
219 | ||
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
220 | 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
|
221 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
222 | 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
|
223 | "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
|
224 | 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
|
225 | 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
|
226 | 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
|
227 | } |
76 | 228 | |
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
|
229 | 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
|
230 | UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_DEFAULT); |
76 | 231 | |
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
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
236 | 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
|
237 | "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
|
238 | 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
|
239 | "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
|
240 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
243 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | |
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
|
246 | |
1fa3f13f774c
added allocator 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 | UCX_TEST(test_ucx_buffer_putc_ae) { |
76 | 248 | 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
|
249 | 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
|
250 | ucx_buffer_putc(b, '1'); |
76 | 251 | |
252 | UCX_TEST_BEGIN | |
253 | ||
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
|
254 | 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
|
255 | 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
|
256 | 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
|
257 | 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
|
258 | |
1fa3f13f774c
added allocator 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 | 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
|
260 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
261 | ucx_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
|
262 | } |
1fa3f13f774c
added allocator 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 | |
1fa3f13f774c
added allocator 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(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
|
265 | UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); |
76 | 266 | ucx_buffer_putc(b, '0'); |
267 | ucx_buffer_putc(b, '1'); | |
268 | ||
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
|
269 | UCX_TEST_BEGIN |
76 | 270 | |
271 | ucx_buffer_putc(b, 'a'); | |
272 | ||
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
|
273 | UCX_TEST_ASSERT(b->pos == 3, "pos wrong after put"); |
76 | 274 | UCX_TEST_ASSERT(b->capacity == 4, "buffer not properly extended"); |
275 | UCX_TEST_ASSERT(b->size == 3, "wrong buffer size"); | |
276 | ||
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
|
277 | UCX_TEST_ASSERT(!memcmp(b->space,"01a\0", 4), "wrong content"); |
76 | 278 | |
279 | UCX_TEST_END | |
280 | ||
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
281 | ucx_buffer_free(b); |
76 | 282 | } |
283 | ||
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
|
284 | 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
|
285 | 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
|
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_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
|
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 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | 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
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | 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
|
298 | |
1fa3f13f774c
added allocator 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_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
|
300 | |
1fa3f13f774c
added allocator tests + started refactoring UcxBuffer tests (HINT: don't fix issues yet, complete tests first)
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
301 | ucx_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
|
302 | } |
1fa3f13f774c
added allocator 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 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
304 | 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
|
305 | 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
|
306 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
307 | 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
|
308 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
310 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
311 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
76 | 312 | b->size = b->capacity; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
314 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | char rb[16]; |
95 | 317 | for (size_t i = 0 ; i < 16 ; i++) { |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
318 | UCX_TEST_ASSERT(b->pos == i, "pos wrong during read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
319 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | "EOF shall not be set during read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
321 | 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
|
322 | } |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
323 | UCX_TEST_ASSERT(b->pos == 16, "pos wrong after read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
324 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "EOF not set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | UCX_TEST_ASSERT(memcmp(rb, " 01234567", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | "read data incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
330 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
334 | UCX_TEST(test_ucx_buffer_write) { |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
335 | 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
|
336 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | 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
|
338 | buffer[i] = 40+i; |
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 | |
61
fb07a0ab9a17
added flag field to buffer
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
341 | UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
344 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
346 | 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
|
347 | r = ucx_buffer_write((void*)teststring, 1, 20, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | UCX_TEST_ASSERT(r == 16, "string not correctly trimed"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | UCX_TEST_ASSERT(memcmp(buffer, teststring, 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | "buffer data incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
351 | UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof shall be set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
352 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
353 | ucx_buffer_seek(b, 8, SEEK_SET); |
71
303dabadff1c
made the code work with g++ without errors (but warnings)
Mike Becker <universe@uap-core.de>
parents:
69
diff
changeset
|
354 | r = ucx_buffer_write((void*)"not", 1, 3, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | UCX_TEST_ASSERT(r == 3, "three bytes should be replace"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | UCX_TEST_ASSERT(memcmp(buffer, "this is not too much", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | "modified buffer is incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
359 | const char* threebytestring = " t h r e e "; |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | memset(buffer, 49, 16); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
361 | ucx_buffer_seek(b, 0, SEEK_SET); |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
362 | r = ucx_buffer_write((void*)threebytestring, 3, 6, b); |
76 | 363 | UCX_TEST_ASSERT(r == 5, "three byte string not correctly trimed"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
364 | UCX_TEST_ASSERT(b->pos == 15, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | "position after write of three byte string incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
366 | UCX_TEST_ASSERT(!ucx_buffer_eof(b), "eof shall not be set"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
367 | UCX_TEST_ASSERT(memcmp(buffer, " t h r e e1", 16) == 0, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
368 | "bufer is incorrect after three byte string has been written"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
370 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
372 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
373 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
374 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
375 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
376 | UCX_TEST(test_ucx_buffer_write_ax) { |
76 | 377 | char *buffer = (char*) malloc(16); |
64
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
378 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
379 | UcxBuffer *b = ucx_buffer_new(buffer, 16, |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
380 | UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
381 | int r; |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
382 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
383 | UCX_TEST_BEGIN |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
384 | |
69
fb59270b1de3
made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents:
64
diff
changeset
|
385 | 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
|
386 | 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
|
387 | 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
|
388 | UCX_TEST_ASSERT(r == 20, "not all characters written"); |
76 | 389 | 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
|
390 | UCX_TEST_ASSERT(b->pos == 20, "position incorrect"); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
391 | UCX_TEST_ASSERT(memcmp(buffer, |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
392 | "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
|
393 | "incorrect buffer content"); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
394 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
395 | UCX_TEST_END |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
396 | |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
397 | ucx_buffer_free(b); |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
398 | } |
16590c9c497c
added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents:
63
diff
changeset
|
399 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
400 | UCX_TEST(test_ucx_buffer_read) { |
76 | 401 | UcxBuffer *b = ucx_buffer_new(NULL, 8, UCX_BUFFER_AUTOFREE); |
402 | ||
403 | char buf[32]; | |
404 | memset(buf, 'X', 32); | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
405 | int r; |
76 | 406 | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
407 | UCX_TEST_BEGIN |
76 | 408 | |
409 | ucx_buffer_write("01234567", 1, 8, b); | |
410 | UCX_TEST_ASSERT(b->pos == 8, "buffer not correctly filled"); | |
411 | b->pos = 0; | |
412 | ||
413 | r = ucx_buffer_read(buf, 1, 2, b); | |
414 | UCX_TEST_ASSERT(r == 2, "wrong number of bytes read"); | |
415 | UCX_TEST_ASSERT(buf[0] == '0' && buf[1] == '1' && buf[2] == 'X', | |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
416 | "buffer incorrect after first read"); |
76 | 417 | |
418 | r = ucx_buffer_read(buf + 2, 1, 8, b); | |
419 | UCX_TEST_ASSERT(r == 6, "wrong number of bytes read(2)"); | |
420 | UCX_TEST_ASSERT(memcmp(buf, "01234567XX", 10) == 0, | |
421 | "buffer incorrect after second read"); | |
422 | ||
423 | memset(buf, 'X', 32); | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
424 | ucx_buffer_seek(b, 0, SEEK_SET); |
76 | 425 | r = ucx_buffer_read(buf, 3, 3, b); |
426 | ||
427 | UCX_TEST_ASSERT(r == 2, "wrong number of blocks read"); | |
428 | UCX_TEST_ASSERT(memcmp(buf, "012345XX", 8) == 0, | |
429 | "buffer incorrect after three byte read"); | |
430 | ||
431 | ||
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
432 | UCX_TEST_END |
76 | 433 | |
147
1aa598f36872
added printf for UcxBuffer + fixed memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
434 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
435 | } |
62 | 436 | |
134
4d320dc3a7af
documented test.h and removed duplicated implement/declare macros for UCX_TEST
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
437 | 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
|
438 | char *buffer = (char*) malloc(16); |
62 | 439 | strcpy(buffer, "this is a test!"); |
440 | ||
76 | 441 | UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE); |
442 | src->size = 15; | |
443 | UcxBuffer *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_DEFAULT); | |
62 | 444 | |
445 | UCX_TEST_BEGIN | |
76 | 446 | UCX_TEST_ASSERT(dst != NULL, "ucx_buffer_extract returned NULL"); |
447 | ||
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
448 | UCX_TEST_ASSERT((dst->flags & UCX_BUFFER_AUTOFREE) == UCX_BUFFER_AUTOFREE, |
62 | 449 | "autofree flag shall be enforced"); |
63
1d3500806565
discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents:
62
diff
changeset
|
450 | UCX_TEST_ASSERT(dst->size == 5, "wrong size for new buffer"); |
62 | 451 | char rb[5]; |
452 | ucx_buffer_read(rb, 1, 5, dst); | |
453 | UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0, | |
454 | "new buffer has incorrect content"); | |
455 | ||
456 | UCX_TEST_ASSERT(ucx_buffer_extract(dst, 3, 3, UCX_BUFFER_DEFAULT) == NULL, | |
457 | "extract shall fail on invalid bounds"); | |
458 | ||
459 | UCX_TEST_END | |
460 | ||
461 | ucx_buffer_free(dst); | |
462 | ucx_buffer_free(src); | |
463 | } | |
76 | 464 | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
465 | UCX_TEST(test_ucx_stream_copy) { |
76 | 466 | UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT); |
467 | UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND); | |
468 | ||
469 | UCX_TEST_BEGIN | |
470 | ||
471 | ucx_buffer_write("01234567", 1, 8, b1); | |
472 | ucx_buffer_write("abcdefgh", 1, 8, b1); | |
473 | UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1"); | |
474 | ucx_buffer_seek(b1, 0, SEEK_SET); | |
475 | ||
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
476 | size_t ncp = ucx_stream_hcopy(b1, b2, ucx_buffer_read, ucx_buffer_write); |
76 | 477 | UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes"); |
478 | UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size"); | |
479 | UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0, | |
480 | "b1 and b2 have not the same content"); | |
481 | ||
482 | memset(b2->space, 0, b2->capacity); | |
483 | b2->pos = 0; | |
484 | b2->size = 0; | |
485 | ucx_buffer_seek(b1, 0, SEEK_SET); | |
486 | ||
487 | FILE *file = tmpfile(); | |
488 | UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted"); | |
489 | ||
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
490 | ncp = ucx_stream_hcopy(b1, file, ucx_buffer_read, fwrite); |
76 | 491 | UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file"); |
492 | ||
493 | fseek(file, 0, SEEK_SET); | |
494 | ||
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
495 | ncp = ucx_stream_hcopy(file, b2, fread, ucx_buffer_write); |
76 | 496 | UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file"); |
497 | ||
498 | UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0, | |
499 | "b1 and b2 content mismatch"); | |
500 | ||
501 | fclose(file); | |
140
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
502 | |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
503 | ucx_buffer_clear(b1); |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
504 | ucx_buffer_seek(b2, 0, SEEK_SET); |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
505 | ncp = ucx_stream_ncopy(b2, b1, ucx_buffer_read, ucx_buffer_write, 8); |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
506 | UCX_TEST_ASSERT(ncp == 8, "copied wrong number of bytes with ncopy"); |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
507 | UCX_TEST_ASSERT(memcmp(b1->space, "01234567\0\0\0\0\0\0\0\0", 16) == 0, |
15f871f50bfd
completed documentation + changed API for buffer/stream generic copy functions
Mike Becker <universe@uap-core.de>
parents:
134
diff
changeset
|
508 | "content wrong after ncopy"); |
76 | 509 | |
510 | UCX_TEST_END | |
511 | ||
512 | ucx_buffer_free(b1); | |
513 | ucx_buffer_free(b2); | |
514 | } |