Commit the local DARCS CFFI repo, as well as update to today.
[CommonLispStat.git] / external / cffi.darcs / tests / bindings.lisp
blobce69c6fa95d4142ee4538eba0462368859f57637
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; libtest.lisp --- Setup CFFI bindings for libtest.
4 ;;;
5 ;;; Copyright (C) 2005-2007, Luis Oliveira <loliveira(@)common-lisp.net>
6 ;;;
7 ;;; Permission is hereby granted, free of charge, to any person
8 ;;; obtaining a copy of this software and associated documentation
9 ;;; files (the "Software"), to deal in the Software without
10 ;;; restriction, including without limitation the rights to use, copy,
11 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12 ;;; of the Software, and to permit persons to whom the Software is
13 ;;; furnished to do so, subject to the following conditions:
14 ;;;
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
17 ;;;
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ;;; DEALINGS IN THE SOFTWARE.
26 ;;;
28 (in-package #:cffi-tests)
30 (define-foreign-library libtest
31 (:unix (:or "libtest.so" "libtest32.so"))
32 (:windows "libtest.dll")
33 (t (:default "libtest")))
35 (define-foreign-library libtest2
36 (:unix (:or "libtest2.so" "libtest2_32.so"))
37 (:darwin "libtest2.so")
38 (t (:default "libtest2")))
40 (define-foreign-library libc
41 (:windows "msvcrt.dll"))
43 (define-foreign-library libm
44 (t (:default "libm")))
46 ;;; Return the directory containing the source when compiling or
47 ;;; loading this file. We don't use *LOAD-TRUENAME* because the fasl
48 ;;; file may be in a different directory than the source with certain
49 ;;; ASDF extensions loaded.
50 (defun load-directory ()
51 (let ((here #.(or *compile-file-truename* *load-truename*)))
52 (make-pathname :name nil :type nil :version nil
53 :defaults here)))
55 (defun load-test-libraries ()
56 (let ((*foreign-library-directories* (list (load-directory))))
57 (load-foreign-library 'libtest)
58 (load-foreign-library 'libtest2)
59 (load-foreign-library 'libc)
60 #+lispworks (load-foreign-library 'libm)))
62 #-(:and :ecl (:not :dffi))
63 (load-test-libraries)
65 #+(:and :ecl (:not :dffi))
66 (ffi:load-foreign-library
67 #.(make-pathname :name "libtest" :type "so"
68 :defaults (or *compile-file-truename* *load-truename*)))
70 ;;; check libtest version
71 (defparameter *required-dll-version* "20060907")
73 (defcvar "dll_version" :string)
75 (unless (string= *dll-version* *required-dll-version*)
76 (error "version check failed: expected ~s but libtest reports ~s"
77 *required-dll-version*
78 *dll-version*))
80 ;;; The maximum and minimum values for single and double precision C
81 ;;; floating point values, which may be quite different from the
82 ;;; corresponding Lisp versions.
83 (defcvar "float_max" :float)
84 (defcvar "float_min" :float)
85 (defcvar "double_max" :double)
86 (defcvar "double_min" :double)
88 ;;; This is not the best place for this code...
89 (defparameter *repeat* 1)
91 (defun run-cffi-tests (&key (compiled nil))
92 (let ((regression-test::*compile-tests* compiled)
93 (*package* (find-package '#:cffi-tests)))
94 (format t "~2&How many times shall we run the tests (~Acompiled)? [~D]: "
95 (if compiled "" "un") *repeat*)
96 (force-output *standard-output*)
97 (let* ((ntimes (or (ignore-errors (parse-integer (read-line))) *repeat*))
98 (ret-values (loop repeat ntimes collect (do-tests))))
99 (format t "~&;;; Finished running tests (~Acompiled) ~D times."
100 (if compiled "" "un") ntimes)
101 (every #'identity ret-values))))