2021-08-21 15:29:43 +02:00
|
|
|
;;; endec.lisp --- test suite for the MIME encoder/decoder functions
|
|
|
|
|
|
|
|
;;; Copyright (C) 2006, 2007, 2009, 2010 by Walter C. Pelissero
|
2022-01-24 12:01:39 +01:00
|
|
|
;;; Copyright (C) 2022 by The TVL Authors
|
2021-08-21 15:29:43 +02:00
|
|
|
|
|
|
|
;;; Author: Walter C. Pelissero <walter@pelissero.de>
|
|
|
|
;;; Project: mime4cl
|
|
|
|
|
|
|
|
;;; This library is free software; you can redistribute it and/or
|
|
|
|
;;; modify it under the terms of the GNU Lesser General Public License
|
|
|
|
;;; as published by the Free Software Foundation; either version 2.1
|
|
|
|
;;; of the License, or (at your option) any later version.
|
|
|
|
;;; This library 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
|
|
|
|
;;; Lesser General Public License for more details.
|
|
|
|
;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
;;; License along with this library; if not, write to the Free
|
|
|
|
;;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
;;; 02111-1307 USA
|
|
|
|
|
|
|
|
(in-package :mime4cl-tests)
|
|
|
|
|
|
|
|
(deftest quoted-printable.1
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"Français, Español, böse, skøl"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l")
|
|
|
|
|
|
|
|
(deftest quoted-printable.2
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"Français, Español, böse, skøl")
|
|
|
|
:start 10 :end 17)
|
2021-08-21 15:29:43 +02:00
|
|
|
"Espa=F1ol")
|
|
|
|
|
|
|
|
(deftest quoted-printable.3
|
|
|
|
(map 'string #'code-char
|
2022-01-19 14:39:58 +01:00
|
|
|
(decode-quoted-printable-string "Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"Français, Español, böse, skøl")
|
|
|
|
|
|
|
|
(deftest quoted-printable.4
|
|
|
|
(map 'string #'code-char
|
2022-01-19 14:39:58 +01:00
|
|
|
(decode-quoted-printable-string "Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l"
|
|
|
|
:start 12 :end 21))
|
2021-08-21 15:29:43 +02:00
|
|
|
"Español")
|
|
|
|
|
|
|
|
(deftest quoted-printable.5
|
|
|
|
(map 'string #'code-char
|
2022-01-19 14:39:58 +01:00
|
|
|
(decode-quoted-printable-string "this = wrong"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"this = wrong")
|
|
|
|
|
|
|
|
(deftest quoted-printable.6
|
|
|
|
(map 'string #'code-char
|
2022-01-19 14:39:58 +01:00
|
|
|
(decode-quoted-printable-string "this is wrong="))
|
2021-08-21 15:29:43 +02:00
|
|
|
"this is wrong=")
|
|
|
|
|
|
|
|
(deftest quoted-printable.7
|
|
|
|
(map 'string #'code-char
|
2022-01-19 14:39:58 +01:00
|
|
|
(decode-quoted-printable-string "this is wrong=1"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"this is wrong=1")
|
|
|
|
|
|
|
|
(deftest quoted-printable.8
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"x = x + 1"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"x =3D x + 1")
|
|
|
|
|
|
|
|
(deftest quoted-printable.9
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"x = x + 1 "))
|
2021-08-21 15:29:43 +02:00
|
|
|
"x =3D x + 1 =20")
|
|
|
|
|
|
|
|
(deftest quoted-printable.10
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"this string is very very very very very very very very very very very very very very very very very very very very long"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"this string is very very very very very very very very very very very ve=
|
|
|
|
ry very very very very very very very very long")
|
|
|
|
|
|
|
|
(deftest quoted-printable.11
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"this string is very very very very long"))
|
2021-08-21 15:29:43 +02:00
|
|
|
"this string is very very =
|
|
|
|
very very long")
|
|
|
|
|
|
|
|
(deftest quoted-printable.12
|
|
|
|
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"please read the next
|
2021-08-21 15:29:43 +02:00
|
|
|
line"))
|
|
|
|
"please read the next =20
|
|
|
|
line")
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(deftest base64.1
|
|
|
|
(let ((*base64-line-length* nil))
|
|
|
|
(encode-base64-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"Some random string.")))
|
2021-08-21 15:29:43 +02:00
|
|
|
"U29tZSByYW5kb20gc3RyaW5nLg==")
|
|
|
|
|
|
|
|
(deftest base64.2
|
|
|
|
(let ((*base64-line-length* nil))
|
|
|
|
(encode-base64-sequence (map '(vector (unsigned-byte 8)) #'char-code
|
2022-01-19 14:39:58 +01:00
|
|
|
"Some random string.") :start 5 :end 11))
|
2021-08-21 15:29:43 +02:00
|
|
|
"cmFuZG9t")
|
|
|
|
|
|
|
|
(deftest base64.3
|
|
|
|
(map 'string #'code-char
|
2023-05-18 17:19:34 +02:00
|
|
|
(qbase64:decode-string "U29tZSByYW5kb20gc3RyaW5nLg=="))
|
2021-08-21 15:29:43 +02:00
|
|
|
"Some random string.")
|
|
|
|
|
|
|
|
(deftest base64.4
|
|
|
|
(map 'string #'code-char
|
2023-05-18 17:19:34 +02:00
|
|
|
(qbase64:decode-string "U29tZSByYW5kb20gc3RyaW5nLg=="))
|
2021-08-21 15:29:43 +02:00
|
|
|
"Some random string.")
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(deftest RFC2047.1
|
|
|
|
(parse-RFC2047-text "foo bar")
|
|
|
|
("foo bar"))
|
2023-05-18 17:53:52 +02:00
|
|
|
|
|
|
|
;; from RFC2047 section 8
|
|
|
|
(deftest RFC2047.2
|
|
|
|
(decode-RFC2047 "=?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>")
|
|
|
|
"Keith Moore <moore@cs.utk.edu>")
|
|
|
|
|
|
|
|
;; from RFC2047 section 8
|
|
|
|
(deftest RFC2047.3
|
|
|
|
(decode-RFC2047 "=?ISO-8859-1?Q?Olle_J=E4rnefors?=")
|
|
|
|
"Olle Järnefors")
|
|
|
|
|
|
|
|
;; from RFC2047 section 8
|
|
|
|
(deftest RFC2047.4
|
|
|
|
(decode-RFC2047 "Nathaniel Borenstein <nsb@thumper.bellcore.com> (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)")
|
|
|
|
"Nathaniel Borenstein <nsb@thumper.bellcore.com> (םולש ןב ילטפנ)")
|
|
|
|
|
|
|
|
;; from RFC2047 section 8
|
|
|
|
(deftest RFC2047.5
|
|
|
|
(decode-RFC2047 "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>")
|
|
|
|
"Keld Jørn Simonsen <keld@dkuug.dk>")
|
2021-08-21 15:29:43 +02:00
|
|
|
|
|
|
|
(defun perftest-encoder (encoder-class &optional (megs 100))
|
|
|
|
(declare (optimize (speed 3) (debug 0) (safety 0))
|
2022-01-19 14:39:58 +01:00
|
|
|
(type fixnum megs))
|
2021-08-21 15:29:43 +02:00
|
|
|
(with-open-file (in #P"/dev/random" :element-type '(unsigned-byte 8))
|
|
|
|
(let* ((meg (* 1024 1024))
|
2022-01-19 14:39:58 +01:00
|
|
|
(buffer (make-sequence '(vector (unsigned-byte 8)) meg))
|
|
|
|
(encoder (make-instance encoder-class
|
|
|
|
:output-function #'(lambda (c) (declare (ignore c))))))
|
2021-08-21 15:29:43 +02:00
|
|
|
(declare (type fixnum meg))
|
|
|
|
(time
|
|
|
|
(progn
|
2022-01-19 14:39:58 +01:00
|
|
|
(dotimes (x megs)
|
|
|
|
(read-sequence buffer in)
|
|
|
|
(dotimes (i meg)
|
|
|
|
(mime4cl:encoder-write-byte encoder (aref buffer i))))
|
|
|
|
(mime4cl:encoder-finish-output encoder))))))
|
2021-08-21 15:29:43 +02:00
|
|
|
|
|
|
|
(defun perftest-decoder (decoder-class &optional (megs 100))
|
|
|
|
(declare (optimize (speed 3) (debug 0) (safety 0))
|
2022-01-19 14:39:58 +01:00
|
|
|
(type fixnum megs))
|
2021-08-21 15:29:43 +02:00
|
|
|
(with-open-file (in #P"/dev/random" :element-type '(unsigned-byte 8))
|
2022-07-04 15:56:52 +02:00
|
|
|
(let ((*tmp-file-defaults* (make-pathname :defaults #.(or *load-pathname* *compile-file-pathname*)
|
2022-01-19 14:39:58 +01:00
|
|
|
:type "encoded-data")))
|
2022-07-04 15:56:52 +02:00
|
|
|
(with-temp-file (tmp nil :direction :io)
|
2022-01-19 14:39:58 +01:00
|
|
|
(let* ((meg (* 1024 1024))
|
|
|
|
(buffer (make-sequence '(vector (unsigned-byte 8)) meg))
|
|
|
|
(encoder-class (ecase decoder-class
|
|
|
|
(mime4cl:quoted-printable-decoder 'mime4cl:quoted-printable-encoder)))
|
|
|
|
(encoder (make-instance encoder-class
|
|
|
|
:output-function #'(lambda (c)
|
|
|
|
(write-char c tmp))))
|
|
|
|
(decoder (make-instance decoder-class
|
|
|
|
:input-function #'(lambda ()
|
|
|
|
(read-char tmp nil)))))
|
|
|
|
(declare (type fixnum meg))
|
|
|
|
(dotimes (x megs)
|
|
|
|
(read-sequence buffer in)
|
|
|
|
(dotimes (i meg)
|
|
|
|
(mime4cl:encoder-write-byte encoder (aref buffer i))))
|
|
|
|
(mime4cl:encoder-finish-output encoder)
|
|
|
|
(file-position tmp 0)
|
|
|
|
(time
|
|
|
|
(loop
|
|
|
|
for b = (mime4cl:decoder-read-byte decoder)
|
|
|
|
while b)))))))
|