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.2 2003/04/28 19:06:13 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (defpackage #:hyperobject-tests
17 (:use #:hyperobject #:cl #:rtest))
18 (in-package #:hyperobject-tests)
20 (defun format-date (ut)
21 (when (typep ut 'integer)
22 (multiple-value-bind (sec min hr day mon year dow daylight-p zone)
23 (decode-universal-time ut)
24 (declare (ignore daylight-p zone))
25 (format nil "~[Mon~;Tue~;Wed~;Thu~;Fri~;Sat~;Sun~], ~d ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~d ~2,'0d:~2,'0d:~2,'0d"
32 (defclass person (hyperobject)
33 ((first-name :initarg :first-name :accessor first-name
34 :value-type (varchar 20)
35 :value-constraint stringp
37 (last-name :initarg :last-name :accessor last-name
38 :value-type (varchar 30)
39 :value-constraint stringp
40 :hyperlink find-person-by-last-name
42 (full-name :value-type string :stored nil)
43 (dob :initarg :dob :accessor dob
45 :print-formatter format-date
46 :value-constraint integerp
47 :input-filter convert-to-date)
48 (resume :initarg :resume :accessor resume
50 :value-constraint stringp)
51 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
52 (addresses :initarg :addresses :accessor addresses
54 (:metaclass hyperobject-class)
55 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
56 (:default-print-slots first-name last-name dob resume)
58 (:description "A Person")
60 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
61 (setf full-name (concatenate 'string first-name " " last-name)))))
63 (defclass address (hyperobject)
64 ((title :initarg :title :accessor title
65 :value-type (varchar 20)
66 :value-constraint stringp)
67 (street :initarg :street :accessor street
68 :value-type (varchar 30)
69 :value-constraint stringp)
70 (phones :initarg :phones :accessor phones
72 (:metaclass hyperobject-class)
73 (:default-initargs :title nil :street nil)
74 (:user-name "Address")
75 (:default-print-slots title street)
76 (:description "An address"))
78 (defclass phone (hyperobject)
79 ((title :initarg :title :accessor title
80 :value-type (varchar 20)
81 :value-constraint stringp)
82 (phone-number :initarg :phone-number :accessor phone-number
83 :value-type (varchar 16)
84 :value-constraint stringp))
85 (:metaclass hyperobject-class)
86 (:user-name "Phone Number")
87 (:default-initargs :title nil :phone-number nil)
88 (:default-print-slots title phone-number)
89 (:description "A phone number"))
91 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
92 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
94 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
95 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
96 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
98 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
99 :phones (list home-phone-1 home-phone-2)))
101 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
102 :phones (list office-phone-1 office-phone-2 office-phone-3)))
105 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
106 :dob (encode-universal-time
108 :addresses (list home office)
109 :resume "Style & Grace"))
111 ;(format t "~&Text Format~%")
112 ;(view mary :subobjects t)
114 ;(format t "~&XML Format with field labels and hyperlinks~%")
115 ;(view mary :subobjects t :category :xml-link-labels)
117 (defun view-to-string (obj &rest args)
118 (with-output-to-string (strm)
119 (apply #'view obj :stream strm args)))
123 (deftest p1 (view-to-string mary) " Person:
124 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
127 (deftest p2 (view-to-string mary :subobjects t) " Person:
128 Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace