X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=examples%2Fc-test-fns.cl;h=0bdb90fda7ec735b10a285c882e225bb8c05a12c;hb=839b3e4b9627ecf5d3b0d8d2910a95d7f9010dc5;hp=3bb4f6157c3534c7e88faf707b6657ab5e90ce34;hpb=d5e4894a4d66611f1a585cbe53c692af8fabff5d;p=uffi.git diff --git a/examples/c-test-fns.cl b/examples/c-test-fns.cl index 3bb4f61..0bdb90f 100644 --- a/examples/c-test-fns.cl +++ b/examples/c-test-fns.cl @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: c-test-fns.cl,v 1.1 2002/03/21 04:04:45 kevin Exp $ +;;;; $Id: c-test-fns.cl,v 1.7 2002/04/03 00:31:32 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -19,9 +19,7 @@ (in-package :cl-user) (unless (uffi:load-foreign-library - (make-pathname :name "c-test-fns" - :type #+(or linux unix)"so" #+(or win32 mswindows) "dll" - :defaults *load-truename*) + (uffi:find-foreign-library "c-test-fns" *load-truename*) :supporting-libraries '("c") :force-load t) (warn "Unable to load c-test-fns library")) @@ -45,22 +43,79 @@ (uffi:with-cstring (str-cstring str) (cs-count-upper str-cstring))) -#+test-uffi +(uffi:def-function ("half_double_vector" half-double-vector) + ((size :int) + (vec (* :double))) + :returning :void) + +(uffi:def-constant +double-vec-length+ 10) +(defun test-half-double-vector () + (let ((vec (uffi:allocate-foreign-object :double +double-vec-length+)) + results) + (dotimes (i +double-vec-length+) + (setf (uffi:deref-array vec '(:array :double) i) + (coerce i 'double-float))) + (half-double-vector +double-vec-length+ vec) + (dotimes (i +double-vec-length+) + (push (uffi:deref-array vec '(:array :double) i) results)) + (uffi:free-foreign-object vec) + (nreverse results))) + +(defun t2 () + (let ((vec (make-array +double-vec-length+ :element-type 'double-float))) + (dotimes (i +double-vec-length+) + (setf (aref vec i) (coerce i 'double-float))) + (half-double-vector +double-vec-length+ vec) + vec)) + +#+cmu +(defun t3 () + (let ((vec (make-array +double-vec-length+ :element-type 'double-float))) + (dotimes (i +double-vec-length+) + (setf (aref vec i) (coerce i 'double-float))) + (system:without-gcing + (half-double-vector +double-vec-length+ (system:vector-sap vec))) + vec)) + +#+examples-uffi (format t "~&(string-to-upper \"this is a test\") => ~A" (string-to-upper "this is a test")) -#+test-uffi +#+examples-uffi (format t "~&(string-to-upper nil) => ~A" (string-to-upper nil)) -#+test-uffi +#+examples-uffi (format t "~&(string-count-upper \"This is a Test\") => ~A" (string-count-upper "This is a Test")) -#+test-uffi +#+examples-uffi (format t "~&(string-count-upper nil) => ~A" (string-count-upper nil)) +#+examples-uffi +(format t "~&Half vector: ~S" (test-half-double-vector)) +#+test-uffi +(progn + (util.test:test (string= (string-to-upper "this is a test") "THIS IS A TEST") + t + :test #'eql + :fail-info "Error with string-to-upper") + (util.test:test (string-to-upper nil) nil + :fail-info "string-to-upper with nil failed") + (util.test:test (string-count-upper "This is a Test") + 2 + :test #'eql + :fail-info "Error with string-count-upper") + (util.test:test (string-count-upper nil) -1 + :test #'eql + :fail-info "string-count-upper with nil failed") + + (util.test:test (test-half-double-vector) + '(0.0d0 0.5d0 1.0d0 1.5d0 2.0d0 2.5d0 3.0d0 3.5d0 4.0d0 4.5d0) + :test #'equal + :fail-info "Error comparing half-double-vector") + )