source: branches/1.1.x/test/lisp/abcl/metaclass.lisp

Last change on this file was 12658, checked in by ehuelsmann, 15 years ago

Close #38: Add some metaclass tests - to be expanded
upon fixing encountered issues.

File size: 3.5 KB
Line 
1;;; metaclass.lisp
2;;;
3;;; Copyright (C) 2005 Peter Graves
4;;; $Id: misc-tests.lisp 12402 2010-01-26 11:15:48Z mevenson $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package #:abcl.test.lisp)
21
22(defclass testclass1 () ()
23  (:metaclass standard-class))
24(defclass testclass2 () ()
25  (:metaclass standard-class)
26  (:documentation "test"))
27(defclass metaclass1 (standard-class) ()
28  (:metaclass standard-class))
29(defclass metaclass2 (standard-class) ()
30  (:metaclass standard-class)
31  (:documentation "test"))
32
33(defclass testclass3 () ()
34  (:metaclass metaclass1)
35  (:documentation "test"))
36
37(deftest testclass1.instantiate
38    (not (null (make-instance 'testclass1)))
39  T)
40(deftest testclass2.instantiate
41    (not (null (make-instance 'testclass2)))
42  T)
43(deftest testclass3.instantiate
44    (not (null (make-instance 'testclass3)))
45  T)
46
47(deftest testclass1.class-of
48    (eq (class-of (make-instance 'testclass1)) (find-class 'testclass1))
49  T)
50(deftest testclass1.metaclass-of
51    (eq (class-of (class-of (make-instance 'testclass1)))
52        (find-class 'standard-class))
53  T)
54
55(deftest testclass3.metaclass-of
56    (eq (class-of (class-of (make-instance 'testclass3)))
57        (find-class 'metaclass1))
58  T)
59
60(deftest standard-class.typep.class
61    (typep (class-of (find-class 'standard-class)) 'class)
62  T)
63(deftest standard-class.typep.standard-class
64    (typep (class-of (class-of (find-class 'standard-class))) 'standard-class)
65  T)
66(deftest metaclass1.typep.class
67    (typep (find-class 'metaclass1) 'class)
68  T)
69(deftest metaclass1.typep.standard-class
70    (typep (find-class 'metaclass1) 'standard-class)
71  T)
72(deftest testclass3.class-of.typep
73    (typep (class-of (make-instance 'testclass3)) 'metaclass1)
74  T)
75(deftest testclass3.metaclass-of.typep
76    (typep (class-of (class-of (make-instance 'testclass3))) 'standard-class)
77  T)
78
79(defclass testclass4 ()
80  ((a :initarg :a :initform 3)
81   (b :initarg :b :initform 4))
82  (:metaclass metaclass1)
83  (:documentation "test"))
84
85(deftest testclass4.init-noargs
86    (slot-value (make-instance 'testclass4) 'a)
87  3)
88
89(deftest testclass4.initargs
90    (slot-value (make-instance 'testclass4 :a 2) 'a)
91  2)
92
93(defclass testclass5 ()
94  ((a :initarg :a)
95   (b :initarg :b :initform 1))
96  (:metaclass metaclass1)
97  (:default-initargs :a 5))
98
99(deftest testclass5.init-noargs
100    (slot-value (make-instance 'testclass5) 'a)
101  5)
102
103(deftest testclass5.initargs
104    (slot-value (make-instance 'testclass5 :a 3) 'a)
105  3)
106
107(defclass testclass6 ()
108  ((a :initarg :a :allocation :class))
109  (:metaclass metaclass1)
110  (:documentation "test"))
111
112(deftest testclass6.1
113    (let ((instance1 (make-instance 'testclass6 :a 3))
114          (instance2 (make-instance 'testclass6 :a 4)))
115      (slot-value instance1 'a))
116  4)
117
118
Note: See TracBrowser for help on using the repository browser.