--- /dev/null
+### -*-autotest-*-
+###
+### Test script for utilities
+###
+### (c) 2009 Straylight/Edgeware
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the mLib utilities library.
+###
+### mLib is free software; you can redistribute it and/or modify
+### it under the terms of the GNU Library General Public License as
+### published by the Free Software Foundation; either version 2 of the
+### License, or (at your option) any later version.
+###
+### mLib 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 Library General Public License for more details.
+###
+### You should have received a copy of the GNU Library General Public
+### License along with mLib; if not, write to the Free
+### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+### MA 02111-1307, USA.
+
+###--------------------------------------------------------------------------
+### Useful macros.
+
+m4_define([NEWLINE], [
+])
+
+## CODEC_TESTENCODE(codec, raw-data, encoding, [options])
+##
+## Check that CODEC encodes RAW-DATA as ENCODING, and that it can decode
+## ENCODING as RAW-DATA, using OPTIONS.
+m4_define([CODEC_TESTENCODE], [
+ printf '%s' '$2' >in
+ printf '%s\n' '$3' >expout
+ AT_CHECK([BUILDDIR/bincode $4 $1 in], [0], [expout])
+ mv in expout
+ printf '%s' '$3' >in
+ AT_CHECK([BUILDDIR/bincode -d $4 $1 in], [0], [expout])
+])
+
+## CODEC_TESTDECODE(codec, encoding, [raw-data],
+## [options], [exp-status], [exp-stderr])
+##
+## Check that CODEC decodes ENCODING as RAW-DATA, given the OPTIONS, or that
+## it reports EXP-STATUS and produces EXP-STDERR.
+m4_define([CODEC_TESTDECODE], [
+ printf '%s' '$2' >in
+ printf '%s' '$3' >expout
+ AT_CHECK([BUILDDIR/bincode -d $4 $1 in], [$5], [expout],
+ m4_if([$6], [], [], [bincode: decoding error: $6[]NEWLINE]))
+])
+
+###--------------------------------------------------------------------------
+### base64
+AT_SETUP([codec: base64])
+AT_KEYWORDS([codec base64])
+
+## Test vectors from RFC4648.
+CODEC_TESTENCODE([base64], [], [])
+CODEC_TESTENCODE([base64], [f], [Zg==])
+CODEC_TESTENCODE([base64], [fo], [Zm8=])
+CODEC_TESTENCODE([base64], [foo], [Zm9v])
+CODEC_TESTENCODE([base64], [foob], [Zm9vYg==])
+CODEC_TESTENCODE([base64], [fooba], [Zm9vYmE=])
+CODEC_TESTENCODE([base64], [foobar], [Zm9vYmFy])
+
+## Test vectors for Base64-URL.
+CODEC_TESTENCODE([base64url], [fooba], [Zm9vYmE=])
+CODEC_TESTENCODE([base64], [fooba?], [Zm9vYmE/])
+CODEC_TESTENCODE([base64url], [fooba?], [Zm9vYmE_])
+CODEC_TESTENCODE([file64], [fooba?], [Zm9vYmE%])
+CODEC_TESTENCODE([base64], [fooba~], [Zm9vYmF+])
+CODEC_TESTENCODE([base64url], [fooba~], [Zm9vYmF-])
+CODEC_TESTENCODE([file64], [fooba~], [Zm9vYmF+])
+
+## Some noeqpad tests.
+CODEC_TESTENCODE([base64], [f], [Zg], [-fnoeqpad])
+CODEC_TESTENCODE([base64], [foo], [Zm9v], [-fnoeqpad])
+CODEC_TESTENCODE([base64], [foob], [Zm9vYg], [-fnoeqpad])
+
+## Test for pad-character errors.
+CODEC_TESTDECODE([base64], [Zg], [f], [],
+ [1], [Invalid padding character])
+CODEC_TESTDECODE([base64], [Zg], [f], [-figneqpad])
+CODEC_TESTDECODE([base64], [Zg=], [f], [-figneqpad])
+CODEC_TESTDECODE([base64], [Zg==], [f], [-figneqpad])
+CODEC_TESTDECODE([base64], [Zg], [f], [-fnoeqpad])
+CODEC_TESTDECODE([base64], [Zg=], [], [-fnoeqpad],
+ [1], [Invalid character])
+CODEC_TESTDECODE([base64], [Zg], [f], [-figneqmid])
+CODEC_TESTDECODE([base64], [Z==g=], [f], [-figneqmid])
+
+## Test for other crappy characters.
+CODEC_TESTDECODE([base64], [Z:g=:=], [], [],
+ [1], [Invalid character])
+CODEC_TESTDECODE([base64], [Z:g=:=], [f], [-figninvch])
+CODEC_TESTDECODE([base64], [Z:g=:==], [], [-figninvch],
+ [1], [Invalid padding character])
+
+## Test for incorrect padding bits.
+CODEC_TESTDECODE([base64], [Zh==], [], [],
+ [1], [Nonzero padding bits])
+CODEC_TESTDECODE([base64], [Zh==], [f], [-fignzpad])
+
+## Make sure the case flags are suppressed.
+CODEC_TESTENCODE([base64], [fooba], [Zm9vYmE=], [-flowerc])
+
+## Multiline formatting.
+AT_DATA([bigfile],
+[There are three infallible ways of pleasing an author, and the three form a
+rising scale of compliment: 1, to tell him you have read one of his books; 2,
+to tell him you have read all of his books; 3, to ask him to let you read the
+manuscript of his forthcoming book. No. 1 admits you to his respect; No. 2
+admits you to his admiration; No. 3 carries you clear into his heart.
+ -- Mark Twain, "Pudd'nhead Wilson's Calendar"
+])
+
+AT_DATA([bigfile.b64],
+[VGhlcmUgYXJlIHRocmVlIGluZmFsbGlibGUgd2F5cyBvZiBwbGVhc2luZyBhbiBh
+dXRob3IsIGFuZCB0aGUgdGhyZWUgZm9ybSBhCnJpc2luZyBzY2FsZSBvZiBjb21w
+bGltZW50OiAxLCB0byB0ZWxsIGhpbSB5b3UgaGF2ZSByZWFkIG9uZSBvZiBoaXMg
+Ym9va3M7IDIsCnRvIHRlbGwgaGltIHlvdSBoYXZlIHJlYWQgYWxsIG9mIGhpcyBi
+b29rczsgMywgdG8gYXNrIGhpbSB0byBsZXQgeW91IHJlYWQgdGhlCm1hbnVzY3Jp
+cHQgb2YgaGlzIGZvcnRoY29taW5nIGJvb2suICBOby4gMSBhZG1pdHMgeW91IHRv
+IGhpcyByZXNwZWN0OyBOby4gMgphZG1pdHMgeW91IHRvIGhpcyBhZG1pcmF0aW9u
+OyBOby4gMyBjYXJyaWVzIHlvdSBjbGVhciBpbnRvIGhpcyBoZWFydC4KICAgICAg
+ICAgICAgICAgIC0tIE1hcmsgVHdhaW4sICJQdWRkJ25oZWFkIFdpbHNvbidzIENh
+bGVuZGFyIgo=
+])
+cp bigfile.b64 expout
+AT_CHECK([BUILDDIR/bincode base64 bigfile], [0], [expout])
+AT_CHECK([BUILDDIR/bincode -f-ignnewl -d base64 bigfile.b64], [1], [ignore],
+ [bincode: decoding error: Invalid character[]NEWLINE])
+cp bigfile expout
+AT_CHECK([BUILDDIR/bincode -d base64 bigfile.b64], [0], [expout])
+
+AT_CLEANUP
+
+## base32
+AT_SETUP([codec: base32])
+AT_KEYWORDS([codec base32])
+
+CODEC_TESTENCODE([base32], [], [])
+CODEC_TESTENCODE([base32], [f], [MY======])
+CODEC_TESTENCODE([base32], [fo], [MZXQ====])
+CODEC_TESTENCODE([base32], [foo], [MZXW6===])
+CODEC_TESTENCODE([base32], [foob], [MZXW6YQ=])
+CODEC_TESTENCODE([base32], [fooba], [MZXW6YTB])
+CODEC_TESTENCODE([base32], [foobar], [MZXW6YTBOI======])
+
+CODEC_TESTENCODE([base32hex], [], [])
+CODEC_TESTENCODE([base32hex], [f], [CO======])
+CODEC_TESTENCODE([base32hex], [fo], [CPNG====])
+CODEC_TESTENCODE([base32hex], [foo], [CPNMU===])
+CODEC_TESTENCODE([base32hex], [foob], [CPNMUOG=])
+CODEC_TESTENCODE([base32hex], [fooba], [CPNMUOJ1])
+CODEC_TESTENCODE([base32hex], [foobar], [CPNMUOJ1E8======])
+
+AT_CLEANUP
+
+## hex
+AT_SETUP([codec: hex])
+AT_KEYWORDS([codec hex])
+
+CODEC_TESTENCODE([hex], [], [])
+CODEC_TESTENCODE([hex], [f], [66])
+CODEC_TESTENCODE([hex], [fo], [666F])
+CODEC_TESTENCODE([hex], [foo], [666F6F])
+CODEC_TESTENCODE([hex], [foob], [666F6F62])
+CODEC_TESTENCODE([hex], [fooba], [666F6F6261])
+CODEC_TESTENCODE([hex], [foobar], [666F6F626172])
+
+AT_CLEANUP
+
+###----- That's all, folks --------------------------------------------------