1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: xptest-clsql.cl
6 ;;;; Purpose: Test of CLSQL using XPTest package
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
10 ;;;; $Id: xptest-clsql.cl,v 1.1 2002/03/27 09:00:15 kevin Exp $
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ;;;; *************************************************************************
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
21 (mk:load-system "XPTest")
23 (in-package :clsql-user)
26 (def-test-fixture clsql-fixture ()
27 ((aodbc-spec :accessor aodbc-spec)
28 (mysql-spec :accessor mysql-spec)
29 (postgresql-spec :accessor postgresql-spec)
30 (postgresql-socket-spec :accessor postgresql-socket-spec))
31 (:documentation "Test fixture for CLSQL testing"))
33 (defvar *config-pathname* (make-pathname :name "test-clsql"
35 :defaults *load-truename*))
36 (defmethod setup ((fix clsql-fixture))
37 (if (probe-file *config-pathname*)
39 (with-open-file (stream *config-pathname* :direction :input)
40 (setq config (read stream)))
41 (setf (aodbc-spec fix) (cadr (assoc :aodbc config)))
42 (setf (mysql-spec fix) (cadr (assoc :mysql config)))
43 (setf (postgresql-spec fix) (cadr (assoc :postgresql config)))
44 (setf (postgresql-socket-spec fix)
45 (cadr (assoc :postgresql-socket config))))
46 (error "XPTest Config file ~S not found" *config-pathname*)))
48 (defmethod teardown ((fix clsql-fixture))
51 (defmethod mysql-test ((test clsql-fixture))
52 (let ((spec (mysql-spec test)))
54 (let ((db (clsql:connect spec :database-type :mysql
58 (create-test-table db)
59 (pprint (query "select * from test_clsql"
62 (pprint (map-query 'vector #'list "select * from test_clsql"
67 (disconnect :database db))))))
69 (defparameter clsql-test-suite
72 "Basic test suite for database operations."
73 ("MySQL Test" 'clsql-fixture
74 :test-thunk 'mysql-test
75 :description "A test of MySQL")))
77 (report-result (run-test clsql-test-suite) :verbose t)
80 ;;;; Testing functions
82 (defun create-test-table (db)
84 (clsql:execute-command
85 "DROP TABLE test_clsql" :database db))
86 (clsql:execute-command
87 "CREATE TABLE test_clsql (n integer, n_pi float, n_pi_str CHAR(20))"
91 (clsql:execute-command
92 (format nil "INSERT INTO test_clsql VALUES (~a,~a,'~a')"
93 n (clsql:float-to-sql-string (* pi n))
94 (clsql:float-to-sql-string (* pi n)))
97 (defun drop-test-table (db)
98 (clsql:execute-command "DROP TABLE test_clsql"))