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