Last active
August 29, 2015 13:56
-
-
Save cyphre/9254624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REBOL [ | |
title: "basic DO-CODEC test" | |
author: "Richard Smolak" | |
] | |
print "Loading images..." | |
;NOTE: these images are needed so the test results are correct | |
site: http://cyphre.mysteria.cz/pics | |
bmp-src: read site/rebol-logo.bmp | |
gif-src: read site/rebol-logo.gif | |
jpg-src: read site/rebol-logo.jpg | |
png-src: read site/rebol-logo.png | |
text-src: "Hello world" | |
markup-src: "<b>hello</b>" | |
markup-result: [<b> "hello" </b>] | |
bmp-dec: do-codec system/codecs/bmp/entry 'decode bmp-src | |
bmp-enc: do-codec system/codecs/bmp/entry 'encode bmp-dec | |
gif-dec: do-codec system/codecs/gif/entry 'decode gif-src | |
gif-enc: try [ | |
;not yet implemented | |
do-codec system/codecs/gif/entry 'encode gif-dec | |
] | |
jpg-dec: do-codec system/codecs/jpeg/entry 'decode jpg-src | |
jpg-enc: try [ | |
;not yet implemented | |
do-codec system/codecs/jpeg/entry 'encode jpg-dec | |
] | |
png-dec: do-codec system/codecs/png/entry 'decode png-src | |
png-enc: do-codec system/codecs/png/entry 'encode png-dec | |
text-dec: do-codec system/codecs/text/entry 'decode to binary! text-src | |
;not yet implemented properly but shouldn't crash | |
text-enc: do-codec system/codecs/text/entry 'encode make image! 1x1 | |
markup-dec: do-codec system/codecs/markup/entry 'decode to binary! markup-src | |
markup-enc: try [ | |
;not yet implemented properly but shouldn't crash | |
do-codec system/codecs/markup/entry 'encode make image! 1x1 | |
] | |
if all [ | |
;decoders output tests | |
image? bmp-dec | |
image? gif-dec | |
image? jpg-dec | |
image? png-dec | |
equal? gif-dec bmp-dec | |
not-equal? jpg-dec bmp-dec ;lossy compression | |
equal? png-dec bmp-dec | |
;encoders output tests | |
equal? bmp-src bmp-enc | |
equal? png-src png-enc | |
;text codec tests | |
equal? text-dec text-src | |
binary? text-enc | |
empty? text-enc | |
;markup codec tests | |
equal? markup-dec markup-result | |
;missing encoders tests | |
jpg-enc/id = 'bad-media | |
gif-enc/id = 'bad-media | |
markup-enc/id = 'bad-media | |
][ | |
print "DO-CODEC test passed" | |
][ | |
print "DO-CODEC test failed" | |
] | |
halt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment