--- libdbi-drivers-0.8.3/debian/changelog	2010-08-11 05:54:13.000000000 -0700
+++ libdbi-drivers-0.8.3-1/debian/changelog	2010-08-11 05:54:13.000000000 -0700
@@ -1,3 +1,9 @@
+libdbi-drivers (0.8.3-1-1~cb0) unstable; urgency=low
+
+  * adding tests for mysql, pgsql, sqlite, sqlite3
+
+ -- Clint Byrum <clint@ubuntu.com>  Wed, 11 Aug 2010 02:54:34 -0700
+
 libdbi-drivers (0.8.3-1) unstable; urgency=low
 
   * New upstream version.
--- libdbi-drivers-0.8.3/debian/control	2010-08-11 05:54:13.000000000 -0700
+++ libdbi-drivers-0.8.3-1/debian/control	2010-08-11 05:54:13.000000000 -0700
@@ -2,7 +2,11 @@
 Section: libs
 Priority: optional
 Maintainer: Thomas Goirand <zigo@debian.org>
-Build-Depends: debhelper (>= 7), autotools-dev, libdbi0-dev (>= 0.8.3), libmysqlclient-dev, libpq-dev (>= 8.3~rc2-1+b1), libsqlite0-dev, libsqlite3-dev, freetds-dev, automake, libtool
+Build-Depends: debhelper (>= 7), autotools-dev, libdbi0-dev (>= 0.8.3), libmysqlclient-dev, libpq-dev (>= 8.3~rc2-1+b1), libsqlite0-dev, libsqlite3-dev, freetds-dev, automake, libtool,
+    quilt (>= 0.46-7~),
+    mysql-server, mysql-client,
+    postgresql, postgresql-client,
+    locales-all | language-pack-en
 Standards-Version: 3.9.1
 Vcs-Browser: http://git.debian.org/?p=users/zigo/libdbi-drivers.git
 Vcs-Git: http://git.debian.org/git/users/zigo/libdbi-drivers.git
--- libdbi-drivers-0.8.3/debian/patches/remove_test_17_pgsql.patch	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/patches/remove_test_17_pgsql.patch	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1,24 @@
+--- a/tests/test_dbi.c
++++ b/tests/test_dbi.c
+@@ -305,6 +305,11 @@
+     conn = NULL;
+ 
+     /* repeat test for latin1 encoding */
++    if (!strcmp(cinfo.drivername, "pgsql")) {
++        printf("pgsql cannot handle ISO-8859-1 tests because of hard initdb requirements. Skipping.\n");
++        goto SUCCESS;
++    }
++
+     printf("\nNow repeat this test with a ISO-8859-1 encoding\n");
+     if ((conn = dbi_conn_new(cinfo.drivername)) == NULL) {
+       printf("Can't instantiate '%s' driver into a dbi_conn!\n", cinfo.drivername);
+@@ -429,7 +434,8 @@
+       exit(1);
+     }
+   }
+-	
++
++SUCCESS:
+   printf("\n\n");
+   printf("SUCCESS! All done, disconnecting and shutting down libdbi. Have a nice day.\n\n");
+ 	
--- libdbi-drivers-0.8.3/debian/patches/series	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/patches/series	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1 @@
+remove_test_17_pgsql.patch
--- libdbi-drivers-0.8.3/debian/README.source	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/README.source	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1,7 @@
+The testing suite for libdbi-drivers has been patched to work around
+issues with creating databases that have different encodings than the
+"cluster".
+
+This issue was reported upstream here:
+
+https://sourceforge.net/tracker/?func=detail&aid=3042565&group_id=65979&atid=512945
--- libdbi-drivers-0.8.3/debian/rules	2010-08-11 05:54:13.000000000 -0700
+++ libdbi-drivers-0.8.3-1/debian/rules	2010-08-11 05:54:13.000000000 -0700
@@ -19,6 +19,8 @@
 	cp /usr/share/misc/config.sub .
 	cp /usr/share/misc/config.guess .
 
+	dh_quilt_patch
+
 	./autogen.sh
 	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
 		--prefix=/usr --with-pgsql --with-mysql --with-sqlite \
@@ -27,7 +29,7 @@
 # This is for the moment removed until the upstream fixes the problems with
 # the new API: --with-firebird
 
-build: build-stamp
+build: build-stamp test-stamp
 build-stamp:  config.status
 	dh_testdir
 
@@ -35,10 +37,23 @@
 
 	touch build-stamp
 
+test-stamp: build-stamp
+	cd tests && make test_dbi
+	mkdir -p /tmp/sqlite3.test
+	/bin/sh debian/run_test_driver.sh sqlite3 /tmp/sqlite3.test libdbitest
+	rm -rf /tmp/sqlite3.test
+	mkdir -p /tmp/sqlite.test
+	/bin/sh debian/run_test_driver.sh sqlite /tmp/sqlite.test libdbitest
+	rm -rf /tmp/sqlite.test
+	/bin/sh debian/test_mysql.sh
+	/bin/sh debian/test_postgres.sh
+	touch test-stamp
+
 clean:
 	dh_testdir
 	dh_testroot
 	rm -f build-stamp 
+	rm -f test-stamp
 
 	[ ! -f Makefile ] || $(MAKE) distclean
 	-test -r /usr/share/misc/config.sub && \
@@ -47,6 +62,7 @@
 	  cp -f /usr/share/misc/config.guess config.guess
 
 	rm -f config.log config.guess config.sub doc/include/Makefile doc/Makefile
+	dh_quilt_unpatch
 	dh_clean
 
 install: build
--- libdbi-drivers-0.8.3/debian/run_test_driver.sh	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/run_test_driver.sh	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+TEST_DBI="tests/test_dbi"
+driver=$1
+shift
+args=$*
+
+echoargs=""
+for arg in $args ; do
+    # helps work around empty argument problems
+    if [ "$arg" = "##" ] ; then
+        arg=""
+    fi
+    echoargs="${echoargs}\\n${arg}"
+done
+
+# have to use coreutils echo, dash doesn't have -e
+/bin/echo -e "./drivers/${driver}/.libs\\n${driver}${echoargs}" | $TEST_DBI
+
--- libdbi-drivers-0.8.3/debian/test_mysql.sh	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/test_mysql.sh	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1,33 @@
+#!/bin/sh
+tdir=`mktemp -d /tmp/mytest.XXXX`
+tsock=$tdir/mysql.sock
+
+# --force is needed because buildd's can't resolve their own hostnames to ips
+/usr/bin/mysql_install_db --no-defaults --datadir=$tdir --user=nobody --force --skip-name-resolve
+/usr/sbin/mysqld --no-defaults --user=nobody --skip-grant --socket=$tsock --datadir=$tdir --bind-address=127.0.0.2 &
+
+echo -n pinging mysqld.
+attempts=0
+while ! /usr/bin/mysqladmin -h 127.0.0.2 ping ; do
+    sleep 3
+    attempts=$((attempts+1))
+    if [ $attempts -gt 10 ] ; then
+        echo "skipping test, mysql server could not be contacted after 30 seconds"
+        exit 0
+    fi
+done
+# verify that this is the mysqld we started
+datadir=`/usr/bin/mysql -h 127.0.0.2 -N -e "SHOW VARIABLES LIKE 'datadir'"|cut -f2`
+if [ "$datadir" != "${tdir}/" ] ; then
+    echo "mysqld listening on 127.0.0.2 running in $datadir instead of $tdir, skipping mysql tests..."
+    /usr/bin/mysqladmin --socket=$tsock shutdown
+    rm -rf $tdir
+    exit 0
+fi
+
+/bin/sh debian/run_test_driver.sh mysql root "#" "127.0.0.2" libdbitest
+ecode=$?
+/usr/bin/mysqladmin -h 127.0.0.2 --socket=$tsock shutdown
+wait
+rm -rf $tdir
+exit $ecode
--- libdbi-drivers-0.8.3/debian/test_postgres.sh	1969-12-31 16:00:00.000000000 -0800
+++ libdbi-drivers-0.8.3-1/debian/test_postgres.sh	2010-08-11 05:54:13.000000000 -0700
@@ -0,0 +1,40 @@
+#!/bin/sh
+user=`whoami`
+# initdb refuses to run as root
+if [ "$user" = "root" ] ; then
+    echo dropping root privs...
+    exec /bin/su postgres -- "$0" "$@"
+fi
+tdir=`mktemp -d /tmp/pgtest.XXXXXXXX`
+bindir=`pg_config --bindir`
+# depends on language-pack-en -- needed because initdb acquires encoding from locale
+export LC_ALL="en_US.UTF-8"
+$bindir/initdb -D $tdir
+sed -i -e 's/127.0.0.1/127.0.0.2/' $tdir/pg_hba.conf
+$bindir/postgres -D $tdir -h 127.0.0.2 -k $tdir &
+attempts=0
+while ! [ -e $tdir/postmaster.pid ] ; do
+    attempts=$((attempts+1))
+    if [ $attempts -gt 10 ] ; then
+        echo "skipping test, postgres pid file was not created after 30 seconds"
+        exit 0
+    fi
+    sleep 3
+    echo `date`: retrying..
+done
+if ! createdb -h 127.0.0.2 -e libdbitest ; then
+    echo Skipping postgres test as libdbitest database creation failed
+    exit 0
+fi
+dropdb -h 127.0.0.2 -e libdbitest
+createdb -h 127.0.0.2 -e $user
+cmd="ALTER USER $user WITH PASSWORD 'abcdefg'"
+psql -h 127.0.0.2 -e -c "$cmd" 
+
+/bin/sh debian/run_test_driver.sh pgsql $user "abcdefg" "127.0.0.2" libdbitest
+ecode=$?
+
+kill `cat $tdir/postmaster.pid|cut -d' ' -f1`
+wait
+rm -rf $tdir
+exit $ecode
