r9014: odbc backend now working on allegro and lispworks
[clsql.git] / tests / utils.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:    utils.lisp
6 ;;;; Purpose: Classes and utilities for testing
7 ;;;; Author:  Kevin M. Rosenberg
8 ;;;; Created: Mar 2002
9 ;;;;
10 ;;;; $Id: tests.lisp 8926 2004-04-10 21:12:52Z kevin $
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package #:clsql-tests)
20
21 (defvar *config-pathname*
22   (make-pathname :defaults (user-homedir-pathname)
23                  :name ".clsql-test"
24                  :type "config"))
25
26 (defvar +all-db-types+
27   #-clisp '(:postgresql :postgresql-socket :sqlite :mysql :odbc :aodbc)
28   #+clisp '(:sqlite))
29
30 (defclass conn-specs ()
31   ((aodbc-spec :accessor aodbc-spec :initform nil)
32    (odbc-spec :accessor odbc-spec :initform nil)
33    (mysql-spec :accessor mysql-spec :initform nil)
34    (postgresql-spec :accessor postgresql-spec :initform nil)
35    (postgresql-socket-spec :accessor postgresql-socket-spec :initform nil)
36    (sqlite-spec :accessor sqlite-spec :initform nil))
37   (:documentation "Connection specs for CLSQL testing"))
38
39
40 (defun read-specs (&optional (path *config-pathname*))
41   (if (probe-file path)
42       (with-open-file (stream path :direction :input)
43         (let ((config (read stream))
44               (specs (make-instance 'conn-specs)))
45           (dolist (db-type +all-db-types+)
46             (setf (slot-value specs (spec-fn db-type))
47                   (cadr (assoc db-type config))))
48           specs))
49       (progn
50         (warn "CLSQL test config file ~S not found" path)
51         nil)))
52
53 (defun spec-fn (db-type)
54   (intern (concatenate 'string (symbol-name db-type)
55                        (symbol-name '#:-spec))
56           (find-package '#:clsql-tests)))
57
58 (defun db-type-spec (db-type specs)
59   (funcall (spec-fn db-type) specs))
60
61 (defun db-type-ensure-system (db-type)
62   (unless (find-package (symbol-name db-type))
63     (asdf:operate 'asdf:load-op
64                   (intern (concatenate 'string
65                                        (symbol-name '#:clsql-)
66                                        (symbol-name db-type))))))
67
68