X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Fcompress.lisp;h=d6f5178fc4ea4b9ebb3d7df1c8068f219226c24e;hb=27073cc090c29aa5dcf9ed9becdf3e73b937b0bb;hp=9e73326f469636cc9356bff26d1efe00a79e8583;hpb=3ade95bab16abe09642554e9cbf56f117f01e507;p=uffi.git diff --git a/tests/compress.lisp b/tests/compress.lisp index 9e73326..d6f5178 100644 --- a/tests/compress.lisp +++ b/tests/compress.lisp @@ -7,9 +7,7 @@ ;;;; Author: Kevin M. Rosenberg ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id$ -;;;; -;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg +;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg ;;;; ;;;; ************************************************************************* @@ -22,27 +20,27 @@ (source-len :long)) :returning :int :module "zlib") - + (defun compress (source) "Returns two values: array of bytes containing the compressed data and the numbe of compressed bytes" (let* ((sourcelen (length source)) - (destsize (+ 12 (ceiling (* sourcelen 1.01)))) - (dest (uffi:allocate-foreign-string destsize :unsigned t)) - (destlen (uffi:allocate-foreign-object :long))) + (destsize (+ 12 (ceiling (* sourcelen 1.01)))) + (dest (uffi:allocate-foreign-string destsize :unsigned t)) + (destlen (uffi:allocate-foreign-object :long))) (setf (uffi:deref-pointer destlen :long) destsize) (uffi:with-cstring (source-native source) (let ((result (c-compress dest destlen source-native sourcelen)) - (newdestlen (uffi:deref-pointer destlen :long))) - (unwind-protect - (if (zerop result) - (values (uffi:convert-from-foreign-usb8 - dest newdestlen) - newdestlen) - (error "zlib error, code ~D" result)) - (progn - (uffi:free-foreign-object destlen) - (uffi:free-foreign-object dest))))))) + (newdestlen (uffi:deref-pointer destlen :long))) + (unwind-protect + (if (zerop result) + (values (uffi:convert-from-foreign-usb8 + dest newdestlen) + newdestlen) + (error "zlib error, code ~D" result)) + (progn + (uffi:free-foreign-object destlen) + (uffi:free-foreign-object dest))))))) (uffi:def-function ("uncompress" c-uncompress) ((dest (* :unsigned-char)) @@ -54,23 +52,23 @@ (defun uncompress (source) (let* ((sourcelen (length source)) - (destsize 200000) ;adjust as needed - (dest (uffi:allocate-foreign-string destsize :unsigned t)) - (destlen (uffi:allocate-foreign-object :long))) + (destsize 200000) ;adjust as needed + (dest (uffi:allocate-foreign-string destsize :unsigned t)) + (destlen (uffi:allocate-foreign-object :long))) (setf (uffi:deref-pointer destlen :long) destsize) (uffi:with-cstring (source-native source) (let ((result (c-uncompress dest destlen source-native sourcelen)) - (newdestlen (uffi:deref-pointer destlen :long))) - (unwind-protect - (if (zerop result) - (uffi:convert-from-foreign-string - dest - :length newdestlen - :null-terminated-p nil) - (error "zlib error, code ~D" result)) - (progn - (uffi:free-foreign-object destlen) - (uffi:free-foreign-object dest))))))) + (newdestlen (uffi:deref-pointer destlen :long))) + (unwind-protect + (if (zerop result) + (uffi:convert-from-foreign-string + dest + :length newdestlen + :null-terminated-p nil) + (error "zlib error, code ~D" result)) + (progn + (uffi:free-foreign-object destlen) + (uffi:free-foreign-object dest))))))) (deftest :compress.1 (compress "") #(120 156 3 0 0 0 0 1) 8)