test/buffer_tests.c

Fri, 12 Oct 2012 10:54:55 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Oct 2012 10:54:55 +0200
changeset 69
fb59270b1de3
parent 64
16590c9c497c
child 71
303dabadff1c
permissions
-rw-r--r--

made the code work with VC++ compiler (use make CONF=windows)

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) {
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
8 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
9 memset(buffer, 32, 7);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 buffer[7] = 0;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
12 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
13 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
17 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
18 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
19 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
20
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
21 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
22 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
23 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
24 "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
25
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
26 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
27 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
28 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
29
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
30 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
31 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
32 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
33 "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
34
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
35 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
36 UCX_TEST_ASSERT(r == 0, "seek END-5 failed");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
37 UCX_TEST_ASSERT(b->pos == 2, "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
38
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
39 r = ucx_buffer_seek(b, -10, SEEK_END);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 UCX_TEST_ASSERT(r != 0, "seek END beyond bounds shall fail");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
41 UCX_TEST_ASSERT(b->pos == 2,
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 "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
43
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 UCX_TEST_END
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_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
50 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
51 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
52 memset(buffer, 32, 16);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
54 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
55 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
59 ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48);
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);
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
62 ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48); ucx_buffer_putc(b, 48);
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
63 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
64 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
65 UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
66 "put shall return EOF when buffer is full");
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 UCX_TEST_ASSERT(memcmp(buffer, "000 000", 16) == 0,
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 "buffer contains incorrect content");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
72 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
76 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
77 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
78 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 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
80 buffer[i] = 40+i;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
83 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
84 int r;
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 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 char rb[16];
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 for (int i = 0 ; i < 16 ; i++) {
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
90 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
91 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
92 "EOF shall not be set during read loop");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
93 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
94 }
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
95 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
96 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
97 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
98 "read data incorrect");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
102 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
106 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
107 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
108 memset(buffer, 32, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 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
110 buffer[i] = 40+i;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
113 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
114 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
118 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
119 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
120 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
121 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
122 "buffer data incorrect");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
123 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
124
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
125 ucx_buffer_seek(b, 8, SEEK_SET);
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
126 r = ucx_buffer_write("not", 1, 3, b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 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
128 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
129 "modified buffer is incorrect");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
131 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
132 memset(buffer, 49, 16);
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
133 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
134 r = ucx_buffer_write((void*)threebytestring, 3, 6, b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 UCX_TEST_ASSERT(r == 15, "three byte string not correctly trimed");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
136 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
137 "position after write of three byte string incorrect");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
138 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
139 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
140 "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
141
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
144 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 }
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147
64
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
148 UCX_TEST_IMPLEMENT(test_ucx_buffer_write_ax) {
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
149 char *buffer = (char*) malloc(4);
64
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
150
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
151 UcxBuffer *b = ucx_buffer_new(buffer, 16,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
152 UCX_BUFFER_AUTOEXTEND | UCX_BUFFER_AUTOFREE);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
153 int r;
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
154
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
155 UCX_TEST_BEGIN
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
156
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
157 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
158 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
159 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
160 UCX_TEST_ASSERT(r == 20, "not all characters written");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
161 UCX_TEST_ASSERT(b->size == 32, "buffer not properly extended");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
162 UCX_TEST_ASSERT(b->pos == 20, "position incorrect");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
163 UCX_TEST_ASSERT(memcmp(buffer,
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
164 "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
165 "incorrect buffer content");
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
166
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
167 UCX_TEST_END
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
168
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
169 ucx_buffer_free(b);
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
170 }
16590c9c497c added autoextend feature to buffer
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
171
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
172 UCX_TEST_IMPLEMENT(test_ucx_buffer_read) {
69
fb59270b1de3 made the code work with VC++ compiler (use make CONF=windows)
Mike Becker <universe@uap-core.de>
parents: 64
diff changeset
173 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
174 memset(buffer, 56, 8);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 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
176 buffer[i] = 40+i;
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
61
fb07a0ab9a17 added flag field to buffer
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
179 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
180 int r;
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 UCX_TEST_BEGIN
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 char rb[16];
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 memset(rb, 32, 16);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
187 ucx_buffer_seek(b, 8, SEEK_SET);
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
188 r = ucx_buffer_read(rb, 1, 16, b);
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 == 8, "read did not stop at buffer end");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 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
191 "buffer incorrect after first read");
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
192 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
193
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
194 ucx_buffer_seek(b, 0, SEEK_SET);
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
195 r = ucx_buffer_read(rb+8, 1, 8, b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 UCX_TEST_ASSERT(r == 8, "read did not read the specified amount of bytes");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 UCX_TEST_ASSERT(memcmp(rb, "0123456788888888", 16) == 0,
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 "buffer incorrect after second read");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
200 ucx_buffer_seek(b, 0, SEEK_SET);
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
201 r = ucx_buffer_read(rb, 3, 6, b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 UCX_TEST_ASSERT(r == 15,
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 "three byte read did not read the desired amount of bytes");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 UCX_TEST_ASSERT(memcmp(rb, "8888888801234568", 16) == 0,
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 "buffer incorrect after three byte read");
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 UCX_TEST_END
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208
60
abae4669fba7 renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
209 ucx_buffer_free(b);
56
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 free(buffer);
76caac0da4a0 added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 }
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
212
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
213 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
214 char *buffer = (char*) malloc(16);
62
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
215 strcpy(buffer, "this is a test!");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
216
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
217 UcxBuffer *src = ucx_buffer_new(buffer, 16, UCX_BUFFER_AUTOFREE),
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
218 *dst = ucx_buffer_extract(src, 5, 5, UCX_BUFFER_DEFAULT);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
219
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
220 UCX_TEST_BEGIN
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
221 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
222 "autofree flag shall be enforced");
63
1d3500806565 discarded fascism from buffer
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
223 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
224 char rb[5];
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
225 ucx_buffer_read(rb, 1, 5, dst);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
226 UCX_TEST_ASSERT(memcmp(rb, "is a ", 5) == 0,
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
227 "new buffer has incorrect content");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
228
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
229 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
230 "extract shall fail on invalid bounds");
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
231
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
232 UCX_TEST_END
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
233
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
234 ucx_buffer_free(dst);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
235 ucx_buffer_free(src);
6814aea8462d added extract function
Mike Becker <universe@uap-core.de>
parents: 61
diff changeset
236 }

mercurial