main.test revision 2
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2001 September 15
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is exercising the code in main.c.
2N/A#
2N/A# $Id: main.test,v 1.14 2003/05/04 17:58:27 drh Exp $
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/A# Tests of the sqlite_complete() function.
2N/A#
2N/Ado_test main-1.1 {
2N/A db complete {This is a test}
2N/A} {0}
2N/Ado_test main-1.2 {
2N/A db complete {
2N/A }
2N/A} {1}
2N/Ado_test main-1.3 {
2N/A db complete {
2N/A -- a comment ;
2N/A }
2N/A} {1}
2N/Ado_test main-1.4 {
2N/A db complete {
2N/A -- a comment ;
2N/A ;
2N/A }
2N/A} {1}
2N/Ado_test main-1.5 {
2N/A db complete {DROP TABLE 'xyz;}
2N/A} {0}
2N/Ado_test main-1.6 {
2N/A db complete {DROP TABLE 'xyz';}
2N/A} {1}
2N/Ado_test main-1.7 {
2N/A db complete {DROP TABLE "xyz;}
2N/A} {0}
2N/Ado_test main-1.8 {
2N/A db complete {DROP TABLE "xyz';}
2N/A} {0}
2N/Ado_test main-1.9 {
2N/A db complete {DROP TABLE "xyz";}
2N/A} {1}
2N/Ado_test main-1.10 {
2N/A db complete {DROP TABLE xyz; hi}
2N/A} {0}
2N/Ado_test main-1.11 {
2N/A db complete {DROP TABLE xyz; }
2N/A} {1}
2N/Ado_test main-1.12 {
2N/A db complete {DROP TABLE xyz; -- hi }
2N/A} {1}
2N/Ado_test main-1.13 {
2N/A db complete {DROP TABLE xyz; -- hi
2N/A }
2N/A} {1}
2N/Ado_test main-1.14 {
2N/A db complete {SELECT a-b FROM t1; }
2N/A} {1}
2N/Ado_test main-1.15 {
2N/A db complete {SELECT a-b FROM t1 }
2N/A} {0}
2N/Ado_test main-1.16 {
2N/A db complete {
2N/A CREATE TABLE abc(x,y);
2N/A }
2N/A} {1}
2N/Ado_test main-1.17 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
2N/A }
2N/A} {0}
2N/Ado_test main-1.18 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
2N/A }
2N/A} {1}
2N/Ado_test main-1.19 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE abc BEGIN
2N/A UPDATE pqr;
2N/A unknown command;
2N/A }
2N/A} {0}
2N/Ado_test main-1.20 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr;
2N/A }
2N/A} {0}
2N/Ado_test main-1.21 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE end BEGIN
2N/A SELECT a, b FROM end;
2N/A }
2N/A} {0}
2N/Ado_test main-1.22 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE end BEGIN
2N/A SELECT a, b FROM end;
2N/A END;
2N/A }
2N/A} {1}
2N/Ado_test main-1.23 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE end BEGIN
2N/A SELECT a, b FROM end;
2N/A END;
2N/A SELECT a, b FROM end;
2N/A }
2N/A} {1}
2N/Ado_test main-1.24 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
2N/A UPDATE pqr;
2N/A }
2N/A} {0}
2N/Ado_test main-1.25 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=[;end;];;;
2N/A }
2N/A} {0}
2N/Ado_test main-1.26 {
2N/A db complete {
2N/A CREATE -- a comment
2N/A TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {0}
2N/Ado_test main-1.27.1 {
2N/A db complete {
2N/A CREATE -- a comment
2N/A TRIGGERX xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {1}
2N/Ado_test main-1.27.2 {
2N/A db complete {
2N/A CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {0}
2N/Ado_test main-1.27.3 {
2N/A db complete {
2N/A /* */ EXPLAIN -- A comment
2N/A CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {0}
2N/Ado_test main-1.27.4 {
2N/A db complete {
2N/A BOGUS token
2N/A CREATE TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {1}
2N/Ado_test main-1.27.5 {
2N/A db complete {
2N/A EXPLAIN
2N/A CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {0}
2N/Ado_test main-1.28 {
2N/A db complete {
2N/A CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A }
2N/A} {0}
2N/Ado_test main-1.29 {
2N/A db complete {
2N/A CREATE TRIGGER xyz AFTER DELETE backend BEGIN
2N/A UPDATE pqr SET a=5;
2N/A EXPLAIN select * from xyz;
2N/A }
2N/A} {0}
2N/Ado_test main-1.30 {
2N/A db complete {
2N/A CREATE TABLE /* In comment ; */
2N/A }
2N/A} {0}
2N/Ado_test main-1.31 {
2N/A db complete {
2N/A CREATE TABLE /* In comment ; */ hi;
2N/A }
2N/A} {1}
2N/Ado_test main-1.31 {
2N/A db complete {
2N/A CREATE TABLE /* In comment ; */;
2N/A }
2N/A} {1}
2N/Ado_test main-1.32 {
2N/A db complete {
2N/A stuff;
2N/A /*
2N/A CREATE TABLE
2N/A multiple lines
2N/A of text
2N/A */
2N/A }
2N/A} {1}
2N/Ado_test main-1.33 {
2N/A db complete {
2N/A /*
2N/A CREATE TABLE
2N/A multiple lines
2N/A of text;
2N/A }
2N/A} {0}
2N/Ado_test main-1.34 {
2N/A db complete {
2N/A /*
2N/A CREATE TABLE
2N/A multiple lines "*/
2N/A of text;
2N/A }
2N/A} {1}
2N/Ado_test main-1.35 {
2N/A db complete {hi /**/ there;}
2N/A} {1}
2N/Ado_test main-1.36 {
2N/A db complete {hi there/***/;}
2N/A} {1}
2N/A
2N/A
2N/A# Try to open a database with a corrupt database file.
2N/A#
2N/Ado_test main-2.0 {
2N/A catch {db close}
2N/A file delete -force test.db
2N/A set fd [open test.db w]
2N/A puts $fd hi!
2N/A close $fd
2N/A set v [catch {sqlite db test.db} msg]
2N/A if {$v} {lappend v $msg} {lappend v {}}
2N/A} {0 {}}
2N/A
2N/A# Here are some tests for tokenize.c.
2N/A#
2N/Ado_test main-3.1 {
2N/A catch {db close}
2N/A foreach f [glob -nocomplain testdb/*] {file delete -force $f}
2N/A file delete -force testdb
2N/A sqlite db testdb
2N/A set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
2N/A lappend v $msg
2N/A} {1 {unrecognized token: "!!"}}
2N/Ado_test main-3.2 {
2N/A catch {db close}
2N/A foreach f [glob -nocomplain testdb/*] {file delete -force $f}
2N/A file delete -force testdb
2N/A sqlite db testdb
2N/A set v [catch {execsql {SELECT * from T1 where @x}} msg]
2N/A lappend v $msg
2N/A} {1 {unrecognized token: "@"}}
2N/A
2N/Ado_test main-3.3 {
2N/A catch {db close}
2N/A foreach f [glob -nocomplain testdb/*] {file delete -force $f}
2N/A file delete -force testdb
2N/A sqlite db testdb
2N/A execsql {
2N/A create table T1(X REAL);
2N/A insert into T1 values(0.5);
2N/A insert into T1 values(0.5e2);
2N/A insert into T1 values(0.5e-002);
2N/A insert into T1 values(5e-002);
2N/A insert into T1 values(-5.0e-2);
2N/A insert into T1 values(-5.1e-2);
2N/A insert into T1 values(0.5e2);
2N/A insert into T1 values(0.5E+02);
2N/A insert into T1 values(5E+02);
2N/A insert into T1 values(5.0E+03);
2N/A select x*10 from T1 order by x*5;
2N/A }
2N/A} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
2N/Ado_test main-3.4 {
2N/A set v [catch {execsql {create bogus}} msg]
2N/A lappend v $msg
2N/A} {1 {near "bogus": syntax error}}
2N/Ado_test main-3.5 {
2N/A set v [catch {execsql {create}} msg]
2N/A lappend v $msg
2N/A} {1 {near "create": syntax error}}
2N/A
2N/Afinish_test