From: Ian Jackson Date: Sun, 17 Nov 2019 11:45:57 +0000 (+0000) Subject: Provide test cases for maxlen functions X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=base91.git;a=commitdiff_plain;h=664054e8f603f09badb98ef09ee1bd1e58d93659 Provide test cases for maxlen functions Signed-off-by: Ian Jackson --- diff --git a/.gitignore b/.gitignore index 9fa91e1..4863b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /base91 +/lentest *.o /test/b91dec /test/b91enc +/test/lentest /test/*.dat /test/*.b91 diff --git a/Makefile b/Makefile index 246aede..feb0e45 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ mandir = $(prefix)/share/man man1dir = $(mandir)/man1 manext = .1 -BIN = base91 +BIN = base91 lentest .PHONY: all install check clean @@ -25,6 +25,8 @@ all: $(BIN) base91: cli.o base91.o $(CC) $(LDFLAGS) -o $@ $^ +lentest: lentest.o base91.o + install: all mkdir -p $(DESTDIR)$(bindir) $(INSTALL_PROGRAM) base91 $(DESTDIR)$(bindir)/base91 diff --git a/lentest.c b/lentest.c new file mode 100644 index 0000000..3e43d70 --- /dev/null +++ b/lentest.c @@ -0,0 +1,93 @@ +/* + * basE91 length calculation test + * + * Copyright (c) 2019 Ian Jackson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Joachim Henke nor the names of his contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "base91.h" + +static size_t upto = (14*16 + 14 + 16)*2; + +static int do_test(int do_do, int fill, const char *what, + size_t f(struct basE91 *, const void *, size_t, void *), + size_t f_end(struct basE91 *, void *), + size_t f_maxlen(size_t) + ) +{ + struct basE91 b; + size_t i, o, exp; + int bad = 0; + char ibuf[upto]; + char obuf[upto*2+100]; /* in case we have bugs */ + + memset(ibuf,fill,upto); + + if (!do_do) { + printf("%s: skipping\n",what); + return 0; + } + + for (i=0; i=2) { + do_encode = !!strchr(argv[1],'e'); + do_decode = !!strchr(argv[1],'d'); + } + if (argc>=3) { + upto = atoi(argv[2]); + } + +#define MAYBE_DO_TEST(ed, fill) \ + (bad |= do_test(do_##ed, (fill), #ed, \ + basE91_##ed, basE91_##ed##_end, basE91_##ed##_maxlen)) + MAYBE_DO_TEST(encode, 0xff); + MAYBE_DO_TEST(decode, 'A'); + + if (bad) exit(8); + printf("ok\n"); + exit(0); +} diff --git a/test/Makefile b/test/Makefile index 48e3906..2ce31df 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,6 +5,7 @@ SHELL = /bin/sh all: ln -sf ../base91 b91enc ln -sf ../base91 b91dec + ln -sf ../lentest . $(SHELL) test.sh clean: diff --git a/test/test.sh b/test/test.sh index cb79d40..09548f9 100644 --- a/test/test.sh +++ b/test/test.sh @@ -81,6 +81,10 @@ echo "+-- random data $T" fold -w 73 rnd0.b91 | ./b91dec -vvm 89 | cmp rnd0.dat && echo PASSED || fail_exit fold -w 71 rnd1.b91 | ./b91dec -vvm 73 | cmp rnd1.dat && echo PASSED || fail_exit +echo " +maxlength tests:" +./lentest && echo PASSED || fail_exit + echo ' ================ all tests passed