Remove old CVS $Id$ keyword
[uffi.git] / tests / union.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          union.lisp
6 ;;;; Purpose:       UFFI Example file to test unions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2002
9 ;;;;
10 ;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package #:uffi-tests)
15
16 (uffi:def-union tunion1
17     (char :char)
18   (int :int)
19   (uint :unsigned-int)
20   (sf :float)
21   (df :double))
22
23 (defvar *u* (uffi:allocate-foreign-object 'tunion1))
24 (setf (uffi:get-slot-value *u* 'tunion1 'uint)
25       #-(or sparc sparc-v9 powerpc ppc)
26       (+ (* 1 (char-code #\A))
27          (* 256 (char-code #\B))
28          (* 65536 (char-code #\C))
29          (* 16777216 128))
30       #+(or sparc sparc-v9 powerpc ppc)
31       (+ (* 16777216 (char-code #\A))
32          (* 65536 (char-code #\B))
33          (* 256 (char-code #\C))
34          (* 1 128)))
35
36 (deftest :union.1
37     (uffi:ensure-char-character
38      (uffi:get-slot-value *u* 'tunion1 'char))
39   #\A)
40
41 (deftest :union.2
42     (uffi:ensure-char-integer
43      (uffi:get-slot-value *u* 'tunion1 'char))
44   65)
45
46 #-(or sparc sparc-v9 openmcl digitool)
47 (deftest :union.3 (plusp (uffi:get-slot-value *u* 'tunion1 'uint)) t)
48
49
50 (uffi:def-union foo-u
51     (bar :pointer-self))
52
53 (uffi:def-foreign-type foo-u-ptr (* foo-u))
54
55 ;; tests that compilation worked
56 (deftest :unions.4
57   (with-foreign-object (p 'foo-u)
58     t)
59   t)
60
61 (deftest :unions.5
62     (progn
63       (uffi:def-foreign-type foo-union (:union foo-u))
64       t)
65   t)
66
67
68
69