test/buffer_tests.c

Fri, 30 Nov 2012 13:10:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 30 Nov 2012 13:10:58 +0100
changeset 76
655020a30e77
parent 71
303dabadff1c
child 83
3b552d7a9610
permissions
-rw-r--r--

fixed buffer

56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 *
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 */
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
5 #include "buffer_tests.h"
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
7 UCX_TEST_IMPLEMENT(test_ucx_buffer_seektell) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
8 UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
9 b->size = 16; // less than capacity
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
14 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
15 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
16 UCX_TEST_ASSERT(b->pos == 5, "seek SET+5 set wrong position");
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
18 r = ucx_buffer_seek(b, 20, SEEK_SET);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 UCX_TEST_ASSERT(r != 0, "seek beyond bounds shall fail");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
20 UCX_TEST_ASSERT(b->pos == 5,
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 "failed seek shall leave pos unchanged");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
23 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
24 UCX_TEST_ASSERT(r == 0, "seek CUR+5 failed");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
25 UCX_TEST_ASSERT(b->pos == 10, "seek CUR+5 set wrong position");
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
27 r = ucx_buffer_seek(b, 10, SEEK_CUR);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 UCX_TEST_ASSERT(r != 0, "seek CUR beyond bounds shall fail");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
29 UCX_TEST_ASSERT(b->pos == 10,
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 "failed seek shall leave pos unchanged");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
32 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
33 UCX_TEST_ASSERT(r == 0, "seek END-5 failed");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
34 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
35
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
36 r = ucx_buffer_seek(b, -20, SEEK_END);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 UCX_TEST_ASSERT(r != 0, "seek END beyond bounds shall fail");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
38 UCX_TEST_ASSERT(b->pos == 11,
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 "failed seek shall leave pos unchanged");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
43 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
46 UCX_TEST_IMPLEMENT(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
47 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
48 memset(buffer, 32, 16);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
50 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
51 b->size = b->capacity;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
56 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
57 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
58 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
59
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
60 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
61 ucx_buffer_seek(b, 10, SEEK_CUR);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
62
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
63 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
64 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
65 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
66
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
67 UCX_TEST_ASSERT(b->pos == 16, "pos wrong after last 3 puts");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
68 UCX_TEST_ASSERT(ucx_buffer_eof(b), "eof not set");
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
69 UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
70 "put shall return EOF when buffer is full");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
71
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
72 ucx_buffer_seek(b, 3, SEEK_SET);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
73 ucx_buffer_putc(b, 'a');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
74 ucx_buffer_putc(b, 'b');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
75 ucx_buffer_putc(b, 'c');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
77 UCX_TEST_ASSERT(b->size == 16, "wrong size after seek and puts");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
78 UCX_TEST_ASSERT(memcmp(buffer, "000abc 000", 16) == 0,
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 "buffer contains incorrect content");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
83 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
87 UCX_TEST_IMPLEMENT(test_ucx_buffer_putc_ax) {
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
88 UcxBuffer *b = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
89
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
90 UCX_TEST_BEGIN
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
91
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
92 ucx_buffer_putc(b, '0');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
93 ucx_buffer_putc(b, '1');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
94
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
95 UCX_TEST_ASSERT(b->pos == 2, "pos wrong after first 2 puts");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
96 UCX_TEST_ASSERT(b->capacity == 2, "buffer erroneously extended");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
97
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
98 ucx_buffer_putc(b, 'a');
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
99
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
100 UCX_TEST_ASSERT(b->pos == 3, "pos wrong after 1 put");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
101 UCX_TEST_ASSERT(b->capacity == 4, "buffer not properly extended");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
102 UCX_TEST_ASSERT(b->size == 3, "wrong buffer size");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
103
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
104 UCX_TEST_ASSERT(b->space[2] == 'a', "wrong content");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
105
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
106 UCX_TEST_END
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
107
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
108
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
109 }
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
110
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
111 UCX_TEST_IMPLEMENT(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
112 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
113 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 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
115 buffer[i] = 40+i;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
118 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
119 b->size = b->capacity;
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 char rb[16];
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 for (int i = 0 ; i < 16 ; i++) {
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
126 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
127 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
128 "EOF shall not be set during read loop");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
129 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
130 }
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
131 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
132 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
133 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
134 "read data incorrect");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
138 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
142 UCX_TEST_IMPLEMENT(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
143 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
144 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 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
146 buffer[i] = 40+i;
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
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
149 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
150 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
154 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
155 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
156 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
157 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
158 "buffer data incorrect");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
159 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
160
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
161 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
162 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
163 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
164 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
165 "modified buffer is incorrect");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
167 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
168 memset(buffer, 49, 16);
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
169 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
170 r = ucx_buffer_write((void*)threebytestring, 3, 6, b);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
171 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
172 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
173 "position after write of three byte string incorrect");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
174 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
175 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
176 "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
177
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
180 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183
64
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
184 UCX_TEST_IMPLEMENT(test_ucx_buffer_write_ax) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
185 char *buffer = (char*) malloc(16);
64
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
186
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
187 UcxBuffer *b = ucx_buffer_new(buffer, 16,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
188 UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
189 int r;
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
190
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
191 UCX_TEST_BEGIN
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
192
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
193 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
194 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
195 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
196 UCX_TEST_ASSERT(r == 20, "not all characters written");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
197 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
198 UCX_TEST_ASSERT(b->pos == 20, "position incorrect");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
199 UCX_TEST_ASSERT(memcmp(buffer,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
200 "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
201 "incorrect buffer content");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
202
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
203 UCX_TEST_END
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
204
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
205 ucx_buffer_free(b);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
206 }
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
207
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
208 UCX_TEST_IMPLEMENT(test_ucx_buffer_read) {
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
209 UcxBuffer *b = ucx_buffer_new(NULL, 8, UCX_BUFFER_AUTOFREE);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
210
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
211 char buf[32];
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
212 memset(buf, 'X', 32);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 int r;
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
214
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 UCX_TEST_BEGIN
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
216
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
217 ucx_buffer_write("01234567", 1, 8, b);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
218 UCX_TEST_ASSERT(b->pos == 8, "buffer not correctly filled");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
219 b->pos = 0;
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
220
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
221 r = ucx_buffer_read(buf, 1, 2, b);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
222 UCX_TEST_ASSERT(r == 2, "wrong number of bytes read");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
223 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
224 "buffer incorrect after first read");
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
225
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
226 r = ucx_buffer_read(buf + 2, 1, 8, b);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
227 UCX_TEST_ASSERT(r == 6, "wrong number of bytes read(2)");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
228 UCX_TEST_ASSERT(memcmp(buf, "01234567XX", 10) == 0,
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
229 "buffer incorrect after second read");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
230
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
231 memset(buf, 'X', 32);
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
232 ucx_buffer_seek(b, 0, SEEK_SET);
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
233 r = ucx_buffer_read(buf, 3, 3, b);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
234
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
235 UCX_TEST_ASSERT(r == 2, "wrong number of blocks read");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
236 UCX_TEST_ASSERT(memcmp(buf, "012345XX", 8) == 0,
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
237 "buffer incorrect after three byte read");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
238
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
239
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 UCX_TEST_END
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
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 }
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
244
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
245 UCX_TEST_IMPLEMENT(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
246 char *buffer = (char*) malloc(16);
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
247 strcpy(buffer, "this is a test!");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
248
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
249 UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
250 src->size = 15;
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
251 UcxBuffer *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_DEFAULT);
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
252
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
253 UCX_TEST_BEGIN
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
254 UCX_TEST_ASSERT(dst != NULL, "ucx_buffer_extract returned NULL");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
255
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
256 UCX_TEST_ASSERT((dst->flags & UCX_BUFFER_AUTOFREE) == UCX_BUFFER_AUTOFREE,
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
257 "autofree flag shall be enforced");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
258 UCX_TEST_ASSERT(dst->size == 5, "wrong size for new buffer");
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
259 char rb[5];
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
260 ucx_buffer_read(rb, 1, 5, dst);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
261 UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
262 "new buffer has incorrect content");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
263
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
264 UCX_TEST_ASSERT(ucx_buffer_extract(dst, 3, 3, UCX_BUFFER_DEFAULT) == NULL,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
265 "extract shall fail on invalid bounds");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
266
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
267 UCX_TEST_END
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
268
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
269 ucx_buffer_free(dst);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
270 ucx_buffer_free(src);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
271 }
76
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
272
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
273 UCX_TEST_IMPLEMENT(test_ucx_buffer_generic_copy) {
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
274 UcxBuffer *b1 = ucx_buffer_new(NULL, 64, UCX_BUFFER_DEFAULT);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
275 UcxBuffer *b2 = ucx_buffer_new(NULL, 2, UCX_BUFFER_AUTOEXTEND);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
276
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
277 UCX_TEST_BEGIN
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
278
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
279 ucx_buffer_write("01234567", 1, 8, b1);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
280 ucx_buffer_write("abcdefgh", 1, 8, b1);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
281 UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
282 ucx_buffer_seek(b1, 0, SEEK_SET);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
283
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
284 size_t ncp = ucx_buffer_copy(b1, b2, ucx_buffer_read, ucx_buffer_write);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
285 UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
286 UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
287 UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
288 "b1 and b2 have not the same content");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
289
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
290 memset(b2->space, 0, b2->capacity);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
291 b2->pos = 0;
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
292 b2->size = 0;
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
293 ucx_buffer_seek(b1, 0, SEEK_SET);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
294
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
295 FILE *file = tmpfile();
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
296 UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
297
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
298 ncp = ucx_buffer_copy(b1, file, ucx_buffer_read, fwrite);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
299 UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
300
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
301 fseek(file, 0, SEEK_SET);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
302
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
303 ncp = ucx_buffer_copy(file, b2, fread, ucx_buffer_write);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
304 UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file");
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
305
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
306 UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
307 "b1 and b2 content mismatch");
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 fclose(file);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
310
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
311
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
312 UCX_TEST_END
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
313
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
314 ucx_buffer_free(b1);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
315 ucx_buffer_free(b2);
655020a30e77 fixed buffer
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 71
diff changeset
316 }

mercurial