1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: uffi-c-test-lib.lisp
6 ;;;; Purpose: UFFI Example file for zlib compression
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2003 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (in-package #:uffi-tests)
19 (uffi:def-function ("cs_to_upper" cs-to-upper)
20 ((input (* :unsigned-char)))
24 (defun string-to-upper (str)
25 (uffi:with-foreign-string (str-foreign str)
26 (cs-to-upper str-foreign)
27 (uffi:convert-from-foreign-string str-foreign)))
29 (uffi:def-function ("cs_count_upper" cs-count-upper)
34 (defun string-count-upper (str)
35 (uffi:with-cstring (str-cstring str)
36 (cs-count-upper str-cstring)))
38 (uffi:def-function ("half_double_vector" half-double-vector)
43 (uffi:def-constant +double-vec-length+ 10)
44 (defun test-half-double-vector ()
45 (let ((vec (uffi:allocate-foreign-object :double +double-vec-length+))
47 (dotimes (i +double-vec-length+)
48 (setf (uffi:deref-array vec '(:array :double) i)
49 (coerce i 'double-float)))
50 (half-double-vector +double-vec-length+ vec)
51 (dotimes (i +double-vec-length+)
52 (push (uffi:deref-array vec '(:array :double) i) results))
53 (uffi:free-foreign-object vec)
57 (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
58 (dotimes (i +double-vec-length+)
59 (setf (aref vec i) (coerce i 'double-float)))
60 (half-double-vector +double-vec-length+ vec)
65 (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
66 (dotimes (i +double-vec-length+)
67 (setf (aref vec i) (coerce i 'double-float)))
69 (half-double-vector +double-vec-length+ (system:vector-sap vec)))
72 (deftest c-test.1 (string-to-upper "this is a test") "THIS IS A TEST")
73 (deftest c-test.2 (string-to-upper nil) nil)
74 (deftest c-test.3 (string-count-upper "This is a Test") 2)
75 (deftest c-test.4 (string-count-upper nil) -1)
76 (deftest c-test.5 (test-half-double-vector)
77 (0.0d0 0.5d0 1.0d0 1.5d0 2.0d0 2.5d0 3.0d0 3.5d0 4.0d0 4.5d0))