xref: /sqlite-3.40.0/ext/rtree/rtree3.test (revision 6695f47e)
1# 2008 Feb 19
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
6#    May you do good and not evil.
7#    May you find forgiveness for yourself and forgive others.
8#    May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# The focus of this file is testing that the r-tree correctly handles
13# out-of-memory conditions.
14#
15
16if {![info exists testdir]} {
17  set testdir [file join [file dirname $argv0] .. .. test]
18}
19source $testdir/tester.tcl
20
21ifcapable !rtree {
22  finish_test
23  return
24}
25
26# Only run these tests if memory debugging is turned on.
27#
28source $testdir/malloc_common.tcl
29if {!$MEMDEBUG} {
30   puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
31   finish_test
32   return
33}
34
35do_malloc_test rtree3-1 -sqlbody {
36  BEGIN TRANSACTION;
37  CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
38  INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
39  INSERT INTO rt VALUES(NULL, 13, 15, 17, 19);
40  DELETE FROM rt WHERE ii = 1;
41  SELECT * FROM rt;
42  SELECT ii FROM rt WHERE ii = 2;
43  COMMIT;
44}
45do_malloc_test rtree3-2 -sqlprep {
46  CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
47  INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
48} -sqlbody {
49  DROP TABLE rt;
50}
51
52
53do_malloc_test rtree3-3 -sqlprep {
54  CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
55  INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
56} -tclbody {
57  db eval BEGIN
58  for {set ii 0} {$ii < 100} {incr ii} {
59    set f [expr rand()]
60    db eval {INSERT INTO rt VALUES(NULL, $f*10.0, $f*10.0, $f*15.0, $f*15.0)}
61  }
62  db eval COMMIT
63  db eval BEGIN
64  for {set ii 0} {$ii < 100} {incr ii} {
65    set f [expr rand()]
66    db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
67  }
68  db eval COMMIT
69}
70
71finish_test
72