From b021d3c7188a5705a858144c0bdd8e6a962fc677 Mon Sep 17 00:00:00 2001 From: Vivien Kraus Date: Fri, 27 Nov 2020 19:28:50 +0100 Subject: Add a base64 encoder and decoder --- tests/Makefile.am | 11 ++++++++++- tests/base64-error.scm | 22 ++++++++++++++++++++++ tests/base64-ok.scm | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/base64-error.scm create mode 100644 tests/base64-ok.scm (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 1e4b2df..12699f9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,7 @@ -TESTS = %reldir%/load-library.scm +TESTS = \ + %reldir%/load-library.scm \ + %reldir%/base64-ok.scm \ + %reldir%/base64-error.scm EXTRA_DIST += $(TESTS) @@ -7,3 +10,9 @@ TEST_EXTENSIONS = .scm AM_TESTS_ENVIRONMENT = $(top_builddir)/pre-inst-env SCM_LOG_COMPILER = $(GUILE) AM_SCM_LOG_FLAGS = --no-auto-compile -s + +clean-local: %canon_reldir%-clean-local + +%canon_reldir%-clean-local: + rm -rf %reldir%/*.cache + rm -rf %reldir%/*.home diff --git a/tests/base64-error.scm b/tests/base64-error.scm new file mode 100644 index 0000000..096e1e8 --- /dev/null +++ b/tests/base64-error.scm @@ -0,0 +1,22 @@ +(use-modules + (webid-oidc testing) + ((webid-oidc stubs) #:prefix stubs:) + (webid-oidc errors) + (rnrs bytevectors)) + +(with-test-environment + "base64-error" + (lambda () + (let ((test "hello :)")) + (unless + (with-exception-handler + (lambda (error) + (unless ((record-predicate ¬-base64) error) + (exit 1)) + #t) + (lambda () + (stubs:base64-decode test) + #f) + #:unwind? #t + #:unwind-for-type ¬-base64) + (exit 2))))) diff --git a/tests/base64-ok.scm b/tests/base64-ok.scm new file mode 100644 index 0000000..724f2db --- /dev/null +++ b/tests/base64-ok.scm @@ -0,0 +1,17 @@ +(use-modules + (webid-oidc testing) + ((webid-oidc stubs) #:prefix stubs:) + (rnrs bytevectors)) + +(with-test-environment + "base64-ok" + (lambda () + (let ((test "hello :)")) + (let ((encoded (stubs:base64-encode test))) + (unless (string? encoded) + (exit 1)) + (let ((decoded (stubs:base64-decode encoded))) + (unless (bytevector? decoded) + (exit 2)) + (unless (equal? test (utf8->string decoded)) + (exit 3))))))) -- cgit v1.2.3