r9234: rename package
[clsql.git] / tests / test-ooddl.lisp
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
6 ;;;; Updated: $Id$
7 ;;;;
8 ;;;; Tests for the CLSQL Object Oriented Data Definition Language
9 ;;;; (OODDL).
10 ;;;;
11 ;;;; This file is part of CLSQL.
12 ;;;;
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 ;;;; ======================================================================
17
18
19 (in-package #:clsql-tests)
20
21 #.(clsql:locally-enable-sql-reader-syntax)
22
23 (setq *rt-ooddl*
24       '(
25         
26 ;; Ensure slots inherited from standard-classes are :virtual
27 (deftest :ooddl/metaclass/1
28     (values 
29      (clsql::view-class-slot-db-kind
30       (clsql::slotdef-for-slot-with-class 'extraterrestrial
31                                              (find-class 'person)))
32      (clsql::view-class-slot-db-kind
33       (clsql::slotdef-for-slot-with-class 'hobby (find-class 'person))))
34   :virtual :virtual)
35
36 ;; Ensure all slots in view-class are view-class-effective-slot-definition
37 (deftest :ooddl/metaclass/2
38     (values
39      (every #'(lambda (slotd)
40                 (typep slotd 'clsql::view-class-effective-slot-definition))
41             (clsql::class-slots (find-class 'person)))
42      (every #'(lambda (slotd)
43                 (typep slotd 'clsql::view-class-effective-slot-definition))
44             (clsql::class-slots (find-class 'employee)))
45      (every #'(lambda (slotd)
46                 (typep slotd 'clsql::view-class-effective-slot-definition))
47             (clsql::class-slots (find-class 'company))))
48   t t t)
49
50 (deftest :ooddl/join/1
51     (mapcar #'(lambda (e)
52                 (slot-value e 'companyid))
53             (company-employees company1))
54   (1 1 1 1 1 1 1 1 1 1))
55
56 (deftest :ooddl/join/2
57     (slot-value (president company1) 'last-name)
58   "Lenin")
59
60 (deftest :ooddl/join/3
61     (slot-value (employee-manager employee2) 'last-name)
62   "Lenin")
63
64 (deftest :ooddl/time/1
65     (let* ((now (clsql-base:get-time)))
66       (when (member *test-database-underlying-type* '(:postgresql :postgresql-socket))
67         (clsql:execute-command "set datestyle to 'iso'"))
68       (clsql:update-records [employee] :av-pairs `((birthday ,now))
69                            :where [= [emplid] 1])
70       (let ((dbobj (car (clsql:select 'employee :where [= [birthday] now] 
71                                       :flatp t))))
72         (values
73          (slot-value dbobj 'last-name)
74          (clsql-base:time= (slot-value dbobj 'birthday) now))))
75   "Lenin" t)
76
77 (deftest :ooddl/time/2
78     (let* ((now (clsql-base:get-time))
79            (fail-index -1))
80       (when (member *test-database-underlying-type* '(:postgresql :postgresql-socket))
81         (clsql:execute-command "set datestyle to 'iso'"))
82       (dotimes (x 40)
83         (clsql:update-records [employee] :av-pairs `((birthday ,now))
84                              :where [= [emplid] 1])
85         (let ((dbobj (car (clsql:select 'employee :where [= [birthday] now]
86                                         :flatp t))))
87           (unless (clsql-base:time= (slot-value dbobj 'birthday) now)
88             (setf fail-index x))
89           (setf now (clsql-base:roll now :day (* 10 x)))))
90       fail-index)
91   -1)
92
93 ))
94
95 #.(clsql:restore-sql-reader-syntax-state)
96