fts5secure7.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # 2023 Feb 17
  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. # TESTRUNNER: slow
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. ifcapable !fts5 { finish_test ; return }
  16. set ::testprefix fts5secure7
  17. set NVOCAB 500
  18. set NDOC [expr 1000]
  19. set NREP 100
  20. set nDeletePerRep [expr 5]
  21. set VOCAB [list]
  22. proc select_one {list} {
  23. set n [llength $list]
  24. lindex $list [expr {abs(int(rand()*$n))}]
  25. }
  26. proc init_vocab {} {
  27. set L [split "abcdefghijklmnopqrstuvwxyz" {}]
  28. set nL [llength $L]
  29. for {set i 0} {$i < $::NVOCAB} {incr i} {
  30. set n [expr {6 + int(rand()*8)}]
  31. set word ""
  32. for {set j 0} {$j < $n} {incr j} {
  33. append word [select_one $L]
  34. }
  35. lappend ::VOCAB $word
  36. }
  37. }
  38. proc get_word {} {
  39. select_one $::VOCAB
  40. }
  41. proc get_document {nWord} {
  42. set ret [list]
  43. for {set i 0} {$i < $nWord} {incr i} {
  44. lappend ret [get_word]
  45. }
  46. return $ret
  47. }
  48. init_vocab
  49. db func document [list get_document 12]
  50. do_execsql_test 1.0 {
  51. CREATE VIRTUAL TABLE t1 USING fts5(body);
  52. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  53. }
  54. do_execsql_test 1.1 {
  55. WITH s(i) AS (
  56. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<$NDOC
  57. )
  58. INSERT INTO t1 SELECT document() FROM s;
  59. }
  60. for {set iRep 0} {$iRep < $NREP} {incr iRep} {
  61. set lRowid [db eval {SELECT rowid FROM t1}]
  62. for {set iDel 0} {$iDel < $nDeletePerRep} {incr iDel} {
  63. set idx [select_one $lRowid]
  64. db eval {
  65. DELETE FROM t1 WHERE rowid=$idx
  66. }
  67. }
  68. db eval {
  69. WITH s(i) AS (
  70. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<$nDeletePerRep
  71. )
  72. INSERT INTO t1 SELECT document() FROM s;
  73. }
  74. do_execsql_test 1.2.$iRep {
  75. INSERT INTO t1(t1) VALUES('integrity-check');
  76. }
  77. }
  78. reset_db
  79. db func document [list get_document 12]
  80. do_execsql_test 2.0 {
  81. CREATE VIRTUAL TABLE t1 USING fts5(body);
  82. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  83. INSERT INTO t1(t1, rank) VALUES('pgsz', 128);
  84. }
  85. do_execsql_test 2.1 {
  86. WITH s(i) AS (
  87. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<$NDOC
  88. )
  89. INSERT INTO t1 SELECT document() FROM s;
  90. }
  91. for {set ii 0} {$ii < $NDOC} {incr ii} {
  92. set lRowid [db eval {SELECT rowid FROM t1}]
  93. set idx [select_one $lRowid]
  94. db eval { DELETE FROM t1 WHERE rowid=$idx }
  95. do_execsql_test 2.2.$ii {
  96. INSERT INTO t1(t1) VALUES('integrity-check');
  97. }
  98. }
  99. finish_test