716844893801679bbd6b03d59db6dda65209b99e
[uffi.git] / tests / pointers.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          pointers.lisp
6 ;;;; Purpose:       Test file for UFFI pointers
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Aug 2003
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2003 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15
16 (in-package #:uffi-tests)
17
18 (deftest chptr.1
19     (let ((native-string "test string"))
20       (uffi:with-foreign-string (fs native-string)
21         (ensure-char-character
22          (deref-pointer fs :char))))
23   #\t)
24
25 (deftest chptr.2
26     (let ((native-string "test string"))
27       (uffi:with-foreign-string (fs native-string)
28         (ensure-char-character
29          (deref-pointer fs :unsigned-char))))
30   #\t)
31
32 (deftest chptr.3
33     (let ((native-string "test string"))
34       (uffi:with-foreign-string (fs native-string)
35         (ensure-char-integer
36          (deref-pointer fs :unsigned-char))))
37   116)
38
39 (deftest chptr.4
40     (let ((native-string "test string"))
41       (uffi:with-foreign-string (fs native-string)
42         (numberp
43          (deref-pointer fs :byte))))
44   t)
45         
46 (deftest chptr.5
47     (let ((fs (uffi:allocate-foreign-object :unsigned-char 128)))
48       (setf (uffi:deref-array fs '(:array :unsigned-char) 0)
49             (uffi:ensure-char-storable #\a))
50       (setf (uffi:deref-array fs '(:array :unsigned-char) 1)
51             (uffi:ensure-char-storable (code-char 0)))
52       (uffi:convert-from-foreign-string fs))
53   "a")
54
55 ;; This produces an array which needs fli:foreign-aref to access
56 ;; rather than fli:dereference
57
58 #-lispworks
59 (deftest chptr.6
60     (uffi:with-foreign-object (fs '(:array :unsigned-char 128))
61       (setf (uffi:deref-array fs '(:array :unsigned-char) 0)
62             (uffi:ensure-char-storable #\a))
63       (setf (uffi:deref-array fs '(:array :unsigned-char) 1)
64             (uffi:ensure-char-storable (code-char 0)))
65       (uffi:convert-from-foreign-string fs))
66   "a")
67
68       
69