r7061: initial property settings
[uffi.git] / tests / uffi-c-test-lib.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
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
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2003 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15
16 (in-package #:uffi-tests)
17
18
19 (uffi:def-function ("cs_to_upper" cs-to-upper)
20   ((input (* :unsigned-char)))
21   :returning :void
22   )
23
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)))
28
29 (uffi:def-function ("cs_count_upper" cs-count-upper)
30   ((input :cstring))
31   :returning :int
32   )
33
34 (defun string-count-upper (str)
35   (uffi:with-cstring (str-cstring str)
36     (cs-count-upper str-cstring)))
37
38 (uffi:def-function ("half_double_vector" half-double-vector)
39     ((size :int)
40      (vec (* :double)))
41   :returning :void)
42
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+))
46         results)
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)
54     (nreverse results)))
55
56 (defun t2 ()
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)
61     vec))
62
63 #+(or cmu scl)
64 (defun t3 ()
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     (system:without-gcing
69      (half-double-vector +double-vec-length+ (system:vector-sap vec)))
70     vec))
71     
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))
78