1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: hyperobject-tests.lisp
6 ;;;; Purpose: Hyperobject tests file
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2003
12 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
15 (defpackage #:hyperobject-tests
16 (:use #:hyperobject #:cl #:rtest #:kmrcl))
17 (in-package #:hyperobject-tests)
19 (defvar *now* (get-universal-time))
20 (defun get-now () *now*)
22 (defclass person (hyperobject)
23 ((first-name :initarg :first-name :accessor first-name
24 :value-type (varchar 20)
25 :value-constraint stringp
27 (last-name :initarg :last-name :accessor last-name
28 :value-type (varchar 30)
29 :value-constraint stringp
30 :hyperlink find-person-by-last-name
31 :hyperlink-parameters (("narrow" . "yes"))
33 (full-name :value-type string :stored nil)
34 (dob :initarg :dob :accessor dob
36 :print-formatter date-string
37 :value-constraint integerp
38 :input-filter convert-to-date)
39 (resume :initarg :resume :accessor resume
41 :value-constraint stringp)
42 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
43 (addresses :initarg :addresses :accessor addresses
45 (create-time :accessor create-time :compute-cached-value (get-now)))
46 (:metaclass hyperobject-class)
47 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
48 (:default-print-slots first-name last-name dob resume)
50 (:description "A Person")
52 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
53 (setf full-name (concatenate 'string first-name " " last-name)))))
55 (defclass address (hyperobject)
56 ((title :initarg :title :accessor title
57 :value-type (varchar 20)
58 :value-constraint stringp)
59 (street :initarg :street :accessor street
60 :value-type (varchar 30)
61 :value-constraint stringp)
62 (phones :initarg :phones :accessor phones
64 (years-at-address :initarg :years-at-address :value-type fixnum
65 :accessor years-at-address
66 :value-constraint integerp))
67 (:metaclass hyperobject-class)
68 (:default-initargs :title nil :street nil)
69 (:user-name "Address" "Addresses")
70 (:default-print-slots title street years-at-address)
71 (:description "An address"))
73 (defclass phone (hyperobject)
74 ((title :initarg :title :accessor title
75 :value-type (varchar 20)
76 :value-constraint stringp)
77 (phone-number :initarg :phone-number :accessor phone-number
78 :value-type (varchar 16)
79 :value-constraint stringp
80 :hyperlink search-phone-number))
81 (:metaclass hyperobject-class)
82 (:user-name "Phone Number")
83 (:default-initargs :title nil :phone-number nil)
84 (:default-print-slots title phone-number)
85 (:description "A phone number"))
87 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
88 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
90 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
91 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
92 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
94 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
96 :phones (list home-phone-1 home-phone-2)))
98 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
100 :phones (list office-phone-1 office-phone-2 office-phone-3)))
103 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
104 :dob (encode-universal-time
106 :addresses (list home office)
107 :resume "Style & Grace"))
110 (defun view-to-string (obj &rest args)
111 (with-output-to-string (strm)
112 (apply #'view obj :stream strm args)))
116 (deftest :p1 (view-to-string mary :vid :compact-text) "Person:
117 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
120 (deftest :p2 (view-to-string mary :subobjects t :vid :compact-text) "Person:
121 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
123 Home 321 Shady Lane 10
127 Office 113 Main St. 5
134 (deftest :p3 (view-to-string mary :vid :compact-text-labels)
136 first-name Mary last-name Jackson dob Thu, 4 May 2000 03:02:01 resume Style & Grace
139 (deftest :p4 (view-to-string mary :vid :compact-text)
141 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
144 (deftest :cv1 (years-at-address home)
147 (deftest :cv2 (years-at-address office)
150 (deftest :cv3 (equal (create-time mary) *now*)
154 (deftest :s1 (slot-value (class-of mary) 'ho::user-name)
157 (deftest :s2 (slot-value (class-of mary) 'ho::user-name-plural)
160 (deftest :s3 (slot-value (class-of home) 'ho::user-name-plural)
163 (deftest :s4 (slot-value (class-of mary) 'ho::description)