Annotation of embedaddon/sqlite3/ext/rtree/rtree9.test, revision 1.1

1.1     ! misho       1: # 2010 August 28
        !             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: # This file contains tests for the r-tree module. Specifically, it tests
        !            12: # that custom r-tree queries (geometry callbacks) work.
        !            13: # 
        !            14: 
        !            15: if {![info exists testdir]} {
        !            16:   set testdir [file join [file dirname [info script]] .. .. test]
        !            17: } 
        !            18: source $testdir/tester.tcl
        !            19: ifcapable !rtree { finish_test ; return }
        !            20: 
        !            21: register_cube_geom db
        !            22: 
        !            23: do_execsql_test rtree9-1.1 {
        !            24:   CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2, z1, z2);
        !            25:   INSERT INTO rt VALUES(1, 1, 2, 1, 2, 1, 2);
        !            26: } {}
        !            27: do_execsql_test rtree9-1.2 {
        !            28:   SELECT * FROM rt WHERE id MATCH cube(0, 0, 0, 2, 2, 2);
        !            29: } {1 1.0 2.0 1.0 2.0 1.0 2.0}
        !            30: do_execsql_test rtree9-1.3 {
        !            31:   SELECT * FROM rt WHERE id MATCH cube(3, 3, 3, 2, 2, 2);
        !            32: } {}
        !            33: do_execsql_test rtree9-1.4 {
        !            34:   DELETE FROM rt;
        !            35: } {}
        !            36: 
        !            37: 
        !            38: for {set i 0} {$i < 1000} {incr i} {
        !            39:   set x [expr $i%10]
        !            40:   set y [expr ($i/10)%10]
        !            41:   set z [expr ($i/100)%10]
        !            42:   execsql { INSERT INTO rt VALUES($i, $x, $x+1, $y, $y+1, $z, $z+1) }
        !            43: }
        !            44: do_execsql_test rtree9-2.1 {
        !            45:   SELECT id FROM rt WHERE id MATCH cube(2.5, 2.5, 2.5, 1, 1, 1) ORDER BY id;
        !            46: } {222 223 232 233 322 323 332 333}
        !            47: do_execsql_test rtree9-2.2 {
        !            48:   SELECT id FROM rt WHERE id MATCH cube(5.5, 5.5, 5.5, 1, 1, 1) ORDER BY id;
        !            49: } {555 556 565 566 655 656 665 666}
        !            50: 
        !            51: 
        !            52: do_execsql_test rtree9-3.1 {
        !            53:   CREATE VIRTUAL TABLE rt32 USING rtree_i32(id, x1, x2, y1, y2, z1, z2);
        !            54: } {} 
        !            55: for {set i 0} {$i < 1000} {incr i} {
        !            56:   set x [expr $i%10]
        !            57:   set y [expr ($i/10)%10]
        !            58:   set z [expr ($i/100)%10]
        !            59:   execsql { INSERT INTO rt32 VALUES($i, $x, $x+1, $y, $y+1, $z, $z+1) }
        !            60: }
        !            61: do_execsql_test rtree9-3.2 {
        !            62:   SELECT id FROM rt32 WHERE id MATCH cube(3, 3, 3, 1, 1, 1) ORDER BY id;
        !            63: } {222 223 224 232 233 234 242 243 244 322 323 324 332 333 334 342 343 344 422 423 424 432 433 434 442 443 444}
        !            64: do_execsql_test rtree9-3.3 {
        !            65:   SELECT id FROM rt32 WHERE id MATCH cube(5.5, 5.5, 5.5, 1, 1, 1) ORDER BY id;
        !            66: } {555 556 565 566 655 656 665 666}
        !            67: 
        !            68: 
        !            69: do_catchsql_test rtree9-4.1 {
        !            70:   SELECT id FROM rt32 WHERE id MATCH cube(5.5, 5.5, 1, 1, 1) ORDER BY id;
        !            71: } {1 {SQL logic error or missing database}}
        !            72: for {set x 2} {$x<200} {incr x 2} {
        !            73:   do_catchsql_test rtree9-4.2.[expr $x/2] {
        !            74:     SELECT id FROM rt WHERE id MATCH randomblob($x)
        !            75:   } {1 {SQL logic error or missing database}}
        !            76: }
        !            77: do_catchsql_test rtree9-4.3 {
        !            78:   SELECT id FROM rt WHERE id MATCH CAST( 
        !            79:     (cube(5.5, 5.5, 5.5, 1, 1, 1) || X'1234567812345678') AS blob 
        !            80:   )
        !            81: } {1 {SQL logic error or missing database}}
        !            82: 
        !            83: 
        !            84: #-------------------------------------------------------------------------
        !            85: # Test the example 2d "circle" geometry callback.
        !            86: #
        !            87: register_circle_geom db
        !            88: 
        !            89: breakpoint
        !            90: do_execsql_test rtree9-5.1 {
        !            91:   CREATE VIRTUAL TABLE rt2 USING rtree(id, xmin, xmax, ymin, ymax);
        !            92: 
        !            93:   INSERT INTO rt2 VALUES(1,    1,   2,  1,  2);
        !            94:   INSERT INTO rt2 VALUES(2,    1,   2, -2, -1);
        !            95:   INSERT INTO rt2 VALUES(3,    -2, -1, -2, -1);
        !            96:   INSERT INTO rt2 VALUES(4,    -2, -1,  1,  2);
        !            97: 
        !            98:   INSERT INTO rt2 VALUES(5,    2,   3,  2,  3);
        !            99:   INSERT INTO rt2 VALUES(6,    2,   3, -3, -2);
        !           100:   INSERT INTO rt2 VALUES(7,    -3, -2, -3, -2);
        !           101:   INSERT INTO rt2 VALUES(8,    -3, -2,  2,  3);
        !           102: 
        !           103:   INSERT INTO rt2 VALUES(9,    1.8,   3,  1.8,  3);
        !           104:   INSERT INTO rt2 VALUES(10,   1.8,   3, -3, -1.8);
        !           105:   INSERT INTO rt2 VALUES(11,   -3, -1.8, -3, -1.8);
        !           106:   INSERT INTO rt2 VALUES(12,   -3, -1.8,  1.8,  3);
        !           107: 
        !           108:   INSERT INTO rt2 VALUES(13,   -15, 15, 1.8, 2.2);
        !           109:   INSERT INTO rt2 VALUES(14,   -15, 15, -2.2, -1.8);
        !           110:   INSERT INTO rt2 VALUES(15,   1.8, 2.2, -15, 15);
        !           111:   INSERT INTO rt2 VALUES(16,   -2.2, -1.8, -15, 15);
        !           112: 
        !           113:   INSERT INTO rt2 VALUES(17,   -100, 100, -100, 100);
        !           114: } {}
        !           115: 
        !           116: do_execsql_test rtree9-5.2 {
        !           117:   SELECT id FROM rt2 WHERE id MATCH circle(0.0, 0.0, 2.0);
        !           118: } {1 2 3 4 13 14 15 16 17}
        !           119: 
        !           120: do_execsql_test rtree9-5.3 {
        !           121:   UPDATE rt2 SET xmin=xmin+5, ymin=ymin+5, xmax=xmax+5, ymax=ymax+5;
        !           122:   SELECT id FROM rt2 WHERE id MATCH circle(5.0, 5.0, 2.0);
        !           123: } {1 2 3 4 13 14 15 16 17}
        !           124: 
        !           125: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>