Add test exercising old-style vs new-style inner struct access v0.11.0
authorLuís Oliveira <loliveira@common-lisp.net>
Mon, 25 Feb 2013 00:46:18 +0000 (00:46 +0000)
committerLuís Oliveira <loliveira@common-lisp.net>
Mon, 25 Feb 2013 00:46:18 +0000 (00:46 +0000)
tests/struct.lisp

index 683afbb..460cab9 100644 (file)
     (eql (foreign-type-size 'single-byte-struct-alias)
          (foreign-type-size '(:struct single-byte-struct)))
   t)
+
+;;; Old-style access to inner structure fields.
+
+(defcstruct inner-struct (x :int))
+(defcstruct old-style-outer (inner inner-struct))
+(defcstruct new-style-outer (inner (:struct inner-struct)))
+
+(deftest old-style-struct-access
+    (with-foreign-object (s '(:struct old-style-outer))
+      (let ((inner-ptr (foreign-slot-pointer s 'old-style-outer 'inner)))
+        (setf (foreign-slot-value inner-ptr 'inner-struct 'x) 42))
+      (assert (pointerp (foreign-slot-value s 'old-style-outer 'inner)))
+      (foreign-slot-value (foreign-slot-value s 'old-style-outer 'inner)
+                          'inner-struct 'x))
+  42)
+
+(deftest new-style-struct-access
+    (with-foreign-object (s '(:struct new-style-outer))
+      (let ((inner-ptr (foreign-slot-pointer s 'new-style-outer 'inner)))
+        (setf (foreign-slot-value inner-ptr 'inner-struct 'x) 42))
+      (foreign-slot-value s 'new-style-outer 'inner))
+  (x 42))