6 #define BUF_SIZE 1024 * 3
8 int check_block_sizes(struct test_state *state, int id, int id_len)
10 int bs, status, rsi, max_rsi;
12 for (bs = 8; bs <= 64; bs *= 2) {
13 state->strm->block_size = bs;
15 max_rsi = (int)(state->buf_len / (bs * state->bytes_per_sample));
19 for (rsi = 1; rsi <= max_rsi; rsi++) {
20 state->strm->rsi = rsi;
21 status = state->codec(state);
25 if ((state->cbuf[0] >> (8 - id_len)) != id) {
27 "%s: block of size %i created with ID:%x, expected %x.\n",
28 CHECK_FAIL, bs, state->cbuf[0] >> (8 - id_len), id
37 int check_zero(struct test_state *state)
41 if (state->strm->flags & AEC_DATA_PREPROCESS)
42 memset(state->ubuf, 0x55, state->buf_len);
44 memset(state->ubuf, 0, state->buf_len);
46 printf("Checking zero blocks ... ");
47 status = check_block_sizes(state, 0, state->id_len + 1);
51 printf ("%s\n", CHECK_PASS);
55 int check_splitting(struct test_state *state, int k)
60 size = state->bytes_per_sample;
62 if (state->strm->flags & AEC_DATA_PREPROCESS) {
63 for (tmp = state->ubuf;
64 tmp < state->ubuf + state->buf_len;
66 state->out(tmp, state->xmin + (1ULL << (k - 1)) - 1, size);
67 state->out(tmp + size, state->xmin, size);
68 state->out(tmp + 2 * size, state->xmin
69 + (1ULL << (k + 1)) - 1, size);
70 state->out(tmp + 3 * size, state->xmin, size);
73 for (tmp = state->ubuf;
74 tmp < state->ubuf + state->buf_len;
76 state->out(tmp, 0, size);
77 state->out(tmp + size, (1ULL << k) - 1, size);
78 state->out(tmp + 2 * size, 0, size);
79 state->out(tmp + 3 * size, (1ULL << (k + 2)) - 1, size);
83 printf("Checking splitting with k=%i ... ", k);
84 status = check_block_sizes(state, k + 1, state->id_len);
88 printf ("%s\n", CHECK_PASS);
92 int check_uncompressed(struct test_state *state)
97 size = state->bytes_per_sample;
99 for (tmp = state->ubuf;
100 tmp < state->ubuf + state->buf_len;
102 state->out(tmp, state->xmax, size);
103 state->out(tmp + size, state->xmin, size);
106 printf("Checking uncompressed ... ");
107 status = check_block_sizes(state,
108 (1ULL << state->id_len) - 1,
113 printf ("%s\n", CHECK_PASS);
117 int check_fs(struct test_state *state)
122 size = state->bytes_per_sample;
124 if (state->strm->flags & AEC_DATA_PREPROCESS) {
125 for (tmp = state->ubuf;
126 tmp < state->ubuf + state->buf_len;
128 state->out(tmp, state->xmin + 2, size);
129 state->out(tmp + size, state->xmin, size);
130 state->out(tmp + 2 * size, state->xmin, size);
131 state->out(tmp + 3 * size, state->xmin, size);
134 for (tmp = state->ubuf;
135 tmp < state->ubuf + state->buf_len;
137 state->out(tmp, 0, size);
138 state->out(tmp + size, 0, size);
139 state->out(tmp + 2 * size, 0, size);
140 state->out(tmp + 3 * size, 4, size);
144 printf("Checking FS ... ");
145 status = check_block_sizes(state, 1, state->id_len);
149 printf ("%s\n", CHECK_PASS);
153 int check_se(struct test_state *state)
158 size = state->bytes_per_sample;
160 if (state->strm->flags & AEC_DATA_PREPROCESS) {
161 for (tmp = state->ubuf;
162 tmp < state->ubuf + state->buf_len;
164 state->out(tmp, state->xmax - 1, size);
165 state->out(tmp + size, state->xmax - 1, size);
166 state->out(tmp + 2 * size, state->xmax - 1, size);
167 state->out(tmp + 3 * size, state->xmax - 1, size);
168 state->out(tmp + 4 * size, state->xmax, size);
169 state->out(tmp + 5 * size, state->xmax, size);
170 state->out(tmp + 6 * size, state->xmax, size);
171 state->out(tmp + 7 * size, state->xmax, size);
174 for (tmp = state->ubuf;
175 tmp < state->ubuf + state->buf_len;
177 state->out(tmp, 0, size);
178 state->out(tmp + size, 0, size);
179 state->out(tmp + 2 * size, 0, size);
180 state->out(tmp + 3 * size, 0, size);
181 state->out(tmp + 4 * size, 1, size);
182 state->out(tmp + 5 * size, 0, size);
183 state->out(tmp + 6 * size, 0, size);
184 state->out(tmp + 7 * size, 2, size);
188 printf("Checking Second Extension ... ");
189 status = check_block_sizes(state, 1, state->id_len + 1);
193 printf ("%s\n", CHECK_PASS);
197 int check_bps(struct test_state *state)
201 for (bps = 8; bps <= 32; bps += 8) {
202 state->strm->bits_per_sample = bps;
204 state->strm->flags |= AEC_DATA_3BYTE;
206 state->strm->flags &= ~AEC_DATA_3BYTE;
210 status = check_zero(state);
214 status = check_se(state);
218 status = check_uncompressed(state);
222 status = check_fs(state);
226 for (k = 1; k < bps - 2; k++) {
227 status = check_splitting(state, k);
231 printf("All checks with %i bit per sample passed.\n", bps);
236 int check_byte_orderings(struct test_state *state)
240 printf("-----------------------------------\n");
241 printf("Checking no PP, LSB first, unsigned\n");
242 printf("-----------------------------------\n");
243 status = check_bps(state);
247 printf("-----------------------------------\n");
248 printf("Checking PP, LSB first, unsigned\n");
249 printf("-----------------------------------\n");
250 state->strm->flags |= AEC_DATA_PREPROCESS;
251 status = check_bps(state);
255 printf("-----------------------------------\n");
256 printf("Checking PP, LSB first, signed\n");
257 printf("-----------------------------------\n");
258 state->strm->flags |= AEC_DATA_SIGNED;
260 status = check_bps(state);
264 state->strm->flags &= ~AEC_DATA_SIGNED;
265 state->strm->flags |= AEC_DATA_MSB;
267 printf("-----------------------------------\n");
268 printf("Checking PP, MSB first, unsigned\n");
269 printf("-----------------------------------\n");
270 status = check_bps(state);
274 printf("-----------------------------------\n");
275 printf("Checking PP, MSB first, signed\n");
276 printf("-----------------------------------\n");
277 state->strm->flags |= AEC_DATA_SIGNED;
279 status = check_bps(state);
288 struct aec_stream strm;
289 struct test_state state;
291 state.buf_len = state.ibuf_len = BUF_SIZE;
292 state.cbuf_len = 2 * BUF_SIZE;
294 state.ubuf = (unsigned char *)malloc(state.buf_len);
295 state.cbuf = (unsigned char *)malloc(state.cbuf_len);
296 state.obuf = (unsigned char *)malloc(state.buf_len);
298 if (!state.ubuf || !state.cbuf || !state.obuf) {
299 printf("Not enough memory.\n");
306 printf("***************************\n");
307 printf("Checking with small buffers\n");
308 printf("***************************\n");
309 state.codec = encode_decode_small;
310 status = check_byte_orderings(&state);
314 printf("***************************\n");
315 printf("Checking with large buffers\n");
316 printf("***************************\n");
317 state.codec = encode_decode_large;
318 status = check_byte_orderings(&state);