From 948a5f88ea4c0baf1eaf872f9ba12220415b5fdb Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 16 Nov 2009 16:36:23 +0000 Subject: [PATCH] Add a few extra coverage test cases for fts3. FossilOrigin-Name: f29c8fcade4aadeae3824975cf59f306c11c906b --- ext/fts3/fts3.c | 18 +++++------ manifest | 14 ++++---- manifest.uuid | 2 +- test/fts3malloc.test | 76 ++++++++++++++++++++++++++++++++------------ 4 files changed, 72 insertions(+), 38 deletions(-) diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 07b1fb9793..93ad7a9f8a 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -435,7 +435,7 @@ int sqlite3Fts3VarintLen(sqlite3_uint64 v){ void sqlite3Fts3Dequote(char *z){ int quote; int i, j; - if( z==0 ) return; + quote = z[0]; switch( quote ){ case '\'': break; @@ -494,21 +494,21 @@ static int fts3DisconnectMethod(sqlite3_vtab *pVtab){ assert( p->nPendingData==0 ); + /* Free any prepared statements held */ for(i=0; iaStmt); i++){ sqlite3_finalize(p->aStmt[i]); } + sqlite3_free(p->zSelectLeaves); - if( p->pTokenizer ){ - p->pTokenizer->pModule->xDestroy(p->pTokenizer); - } + /* Invoke the tokenizer destructor to free the tokenizer. */ + p->pTokenizer->pModule->xDestroy(p->pTokenizer); - sqlite3_free(p->zSelectLeaves); sqlite3_free(p); return SQLITE_OK; } /* -** The xDisconnect() virtual table method. +** The xDestroy() virtual table method. */ static int fts3DestroyMethod(sqlite3_vtab *pVtab){ int rc; /* Return code */ @@ -562,7 +562,7 @@ static int fts3DeclareVtab(Fts3Table *p){ "CREATE TABLE x(%s %Q HIDDEN, docid HIDDEN)", zCols, p->zName ); - if( !zSql || !zCols ){ + if( !zCols || !zSql ){ rc = SQLITE_NOMEM; }else{ rc = sqlite3_declare_vtab(p->db, zSql); @@ -588,7 +588,7 @@ static int fts3CreateTables(Fts3Table *p){ zContentCols = sqlite3_mprintf("docid INTEGER PRIMARY KEY"); for(i=0; zContentCols && inColumn; i++){ char *z = p->azColumn[i]; - zContentCols = sqlite3_mprintf("%z, c%d%s", zContentCols, i+1, z); + zContentCols = sqlite3_mprintf("%z, 'c%d%q'", zContentCols, i+1, z); } /* Create the whole SQL script */ @@ -610,7 +610,7 @@ static int fts3CreateTables(Fts3Table *p){ /* Unless a malloc() failure has occurred, execute the SQL script to ** create the tables used to store data for this FTS3 virtual table. */ - if( zSql==0 || zContentCols==0 ){ + if( zContentCols==0 || zSql==0 ){ rc = SQLITE_NOMEM; }else{ rc = sqlite3_exec(p->db, zSql, 0, 0, 0); diff --git a/manifest b/manifest index b44fdcdbbf..6a7164ad9b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fixes\sto\sfts3\sintegrity\scheck\scode. -D 2009-11-14T23:50:11 +C Add\sa\sfew\sextra\scoverage\stest\scases\sfor\sfts3. +D 2009-11-16T16:36:23 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 53f3dfa49f28ab5b80cb083fb7c9051e596bcfa1 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -56,7 +56,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c 1de6c9d40f1534eb542020eba56fb517780ee968 +F ext/fts3/fts3.c 4d701e31cb32cfb9b535edcc33271d8bcb2fa76f F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h f8419da445790c0666d4b4d72dc15a07dd7ae93e F ext/fts3/fts3_expr.c bdf11f3602f62f36f0e42823680bf22033dae0de @@ -398,7 +398,7 @@ F test/fts3d.test 95fb3c862cbc4297c93fceb9a635543744e9ef52 F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851 F test/fts3expr.test 05dab77387801e4900009917bb18f556037d82da F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a -F test/fts3malloc.test b169661934883d99dc33a1dde1959a0448bd4f11 +F test/fts3malloc.test ed11f188d03560d7f44bd5c126ac004f011cc719 F test/fts3near.test dc196dd17b4606f440c580d45b3d23aa975fd077 F test/func.test af106ed834001738246d276659406823e35cde7b F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f @@ -772,7 +772,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P c27d46b33e8596b45c562c2742b05030e8899092 -R 4c52d9528d06bab9b6911bfc5621469d +P d3cae986ee1a176b1b015c3cebcd58ff0c3bdf92 +R 4deae89fec5a2f223cc1fc606b6691c8 U dan -Z 07e55edf8ef0b4c5772a79580f9928fa +Z 34f2a8a40095974f35e0328293748f2b diff --git a/manifest.uuid b/manifest.uuid index 3392457c13..0bd9001018 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d3cae986ee1a176b1b015c3cebcd58ff0c3bdf92 \ No newline at end of file +f29c8fcade4aadeae3824975cf59f306c11c906b \ No newline at end of file diff --git a/test/fts3malloc.test b/test/fts3malloc.test index 5d68bf9f08..78998354d9 100644 --- a/test/fts3malloc.test +++ b/test/fts3malloc.test @@ -19,20 +19,19 @@ ifcapable !fts3 { finish_test ; return } source $testdir/malloc_common.tcl source $testdir/fts3_common.tcl -set sqlite_fts3_enable_parentheses 1 +# Ensure the lookaside buffer is disabled for these tests. +# +sqlite3 db test.db +sqlite3_db_config_lookaside db 0 0 0 -if 0 { -do_malloc_test fts3_malloc-1.1 -sqlbody { - CREATE VIRTUAL TABLE ft USING fts3(a, b, c); -} -do_malloc_test fts3_malloc-1.2 -sqlprep { - CREATE VIRTUAL TABLE ft USING fts3(a, b, c); -} -sqlbody { - DROP TABLE ft; -} -} +set sqlite_fts3_enable_parentheses 1 +set DO_MALLOC_TEST 1 -set DO_MALLOC_TEST 0 +# Test organization: +# +# fts3_malloc-1.*: Test CREATE and DROP table statements. +# +# #------------------------------------------------------------------------- # This proc is used to test a single SELECT statement. Parameter $name is @@ -55,15 +54,15 @@ set DO_MALLOC_TEST 0 # is executed just once. In this case the test case passes if the results # match the expected results passed via parameter $result. # -proc do_select_test {name sql result} { +proc do_passive_test {name sql catchres} { if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 } - if {$::DO_MALLOC_TEST } { - set answers [list {1 {out of memory}} [list 0 $result]] + if {$::DO_MALLOC_TEST} { + set answers [list {1 {out of memory}} $catchres] set modes [list 100000 transient 1 persistent] } else { - set answers [list [list 0 $result]] + set answers [list $catchres] set modes [list 0 nofail] } set str [join $answers " OR "] @@ -83,6 +82,14 @@ proc do_select_test {name sql result} { } } +proc do_select_test {name sql result} { + do_passive_test $name $sql [list 0 $result] +} + +proc do_error_test {name sql error} { + do_passive_test $name $sql [list 1 $error] +} + #------------------------------------------------------------------------- # Test a single write to the database. In this case a "write" is a # DELETE, UPDATE or INSERT statement. @@ -107,6 +114,8 @@ proc do_select_test {name sql result} { # being modified. Parameter $sql contains the SQL statement to test. # proc do_write_test {name tbl sql} { + if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 } + # Figure out an statement to get a checksum for table $tbl. db eval "SELECT * FROM $tbl" V break set cksumsql "SELECT md5sum([join [concat rowid $V(*)] ,]) FROM $tbl" @@ -114,7 +123,6 @@ proc do_write_test {name tbl sql} { # Calculate the initial table checksum. set cksum1 [db one $cksumsql] - if {![info exists ::DO_MALLOC_TEST]} { set ::DO_MALLOC_TEST 1 } if {$::DO_MALLOC_TEST } { set answers [list {1 {out of memory}} {0 {}}] @@ -152,10 +160,36 @@ proc normal_list {l} { set ret } -db close -file delete -force test.db test.db-journal -sqlite3 db test.db -sqlite3_db_config_lookaside db 0 0 0 + +do_write_test fts3_malloc-1.1 sqlite_master { + CREATE VIRTUAL TABLE ft1 USING fts3(a, b) +} +do_write_test fts3_malloc-1.2 sqlite_master { + CREATE VIRTUAL TABLE ft2 USING fts3([a], [b]); +} +do_write_test fts3_malloc-1.3 sqlite_master { + CREATE VIRTUAL TABLE ft3 USING fts3('a', "b"); +} +do_write_test fts3_malloc-1.4 sqlite_master { + CREATE VIRTUAL TABLE ft4 USING fts3(`a`, 'fred''s column'); +} +do_error_test fts3_malloc-1.5 { + CREATE VIRTUAL TABLE ft5 USING fts3(a, b, tokenize unknown) +} {unknown tokenizer: unknown} +do_write_test fts3_malloc-1.6 sqlite_master { + CREATE VIRTUAL TABLE ft6 USING fts3(a, b, tokenize porter) +} + +# Test the xConnect/xDisconnect methods: +db eval { ATTACH 'test2.db' AS aux } +do_write_test fts3_malloc-1.6 aux.sqlite_master { + CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +} +do_write_test fts3_malloc-1.6 aux.sqlite_master { + CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +} + + do_test fts3_malloc-2.0 { execsql { CREATE VIRTUAL TABLE ft USING fts3(a, b) } -- 2.47.2