2
;;;; Author: Paul Dietz
3
;;;; Created: Mon Apr 28 21:06:58 2003
4
;;;; Contains: Tests of ALLOCATE-INSTANCE
8
;;; According to the CLHS, the meaning of adding methods to
9
;;; ALLOCATE-INSTANCE is unspecified, so this will not be tested
12
(defclass allocate-instance-class-01 ()
13
((a :initform 'x) (b :initarg :b)
14
(c :type float) (d :allocation :class)
15
(e :initarg :e) (f :documentation "foo"))
16
(:default-initargs :b 'y))
18
(deftest allocate-instance.1
19
(let* ((class (find-class 'allocate-instance-class-01))
20
(obj (allocate-instance class)))
22
(eqt (class-of obj) class)
23
(typep* obj 'allocate-instance-class-01)
25
(map-slot-boundp* obj '(a b c d e f))))
27
(nil nil nil nil nil nil))
29
(deftest allocate-instance.2
30
(let* ((class (find-class 'allocate-instance-class-01))
31
(obj (allocate-instance class
32
:foo t :a 10 :b 12 :c 1.0 :d 'a :e 17
35
(eqt (class-of obj) class)
36
(typep* obj 'allocate-instance-class-01)
38
(map-slot-boundp* obj '(a b c d e f))))
40
(nil nil nil nil nil nil))
42
(deftest allocate-instance.3
43
(let* ((class (find-class 'allocate-instance-class-01))
44
(obj (allocate-instance class :allow-other-keys nil :xyzzy t)))
46
(eqt (class-of obj) class)
47
(typep* obj 'allocate-instance-class-01)
49
(map-slot-boundp* obj '(a b c d e f))))
51
(nil nil nil nil nil nil))
53
(defclass allocate-instance-class-02 ()
54
(a (b :allocation :class)))
56
(deftest allocate-instance.4
57
(let ((class (find-class 'allocate-instance-class-02)))
58
(setf (slot-value (allocate-instance class) 'b) 'x)
59
(let ((obj (allocate-instance class)))
61
(eqt (class-of obj) class)
62
(typep* obj 'allocate-instance-class-02)
65
(slot-value obj 'b))))
68
(defstruct allocate-instance-struct-01
71
(c #\a :type character)
74
(deftest allocate-instance.5
75
(let* ((class (find-class 'allocate-instance-struct-01))
76
(obj (allocate-instance class)))
77
(setf (allocate-instance-struct-01-a obj) 'x
78
(allocate-instance-struct-01-b obj) 1234567890
79
(allocate-instance-struct-01-c obj) #\Z
80
(allocate-instance-struct-01-d obj) 'foo)
82
(eqt (class-of obj) class)
83
(typep* obj 'allocate-instance-struct-01)
85
(allocate-instance-struct-01-a obj)
86
(allocate-instance-struct-01-b obj)
87
(allocate-instance-struct-01-c obj)
88
(allocate-instance-struct-01-d obj)))
92
;;; Order of evaluation tests
94
(deftest allocate-instance.order.1
95
(let* ((class (find-class 'allocate-instance-class-01))
97
(obj (allocate-instance (progn (setf x (incf i)) class)
100
:e (setf w (incf i)))))
102
(eqt (class-of obj) class)
103
(typep* obj 'allocate-instance-class-01)
110
(deftest allocate-instance.error.1
111
(signals-error (allocate-instance) program-error)
114
;;; Duane Rettig made a convincing argument that the next two
115
;;; tests are bad, since the caller of allocate-instance
116
;;; is supposed to have checked that the initargs are valid
119
(deftest allocate-instance.error.2
120
(signals-error (allocate-instance (find-class 'allocate-instance-class-01)
125
(deftest allocate-instance.error.3
126
(signals-error (allocate-instance (find-class 'allocate-instance-class-01)