1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Add tests for the new feature on this branch.

FossilOrigin-Name: 0268d1a59316d169927cbd4c562725e46a9023b7d7123ade911c12203e222adf
This commit is contained in:
dan
2023-04-14 16:11:05 +00:00
parent 02877e9558
commit d36106c954
5 changed files with 202 additions and 9 deletions

View File

@ -5002,7 +5002,6 @@ static void fts5FlushOneHash(Fts5Index *p){
if( bTermWritten==0 ){
fts5WriteAppendTerm(p, &writer, nTerm, (const u8*)zTerm);
if( p->rc!=SQLITE_OK ) break;
bTermWritten = 1;
assert( writer.bFirstRowidInPage==0 );
}
@ -5012,10 +5011,10 @@ static void fts5FlushOneHash(Fts5Index *p){
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
writer.bFirstRowidInPage = 0;
fts5WriteDlidxAppend(p, &writer, iRowid);
if( p->rc!=SQLITE_OK ) break;
}else{
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid-iPrev);
}
if( p->rc!=SQLITE_OK ) break;
assert( pBuf->n<=pBuf->nSpace );
iPrev = iRowid;

View File

@ -0,0 +1,54 @@
# 2023 April 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
#
source [file join [file dirname [info script]] fts5_common.tcl]
return_if_no_fts5
set ::testprefix fts5secure4
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b, content=x1);
CREATE TABLE x1(rowid INTEGER PRIMARY KEY, a, b);
INSERT INTO x1 VALUES
(1, 'hello world', 'today xyz'),
(2, 'not the day', 'crunch crumble and chomp'),
(3, 'one', 'two');
INSERT INTO t1(t1) VALUES('rebuild');
}
do_execsql_test 1.1 {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
do_execsql_test 1.2 {
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 4, 'nosuchtoken', '');
}
do_execsql_test 1.3 {
INSERT INTO t1(t1) VALUES('integrity-check');
}
do_execsql_test 1.4 {
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 1, 'crunch', '');
}
do_execsql_test 1.5 {
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 3, 'crunch', '');
}
do_execsql_test 1.6 {
INSERT INTO t1(t1) VALUES('integrity-check');
}
finish_test

View File

@ -0,0 +1,138 @@
# 2023 April 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the FTS5 module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
source $testdir/malloc_common.tcl
set testprefix fts5securefault
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
return_if_no_fts5
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(rowid, ab) VALUES
(0, 'abc'), (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'def');
}
faultsim_save_and_close
do_faultsim_test 1.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid=2 }
} -test {
faultsim_test_result {0 {}}
}
do_faultsim_test 1.2 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid IN(0, 1, 2, 3, 4) }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set big [string repeat abcdefghij 5]
set big2 [string repeat klmnopqrst 5]
set doc "$big $big2"
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4
)
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
}
faultsim_save_and_close
do_faultsim_test 2.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 3 }
execsql { DELETE FROM t1 WHERE rowid = 4 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set big [string repeat abcdefghij 5]
set big2 [string repeat klmnopqrst 5]
set doc "$big $big2"
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<25
)
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
DELETE FROM t1 WHERE rowid BETWEEN 3 AND 23;
}
faultsim_save_and_close
do_faultsim_test 3.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 24 }
execsql { DELETE FROM t1 WHERE rowid = 25 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set doc [string repeat "tok " 400]
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
INSERT INTO t1(rowid, ab) VALUES(1, $doc), (2, $doc), (3, $doc);
}
faultsim_save_and_close
do_faultsim_test 4.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 2 }
} -test {
faultsim_test_result {0 {}}
}
finish_test