adding CFFI just in case. Need to make into a submodule at somepoint.
[CommonLispStat.git] / external / cffi.darcs / tests / enum.lisp
blobec6cc861fd4f405e7fed958d795936c15a062c77
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; enum.lisp --- Tests on C enums.
4 ;;;
5 ;;; Copyright (C) 2005-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 (defcenum numeros
31 (:one 1)
32 :two
33 :three
34 :four
35 (:forty-one 41)
36 :forty-two)
38 (defcfun "check_enums" :int
39 (one numeros)
40 (two numeros)
41 (three numeros)
42 (four numeros)
43 (forty-one numeros)
44 (forty-two numeros))
46 (deftest enum.1
47 (check-enums :one :two :three 4 :forty-one :forty-two)
50 (defcenum another-boolean :false :true)
51 (defcfun "return_enum" another-boolean (x :int))
53 (deftest enum.2
54 (and (eq :false (return-enum 0))
55 (eq :true (return-enum 1)))
58 (defctype yet-another-boolean another-boolean)
59 (defcfun ("return_enum" return-enum2) yet-another-boolean
60 (x yet-another-boolean))
62 (deftest enum.3
63 (and (eq :false (return-enum2 :false))
64 (eq :true (return-enum2 :true)))
67 ;;;# Bitfield tests
69 ;;; Regression test: defbitfield was misbehaving when the first value
70 ;;; was provided.
71 (deftest bitfield.1
72 (eval '(defbitfield bf1
73 (:foo 0)))
74 bf1)
76 (defbitfield bf2
77 one
78 two
79 four
80 eight
81 sixteen
82 thirty-two
83 sixty-four)
85 (deftest bitfield.2
86 (mapcar (lambda (symbol)
87 (foreign-bitfield-value 'bf2 (list symbol)))
88 '(one two four eight sixteen thirty-two sixty-four))
89 (1 2 4 8 16 32 64))
91 (defbitfield bf3
92 (three 3)
93 one
94 (seven 7)
95 two
96 (eight 8)
97 sixteen)
99 ;;; Non-single-bit numbers must not influence the progression of
100 ;;; implicit values. Single bits larger than any before *must*
101 ;;; influence said progression.
102 (deftest bitfield.3
103 (mapcar (lambda (symbol)
104 (foreign-bitfield-value 'bf3 (list symbol)))
105 '(one two sixteen))
106 (1 2 16))
108 (defbitfield bf4
109 (zero 0)
110 one)
112 ;;; Yet another edge case with the 0...
113 (deftest bitfield.4
114 (foreign-bitfield-value 'bf4 '(one))