1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
3 ;;; grovel.lisp --- CFFI-Grovel tests.
5 ;;; Copyright (C) 2014, Luis Oliveira <loliveira@common-lisp.net>
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:
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
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.
28 (in-package #:cffi-tests
)
31 (cffi-grovel::invoke
"echo" "test")
34 (defun bug-1395242-helper (enum-type base-type constant-name
)
35 (check-type enum-type
(member constantenum cenum
))
36 (check-type base-type string
)
37 (check-type constant-name string
)
38 (let ((enum-name (intern (symbol-name (gensym))))
39 (base-type-name (intern (symbol-name (gensym)))))
40 (uiop:with-temporary-file
(:stream grovel-stream
:pathname grovel-file
)
41 ;; Write the grovel file
42 (with-open-stream (*standard-output
* grovel-stream
)
43 (write `(ctype ,base-type-name
,base-type
))
44 (write `(,enum-type
(,enum-name
:base-type
,base-type-name
)
45 ((:value
,constant-name
)))))
46 ;; Get the value of :inaddr-broadcast
47 (let ((lisp-file (cffi-grovel:process-grovel-file grovel-file
)))
51 (cffi:foreign-enum-value enum-name
:value
))
52 (uiop/filesystem
:delete-file-if-exists lisp-file
))))))
56 ((process-expression (expression)
57 (loop for enum-type in
'(constantenum cenum
)
58 always
(destructuring-bind (base-type &rest evaluations
) expression
59 (loop for
(name expected-value
) in evaluations
60 for actual-value
= (bug-1395242-helper enum-type base-type name
)
61 always
(or (= expected-value actual-value
)
63 (format *error-output
*
64 "Test failed for case: ~A, ~A, ~A (expected ~A, actual ~A)~%"
65 enum-type base-type name expected-value actual-value
)
67 (every #'process-expression
68 '(("uint8_t" ("UINT8_MAX" 255) ("INT8_MAX" 127) ("INT8_MIN" 128))
69 ("int8_t" ("INT8_MIN" -
128) ("INT8_MAX" 127) ("UINT8_MAX" -
1))
70 ("uint16_t" ("UINT16_MAX" 65535) ("INT8_MIN" 65408))
71 ("int16_t" ("INT16_MIN" -
32768) ("INT16_MAX" 32767) ("UINT16_MAX" -
1))
72 ("uint32_t" ("UINT32_MAX" 4294967295) ("INT8_MIN" 4294967168))
73 ("int32_t" ("INT32_MIN" -
2147483648) ("INT32_MAX" 2147483647)))))