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 (defclass person (hyperobject)
20 ((first-name :initarg :first-name :accessor first-name
21 :value-type (varchar 20)
22 :value-constraint stringp
24 (last-name :initarg :last-name :accessor last-name
25 :value-type (varchar 30)
26 :value-constraint stringp
27 :hyperlink find-person-by-last-name
28 :hyperlink-parameters (("narrow" . "yes"))
30 (full-name :value-type string :stored nil)
31 (dob :initarg :dob :accessor dob
33 :print-formatter date-string
34 :value-constraint integerp
35 :input-filter convert-to-date)
36 (resume :initarg :resume :accessor resume
38 :value-constraint stringp)
39 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
40 (addresses :initarg :addresses :accessor addresses
42 (:metaclass hyperobject-class)
43 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
44 (:default-print-slots first-name last-name dob resume)
46 (:description "A Person")
48 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
49 (setf full-name (concatenate 'string first-name " " last-name)))))
51 (defclass address (hyperobject)
52 ((title :initarg :title :accessor title
53 :value-type (varchar 20)
54 :value-constraint stringp)
55 (street :initarg :street :accessor street
56 :value-type (varchar 30)
57 :value-constraint stringp)
58 (phones :initarg :phones :accessor phones
60 (:metaclass hyperobject-class)
61 (:default-initargs :title nil :street nil)
62 (:user-name "Address" "Addresses")
63 (:default-print-slots title street)
64 (:description "An address"))
66 (defclass phone (hyperobject)
67 ((title :initarg :title :accessor title
68 :value-type (varchar 20)
69 :value-constraint stringp)
70 (phone-number :initarg :phone-number :accessor phone-number
71 :value-type (varchar 16)
72 :value-constraint stringp
73 :hyperlink search-phone-number))
74 (:metaclass hyperobject-class)
75 (:user-name "Phone Number")
76 (:default-initargs :title nil :phone-number nil)
77 (:default-print-slots title phone-number)
78 (:description "A phone number"))
80 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
81 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
83 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
84 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
85 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
87 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
88 :phones (list home-phone-1 home-phone-2)))
90 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
91 :phones (list office-phone-1 office-phone-2 office-phone-3)))
94 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
95 :dob (encode-universal-time
97 :addresses (list home office)
98 :resume "Style & Grace"))
101 (defun view-to-string (obj &rest args)
102 (with-output-to-string (strm)
103 (apply #'view obj :stream strm args)))
107 (deftest p1 (view-to-string mary) "Person:
108 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
111 (deftest p2 (view-to-string mary :subobjects t) "Person:
112 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
125 (deftest p3 (view-to-string mary :vid :compact-text-labels)
127 first-name Mary last-name Jackson dob Thu, 4 May 2000 03:02:01 resume Style & Grace