fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / t / library / mime_base64.t
bloba47604356c0bf0f03c3ca0ab00e99cb9b5697cee
1 #!./parrot
2 # Copyright (C) 2006-2010, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/library/mime_base64.t - test [ 'MIME'; 'Base64' ]
9 =head1 SYNOPSIS
11     % prove t/library/mime_base64.t
13 =head1 DESCRIPTION
15 Test [ 'MIME'; 'Base64' ]
16 Test cases taken from base64.t of MIME::Base64.
18 =cut
20 .sub test :main
21     load_bytecode "dumper.pbc"
22     load_bytecode 'Test/More.pbc'
23     load_bytecode 'MIME/Base64.pbc'
24     load_bytecode 'PGE.pbc'
25     load_bytecode 'PGE/Util.pbc'
26     load_language 'data_json'
28     .local pmc plan, is, ok
29     plan = get_hll_global [ 'Test'; 'More' ], 'plan'
30     is   = get_hll_global [ 'Test'; 'More' ], 'is'
31     ok   = get_hll_global [ 'Test'; 'More' ], 'ok'
33     plan(550)
35     .local pmc json
36     json = compreg 'data_json'
38     .local pmc encode_decode_tests, decode_tests
39     encode_decode_tests = json.'compile'( <<'END_JSON' )
40 [ ["Hello, World!\n","SGVsbG8sIFdvcmxkIQo="],
41   ["\u0000","AA=="],
42   ["\u0001","AQ=="],
43   ["\u0002","Ag=="],
44   ["\u0003","Aw=="],
45   ["\u0004","BA=="],
46   ["\u0005","BQ=="],
47   ["\u0006","Bg=="],
48   ["\u0007","Bw=="],
49   ["\b","CA=="],
50   ["\t","CQ=="],
51   ["\n","Cg=="],
52   ["\u000b","Cw=="],
53   ["\f","DA=="],
54   ["\r","DQ=="],
55   ["\u000e","Dg=="],
56   ["\u000f","Dw=="],
57   ["\u0010","EA=="],
58   ["\u0011","EQ=="],
59   ["\u0012","Eg=="],
60   ["\u0013","Ew=="],
61   ["\u0014","FA=="],
62   ["\u0015","FQ=="],
63   ["\u0016","Fg=="],
64   ["\u0017","Fw=="],
65   ["\u0018","GA=="],
66   ["\u0019","GQ=="],
67   ["\u001a","Gg=="],
68   ["\u001b","Gw=="],
69   ["\u001c","HA=="],
70   ["\u001d","HQ=="],
71   ["\u001e","Hg=="],
72   ["\u001f","Hw=="],
73   [" ","IA=="],
74   ["!","IQ=="],
75   ["\"","Ig=="],
76   ["#","Iw=="],
77   ["$","JA=="],
78   ["%","JQ=="],
79   ["&","Jg=="],
80   ["'","Jw=="],
81   ["(","KA=="],
82   [")","KQ=="],
83   ["*","Kg=="],
84   ["+","Kw=="],
85   [",","LA=="],
86   ["-","LQ=="],
87   [".","Lg=="],
88   ["/","Lw=="],
89   ["0","MA=="],
90   ["1","MQ=="],
91   ["2","Mg=="],
92   ["3","Mw=="],
93   ["4","NA=="],
94   ["5","NQ=="],
95   ["6","Ng=="],
96   ["7","Nw=="],
97   ["8","OA=="],
98   ["9","OQ=="],
99   [":","Og=="],
100   [";","Ow=="],
101   ["<","PA=="],
102   ["=","PQ=="],
103   [">","Pg=="],
104   ["?","Pw=="],
105   ["@","QA=="],
106   ["A","QQ=="],
107   ["B","Qg=="],
108   ["C","Qw=="],
109   ["D","RA=="],
110   ["E","RQ=="],
111   ["F","Rg=="],
112   ["G","Rw=="],
113   ["H","SA=="],
114   ["I","SQ=="],
115   ["J","Sg=="],
116   ["K","Sw=="],
117   ["L","TA=="],
118   ["M","TQ=="],
119   ["N","Tg=="],
120   ["O","Tw=="],
121   ["P","UA=="],
122   ["Q","UQ=="],
123   ["R","Ug=="],
124   ["S","Uw=="],
125   ["T","VA=="],
126   ["U","VQ=="],
127   ["V","Vg=="],
128   ["W","Vw=="],
129   ["X","WA=="],
130   ["Y","WQ=="],
131   ["Z","Wg=="],
132   ["[","Ww=="],
133   ["\\","XA=="],
134   ["]","XQ=="],
135   ["^","Xg=="],
136   ["_","Xw=="],
137   ["`","YA=="],
138   ["a","YQ=="],
139   ["b","Yg=="],
140   ["c","Yw=="],
141   ["d","ZA=="],
142   ["e","ZQ=="],
143   ["f","Zg=="],
144   ["g","Zw=="],
145   ["h","aA=="],
146   ["i","aQ=="],
147   ["j","ag=="],
148   ["k","aw=="],
149   ["l","bA=="],
150   ["m","bQ=="],
151   ["n","bg=="],
152   ["o","bw=="],
153   ["p","cA=="],
154   ["q","cQ=="],
155   ["r","cg=="],
156   ["s","cw=="],
157   ["t","dA=="],
158   ["u","dQ=="],
159   ["v","dg=="],
160   ["w","dw=="],
161   ["x","eA=="],
162   ["y","eQ=="],
163   ["z","eg=="],
164   ["{","ew=="],
165   ["|","fA=="],
166   ["}","fQ=="],
167   ["~","fg=="],
168   ["\x7f","fw=="],
169   ["€","gA=="],
170   ["�","gQ=="],
171   ["‚","gg=="],
172   ["ƒ","gw=="],
173   ["„","hA=="],
174   ["…","hQ=="],
175   ["†","hg=="],
176   ["‡","hw=="],
177   ["ˆ","iA=="],
178   ["‰","iQ=="],
179   ["Š","ig=="],
180   ["‹","iw=="],
181   ["Œ","jA=="],
182   ["�","jQ=="],
183   ["Ž","jg=="],
184   ["�","jw=="],
185   ["�","kA=="],
186   ["‘","kQ=="],
187   ["’","kg=="],
188   ["“","kw=="],
189   ["”","lA=="],
190   ["•","lQ=="],
191   ["–","lg=="],
192   ["—","lw=="],
193   ["˜","mA=="],
194   ["™","mQ=="],
195   ["š","mg=="],
196   ["›","mw=="],
197   ["œ","nA=="],
198   ["�","nQ=="],
199   ["ž","ng=="],
200   ["Ÿ","nw=="],
201   [" ","oA=="],
202   ["¡","oQ=="],
203   ["¢","og=="],
204   ["£","ow=="],
205   ["¤","pA=="],
206   ["¥","pQ=="],
207   ["¦","pg=="],
208   ["§","pw=="],
209   ["¨","qA=="],
210   ["©","qQ=="],
211   ["ª","qg=="],
212   ["«","qw=="],
213   ["¬","rA=="],
214   ["­","rQ=="],
215   ["®","rg=="],
216   ["¯","rw=="],
217   ["°","sA=="],
218   ["±","sQ=="],
219   ["²","sg=="],
220   ["³","sw=="],
221   ["´","tA=="],
222   ["µ","tQ=="],
223   ["¶","tg=="],
224   ["·","tw=="],
225   ["¸","uA=="],
226   ["¹","uQ=="],
227   ["º","ug=="],
228   ["»","uw=="],
229   ["¼","vA=="],
230   ["½","vQ=="],
231   ["¾","vg=="],
232   ["¿","vw=="],
233   ["À","wA=="],
234   ["Á","wQ=="],
235   ["Â","wg=="],
236   ["Ã","ww=="],
237   ["Ä","xA=="],
238   ["Å","xQ=="],
239   ["Æ","xg=="],
240   ["Ç","xw=="],
241   ["È","yA=="],
242   ["É","yQ=="],
243   ["Ê","yg=="],
244   ["Ë","yw=="],
245   ["Ì","zA=="],
246   ["Í","zQ=="],
247   ["Î","zg=="],
248   ["Ï","zw=="],
249   ["Ð","0A=="],
250   ["Ñ","0Q=="],
251   ["Ò","0g=="],
252   ["Ó","0w=="],
253   ["Ô","1A=="],
254   ["Õ","1Q=="],
255   ["Ö","1g=="],
256   ["×","1w=="],
257   ["Ø","2A=="],
258   ["Ù","2Q=="],
259   ["Ú","2g=="],
260   ["Û","2w=="],
261   ["Ü","3A=="],
262   ["Ý","3Q=="],
263   ["Þ","3g=="],
264   ["ß","3w=="],
265   ["à","4A=="],
266   ["á","4Q=="],
267   ["â","4g=="],
268   ["ã","4w=="],
269   ["ä","5A=="],
270   ["å","5Q=="],
271   ["æ","5g=="],
272   ["ç","5w=="],
273   ["è","6A=="],
274   ["é","6Q=="],
275   ["ê","6g=="],
276   ["ë","6w=="],
277   ["ì","7A=="],
278   ["í","7Q=="],
279   ["î","7g=="],
280   ["ï","7w=="],
281   ["ð","8A=="],
282   ["ñ","8Q=="],
283   ["ò","8g=="],
284   ["ó","8w=="],
285   ["ô","9A=="],
286   ["õ","9Q=="],
287   ["ö","9g=="],
288   ["÷","9w=="],
289   ["ø","+A=="],
290   ["ù","+Q=="],
291   ["ú","+g=="],
292   ["û","+w=="],
293   ["ü","/A=="],
294   ["ý","/Q=="],
295   ["þ","/g=="],
296   ["ÿ","/w=="],
297   ["\u0000ÿ","AP8="],
298   ["ÿ\u0000","/wA="],
299   ["\u0000\u0000\u0000","AAAA"],
300   ["",""],
301   ["a","YQ=="],
302   ["aa","YWE="],
303   ["aaa","YWFh"],
304   ["aaa","YWFh"],
305   ["aaa","YWFh"],
306   ["aaa","YWFh"],
307   ["Aladdin:open sesame","QWxhZGRpbjpvcGVuIHNlc2FtZQ=="],
308   ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ=="],
309   ["Multipurpose Internet Mail Extensions: The Base64 Content-Transfer-Encoding is designed to represent sequences of octets in a form that is not humanly readable. ","TXVsdGlwdXJwb3NlIEludGVybmV0IE1haWwgRXh0ZW5zaW9uczogVGhlIEJhc2U2NCBDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nIGlzIGRlc2lnbmVkIHRvIHJlcHJlc2VudCBzZXF1ZW5jZXMgb2Ygb2N0ZXRzIGluIGEgZm9ybSB0aGF0IGlzIG5vdCBodW1hbmx5IHJlYWRhYmxlLiA="]
311 END_JSON
313     decode_tests = json.'compile'( <<'END_JSON' )
314 [ ["YWE=","aa"],
315   [" YWE=","aa"],
316   ["Y WE=","aa"],
317   ["YWE= ","aa"],
318   ["Y\nW\r\nE=","aa"],
319   ["YWE=====","aa"],
320   ["YWE","aa"],
321   ["YWFh====","aaa"],
322   ["YQ","a"],
323   ["",""]
325 END_JSON
327 # TODO: These decoding tests seem to cause weird output
328 # ["Y",""],
329 # ["x==",""],
331     .local int cnt
332     cnt = 0
333     .local pmc test_iterator, test_case
334     .local string plain, base64, comment, comment_cnt
336     encode_decode_tests = encode_decode_tests()
337     test_iterator = iter encode_decode_tests
338     enc_dec_loop:
339         unless test_iterator goto enc_dec_loop_end
340         test_case   = shift test_iterator
341         plain       = shift test_case
342         base64      = shift test_case
343         comment     = 'encode'
344         comment_cnt = cnt
345         concat comment, comment_cnt
346         test_encode( plain, base64, comment )
347         comment     = 'decode'
348         comment_cnt = cnt
349         concat comment, comment_cnt
350         test_decode( plain, base64, comment )
351         inc cnt
352     goto enc_dec_loop
353     enc_dec_loop_end:
355     decode_tests = decode_tests()
356     test_iterator = iter decode_tests
357     dec_loop:
358         unless test_iterator goto dec_loop_end
359         test_case   = shift test_iterator
360         base64      = shift test_case
361         plain       = shift test_case
362         comment     = 'decode'
363         comment_cnt = cnt
364         concat comment, comment_cnt
365         test_decode( plain, base64, comment )
366         inc cnt
367     goto dec_loop
368     dec_loop_end:
370 .end
372 .sub test_encode
373     .param string plain
374     .param string base64
375     .param string comment
377     .local pmc enc_sub
378     enc_sub = get_global [ "MIME"; "Base64" ], 'encode_base64'
380     .local pmc is
381     is   = get_hll_global [ 'Test'; 'More' ], 'is'
383     .local string result_encode
384     result_encode = enc_sub( plain )
385     is( result_encode, base64, comment )
386 .end
389 .sub test_decode
390     .param string plain
391     .param string base64
392     .param string comment
394     .local pmc dec_sub
395     dec_sub = get_global [ "MIME"; "Base64" ], 'decode_base64'
397     .local pmc eight_to_six
398     eight_to_six = get_global 'eight_to_six'
400     .local pmc is
401     is   = get_hll_global [ 'Test'; 'More' ], 'is'
403     .local string result_decode
404     result_decode = dec_sub( base64 )
405     is( result_decode, plain, comment )
406 .end
408 =head1 AUTHOR
410 Bernhard Schmalhofer <Bernhard Schmalhofer@gmx.de>
412 =cut
414 # Local Variables:
415 #   mode: pir
416 #   fill-column: 100
417 # End:
418 # vim: expandtab shiftwidth=4 ft=pir: