1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* SpanDSP - a series of DSP components for telephony
*
* bitstream_tests.c
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2007 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \page bitstream_tests_page Bitstream tests
\section bitstream_tests_page_sec_1 What does it do?
\section bitstream_tests_page_sec_2 How is it used?
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
uint8_t buffer[256];
#define PATTERN 0x11111111
#define SEQUENCE_LENGTH 17
uint8_t left[] =
{
0x28, /* 2 of 4, 3, 2, 1 */
0xC8, /* 1 of 6, 5, 2 of 4 */
0xAE, /* 3 of 7, 5 of 6 */
0x67, /* 4 of 8, 4 of 7 */
0x74, /* 4 of 9, 4 of 8 */
0x43, /* 3 of 10, 5 of 9 */
0x32, /* 1 of 11, 7 of 10 */
0xAA, /* 8 of 11 */
0xAE, /* 6 of 12, 2 of 11 */
0xED, /* 2 of 13, 6 of 12 */
0x99, /* 8 of 13 */
0x8E, /* 5 of 14, 3 of 13 */
0xEE, /* 8 of 14 */
0xEE, /* 7 of 15, 1 of 14 */
0xEE, /* 8 of 15 */
0xFF, /* 8 of 16 */
0xFF, /* 8 of 16 */
0x88, /* 8 of 17 */
0x88, /* 8 of 17 */
0x00 /* 1 of 17 */
};
uint8_t right[] =
{
0xD2, /* 1, 2, 3, 2 of 4 */
0x90, /* 2 of 4, 5, 1 of 6 */
0xCA, /* 5 of 6, 3 of 7 */
0x7C, /* 4 of 7, 4 of 8 */
0x87, /* 4 of 8, 4 of 9 */
0x28, /* 5 of 9, 3 of 10 */
0x33, /* 7 of 10, 1 of 11 */
0x55, /* 8 of 11 */
0xED, /* 2 of 11, 6 of 12 */
0x2E, /* 6 of 12, 2 of 13 */
0x33, /* 8 of 13 */
0xEB, /* 3 of 13, 5 of 14 */
0xEE, /* 8 of 14 */
0xDC, /* 1 of 14, 7 of 15 */
0xDD, /* 8 of 15 */
0xFF, /* 8 of 16 */
0xFF, /* 8 of 16 */
0x10, /* 8 of 17 */
0x11, /* 8 of 17 */
0x01 /* 1 of 17 */
};
int main(int argc, char *argv[])
{
int i;
bitstream_state_t state;
bitstream_state_t *s;
const uint8_t *r;
uint8_t *w;
uint8_t *cc;
unsigned int x;
int total_bits;
s = bitstream_init(&state, TRUE);
w = buffer;
total_bits = 0;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
bitstream_put(s, &w, PATTERN*i, i + 1);
total_bits += (i + 1);
}
bitstream_flush(s, &w);
printf("%d bits written\n", total_bits);
for (cc = buffer; cc < w; cc++)
printf("%02X ", *cc);
printf("\n");
for (cc = right; cc < right + sizeof(right); cc++)
printf("%02X ", *cc);
printf("\n");
if ((w - buffer) != sizeof(right) || memcmp(buffer, right, sizeof(right)))
{
printf("Test failed\n");
exit(2);
}
s = bitstream_init(&state, TRUE);
r = buffer;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
x = bitstream_get(s, &r, i + 1);
if (x != ((PATTERN*i) & ((1 << (i + 1)) - 1)))
{
printf("Error 0x%X 0x%X\n", x, ((PATTERN*i) & ((1 << (i + 1)) - 1)));
printf("Test failed\n");
exit(2);
}
}
s = bitstream_init(&state, FALSE);
w = buffer;
total_bits = 0;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
bitstream_put(s, &w, PATTERN*i, i + 1);
total_bits += (i + 1);
}
bitstream_flush(s, &w);
printf("%d bits written\n", total_bits);
for (cc = buffer; cc < w; cc++)
printf("%02X ", *cc);
printf("\n");
for (cc = left; cc < left + sizeof(left); cc++)
printf("%02X ", *cc);
printf("\n");
if ((w - buffer) != sizeof(left) || memcmp(buffer, left, sizeof(left)))
{
printf("Test failed\n");
exit(2);
}
s = bitstream_init(&state, FALSE);
r = buffer;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
x = bitstream_get(s, &r, i + 1);
if (x != ((PATTERN*i) & ((1 << (i + 1)) - 1)))
{
printf("Error 0x%X 0x%X\n", x, ((PATTERN*i) & ((1 << (i + 1)) - 1)));
printf("Test failed\n");
exit(2);
}
}
printf("Tests passed.\n");
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
|