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: c-test-fns.cl,v 1.7 2002/04/03 00:31:32 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 ;;;; *************************************************************************
21 (unless (uffi:load-foreign-library
22 (uffi:find-foreign-library "c-test-fns" *load-truename*)
23 :supporting-libraries '("c")
25 (warn "Unable to load c-test-fns library"))
27 (uffi:def-function ("cs_to_upper" cs-to-upper)
28 ((input (* :unsigned-char)))
32 (defun string-to-upper (str)
33 (uffi:with-foreign-string (str-foreign str)
34 (cs-to-upper str-foreign)
35 (uffi:convert-from-foreign-string str-foreign)))
37 (uffi:def-function ("cs_count_upper" cs-count-upper)
42 (defun string-count-upper (str)
43 (uffi:with-cstring (str-cstring str)
44 (cs-count-upper str-cstring)))
46 (uffi:def-function ("half_double_vector" half-double-vector)
51 (uffi:def-constant +double-vec-length+ 10)
52 (defun test-half-double-vector ()
53 (let ((vec (uffi:allocate-foreign-object :double +double-vec-length+))
55 (dotimes (i +double-vec-length+)
56 (setf (uffi:deref-array vec '(:array :double) i)
57 (coerce i 'double-float)))
58 (half-double-vector +double-vec-length+ vec)
59 (dotimes (i +double-vec-length+)
60 (push (uffi:deref-array vec '(:array :double) i) results))
61 (uffi:free-foreign-object 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)))
68 (half-double-vector +double-vec-length+ vec)
73 (let ((vec (make-array +double-vec-length+ :element-type 'double-float)))
74 (dotimes (i +double-vec-length+)
75 (setf (aref vec i) (coerce i 'double-float)))
77 (half-double-vector +double-vec-length+ (system:vector-sap vec)))
81 (format t "~&(string-to-upper \"this is a test\") => ~A"
82 (string-to-upper "this is a test"))
85 (format t "~&(string-to-upper nil) => ~A"
86 (string-to-upper nil))
89 (format t "~&(string-count-upper \"This is a Test\") => ~A"
90 (string-count-upper "This is a Test"))
93 (format t "~&(string-count-upper nil) => ~A"
94 (string-count-upper nil))
97 (format t "~&Half vector: ~S" (test-half-double-vector))
103 (util.test:test (string= (string-to-upper "this is a test") "THIS IS A TEST")
106 :fail-info "Error with string-to-upper")
107 (util.test:test (string-to-upper nil) nil
108 :fail-info "string-to-upper with nil failed")
109 (util.test:test (string-count-upper "This is a Test")
112 :fail-info "Error with string-count-upper")
113 (util.test:test (string-count-upper nil) -1
115 :fail-info "string-count-upper with nil failed")
117 (util.test:test (test-half-double-vector)
118 '(0.0d0 0.5d0 1.0d0 1.5d0 2.0d0 2.5d0 3.0d0 3.5d0 4.0d0 4.5d0)
120 :fail-info "Error comparing half-double-vector")