1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
3 ;;; misc.lisp --- Miscellaneous tests.
5 ;;; Copyright (C) 2006, Luis Oliveira <loliveira@common-lisp.net>
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:
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
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.
28 (in-package #:cffi-tests
)
31 (defun featurep (feature-expression)
32 (etypecase feature-expression
33 (symbol (not (null (member feature-expression
*features
*))))
34 (cons ; Not LIST, as we've already eliminated NIL.
35 (ecase (first feature-expression
)
36 (:and
(every #'featurep
(rest feature-expression
)))
37 (:or
(some #'featurep
(rest feature-expression
)))
38 (:not
(not (featurep (cadr feature-expression
))))))))
40 ;;;# Test relations between OS features.
42 (deftest features.os
.1
43 (if (featurep 'cffi-features
:windows
)
44 (not (or (featurep 'cffi-features
:unix
)
45 (featurep 'cffi-features
:darwin
)))
49 (deftest features.os
.2
50 (if (featurep 'cffi-features
:darwin
)
51 (and (not (featurep 'cffi-features
:windows
))
52 (featurep 'cffi-features
:unix
))
56 (deftest features.os
.3
57 (if (featurep 'cffi-features
:unix
)
58 (not (featurep 'cffi-features
:windows
))
62 ;;;# Test mutual exclusiveness of CPU features.
64 (defparameter *cpu-features
*
74 (deftest features.cpu
.1
75 (loop for feature in
*cpu-features
*
76 when
(featurep feature
)
80 ;;;# foreign-symbol-pointer tests
82 ;;; This might be useful for some libraries that compare function
83 ;;; pointers. http://thread.gmane.org/gmane.lisp.cffi.devel/694
84 (defcfun "compare_against_abs" :boolean
(p :pointer
))
86 (deftest foreign-symbol-pointer
.1
87 (compare-against-abs (foreign-symbol-pointer "abs"))
90 (defcfun "compare_against_xpto_fun" :boolean
(p :pointer
))
92 (deftest foreign-symbol-pointer
.2
93 (compare-against-xpto-fun (foreign-symbol-pointer "xpto_fun"))
98 ;;; Need to figure out a way to test this. CLISP, for instance, will
99 ;;; automatically reopen the foreign-library when we call a foreign
100 ;;; function so we can't test CLOSE-FOREIGN-LIBRARY this way.
102 ;;; IIRC, GCC has some extensions to have code run when a library is
103 ;;; loaded and stuff like that. That could work.
106 #-
(and :ecl
(not :dffi
))
107 (deftest library.close
.2
110 (close-foreign-library 'libtest
)
111 (ignore-errors (my-sqrtf 16.0)))
112 (load-test-libraries))
115 #-
(or (and :ecl
(not :dffi
))
116 cffi-features
:flat-namespace
117 cffi-features
:no-foreign-funcall
)
118 (deftest library.close
.2
121 (foreign-funcall ("ns_function" :library libtest
) :boolean
)
122 (close-foreign-library 'libtest
)
123 (foreign-funcall "ns_function" :boolean
)
124 (close-foreign-library 'libtest2
)
125 (close-foreign-library 'libtest2
)
126 (ignore-errors (foreign-funcall "ns_function" :boolean
)))
127 (load-test-libraries))
131 (deftest library.error
.1
132 (handler-case (load-foreign-library "libdoesnotexistimsure")
133 (load-foreign-library-error () 'error
))
136 ;;;# Shareable Byte Vector Tests
138 (deftest shareable-vector
.1
139 (let ((vector (cffi-sys::make-shareable-byte-vector
5)))
140 (cffi::with-pointer-to-vector-data
(pointer vector
)
141 (strcpy pointer
"xpto"))
143 #(120 112 116 111 0))
145 (deftest shareable-vector
.2
147 (let ((vector (cffi-sys::make-shareable-byte-vector
5)))
148 (cffi::with-pointer-to-vector-data
(pointer vector
)
149 (strcpy pointer
"xpto")
151 #(120 112 116 111 0))