Source

eieio / eieio-tests.el

Diff from to

eieio-tests.el

 ;;; eieio-tests.el -- eieio tests routines
 
 ;;;
-;; Copyright (C) 1999, 2000 Eric M. Ludlam
+;; Copyright (C) 1999, 2000, 2001 Eric M. Ludlam
 ;;
 ;; Author: <zappo@gnu.org>
 ;; RCS: $Id$
 ;;
 ;; Please send bug reports, etc. to zappo@gnu.org
 ;;
-;; Updates can be found at:
-;;    ftp://ftp.ultranet.com/pub/zappo
 
 ;;; Commentary:
 ;;  
 ;; Test the various features of EIEIO.  To run the tests, evaluate the
 ;; entire buffer.
 
+(require 'eieio-base)
+
 ;;; Code:
 
 ;;; Multiple Inheritance, and method signal testing
 	      :allocation class)
    (test-tag :initform nil
 	     :documentation "Used to make sure methods are called.")
+   (self :initform nil
+	 :type (or null class-a)
+	 :documentation "Test self referencing types.")
    )
   "Class A")
 
 (defvar a  (class-a "aye"))
 (defvar b (class-b "fooby"))
 
+(condition-case nil
+    (progn
+      ;; Try make-instance on these guys...
+      (make-instance 'class-ab)
+      (make-instance 'class-a :water 'cho)
+      (make-instance 'class-b "a name")
+      )
+  (error "make-instance error."))
+
 ;; Play with call-next-method
 (defmethod class-cn ((a class-a))
   "Try calling `call-next-method' when there isn't one.
     nil
   (error "Call next method MI check failed."))
 
+;; Try the self referencing test
+(oset a self a)
+
 
 ;;; Test the BEFORE, PRIMARY, and AFTER method tags.
 ;;
     nil
   (error "Slot exists-p failed"))
 
+(condition-case nil
+    (progn
+      (oref a water)
+      (error ""))
+  (unbound-slot nil)
+  (error (error "Oref of unbound slot succeeded.")))
+  
+
 (defmethod slot-unbound ((a class-a) &rest foo)
   "If a slot in A is unbound, ignore FOO."
   'moose)
 (if (eq (oref a classslot) (oref aa classslot))
     nil
   (error "Class slots are tracking between objects"))
+
+;;; Test function type in a class
+;;
+(defclass class-typep ()
+  ((slot1 :type function
+	  :initform <
+	  )
+   (slot2 :type integer
+	  :initform (lambda () 1)
+	  )
+   (slot4 :type function
+	  :initform (lambda-default () 2)
+	  )
+   )
+  "Test different types in a class.")
+
+(defvar ct (class-typep "foo"))
 
 
 ;;; Inheritance status
 	   :allocation :instance
 	   :documentation "Fisrt slot testing slot arguments."
 	   :custom symbol
+	   :label "Wild Animal"
+	   :group borg
 	   :protection public)
    (slot-2 :initarg :penguin
 	   :initform "penguin"
 	   :allocation :instance
 	   :documentation "Second slot testing slot arguments."
 	   :custom string
+	   :label "Wild bird"
+	   :group vorlon
 	   :accessor get-slot-2
 	   :protection private)
    )
-  '(:documentation "A class for testing slot arguments.")
+  (:custom-groups (foo))
+  "A class for testing slot arguments."
   )
 
 (defvar t1 (class-c "C1"))
       (error "A string was set on a symbol slot during init."))
   (invalid-slot-type nil))
 
+;;; eieio-instance-inheritor
+;; Test to make sure this works.
+(defclass II (eieio-instance-inheritor)
+  ((slot1 :initform 1)
+   (slot2)
+   (slot3))
+  "Instance Inheritor test class.")
+
+(defvar II1 (II "II Test."))
+(oset II1 slot2 'cat)
+(defvar II2 (clone II1 "II2 Test."))
+(oset II2 slot1 'moose)
+(defvar II3 (clone II2 "II3 Test."))
+(oset II3 slot3 'penguin)
+
+(cond ((not (eq (oref II3 slot1) 'moose))
+       (error "Instance inheritor: Level one inheritance failed."))
+      ((not (eq (oref II3 slot2) 'cat))
+       (error "Instance inheritor: Level two inheritance failed."))
+      ((not (eq (oref II3 slot3) 'penguin))
+       (error "Instance inheritor: Level zero inheritance failed."))
+      (t t))
+
+
+;;; Test the persistent object, and object-write by side-effect.
+;;
+(defclass PO (eieio-persistent)
+  ((slot1 :initarg :slot1
+	  :initform 2)
+   (slot2 :initarg :slot2
+	  :initform "foo"))
+  "A Persistent object with two initializable slots.")
+
+(defvar PO1 (PO "persist" :slot1 4 :slot2 "testing"
+		:file (concat default-directory "test-p.el")))
+
+(eieio-persistent-save PO1)
+
+(eieio-persistent-read "test-p.el")
+
+
+;;; Test the instance tracker
+;;
+(defclass IT (eieio-instance-tracker)
+  ((tracking-symbol :initform IT-list)
+   (slot1 :initform 'die))
+  "Instance Tracker test object.")
+
+(defvar IT-list nil)
+(defvar IT1 (IT "trackme"))
+
+(if (not (eieio-instance-tracker-find 'die 'slot1 'IT-list))
+    (error "Instance tracker lost an instance."))
+
+(delete-instance IT1)
+
+(if (eieio-instance-tracker-find 'die 'slot1 'IT-list)
+    (error "Instance tracker delete failed."))
 
 (message "All tests passed.")