diff options
author | Mathis Rosenhauer <rosenhauer@dkrz.de> | 2012-09-20 19:34:50 +0200 |
---|---|---|
committer | Thomas Jahns <jahns@dkrz.de> | 2013-02-19 11:32:59 +0100 |
commit | e85b4fe2595df7dc94be93c0148b2c10b2d6fa66 (patch) | |
tree | 796e2374ed2b96ae0f48e8c99ce1a79520dc4321 | |
parent | 0604e04b747e2d8ec741ee5a5e50bd0036f38562 (diff) | |
download | libaec-e85b4fe2595df7dc94be93c0148b2c10b2d6fa66.tar.gz libaec-e85b4fe2595df7dc94be93c0148b2c10b2d6fa66.tar.bz2 libaec-e85b4fe2595df7dc94be93c0148b2c10b2d6fa66.zip |
Simple zero block check
-rw-r--r-- | .gitignore | 11 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/check_aec.c | 116 |
5 files changed, 130 insertions, 7 deletions
@@ -1,9 +1,9 @@ Makefile Makefile.in aclocal.m4 -config/ -src/.libs/ -src/.deps/ +config +.libs +.deps src/aec src/test_szcomp *.o @@ -13,5 +13,6 @@ config.log config.status configure libtool -autom4te.cache/ -m4/ +autom4te.cache +m4 + diff --git a/Makefile.am b/Makefile.am index 0a7b929..16e75b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,2 +1,2 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src +SUBDIRS = src tests diff --git a/configure.ac b/configure.ac index cf717c5..2eb9609 100644 --- a/configure.ac +++ b/configure.ac @@ -33,7 +33,8 @@ AC_FUNC_MALLOC AC_CHECK_FUNCS([memset strstr]) AC_CONFIG_FILES([Makefile - src/Makefile]) + src/Makefile + tests/Makefile]) AC_OUTPUT # Checks compilers and preprocessors diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..3e5f560 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,5 @@ +INCLUDES = -I$(top_srcdir)/src +TESTS = check_aec +check_PROGRAMS = check_aec +check_aec_SOURCES = check_aec.c $(top_builddir)/src/libaec.h +check_aec_LDADD = $(top_builddir)/src/libaec-0.0.la diff --git a/tests/check_aec.c b/tests/check_aec.c new file mode 100644 index 0000000..dab1930 --- /dev/null +++ b/tests/check_aec.c @@ -0,0 +1,116 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <inttypes.h> +#include <string.h> +#include "libaec.h" + +#define BUF_SIZE 1024 + +int encode_decode(struct aec_stream *strm, + uint8_t *ubuf, + uint8_t *cbuf, + uint8_t *obuf, + size_t n) +{ + int status; + + strm->avail_in = n; + strm->avail_out = n; + strm->next_in = ubuf; + strm->next_out = cbuf; + + status = aec_encode_init(strm); + if (status != AEC_OK) { + printf("Init failed.\n"); + return 99; + } + + status = aec_encode(strm, AEC_FLUSH); + if (status != AEC_OK) { + printf("Encode failed.\n"); + return 99; + } + + aec_encode_end(strm); + + strm->avail_in = strm->total_out; + strm->avail_out = n; + strm->next_in = cbuf; + strm->next_out = obuf; + + status = aec_decode_init(strm); + if (status != AEC_OK) { + printf("Init failed.\n"); + return 99; + } + + status = aec_decode(strm, AEC_FLUSH); + if (status != AEC_OK) { + printf("Decode failed.\n"); + return 99; + } + + if (memcmp(ubuf, obuf, n)) { + printf("FAIL: Uncompressed output differs from input.\n"); + return 99; + } + aec_decode_end(strm); + return 0; +} + +int check_zero(struct aec_stream *strm, + uint8_t *ubuf, + uint8_t *cbuf, + uint8_t *obuf, + size_t n) +{ + int bs, status; + + for (bs = 8; bs <= 64; bs *= 2) { + memset(ubuf, 0x55, n); + strm->bit_per_sample = 8; + strm->block_size = bs; + strm->rsi = n / bs; + strm->flags = AEC_DATA_PREPROCESS; + + printf("Checking zero blocks with block size %i ... ", bs); + + status = encode_decode(strm, ubuf, cbuf, obuf, n); + if (status) + return status; + + if ((cbuf[0] & 0xf0) != 0) { + printf("FAIL: Unexpected block created.\n"); + return 99; + } + printf ("OK\n"); + } + return 0; +} + +int main (void) +{ + int status; + uint8_t *ubuf, *cbuf, *obuf; + struct aec_stream strm; + + ubuf = (uint8_t *)malloc(BUF_SIZE); + cbuf = (uint8_t *)malloc(BUF_SIZE); + obuf = (uint8_t *)malloc(BUF_SIZE); + + if (!ubuf || !cbuf || !obuf) { + printf("Not enough memory.\n"); + return 99; + } + + status = check_zero(&strm, ubuf, cbuf, obuf, BUF_SIZE); + if (status) + return status; + + free(ubuf); + free(cbuf); + free(obuf); + + return 0; +} |