more 1.9.11 NEWS updates
[bpt/guile.git] / test-suite / tests / foreign.test
CommitLineData
01ad5a7b
LC
1;;;; foreign.test --- FFI. -*- mode: scheme; coding: utf-8; -*-
2;;;;
3;;;; Copyright (C) 2010 Free Software Foundation, Inc.
4;;;;
5;;;; This library is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU Lesser General Public
7;;;; License as published by the Free Software Foundation; either
8;;;; version 3 of the License, or (at your option) any later version.
9;;;;
10;;;; This library is distributed in the hope that it will be useful,
11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;;; Lesser General Public License for more details.
14;;;;
15;;;; You should have received a copy of the GNU Lesser General Public
16;;;; License along with this library; if not, write to the Free Software
17;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19;;;
20;;; See also ../standalone/test-ffi for FFI tests.
21;;;
22
23(define-module (test-foreign)
24 #:use-module (system foreign)
25 #:use-module (rnrs bytevector)
26 #:use-module (test-suite lib))
27
28\f
29(with-test-prefix "null pointer"
30
31 (pass-if "zero"
32 (= 0 (foreign-ref %null-pointer)))
33
34 (pass-if-exception "foreign-set! %null-pointer"
35 exception:null-pointer-error
36 (foreign-set! %null-pointer 2))
37
38 (pass-if "foreign-set! other-null-pointer"
39 (let ((f (bytevector->foreign (make-bytevector 2))))
40 (and (not (= 0 (foreign-ref f)))
41 (begin
42 (foreign-set! f 0)
43 (= 0 (foreign-ref f)))
44 (begin
45 ;; Here changing the pointer value of F is perfectly valid.
46 (foreign-set! f 777)
47 (= 777 (foreign-ref f))))))
48
49 (pass-if-exception "foreign->bytevector %null-pointer"
50 exception:null-pointer-error
51 (foreign->bytevector %null-pointer))
52
53 (pass-if-exception "foreign->bytevector other-null-pointer"
54 exception:null-pointer-error
55 (let ((f (bytevector->foreign (make-bytevector 2))))
56 (foreign-set! f 0)
57 (foreign->bytevector f))))