17652bac3022ad30da8afe2b9809de638fc902fc
[uffi.git] / tests / arrays.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          arrays.lisp
6 ;;;; Purpose:       UFFI test arrays
7 ;;;; Author:        Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2002
9 ;;;;
10 ;;;; $Id: arrays.lisp,v 1.4 2003/05/01 04:59:37 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package :uffi-tests)
20
21 (uffi:def-constant +column-length+ 10)
22 (uffi:def-constant +row-length+ 10)
23
24 (uffi:def-foreign-type long-ptr '(* :long))
25
26 (deftest array.1
27     (let ((a (uffi:allocate-foreign-object :long +column-length+))
28           (results nil))
29       (dotimes (i +column-length+)
30         (setf (uffi:deref-array a '(:array :long) i) (* i i)))
31       (dotimes (i +column-length+)
32         (push (uffi:deref-array a '(:array :long) i) results))
33       (uffi:free-foreign-object a)
34       (nreverse results))
35   (0 1 4 9 16 25 36 49 64 81))
36
37
38 (deftest array.2
39     (let ((a (uffi:allocate-foreign-object 'long-ptr +row-length+))
40           (results nil))
41       (dotimes (r +row-length+)
42         (declare (fixnum r))
43         (setf (uffi:deref-array a '(:array (* :long)) r)
44               (uffi:allocate-foreign-object :long +column-length+))
45         (let ((col (uffi:deref-array a '(:array (* :long)) r)))
46           (dotimes (c +column-length+)
47             (declare (fixnum c))
48             (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
49       
50       (dotimes (r +row-length+)
51         (declare (fixnum r))
52         (let ((col (uffi:deref-array a '(:array (* :long)) r)))
53           (dotimes (c +column-length+)
54             (declare (fixnum c))
55             (push (uffi:deref-array col '(:array :long) c) results))))
56       (uffi:free-foreign-object a)
57       (nreverse results))
58   (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99))
59
60