(use posix z3 testeez utils) (system "cp ../BSD-LICENCE .") (define BSD-LICENCE (read-all "BSD-LICENCE")) (system* "gzip -c BSD-LICENCE >BSD-LICENCE.gz") (testeez "z3" (test-eval "compressing empty buffer" (z3:encode-buffer "")) (test-eval "compressing single char buffer" (z3:encode-buffer "0")) (test-define "opening file" fd (file-open "BSD-LICENCE.gz" (+ open/trunc open/wronly))) (test-define "init" z3 (z3:encode-file fd level: 8)) (test-eval "writing" (z3:write-encoded z3 (substring BSD-LICENCE 0 100))) (test-eval "writing (2)" (z3:write-encoded z3 (substring BSD-LICENCE 100))) (test-eval "writing (3)" (z3:write-encoded z3 #f)) (test-eval "closing" (file-close fd)) (test/equal "testing result" (system "gunzip -c BSD-LICENCE.gz >tmp && cmp tmp BSD-LICENCE") 0) (test-define "opening file" fd (file-open "BSD-LICENCE.gz" open/read)) (test-define "init" z3 (z3:decode-file fd)) (test/equal "reading" (string=? (let loop () (let ((x (z3:read-decoded z3))) (if (eof-object? x) "" (string-append x (loop)) ) ) ) BSD-LICENCE) #t) (test-eval "closing file" (file-close fd)) (test-define "compression destination" dest (open-output-string)) (test-define "definining compression receiver" r (lambda (x) (display x dest))) (test-define "prepare compression" ze (z3:encode-init)) (test-eval "compressing ..." (let loop ((c BSD-LICENCE)) (let ((t (z3:encode ze r c))) (when t (print* ".") (loop (substring c t)) ) ) ) ) (test-define "compressed" compressed (get-output-string dest)) (test-eval "compressed size" (conc (string-length BSD-LICENCE) " -> " (string-length compressed))) (test-define "prepare decompression" z (z3:decode-init)) (test-eval "decomp. destination" (set! dest (open-output-string))) (test-eval "decompressing..." (let loop ((c compressed)) (let ((t (z3:decode z r c))) (when t (print* "(" (string-length c) ")") (loop (substring c t)) ) ) ) ) (test/equal "comparing results" (string=? BSD-LICENCE (get-output-string dest)) #t) )