manual: add Clasp to "Implementation Support"
[cffi.git] / tests / misc.lisp
blob61ab907a752cb167f6fde7386421b87f42dc9d2d
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; misc.lisp --- Miscellaneous tests.
4 ;;;
5 ;;; Copyright (C) 2006, 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 ;;;# foreign-symbol-pointer tests
32 ;;; This might be useful for some libraries that compare function
33 ;;; pointers. http://thread.gmane.org/gmane.lisp.cffi.devel/694
34 (defcfun "compare_against_abs" :boolean (p :pointer))
36 (deftest foreign-symbol-pointer.1
37 (compare-against-abs (foreign-symbol-pointer "abs"))
40 (defcfun "compare_against_xpto_fun" :boolean (p :pointer))
42 (deftest foreign-symbol-pointer.2
43 (compare-against-xpto-fun (foreign-symbol-pointer "xpto_fun"))
46 ;;;# Library tests
47 ;;;
48 ;;; Need to figure out a way to test this. CLISP, for instance, will
49 ;;; automatically reopen the foreign-library when we call a foreign
50 ;;; function so we can't test CLOSE-FOREIGN-LIBRARY this way.
51 ;;;
52 ;;; IIRC, GCC has some extensions to have code run when a library is
53 ;;; loaded and stuff like that. That could work.
55 #||
56 #-(and ecl (not dffi))
57 (deftest library.close.2
58 (unwind-protect
59 (progn
60 (close-foreign-library 'libtest)
61 (ignore-errors (my-sqrtf 16.0)))
62 (load-test-libraries))
63 nil)
65 #-(or (and ecl (not dffi))
66 cffi-sys::flat-namespace
67 cffi-sys::no-foreign-funcall)
68 (deftest library.close.2
69 (unwind-protect
70 (values
71 (foreign-funcall ("ns_function" :library libtest) :boolean)
72 (close-foreign-library 'libtest)
73 (foreign-funcall "ns_function" :boolean)
74 (close-foreign-library 'libtest2)
75 (close-foreign-library 'libtest2)
76 (ignore-errors (foreign-funcall "ns_function" :boolean)))
77 (load-test-libraries))
78 t t nil t nil nil)
79 ||#
81 (deftest library.error.1
82 (handler-case (load-foreign-library "libdoesnotexistimsure")
83 (load-foreign-library-error () 'error))
84 error)
86 (define-foreign-library pseudo-library
87 (t pseudo-library-spec))
89 ;;; RT: T clause was being handled as :T by FEATUREP.
90 ;;;
91 ;;; We might want to export (and clean up) the API used in this test
92 ;;; when the need arises.
93 (deftest library.t-clause
94 (eq (cffi::foreign-library-spec
95 (cffi::get-foreign-library 'pseudo-library))
96 'pseudo-library-spec)
99 ;;;# Shareable Byte Vector Tests
101 #+ecl
102 (mapc (lambda (x) (pushnew x rt::*expected-failures*))
103 '(shareable-vector.1 shareable-vector.2))
105 (deftest shareable-vector.1
106 (let ((vector (cffi-sys::make-shareable-byte-vector 5)))
107 (cffi::with-pointer-to-vector-data (pointer vector)
108 (strcpy pointer "xpto"))
109 vector)
110 #(120 112 116 111 0))
112 (deftest shareable-vector.2
113 (block nil
114 (let ((vector (cffi-sys::make-shareable-byte-vector 5)))
115 (cffi::with-pointer-to-vector-data (pointer vector)
116 (strcpy pointer "xpto")
117 (return vector))))
118 #(120 112 116 111 0))