aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 11:28:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 18:30:01 +0300
commit1153970626892573e5966e135e8d81185f4ea53c (patch)
tree773fdf5a8d00ec2ef752c3a8fd5f32c79829cf23 /tests
downloadeclat-1153970626892573e5966e135e8d81185f4ea53c.tar.gz
eclat-1153970626892573e5966e135e8d81185f4ea53c.tar.bz2
Initial commit
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore8
-rw-r--r--tests/Makefile.am79
-rw-r--r--tests/atlocal.in6
-rw-r--r--tests/hmac01.at25
-rw-r--r--tests/hmac02.at25
-rw-r--r--tests/hmac03.at26
-rw-r--r--tests/testsuite.at30
-rw-r--r--tests/thmac.c128
-rw-r--r--tests/turlenc.c46
-rw-r--r--tests/urlenc01.at28
10 files changed, 401 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..9a2f830
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,8 @@
+atconfig
+atlocal
+package.m4
+testsuite
+testsuite.dir
+testsuite.log
+thmac
+turlenc
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..6d95607
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,79 @@
+# This file is part of Eclat
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4
+DISTCLEANFILES = atconfig $(check_SCRIPTS)
+MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
+
+
+## ------------ ##
+## package.m4. ##
+## ------------ ##
+
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ $(AM_V_GEN){ \
+ echo '# Signature of the current package.'; \
+ echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
+ echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
+ echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
+ echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
+ } >$(srcdir)/package.m4
+
+#
+
+## ------------ ##
+## Test suite. ##
+## ------------ ##
+
+TESTSUITE_AT = \
+ hmac01.at\
+ hmac02.at\
+ hmac03.at\
+ testsuite.at\
+ urlenc01.at
+
+TESTSUITE = $(srcdir)/testsuite
+M4=m4
+
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): package.m4 $(TESTSUITE_AT)
+ $(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
+ mv $@.tmp $@
+
+atconfig: $(top_builddir)/config.status
+ cd $(top_builddir) && ./config.status tests/$@
+
+clean-local:
+ test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
+
+check-local: atconfig atlocal $(TESTSUITE)
+ $(SHELL) $(TESTSUITE)
+
+# Run the test suite on the *installed* tree.
+#installcheck-local:
+# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+
+noinst_PROGRAMS = \
+ thmac\
+ turlenc
+
+LDADD = ../lib/libeclat.a ../grecs/src/libgrecs.a
+INCLUDES = -I$(top_srcdir)/lib
+
+
+
+
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..f75356d
--- /dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,6 @@
+# @configure_input@ -*- shell-script -*-
+# Configurable variable values for Eclat test suite.
+# Copyright (C) 2012 Sergey Poznyakoff
+
+PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_srcdir@/build-aux:$top_srcdir:$srcdir:$PATH
+
diff --git a/tests/hmac01.at b/tests/hmac01.at
new file mode 100644
index 0000000..ecef3c5
--- /dev/null
+++ b/tests/hmac01.at
@@ -0,0 +1,25 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([hmac01])
+AT_KEYWORDS([hmac hmac01])
+
+AT_CHECK([thmac 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b "Hi There"],
+[0],
+[0x675b0b3a1b4ddf4e124872da6c2f632bfed957e9
+])
+
+AT_CLEANUP
diff --git a/tests/hmac02.at b/tests/hmac02.at
new file mode 100644
index 0000000..d2ab2d7
--- /dev/null
+++ b/tests/hmac02.at
@@ -0,0 +1,25 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([hmac02])
+AT_KEYWORDS([hmac hmac02])
+
+AT_CHECK([thmac Jefe "what do ya want for nothing?"],
+[0],
+[0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79
+])
+
+AT_CLEANUP
diff --git a/tests/hmac03.at b/tests/hmac03.at
new file mode 100644
index 0000000..ffa35da
--- /dev/null
+++ b/tests/hmac03.at
@@ -0,0 +1,26 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([hmac03])
+AT_KEYWORDS([hmac hmac03])
+
+AT_CHECK([thmac "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" \
+ "0xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"],
+[0],
+[0xd730594d167e35d5956fd8003d0db3d3f46dc7bb
+])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..c368490
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,30 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+m4_version_prereq([2.52g])
+
+m4_define([AT_SKIP_TEST],[exit 77])
+
+AT_INIT
+AT_BANNER([HMAC-SHA1])
+m4_include(hmac01.at)
+m4_include(hmac02.at)
+m4_include(hmac03.at)
+
+AT_BANNER([URL encode])
+m4_include([urlenc01.at])
+
+# End of testsuite.at
diff --git a/tests/thmac.c b/tests/thmac.c
new file mode 100644
index 0000000..cda0777
--- /dev/null
+++ b/tests/thmac.c
@@ -0,0 +1,128 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "libeclat.h"
+
+char *progname;
+
+static int
+xdecode(const char *in, void **pout, size_t *outlen)
+{
+ unsigned char *out;
+ size_t len;
+
+ if (in[0] == '0' && in[1] == 'x') {
+ size_t i, slen;
+ unsigned char *p;
+
+ slen = strlen(in);
+ if (slen % 2)
+ return -1;
+ len = slen / 2 - 1;
+ out = malloc(len);
+ if (!out) {
+ perror("malloc");
+ abort();
+ }
+ for (i = 2, p = out; i < slen; i+=2, p++) {
+ static char xchar[] = "0123456789abcdef";
+ char *q;
+ unsigned char c;
+
+ q = strchr(xchar, tolower(in[i]));
+ if (q == 0)
+ return i;
+ c = (q - xchar);
+
+ q = strchr(xchar, tolower(in[i+1]));
+ if (q == 0)
+ return i+1;
+ *p = (c << 4) + (q - xchar);
+ }
+ } else {
+ len = strlen(in);
+ out = malloc(len);
+ if (!out) {
+ perror("malloc");
+ abort();
+ }
+ memcpy(out, in, len);
+ }
+ *pout = out;
+ *outlen = len;
+ return 0;
+}
+
+void
+xdecode_assert(int rc, char *in, char *what)
+{
+ switch (rc) {
+ case -1:
+ fprintf(stderr, "%s: odd %s length\n", progname, what);
+ exit(1);
+
+ case 0:
+ break;
+
+ default:
+ fprintf(stderr, "%s: invalid hex character in %s near %s\n",
+ progname, what, in + rc);
+ exit(1);
+ }
+}
+
+void
+xdump(unsigned char *in, size_t len)
+{
+ printf("0x");
+ while (len--)
+ printf("%02x", *in++);
+ printf("\n");
+}
+
+int
+main(int argc, char **argv)
+{
+ int rc;
+ void *key;
+ size_t keylen;
+ void *text;
+ size_t textlen;
+ unsigned char digest[20];
+
+ progname = argv[0];
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s key data\n", progname);
+ return 1;
+ }
+
+ rc = xdecode(argv[1], &key, &keylen);
+ xdecode_assert(rc, argv[1], "key");
+
+ rc = xdecode(argv[2], &text, &textlen);
+ xdecode_assert(rc, argv[2], "text");
+
+ hmac_sha1(text, textlen, key, keylen, digest);
+
+ xdump(digest, sizeof(digest));
+ return 0;
+}
+
+
diff --git a/tests/turlenc.c b/tests/turlenc.c
new file mode 100644
index 0000000..94b2513
--- /dev/null
+++ b/tests/turlenc.c
@@ -0,0 +1,46 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "libeclat.h"
+
+int
+main(int argc, char **argv)
+{
+ char *output;
+ size_t outlen;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s string\n", argv[0]);
+ return 1;
+ }
+
+ urlencode(argv[1], strlen(argv[1]), &output, &outlen);
+
+ printf("%lu\n", (unsigned long) outlen);
+ printf("%s\n", output);
+ return 0;
+}
+
+
+
+
+
+
+
diff --git a/tests/urlenc01.at b/tests/urlenc01.at
new file mode 100644
index 0000000..83f67f3
--- /dev/null
+++ b/tests/urlenc01.at
@@ -0,0 +1,28 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([url encode])
+AT_KEYWORDS([urlenc urlent01])
+
+AT_CHECK([
+turlenc 'http://example.com/~us.er?a-string="a b"&n_1=10'
+],
+[0],
+[69
+http%3A%2F%2Fexample.com%2F~us.er%3Fa-string%3D%22a%20b%22%26n_1%3D10
+])
+
+AT_CLEANUP \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.