r4665: *** empty log message ***
[hyperobject.git] / tests.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          hyperobject-tests.lisp
6 ;;;; Purpose:       Hyperobject tests file
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2003
9 ;;;;
10 ;;;; $Id: tests.lisp,v 1.3 2003/04/28 21:11:55 kevin Exp $
11 ;;;;
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
14
15 (defpackage #:hyperobject-tests
16   (:use #:hyperobject #:cl #:rtest #:kmrcl))
17 (in-package #:hyperobject-tests)
18
19 (defclass person (hyperobject)
20   ((first-name :initarg :first-name :accessor first-name
21                :value-type (varchar 20)
22                :value-constraint stringp
23                :null-allowed nil)
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               :null-allowed nil)
29    (full-name :value-type string :stored nil)
30    (dob :initarg :dob :accessor dob
31         :value-type integer
32         :print-formatter date-string
33         :value-constraint integerp
34         :input-filter convert-to-date)
35    (resume :initarg :resume :accessor resume
36            :value-type string
37            :value-constraint stringp)
38    ;;   (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
39    (addresses :initarg :addresses :accessor addresses
40                :subobject t))
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)
44   (:user-name "Person")
45   (:description "A Person")
46   (:direct-rules
47    (:rule-1 (:dependants (last-name first-name) :volatile full-name)
48             (setf full-name (concatenate 'string first-name " " last-name)))))
49
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
58             :subobject t))
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"))
64
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"))
77
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"))
80
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"))
84
85 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
86                                   :phones (list home-phone-1 home-phone-2)))
87
88 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
89                                     :phones (list office-phone-1 office-phone-2 office-phone-3)))
90
91                               
92 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
93                             :dob (encode-universal-time
94                                   1 2 3 4 5 2000)
95                             :addresses (list home office)
96                             :resume "Style & Grace"))
97
98
99 (defun view-to-string (obj &rest args)
100   (with-output-to-string (strm)
101     (apply #'view obj :stream strm args)))
102
103 (rem-all-tests)
104
105 (deftest p1 (view-to-string mary) " Person:
106   Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
107 ")
108
109 (deftest p2 (view-to-string mary :subobjects t) " Person:
110   Mary Jackson Thu, 4 May 2000 03:02:01 Style & Grace
111   Addresss:
112     Home 321 Shady Lane
113     Phone Numbers:
114       Voice 367-9812
115       Fax 367-9813
116     Office 113 Main St.
117     Phone Numbers:
118       Main line 123-0001
119       Staff line 123-0002
120       Fax 123-0005
121 ")
122
123 (deftest p3 (view-to-string mary :category t)
124   "")
125
126 (deftest p4 (view-to-string mary :subobjects t :category t)
127   "")
128
129 (deftest p5 (view-to-string mary :subobjects t  :category :xml-link-labels)
130   "")