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.3 2002/03/27 09:21:46 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"
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 (query "select * from test_clsql"
62 (map-query 'vector #'list "select * from test_clsql"
67 (disconnect :database db))))))
69 (defmethod mysql-low-level ((test clsql-fixture))
70 (let ((spec (mysql-spec test)))
72 (let ((db (clsql-mysql::database-connect spec :mysql)))
73 (clsql-mysql::database-execute-command "DROP TABLE IF EXISTS test_clsql" db)
74 (clsql-mysql::database-execute-command
75 "CREATE TABLE test_clsql (i integer, sqrt double, sqrt_str CHAR(20))" db)
77 (clsql-mysql::database-execute-command
78 (format nil "INSERT INTO test_clsql VALUES (~d,~d,'~a')"
79 i (sqrt i) (format nil "~d" (sqrt i)))
81 (let ((res (clsql-mysql::database-query-result-set "select * from test_clsql" db :full-set t :types nil)))
82 (unless (= 10 (mysql:mysql-num-rows (clsql-mysql::mysql-result-set-res-ptr res)))
83 (failure "Error calling mysql-num-rows"))
84 (clsql-mysql::database-dump-result-set res db))
85 (clsql-mysql::database-execute-command "DROP TABLE test_clsql" db)
86 (clsql-mysql::database-disconnect db)))))
88 (defparameter clsql-test-suite
91 "Basic test suite for database operations."
92 ("MySQL Low Level Interface Test" 'clsql-fixture
93 :test-thunk 'mysql-low-level
94 :description "A test of MySQL low-level interface")
95 ("MySQL Test" 'clsql-fixture
96 :test-thunk 'mysql-test
97 :description "A test of MySQL")))
100 ;;;; Testing functions
102 (defun create-test-table (db)
104 (clsql:execute-command
105 "DROP TABLE test_clsql" :database db))
106 (clsql:execute-command
107 "CREATE TABLE test_clsql (n integer, n_pi float, n_pi_str CHAR(20))"
111 (clsql:execute-command
112 (format nil "INSERT INTO test_clsql VALUES (~a,~a,'~a')"
113 n (clsql:float-to-sql-string (* pi n))
114 (clsql:float-to-sql-string (* pi n)))
117 (defun drop-test-table (db)
118 (clsql:execute-command "DROP TABLE test_clsql"))
120 (report-result (run-test clsql-test-suite) :verbose t)