X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Funion.cl;h=bd6e5b4fbab628f7244de67068df86c3568f654d;hb=e6ead14af8cd0833a49d7cd33c8bc33d3404da6d;hp=197332f168e0a04b843640241aa96daefd57f47c;hpb=7cb20f3bc266ede16dfcd449986136c43c4a2d57;p=uffi.git diff --git a/tests/union.cl b/tests/union.cl index 197332f..bd6e5b4 100644 --- a/tests/union.cl +++ b/tests/union.cl @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: union.cl,v 1.1 2002/03/21 07:56:45 kevin Exp $ +;;;; $Id: union.cl,v 1.5 2002/04/02 23:27:05 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -25,22 +25,50 @@ (sf :float) (df :double)) -(defun test-union-1 () - (let ((u (uffi:allocate-foreign-object tunion1))) - (setf (uffi:get-slot-value u 'tunion1 'int) +(defun run-union-1 () + (let ((u (uffi:allocate-foreign-object 'tunion1))) + (setf (uffi:get-slot-value u 'tunion1 'uint) (+ (char-code #\A) (* 256 (char-code #\B)) (* 65536 (char-code #\C)) (* 16777216 255))) - (format t "~&Should be #\A: ~S" + (format *standard-output* "~&Should be #\A: ~S" (uffi:ensure-char-character (uffi:get-slot-value u 'tunion1 'char))) - (format t "~&Should be negative number: ~D" + (format *standard-output* "~&Should be negative number: ~D" (uffi:get-slot-value u 'tunion1 'int)) - (format t "~&Should be positive number: ~D" + (format *standard-output* "~&Should be positive number: ~D" (uffi:get-slot-value u 'tunion1 'uint)) (uffi:free-foreign-object u)) (values)) -#+uffi-test +(defun test-union-1 () + (let ((u (uffi:allocate-foreign-object 'tunion1))) + (setf (uffi:get-slot-value u 'tunion1 'uint) + (+ (char-code #\A) + (* 256 (char-code #\B)) + (* 65536 (char-code #\C)) + (* 16777216 255))) + (util.test:test (uffi:ensure-char-character + (uffi:get-slot-value u 'tunion1 'char)) + #\A + :test #'eql + :fail-info "Error with union character") + + (util.test:test (> 0 (uffi:get-slot-value u 'tunion1 'int)) + t + :fail-info + "Error with negative int in union") + (util.test:test (plusp (uffi:get-slot-value u 'tunion1 'uint)) + t + :fail-info + "Error with unsigned int in union") + (uffi:free-foreign-object u)) + (values)) + +#+examples-uffi +(run-union-1) + + +#+test-uffi (test-union-1)