adding CFFI just in case. Need to make into a submodule at somepoint.
[CommonLispStat.git] / external / cffi.darcs / tests / bindings.lisp
blob6eac146a4a6574f666d1aea8e525f113b38d25e1
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 (:darwin "libtest2.so")
37 (t (:default "libtest2")))
39 (define-foreign-library libc
40 (:windows "msvcrt.dll"))
42 ;;; Return the directory containing the source when compiling or
43 ;;; loading this file. We don't use *LOAD-TRUENAME* because the fasl
44 ;;; file may be in a different directory than the source with certain
45 ;;; ASDF extensions loaded.
46 (defun load-directory ()
47 (let ((here #.(or *compile-file-truename* *load-truename*)))
48 (make-pathname :name nil :type nil :version nil
49 :defaults here)))
51 (defun load-test-libraries ()
52 (let ((*foreign-library-directories* (list (load-directory))))
53 (load-foreign-library 'libtest)
54 (load-foreign-library 'libtest2)
55 (load-foreign-library 'libc)))
57 #-(:and :ecl (:not :dffi))
58 (load-test-libraries)
60 #+(:and :ecl (:not :dffi))
61 (ffi:load-foreign-library
62 #.(make-pathname :name "libtest" :type "so"
63 :defaults (or *compile-file-truename* *load-truename*)))
65 ;;; check libtest version
66 (defparameter *required-dll-version* "20060907")
68 (defcvar "dll_version" :string)
70 (unless (string= *dll-version* *required-dll-version*)
71 (error "version check failed: expected ~s but libtest reports ~s"
72 *required-dll-version*
73 *dll-version*))
75 ;;; The maximum and minimum values for single and double precision C
76 ;;; floating point values, which may be quite different from the
77 ;;; corresponding Lisp versions.
78 (defcvar "float_max" :float)
79 (defcvar "float_min" :float)
80 (defcvar "double_max" :double)
81 (defcvar "double_min" :double)
83 ;;; This is not the best place for this code...
84 (defparameter *repeat* 1)
86 (defun run-cffi-tests (&key (compiled nil))
87 (let ((regression-test::*compile-tests* compiled)
88 (*package* (find-package '#:cffi-tests)))
89 (format t "~2&How many times shall we run the tests (~Acompiled)? [~D]: "
90 (if compiled "" "un") *repeat*)
91 (force-output *standard-output*)
92 (let* ((ntimes (or (ignore-errors (parse-integer (read-line))) *repeat*))
93 (ret-values (loop repeat ntimes collect (do-tests))))
94 (format t "~&;;; Finished running tests (~Acompiled) ~D times."
95 (if compiled "" "un") ntimes)
96 (every #'identity ret-values))))