1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: c-test-fns.cl
6 ;;;; Purpose: UFFI Example file for zlib compression
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
10 ;;;; $Id: uffi-c-test-lib.lisp,v 1.1 2003/04/29 14:08:02 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
19 (in-package :uffi-tests)
21 (unless (uffi:load-foreign-library
22 (uffi:find-foreign-library "uffi-c-test-lib"
25 :supporting-libraries '("c"))
26 (warn "Unable to load uffi-c-test-lib library"))
28 (uffi:def-function ("cs_to_upper" cs-to-upper)
29 ((input (* :unsigned-char)))
33 (defun string-to-upper (str)
34 (uffi:with-foreign-string (str-foreign str)
35 (cs-to-upper str-foreign)
36 (uffi:convert-from-foreign-string str-foreign)))
38 (uffi:def-function ("cs_count_upper" cs-count-upper)
43 (defun string-count-upper (str)
44 (uffi:with-cstring (str-cstring str)
45 (cs-count-upper str-cstring)))
47 (uffi:def-function ("half_double_vector" half-double-vector)
52 (uffi:def-constant +double-vec-length+ 10)
53 (defun test-half-double-vector ()
54 (let ((vec (uffi:allocate-foreign-object :double +double-vec-length+))
56 (dotimes (i +double-vec-length+)
57 (setf (uffi:deref-array vec '(:array :double) i)
58 (coerce i 'double-float)))
59 (half-double-vector +double-vec-length+ vec)
60 (dotimes (i +double-vec-length+)
61 (push (uffi:deref-array vec '(:array :double) i) results))
62 (uffi:free-foreign-object vec)
66 (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
67 (dotimes (i +double-vec-length+)
68 (setf (aref vec i) (coerce i 'double-float)))
69 (half-double-vector +double-vec-length+ vec)
74 (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
75 (dotimes (i +double-vec-length+)
76 (setf (aref vec i) (coerce i 'double-float)))
78 (half-double-vector +double-vec-length+ (system:vector-sap vec)))
81 (deftest c-test.1 (string-to-upper "this is a test") "THIS IS A TEST")
82 (deftest c-test.2 (string-to-upper nil) nil)
83 (deftest c-test.3 (string-count-upper "This is a Test") 2)
84 (deftest c-test.4 (string-count-upper nil) -1)
85 (deftest c-test.5 (test-half-double-vector)
86 (0.0d0 0.5d0 1.0d0 1.5d0 2.0d0 2.5d0 3.0d0 3.5d0 4.0d0 4.5d0))