3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
18 source $testdir/tester.tcl
19 set testprefix rtreecheck
26 proc swap_int32 {blob i0 i1} {
27 binary scan $blob I* L
38 proc set_int32 {blob idx val} {
39 binary scan $blob I* L
44 do_catchsql_test 1.0 {
46 } {1 {wrong number of arguments to function rtreecheck()}}
48 do_catchsql_test 1.1 {
49 SELECT rtreecheck(0,0,0);
50 } {1 {wrong number of arguments to function rtreecheck()}}
53 proc setup_simple_db {{module rtree}} {
55 db func swap_int32 swap_int32
57 CREATE VIRTUAL TABLE r1 USING $module (id, x1, x2, y1, y2);
58 INSERT INTO r1 VALUES(1, 5, 5, 5, 5); -- 3
59 INSERT INTO r1 VALUES(2, 6, 6, 6, 6); -- 9
60 INSERT INTO r1 VALUES(3, 7, 7, 7, 7); -- 15
61 INSERT INTO r1 VALUES(4, 8, 8, 8, 8); -- 21
62 INSERT INTO r1 VALUES(5, 9, 9, 9, 9); -- 27
68 SELECT rtreecheck('r1')
72 UPDATE r1_node SET data = swap_int32(data, 3, 9);
73 UPDATE r1_node SET data = swap_int32(data, 23, 29);
77 SELECT rtreecheck('r1')
78 } {{Dimension 0 of cell 0 on node 1 is corrupt
79 Dimension 1 of cell 3 on node 1 is corrupt}}
83 DELETE FROM r1_rowid WHERE rowid = 3;
84 SELECT rtreecheck('r1')
85 } {{Mapping (3 -> 1) missing from %_rowid table
86 Wrong number of entries in %_rowid table - expected 5, actual 4}}
90 UPDATE r1_rowid SET nodeno=2 WHERE rowid=3;
91 SELECT rtreecheck('r1')
92 } {{Found (3 -> 2) in %_rowid table, expected (3 -> 1)}}
96 CREATE VIRTUAL TABLE r1 USING rtree_i32(id, x1, x2);
97 INSERT INTO r1 VALUES(1, 0x7FFFFFFF*-1, 0x7FFFFFFF);
98 INSERT INTO r1 VALUES(2, 0x7FFFFFFF*-1, 5);
99 INSERT INTO r1 VALUES(3, -5, 5);
100 INSERT INTO r1 VALUES(4, 5, 0x11111111);
101 INSERT INTO r1 VALUES(5, 5, 0x00800000);
102 INSERT INTO r1 VALUES(6, 5, 0x00008000);
103 INSERT INTO r1 VALUES(7, 5, 0x00000080);
104 INSERT INTO r1 VALUES(8, 5, 0x40490fdb);
105 INSERT INTO r1 VALUES(9, 0x7f800000, 0x7f900000);
106 SELECT rtreecheck('r1')
109 do_execsql_test 3.1 {
110 CREATE VIRTUAL TABLE r2 USING rtree_i32(id, x1, x2);
111 INSERT INTO r2 VALUES(2, -1*(1<<31), -1*(1<<31)+5);
112 SELECT rtreecheck('r2')
115 do_execsql_test 3.2 {
117 UPDATE r2_node SET data = X'123456';
118 SELECT rtreecheck('r2')!="ok";
121 do_execsql_test 3.3 {
123 UPDATE r2_node SET data = X'00001234';
124 SELECT rtreecheck('r2')!="ok";
127 do_execsql_test 4.0 {
128 CREATE TABLE notanrtree(i);
129 SELECT rtreecheck('notanrtree');
130 } {{Schema corrupt or not an rtree}}
132 #-------------------------------------------------------------------------
135 db func set_int32 set_int32
136 do_execsql_test 5.0 {
137 CREATE VIRTUAL TABLE r3 USING rtree_i32(id, x1, x2, y1, y2);
139 SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<1000
141 INSERT INTO r3 SELECT i, i, i, i, i FROM x;
143 do_execsql_test 5.1 {
145 UPDATE r3_node SET data = set_int32(data, 3, 5000);
146 UPDATE r3_node SET data = set_int32(data, 4, 5000);
147 SELECT rtreecheck('r3')=='ok'
149 do_execsql_test 5.2 {
152 UPDATE r3_node SET data = set_int32(data, 3, 0);
153 UPDATE r3_node SET data = set_int32(data, 4, 0);
154 SELECT rtreecheck('r3')=='ok'