blob: 07763e6a293a4d3650a6305617b755a540212d13 [file] [log] [blame]
drhcc85b412000-06-07 15:11:27 +00001# Copyright (c) 1999, 2000 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 02111-1307, USA.
17#
18# Author contact information:
19# drh@hwaci.com
20# http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library. The
24# focus of this file is exercising the code in main.c.
25#
drhc837e702000-06-08 16:26:24 +000026# $Id: main.test,v 1.2 2000/06/08 16:26:25 drh Exp $
drhcc85b412000-06-07 15:11:27 +000027
28set testdir [file dirname $argv0]
29source $testdir/tester.tcl
30
31# Tests of the sqlite_complete() function.
32#
33do_test main-1.1 {
34 db complete {This is a test}
35} {0}
36do_test main-1.2 {
37 db complete {
38 }
39} {0}
40do_test main-1.3 {
41 db complete {
42 -- a comment ;
43 }
44} {0}
45do_test main-1.4 {
46 db complete {
47 -- a comment ;
48 ;
49 }
50} {1}
51
52# Try to open a database with a corrupt master file.
53#
54do_test main-2.0 {
55 catch {db close}
56 file delete -force testdb
57 file mkdir testdb
58 set fd [open testdb/sqlite_master.tbl w]
59 puts $fd hi!
60 close $fd
61 set v [catch {sqlite db testdb} msg]
62 lappend v $msg
63} {0 {}}
64
drhc837e702000-06-08 16:26:24 +000065# Here are some tests for tokenize.c.
66#
67do_test main-3.1 {
68 catch {db close}
69 file delete -force testdb
70 sqlite db testdb
71 set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
72 lappend v $msg
73} {1 {unrecognized token: "!!"}}
74do_test main-3.2 {
75 catch {db close}
76 file delete -force testdb
77 sqlite db testdb
78 set v [catch {execsql {SELECT * from T1 where ~x}} msg]
79 lappend v $msg
80} {1 {unrecognized token: "~"}}
81
82do_test main-3.3 {
83 catch {db close}
84 file delete -force testdb
85 sqlite db testdb
86 execsql {
87 create table T1(X REAL);
88 insert into T1 values(.5);
89 insert into T1 values(0.5e2);
90 insert into T1 values(0.5e-002);
91 insert into T1 values(5e-002);
92 insert into T1 values(-5.0e-2);
93 insert into T1 values(-5.1e-2);
94 insert into T1 values(.5e2);
95 insert into T1 values(.5E+02);
96 insert into T1 values(5E+02);
97 insert into T1 values(5.E+03);
98 select x*10 from T1 order by x*5;
99 }
100} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
101do_test main-3.4 {
102 set v [catch {execsql {create bogus}} msg]
103 lappend v $msg
104} {1 {near "bogus": syntax error}}
105do_test main-3.5 {
106 set v [catch {execsql {create}} msg]
107 lappend v $msg
108} {1 {near "create": syntax error}}
109
drhcc85b412000-06-07 15:11:27 +0000110finish_test