1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
;;; endec.lisp --- test suite for the MIME encoder/decoder functions
;;; Copyright (C) 2006, 2007, 2009, 2010 by Walter C. Pelissero
;;; Copyright (C) 2022 by The TVL Authors
;;; 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
"Français, Español, böse, skøl"))
"Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l")
(deftest quoted-printable.2
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
"Français, Español, böse, skøl")
:start 10 :end 17)
"Espa=F1ol")
(deftest quoted-printable.3
(map 'string #'code-char
(decode-quoted-printable-string "Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l"))
"Français, Español, böse, skøl")
(deftest quoted-printable.4
(map 'string #'code-char
(decode-quoted-printable-string "Fran=E7ais, Espa=F1ol, b=F6se, sk=F8l"
:start 12 :end 21))
"Español")
(deftest quoted-printable.5
(map 'string #'code-char
(decode-quoted-printable-string "this = wrong"))
"this = wrong")
(deftest quoted-printable.6
(map 'string #'code-char
(decode-quoted-printable-string "this is wrong="))
"this is wrong=")
(deftest quoted-printable.7
(map 'string #'code-char
(decode-quoted-printable-string "this is wrong=1"))
"this is wrong=1")
(deftest quoted-printable.8
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
"x = x + 1"))
"x =3D x + 1")
(deftest quoted-printable.9
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
"x = x + 1 "))
"x =3D x + 1 =20")
(deftest quoted-printable.10
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
"this string is very very very very very very very very very very very very very very very very very very very very long"))
"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
"this string is very very very very long"))
"this string is very very =
very very long")
(deftest quoted-printable.12
(encode-quoted-printable-sequence (map '(vector (unsigned-byte 8)) #'char-code
"please read the next
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
"Some random string.")))
"U29tZSByYW5kb20gc3RyaW5nLg==")
(deftest base64.2
(let ((*base64-line-length* nil))
(encode-base64-sequence (map '(vector (unsigned-byte 8)) #'char-code
"Some random string.") :start 5 :end 11))
"cmFuZG9t")
(deftest base64.3
(map 'string #'code-char
(qbase64:decode-string "U29tZSByYW5kb20gc3RyaW5nLg=="))
"Some random string.")
(deftest base64.4
(map 'string #'code-char
(qbase64:decode-string "U29tZSByYW5kb20gc3RyaW5nLg=="))
"Some random string.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest RFC2047.1
(parse-RFC2047-text "foo bar")
("foo bar"))
;; TODO(sterni): more RFC2047 test cases
(defun perftest-encoder (encoder-class &optional (megs 100))
(declare (optimize (speed 3) (debug 0) (safety 0))
(type fixnum megs))
(with-open-file (in #P"/dev/random" :element-type '(unsigned-byte 8))
(let* ((meg (* 1024 1024))
(buffer (make-sequence '(vector (unsigned-byte 8)) meg))
(encoder (make-instance encoder-class
:output-function #'(lambda (c) (declare (ignore c))))))
(declare (type fixnum meg))
(time
(progn
(dotimes (x megs)
(read-sequence buffer in)
(dotimes (i meg)
(mime4cl:encoder-write-byte encoder (aref buffer i))))
(mime4cl:encoder-finish-output encoder))))))
(defun perftest-decoder (decoder-class &optional (megs 100))
(declare (optimize (speed 3) (debug 0) (safety 0))
(type fixnum megs))
(with-open-file (in #P"/dev/random" :element-type '(unsigned-byte 8))
(let ((*tmp-file-defaults* (make-pathname :defaults #.(or *load-pathname* *compile-file-pathname*)
:type "encoded-data")))
(with-temp-file (tmp nil :direction :io)
(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)))))))
|