sqlite/ext/rtree/rtree3.test
dan 2bf19178f7 Improve coverage of rtree.c some more.
FossilOrigin-Name: bee1959dde19ebec20a7ffcb732aee0c8bb2e67d
2010-08-26 07:59:10 +00:00

199 lines
4.5 KiB
Plaintext

# 2008 Feb 19
#
# 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.
#
#***********************************************************************
#
# The focus of this file is testing that the r-tree correctly handles
# out-of-memory conditions.
#
if {![info exists testdir]} {
set testdir [file join [file dirname $argv0] .. .. test]
}
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
ifcapable !rtree {
finish_test
return
}
# Only run these tests if memory debugging is turned on.
#
source $testdir/malloc_common.tcl
if {!$MEMDEBUG} {
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
finish_test
return
}
if 1 {
do_faultsim_test rtree3-1 -faults oom* -prep {
faultsim_delete_and_reopen
} -body {
execsql {
BEGIN TRANSACTION;
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
INSERT INTO rt VALUES(NULL, 13, 15, 17, 19);
DELETE FROM rt WHERE ii = 1;
SELECT * FROM rt;
SELECT ii FROM rt WHERE ii = 2;
COMMIT;
}
}
do_test rtree3-2.prep {
faultsim_delete_and_reopen
execsql {
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
}
faultsim_save_and_close
} {}
do_faultsim_test rtree3-2 -faults oom* -prep {
faultsim_restore_and_reopen
} -body {
execsql { DROP TABLE rt }
}
do_malloc_test rtree3-3.prep {
faultsim_delete_and_reopen
execsql {
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
}
faultsim_save_and_close
} {}
do_faultsim_test rtree3-3a -faults oom* -prep {
faultsim_restore_and_reopen
} -body {
db eval BEGIN
for {set ii 0} {$ii < 100} {incr ii} {
set f [expr rand()]
db eval {INSERT INTO rt VALUES(NULL, $f*10.0, $f*10.0, $f*15.0, $f*15.0)}
}
db eval COMMIT
}
faultsim_save_and_close
do_faultsim_test rtree3-3b -faults oom* -prep {
faultsim_restore_and_reopen
} -body {
db eval BEGIN
for {set ii 0} {$ii < 100} {incr ii} {
set f [expr rand()]
db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
}
db eval COMMIT
}
}
do_test rtree3-4.prep {
faultsim_delete_and_reopen
execsql {
BEGIN;
PRAGMA page_size = 512;
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
}
for {set i 0} {$i < 1500} {incr i} {
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
}
execsql { COMMIT }
faultsim_save_and_close
} {}
do_faultsim_test rtree3-4a -faults oom-* -prep {
faultsim_restore_and_reopen
} -body {
db eval { SELECT count(*) FROM rt }
} -test {
faultsim_test_result {0 1500}
}
do_faultsim_test rtree3-4b -faults oom-* -prep {
faultsim_restore_and_reopen
} -body {
db eval { DELETE FROM rt WHERE ii BETWEEN 1 AND 100 }
} -test {
faultsim_test_result {0 {}}
}
do_test rtree3-5.prep {
faultsim_delete_and_reopen
execsql {
BEGIN;
PRAGMA page_size = 512;
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
}
for {set i 0} {$i < 100} {incr i} {
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
}
execsql { COMMIT }
faultsim_save_and_close
} {}
do_faultsim_test rtree3-5 -faults oom-* -prep {
faultsim_restore_and_reopen
} -body {
for {set i 100} {$i < 110} {incr i} {
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
}
} -test {
faultsim_test_result {0 {}}
}
do_test rtree3-6.prep {
faultsim_delete_and_reopen
execsql {
BEGIN;
PRAGMA page_size = 512;
CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
}
for {set i 0} {$i < 50} {incr i} {
execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
}
execsql { COMMIT }
faultsim_save_and_close
} {}
do_faultsim_test rtree3-6 -faults oom-* -prep {
faultsim_restore_and_reopen
} -body {
execsql BEGIN
for {set i 0} {$i < 50} {incr i} {
execsql { DELETE FROM rt WHERE ii=$i }
}
execsql COMMIT
} -test {
faultsim_test_result {0 {}}
}
do_test rtree3-7.prep {
faultsim_delete_and_reopen
execsql { CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2) }
faultsim_save_and_close
} {}
do_faultsim_test rtree3-7 -faults oom-* -prep {
faultsim_restore_and_reopen
} -body {
execsql { ALTER TABLE rt RENAME TO rt2 }
} -test {
faultsim_test_result {0 {}}
}
do_faultsim_test rtree3-8 -faults oom-* -prep {
catch { db close }
} -body {
sqlite3 db test.db
}
finish_test