6 #define BUF_SIZE 1024 * 3
8 int check_block_sizes(struct test_state *state, int id, int id_len)
11 for (int bs = 8; bs <= 64; bs *= 2) {
14 state->strm->block_size = bs;
15 max_rsi = (int)(state->buf_len / (bs * state->bytes_per_sample));
19 for (int rsi = 1; rsi <= max_rsi; rsi++) {
21 state->strm->rsi = rsi;
22 status = state->codec(state);
26 if ((state->cbuf[0] >> (8 - id_len)) != id) {
28 "%s: block of size %i created with ID:%x, expected %x.\n",
29 CHECK_FAIL, bs, state->cbuf[0] >> (8 - id_len), id
38 int check_zero(struct test_state *state)
42 if (state->strm->flags & AEC_DATA_PREPROCESS)
43 memset(state->ubuf, 0x55, state->buf_len);
45 memset(state->ubuf, 0, state->buf_len);
47 printf("Checking zero blocks ... ");
48 status = check_block_sizes(state, 0, state->id_len + 1);
52 printf ("%s\n", CHECK_PASS);
56 int check_splitting(struct test_state *state, int k)
61 int size = state->bytes_per_sample;
63 if (state->strm->flags & AEC_DATA_PREPROCESS) {
64 for (tmp = state->ubuf;
65 tmp < state->ubuf + state->buf_len;
67 state->out(tmp, state->xmin + (1ULL << (k - 1)) - 1, size);
68 state->out(tmp + size, state->xmin, size);
69 state->out(tmp + 2 * size, state->xmin
70 + (1ULL << (k + 1)) - 1, size);
71 state->out(tmp + 3 * size, state->xmin, size);
74 for (tmp = state->ubuf;
75 tmp < state->ubuf + state->buf_len;
77 state->out(tmp, 0, size);
78 state->out(tmp + size, (1ULL << k) - 1, size);
79 state->out(tmp + 2 * size, 0, size);
80 state->out(tmp + 3 * size, (1ULL << (k + 2)) - 1, size);
84 printf("Checking splitting with k=%i ... ", k);
85 status = check_block_sizes(state, k + 1, state->id_len);
89 printf ("%s\n", CHECK_PASS);
93 int check_uncompressed(struct test_state *state)
98 int size = state->bytes_per_sample;
100 for (tmp = state->ubuf;
101 tmp < state->ubuf + state->buf_len;
103 state->out(tmp, state->xmax, size);
104 state->out(tmp + size, state->xmin, size);
107 printf("Checking uncompressed ... ");
108 status = check_block_sizes(state,
109 (1ULL << state->id_len) - 1,
114 printf ("%s\n", CHECK_PASS);
118 int check_fs(struct test_state *state)
123 int size = state->bytes_per_sample;
125 if (state->strm->flags & AEC_DATA_PREPROCESS) {
126 for (tmp = state->ubuf;
127 tmp < state->ubuf + state->buf_len;
129 state->out(tmp, state->xmin + 2, size);
130 state->out(tmp + size, state->xmin, size);
131 state->out(tmp + 2 * size, state->xmin, size);
132 state->out(tmp + 3 * size, state->xmin, size);
135 for (tmp = state->ubuf;
136 tmp < state->ubuf + state->buf_len;
138 state->out(tmp, 0, size);
139 state->out(tmp + size, 0, size);
140 state->out(tmp + 2 * size, 0, size);
141 state->out(tmp + 3 * size, 4, size);
145 printf("Checking FS ... ");
146 status = check_block_sizes(state, 1, state->id_len);
150 printf ("%s\n", CHECK_PASS);
154 int check_se(struct test_state *state)
159 int size = state->bytes_per_sample;
161 if (state->strm->flags & AEC_DATA_PREPROCESS) {
162 for (tmp = state->ubuf;
163 tmp < state->ubuf + state->buf_len;
165 state->out(tmp, state->xmax - 1, size);
166 state->out(tmp + size, state->xmax - 1, size);
167 state->out(tmp + 2 * size, state->xmax - 1, size);
168 state->out(tmp + 3 * size, state->xmax - 1, size);
169 state->out(tmp + 4 * size, state->xmax, size);
170 state->out(tmp + 5 * size, state->xmax, size);
171 state->out(tmp + 6 * size, state->xmax, size);
172 state->out(tmp + 7 * size, state->xmax, size);
175 for (tmp = state->ubuf;
176 tmp < state->ubuf + state->buf_len;
178 state->out(tmp, 0, size);
179 state->out(tmp + size, 0, size);
180 state->out(tmp + 2 * size, 0, size);
181 state->out(tmp + 3 * size, 0, size);
182 state->out(tmp + 4 * size, 1, size);
183 state->out(tmp + 5 * size, 0, size);
184 state->out(tmp + 6 * size, 0, size);
185 state->out(tmp + 7 * size, 2, size);
189 printf("Checking Second Extension ... ");
190 status = check_block_sizes(state, 1, state->id_len + 1);
194 printf ("%s\n", CHECK_PASS);
198 int check_bps(struct test_state *state)
202 for (int bps = 8; bps <= 32; bps += 8) {
203 state->strm->bits_per_sample = bps;
205 state->strm->flags |= AEC_DATA_3BYTE;
207 state->strm->flags &= ~AEC_DATA_3BYTE;
211 status = check_zero(state);
215 status = check_se(state);
219 status = check_uncompressed(state);
223 status = check_fs(state);
227 for (int k = 1; k < bps - 2; k++) {
228 status = check_splitting(state, k);
232 printf("All checks with %i bit per sample passed.\n", bps);
237 int check_byte_orderings(struct test_state *state)
241 printf("-----------------------------------\n");
242 printf("Checking no PP, LSB first, unsigned\n");
243 printf("-----------------------------------\n");
244 status = check_bps(state);
248 printf("-----------------------------------\n");
249 printf("Checking PP, LSB first, unsigned\n");
250 printf("-----------------------------------\n");
251 state->strm->flags |= AEC_DATA_PREPROCESS;
252 status = check_bps(state);
256 printf("-----------------------------------\n");
257 printf("Checking PP, LSB first, signed\n");
258 printf("-----------------------------------\n");
259 state->strm->flags |= AEC_DATA_SIGNED;
261 status = check_bps(state);
265 state->strm->flags &= ~AEC_DATA_SIGNED;
266 state->strm->flags |= AEC_DATA_MSB;
268 printf("-----------------------------------\n");
269 printf("Checking PP, MSB first, unsigned\n");
270 printf("-----------------------------------\n");
271 status = check_bps(state);
275 printf("-----------------------------------\n");
276 printf("Checking PP, MSB first, signed\n");
277 printf("-----------------------------------\n");
278 state->strm->flags |= AEC_DATA_SIGNED;
280 status = check_bps(state);
286 int main(int argc, char *argv[])
289 struct aec_stream strm;
290 struct test_state state;
292 if (argc > 1 && strncmp(argv[1], "-d", 2) == 0)
297 state.buf_len = state.ibuf_len = BUF_SIZE;
298 state.cbuf_len = 2 * BUF_SIZE;
300 state.ubuf = (unsigned char *)malloc(state.buf_len);
301 state.cbuf = (unsigned char *)malloc(state.cbuf_len);
302 state.obuf = (unsigned char *)malloc(state.buf_len);
304 if (!state.ubuf || !state.cbuf || !state.obuf) {
305 printf("Not enough memory.\n");
312 printf("***************************\n");
313 printf("Checking with small buffers\n");
314 printf("***************************\n");
315 state.codec = encode_decode_small;
316 status = check_byte_orderings(&state);
320 printf("***************************\n");
321 printf("Checking with large buffers\n");
322 printf("***************************\n");
323 state.codec = encode_decode_large;
324 status = check_byte_orderings(&state);