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
10 ;;;; $Id: tests.lisp,v 1.3 2003/04/28 21:11:55 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2002 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
29 (full-name :value-type string :stored nil)
30 (dob :initarg :dob :accessor dob
32 :print-formatter date-string
33 :value-constraint integerp
34 :input-filter convert-to-date)
35 (resume :initarg :resume :accessor resume
37 :value-constraint stringp)
38 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
39 (addresses :initarg :addresses :accessor addresses
41 (:metaclass hyperobject-class)
42 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
43 (:default-print-slots first-name last-name dob resume)
45 (:description "A Person")
47 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
48 (setf full-name (concatenate 'string first-name " " last-name)))))
50 (defclass address (hyperobject)
51 ((title :initarg :title :accessor title
52 :value-type (varchar 20)
53 :value-constraint stringp)
54 (street :initarg :street :accessor street
55 :value-type (varchar 30)
56 :value-constraint stringp)
57 (phones :initarg :phones :accessor phones
59 (:metaclass hyperobject-class)
60 (:default-initargs :title nil :street nil)
61 (:user-name "Address")
62 (:default-print-slots title street)
63 (:description "An address"))
65 (defclass phone (hyperobject)
66 ((title :initarg :title :accessor title
67 :value-type (varchar 20)
68 :value-constraint stringp)
69 (phone-number :initarg :phone-number :accessor phone-number
70 :value-type (varchar 16)
71 :value-constraint stringp))
72 (:metaclass hyperobject-class)
73 (:user-name "Phone Number")
74 (:default-initargs :title nil :phone-number nil)
75 (:default-print-slots title phone-number)
76 (:description "A phone number"))
78 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
79 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
81 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
82 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
83 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
85 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
86 :phones (list home-phone-1 home-phone-2)))
88 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
89 :phones (list office-phone-1 office-phone-2 office-phone-3)))
92 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
93 :dob (encode-universal-time
95 :addresses (list home office)
96 :resume "Style & Grace"))
99 (defun view-to-string (obj &rest args)
100 (with-output-to-string (strm)
101 (apply #'view obj :stream strm args)))
105 (deftest p1 (view-to-string mary) " Person:
106 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
109 (deftest p2 (view-to-string mary :subobjects t) " Person:
110 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
123 (deftest p3 (view-to-string mary :category t)
126 (deftest p4 (view-to-string mary :subobjects t :category t)
129 (deftest p5 (view-to-string mary :subobjects t :category :xml-link-labels)