aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fts3_common.tcl63
-rw-r--r--test/fts4merge.test80
-rw-r--r--test/fts4merge2.test38
-rw-r--r--test/permutations.test2
4 files changed, 152 insertions, 31 deletions
diff --git a/test/fts3_common.tcl b/test/fts3_common.tcl
index 23a8cfca6..6c9c2fcec 100644
--- a/test/fts3_common.tcl
+++ b/test/fts3_common.tcl
@@ -14,6 +14,67 @@
# to use Tcl.
#
+
+#-------------------------------------------------------------------------
+# USAGE: fts3_build_db_1 N
+#
+# Build a sample FTS table in the database opened by database connection
+# [db]. The name of the new table is "t1".
+#
+proc fts3_build_db_1 {n} {
+
+ if {$n > 10000} {error "n must be <= 10000"}
+
+ db eval { CREATE VIRTUAL TABLE t1 USING fts4(x, y) }
+
+ set xwords [list zero one two three four five six seven eight nine ten]
+ set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa]
+
+ for {set i 0} {$i < $n} {incr i} {
+ set x ""
+ set y ""
+
+ set x [list]
+ lappend x [lindex $xwords [expr ($i / 1000) % 10]]
+ lappend x [lindex $xwords [expr ($i / 100) % 10]]
+ lappend x [lindex $xwords [expr ($i / 10) % 10]]
+ lappend x [lindex $xwords [expr ($i / 1) % 10]]
+
+ set y [list]
+ lappend y [lindex $ywords [expr ($i / 1000) % 10]]
+ lappend y [lindex $ywords [expr ($i / 100) % 10]]
+ lappend y [lindex $ywords [expr ($i / 10) % 10]]
+ lappend y [lindex $ywords [expr ($i / 1) % 10]]
+
+ db eval { INSERT INTO t1(docid, x, y) VALUES($i, $x, $y) }
+ }
+}
+
+#-------------------------------------------------------------------------
+# USAGE: fts3_build_db_2 N
+#
+# Build a sample FTS table in the database opened by database connection
+# [db]. The name of the new table is "t2".
+#
+proc fts3_build_db_2 {n} {
+
+ if {$n > 100000} {error "n must be <= 100000"}
+
+ db eval { CREATE VIRTUAL TABLE t2 USING fts4 }
+
+ set chars [list a b c d e f g h i j k l m n o p q r s t u v w x y z ""]
+
+ for {set i 0} {$i < $n} {incr i} {
+ set word ""
+ set n [llength $chars]
+ append word [lindex $chars [expr {($i / 1) % $n}]]
+ append word [lindex $chars [expr {($i / $n) % $n}]]
+ append word [lindex $chars [expr {($i / ($n*$n)) % $n}]]
+
+ db eval { INSERT INTO t2(docid, content) VALUES($i, $word) }
+ }
+}
+
#-------------------------------------------------------------------------
# USAGE: fts3_integrity_check TBL
#
@@ -98,7 +159,7 @@ proc fts3_integrity_check {tbl} {
set es "Error at docid=$iDoc col=$iCol pos=$pos. Index is missing"
lappend errors $es
} else {
- if {$C($iDoc,$iCol,$pos) != "$term"} {
+ if {[string compare $C($iDoc,$iCol,$pos) $term]} {
set es "Error at docid=$iDoc col=$iCol pos=$pos. Index "
append es "has \"$C($iDoc,$iCol,$pos)\", document has \"$term\""
lappend errors $es
diff --git a/test/fts4merge.test b/test/fts4merge.test
index 805a78cf9..a5995921f 100644
--- a/test/fts4merge.test
+++ b/test/fts4merge.test
@@ -23,35 +23,6 @@ ifcapable !fts3 {
return
}
-proc fts3_build_db_1 {n} {
-
- if {$n > 10000} {error "n must be <= 10000"}
-
- db eval { CREATE VIRTUAL TABLE t1 USING fts4(x, y) }
-
- set xwords [list zero one two three four five six seven eight nine ten]
- set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa]
-
- for {set i 0} {$i < $n} {incr i} {
- set x ""
- set y ""
-
- set x [list]
- lappend x [lindex $xwords [expr ($i / 1000) % 10]]
- lappend x [lindex $xwords [expr ($i / 100) % 10]]
- lappend x [lindex $xwords [expr ($i / 10) % 10]]
- lappend x [lindex $xwords [expr ($i / 1) % 10]]
-
- set y [list]
- lappend y [lindex $ywords [expr ($i / 1000) % 10]]
- lappend y [lindex $ywords [expr ($i / 100) % 10]]
- lappend y [lindex $ywords [expr ($i / 10) % 10]]
- lappend y [lindex $ywords [expr ($i / 1) % 10]]
-
- db eval { INSERT INTO t1(docid, x, y) VALUES($i, $x, $y) }
- }
-}
-
#-------------------------------------------------------------------------
# Test cases 1.*
#
@@ -98,6 +69,57 @@ do_execsql_test 1.5 {
3 {0 1 2}
}
+#-------------------------------------------------------------------------
+# Test cases 2.* test that errors in the xxx part of the 'merge=xxx' are
+# handled correctly.
+#
+do_execsql_test 2.0 { CREATE VIRTUAL TABLE t2 USING fts4 }
+
+foreach {tn arg} {
+ 1 {merge=abc}
+ 2 {merge=%%%}
+ 3 {merge=,}
+ 4 {merge=5,}
+ 5 {merge=6,%}
+ 6 {merge=6,six}
+ 7 {merge=6,1}
+ 8 {merge=6,0}
+} {
+ do_catchsql_test 2.$tn {
+ INSERT INTO t2(t2) VALUES($arg);
+ } {1 {SQL logic error or missing database}}
+}
+
+#-------------------------------------------------------------------------
+# Test cases 3.*
+#
+do_test 3.0 {
+ reset_db
+ execsql { PRAGMA page_size = 512 }
+ fts3_build_db_2 30040
+} {}
+do_test 3.1 { fts3_integrity_check t2 } {ok}
+
+do_execsql_test 3.2 {
+ SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level
+} {
+ 0 {0 1 2 3 4 5 6 7}
+ 1 {0 1 2 3 4}
+ 2 {0 1 2 3 4}
+ 3 {0 1 2 3 4 5 6}
+}
+
+do_execsql_test 3.3 {
+ INSERT INTO t2(t2) VALUES('merge=1000000,2');
+ SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level
+} {
+ 0 {0 1}
+ 1 {0 1}
+ 2 0
+ 3 {0 1}
+ 4 {0 1}
+ 5 0
+}
finish_test
diff --git a/test/fts4merge2.test b/test/fts4merge2.test
new file mode 100644
index 000000000..308b6929f
--- /dev/null
+++ b/test/fts4merge2.test
@@ -0,0 +1,38 @@
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/fts3_common.tcl
+source $testdir/malloc_common.tcl
+set ::testprefix fts4merge2
+
+# If SQLITE_ENABLE_FTS3 is defined, omit this file.
+ifcapable !fts3 {
+ finish_test
+ return
+}
+
+do_test 1.0 {
+ fts3_build_db_1 1000
+ faultsim_save_and_close
+} {}
+
+do_faultsim_test 1.1 -faults oom-* -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql { INSERT INTO t1(t1) VALUES('merge=32,4') }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+do_faultsim_test 1.2 -faults oom-t* -prep {
+ if {$iFail<100} {set iFail 803}
+ faultsim_restore_and_reopen
+} -body {
+ execsql { INSERT INTO t1(t1) VALUES('merge=1,2') }
+ execsql { INSERT INTO t1(t1) VALUES('merge=1,2') }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+finish_test
diff --git a/test/permutations.test b/test/permutations.test
index 26c1b2a51..6f66e85e9 100644
--- a/test/permutations.test
+++ b/test/permutations.test
@@ -184,7 +184,7 @@ test_suite "fts3" -prefix "" -description {
fts3aux1.test fts3comp1.test fts3auto.test
fts4aa.test fts4content.test
fts3conf.test fts3prefix.test fts3fault2.test fts3corrupt.test
- fts3corrupt2.test fts3first.test fts4langid.test
+ fts3corrupt2.test fts3first.test fts4langid.test fts4merge.test
}