Remove old CVS $Id$ keyword
[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 ;;;; 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-constant +column-length+ 10)
17 (uffi:def-constant +row-length+ 10)
18
19 (uffi:def-foreign-type long-ptr (* :long))
20
21 (deftest :array.1
22     (let ((a (uffi:allocate-foreign-object :long +column-length+))
23           (results nil))
24       (dotimes (i +column-length+)
25         (setf (uffi:deref-array a '(:array :long) i) (* i i)))
26       (dotimes (i +column-length+)
27         (push (uffi:deref-array a '(:array :long) i) results))
28       (uffi:free-foreign-object a)
29       (nreverse results))
30   (0 1 4 9 16 25 36 49 64 81))
31
32
33 (deftest :array.2
34     (let ((a (uffi:allocate-foreign-object 'long-ptr +row-length+))
35           (results nil))
36       (dotimes (r +row-length+)
37         (declare (fixnum r))
38         (setf (uffi:deref-array a '(:array (* :long)) r)
39               (uffi:allocate-foreign-object :long +column-length+))
40         (let ((col (uffi:deref-array a '(:array (* :long)) r)))
41           (dotimes (c +column-length+)
42             (declare (fixnum c))
43             (setf (uffi:deref-array col '(:array :long) c) (+ (* r +column-length+) c)))))
44
45       (dotimes (r +row-length+)
46         (declare (fixnum r))
47         (let ((col (uffi:deref-array a '(:array (* :long)) r)))
48           (dotimes (c +column-length+)
49             (declare (fixnum c))
50             (push (uffi:deref-array col '(:array :long) c) results))))
51       (uffi:free-foreign-object a)
52       (nreverse results))
53   (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))
54
55