2 # Copyright (C) 2006-2010, Parrot Foundation.
7 t/library/mime_base64.t - test [ 'MIME'; 'Base64' ]
11 % prove t/library/mime_base64.t
15 Test [ 'MIME'; 'Base64' ]
16 Test cases taken from base64.t of MIME::Base64.
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'
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="],
299 ["\u0000\u0000\u0000","AAAA"],
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="]
313 decode_tests = json.'compile'( <<'END_JSON' )
327 # TODO: These decoding tests seem to cause weird output
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
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
345 concat comment, comment_cnt
346 test_encode( plain, base64, comment )
349 concat comment, comment_cnt
350 test_decode( plain, base64, comment )
355 decode_tests = decode_tests()
356 test_iterator = iter decode_tests
358 unless test_iterator goto dec_loop_end
359 test_case = shift test_iterator
360 base64 = shift test_case
361 plain = shift test_case
364 concat comment, comment_cnt
365 test_decode( plain, base64, comment )
375 .param string comment
378 enc_sub = get_global [ "MIME"; "Base64" ], 'encode_base64'
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 )
392 .param string comment
395 dec_sub = get_global [ "MIME"; "Base64" ], 'decode_base64'
397 .local pmc eight_to_six
398 eight_to_six = get_global 'eight_to_six'
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 )
410 Bernhard Schmalhofer <Bernhard Schmalhofer@gmx.de>
418 # vim: expandtab shiftwidth=4 ft=pir: