2 * basE91 length calculation test
4 * Copyright (c) 2019 Ian Jackson
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Joachim Henke nor the names of his contributors may
15 * be used to endorse or promote products derived from this software without
16 * specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
37 static size_t upto = (14*16 + 14 + 16)*2;
39 static int do_test(int do_do, int fill, const char *what,
40 size_t f(struct basE91 *, const void *, size_t, void *),
41 size_t f_end(struct basE91 *, void *),
42 size_t f_maxlen(size_t)
49 char obuf[upto*2+100]; /* in case we have bugs */
51 memset(ibuf,fill,upto);
54 printf("%s: skipping\n",what);
58 for (i=0; i<upto; i++) {
60 o = f(&b, ibuf, i, obuf);
61 o += f_end(&b, obuf+o);
64 if (o == exp) continue;
67 fprintf(stderr,"%s: i=%lu o=%lu expected=%lu\n",
68 what, (unsigned long)i, (unsigned long)o, (unsigned long)exp);
73 int main(int argc, const char **argv) {
74 int do_encode=1, do_decode=1, bad=0;
77 do_encode = !!strchr(argv[1],'e');
78 do_decode = !!strchr(argv[1],'d');
84 #define MAYBE_DO_TEST(ed, fill) \
85 (bad |= do_test(do_##ed, (fill), #ed, \
86 basE91_##ed, basE91_##ed##_end, basE91_##ed##_maxlen))
87 MAYBE_DO_TEST(encode, 0xff);
88 MAYBE_DO_TEST(decode, 'A');