Wed, 10 Oct 2012 09:54:57 +0200
renamed UcxMemstream to UcxBuffer
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) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | char *buffer = malloc(16); |
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 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
12 | UcxBuffer *b = ucx_buffer_new(buffer, 16); |
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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
19 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
23 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
28 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
32 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
37 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
41 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 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) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | char *buffer = malloc(16); |
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 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
54 | UcxBuffer *b = ucx_buffer_new(buffer, 16); |
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); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
60 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 3, "pos wrong after first 3 puts"); |
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); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
63 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 16, "pos wrong after last 3 puts"); |
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"); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
65 | UCX_TEST_ASSERT(ucx_buffer_putc(b, 48) == EOF, "put shall return EOF on memof"); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | 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
|
67 | "buffer contains incorrect content"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
71 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
75 | UCX_TEST_IMPLEMENT(test_ucx_buffer_getc) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | 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
|
79 | buffer[i] = 40+i; |
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 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
82 | UcxBuffer *b = ucx_buffer_new(buffer, 16); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | char rb[16]; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | for (int i = 0 ; i < 16 ; i++) { |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
89 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == i, "pos wrong during read loop"); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
90 | 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
|
91 | "EOF shall not be set during read loop"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
92 | 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
|
93 | } |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
94 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 16, "pos wrong after read loop"); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
95 | 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
|
96 | 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
|
97 | "read data incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
101 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
105 | UCX_TEST_IMPLEMENT(test_ucx_buffer_write) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | memset(buffer, 32, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | 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
|
109 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
112 | UcxBuffer *b = ucx_buffer_new(buffer, 16); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | UCX_TEST_BEGIN |
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 | char* teststring = "this is way too much"; |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
118 | r = ucx_buffer_write(teststring, 1, 20, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | 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
|
120 | 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
|
121 | "buffer data incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
122 | 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
|
123 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
124 | ucx_buffer_seek(b, 8, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | "modified buffer is incorrect"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | char* threebytestring = " t h r e e "; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | memset(buffer, 49, 16); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
132 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
133 | r = ucx_buffer_write(threebytestring, 3, 6, b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | UCX_TEST_ASSERT(r == 15, "three byte string not correctly trimed"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
135 | UCX_TEST_ASSERT(ucx_buffer_tell(b) == 15, |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | "position after write of three byte string incorrect"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
137 | 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
|
138 | 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
|
139 | "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
|
140 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
143 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
147 | UCX_TEST_IMPLEMENT(test_ucx_buffer_read) { |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | char *buffer = malloc(16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | memset(buffer, 56, 8); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | 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
|
151 | buffer[i] = 40+i; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | } |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
154 | UcxBuffer *b = ucx_buffer_new(buffer, 16); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | int r; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | UCX_TEST_BEGIN |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | char rb[16]; |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | memset(rb, 32, 16); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
162 | ucx_buffer_seek(b, 8, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
163 | 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
|
164 | 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
|
165 | 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
|
166 | "buffer incorrect after first read"); |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
167 | 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
|
168 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
169 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
170 | 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
|
171 | 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
|
172 | 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
|
173 | "buffer incorrect after second read"); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
175 | ucx_buffer_seek(b, 0, SEEK_SET); |
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
176 | 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
|
177 | UCX_TEST_ASSERT(r == 15, |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | "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
|
179 | 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
|
180 | "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
|
181 | |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | UCX_TEST_END |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
183 | |
60
abae4669fba7
renamed UcxMemstream to UcxBuffer
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
184 | ucx_buffer_free(b); |
56
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | free(buffer); |
76caac0da4a0
added memstream to ucx - still little work to do
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | } |