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