rtree9.test 4.1 KB

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