1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; ======================================================================
3 ;;;; File: test-ooddl.lisp
4 ;;;; Author: Marcus Pearce <m.t.pearce@city.ac.uk>
5 ;;;; Created: 30/03/2004
8 ;;;; Tests for the CLSQL Object Oriented Data Definition Language
11 ;;;; This file is part of CLSQL.
13 ;;;; CLSQL users are granted the rights to distribute and use this software
14 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
15 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16 ;;;; ======================================================================
19 (in-package #:clsql-tests)
21 #.(clsql:locally-enable-sql-reader-syntax)
26 ;; Ensure slots inherited from standard-classes are :virtual
27 (deftest :ooddl/metaclass/1
29 (clsql-sys::view-class-slot-db-kind
30 (clsql-sys::slotdef-for-slot-with-class 'extraterrestrial
31 (find-class 'person)))
32 (clsql-sys::view-class-slot-db-kind
33 (clsql-sys::slotdef-for-slot-with-class 'hobby (find-class 'person))))
36 ;; Ensure all slots in view-class are view-class-effective-slot-definition
37 (deftest :ooddl/metaclass/2
39 (every #'(lambda (slotd)
40 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
41 (clsql-sys::class-slots (find-class 'person)))
42 (every #'(lambda (slotd)
43 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
44 (clsql-sys::class-slots (find-class 'employee)))
45 (every #'(lambda (slotd)
46 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
47 (clsql-sys::class-slots (find-class 'setting)))
48 (every #'(lambda (slotd)
49 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
50 (clsql-sys::class-slots (find-class 'theme)))
51 (every #'(lambda (slotd)
52 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
53 (clsql-sys::class-slots (find-class 'node)))
54 (every #'(lambda (slotd)
55 (typep slotd 'clsql-sys::view-class-effective-slot-definition))
56 (clsql-sys::class-slots (find-class 'company))))
59 ;; Ensure classes are correctly marked normalised or not, default not
60 ;(deftest :ooddl/metaclass/3
62 ; (clsql-sys::normalisedp derivednode1)
63 ; (clsql-sys::normalisedp basenode)
64 ; (clsql-sys::normalisedp company1)
65 ; (clsql-sys::normalisedp employee3)
66 ; (clsql-sys::normalisedp derivednode-sc-2))
69 ;(deftest :ooddl/metaclass/3
71 ; (normalisedp (find-class 'baseclass))
72 ; (normalisedp (find-class 'normderivedclass)))
75 (deftest :ooddl/join/1
76 (mapcar #'(lambda (e) (slot-value e 'ecompanyid))
77 (company-employees company1))
78 (1 1 1 1 1 1 1 1 1 1))
80 (deftest :ooddl/join/2
81 (slot-value (president company1) 'last-name)
84 (deftest :ooddl/join/3
85 (slot-value (employee-manager employee2) 'last-name)
88 (deftest :ooddl/time/1
89 (let* ((now (clsql:get-time)))
90 (when (member *test-database-underlying-type* '(:postgresql :postgresql-socket))
91 (clsql:execute-command "set datestyle to 'iso'"))
92 (clsql:update-records [employee] :av-pairs `((birthday ,now))
93 :where [= [emplid] 1])
94 (let ((dbobj (car (clsql:select 'employee :where [= [birthday] now]
97 (slot-value dbobj 'last-name)
98 (clsql:time= (slot-value dbobj 'birthday) now))))
101 (deftest :ooddl/time/2
102 (let* ((now (clsql:get-time))
104 (when (member *test-database-underlying-type* '(:postgresql :postgresql-socket))
105 (clsql:execute-command "set datestyle to 'iso'"))
107 (clsql:update-records [employee] :av-pairs `((birthday ,now))
108 :where [= [emplid] 1])
109 (let ((dbobj (car (clsql:select 'employee :where [= [birthday] now]
111 (unless (clsql:time= (slot-value dbobj 'birthday) now)
113 (setf now (clsql:roll now :day (* 10 x)))))
117 (deftest :ooddl/time/3
119 (when (member *test-database-underlying-type* '(:postgresql :postgresql-socket))
120 (clsql:execute-command "set datestyle to 'iso'"))
121 (let ((dbobj (car (clsql:select 'employee :where [= [emplid] 10]
124 (eql *test-start-utime* (slot-value dbobj 'bd-utime))
125 (clsql:time= (slot-value dbobj 'birthday)
126 (clsql:utime->time (slot-value dbobj 'bd-utime))))))
131 #.(clsql:restore-sql-reader-syntax-state)