| 1 |
# 2013 May 29 |
| 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 implements regression tests for SQLite library. |
| 12 |
# |
| 13 |
|
| 14 |
set testdir [file dirname $argv0] |
| 15 |
source $testdir/tester.tcl |
| 16 |
source $testdir/fts3_common.tcl |
| 17 |
set ::testprefix fts4merge4 |
| 18 |
|
| 19 |
ifcapable !fts3||!shared_cache { |
| 20 |
finish_test |
| 21 |
return |
| 22 |
} |
| 23 |
|
| 24 |
set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
| 25 |
|
| 26 |
do_execsql_test 1.1 { CREATE VIRTUAL TABLE t1 USING fts4 } |
| 27 |
|
| 28 |
do_test 1.2 { |
| 29 |
for {set i 0} {$i < 2000} {incr i} { |
| 30 |
execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} |
| 31 |
} |
| 32 |
} {} |
| 33 |
|
| 34 |
do_test 1.3 { |
| 35 |
execsql BEGIN |
| 36 |
for {set i 0} {$i < 2000} {incr i} { |
| 37 |
execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} |
| 38 |
} |
| 39 |
execsql { |
| 40 |
INSERT INTO t1(t1) VALUES('merge=8,50'); |
| 41 |
COMMIT |
| 42 |
} |
| 43 |
} {} |
| 44 |
|
| 45 |
reset_db |
| 46 |
do_execsql_test 2.0 { CREATE VIRTUAL TABLE t1 USING fts4 } |
| 47 |
do_test 2.1 { |
| 48 |
for {set i 0} {$i < 2000} {incr i} { |
| 49 |
execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} |
| 50 |
} |
| 51 |
} {} |
| 52 |
do_execsql_test 2.2 { SELECT count(*) FROM t1_segdir; } 35 |
| 53 |
do_execsql_test 2.3 { INSERT INTO t1(t1) VALUES('optimize') } {} |
| 54 |
do_execsql_test 2.4 { SELECT count(*) FROM t1_segdir; } 1 |
| 55 |
|
| 56 |
#------------------------------------------------------------------------- |
| 57 |
# Now test that the automerge=? option appears to work. |
| 58 |
# |
| 59 |
do_execsql_test 2.1 { CREATE VIRTUAL TABLE t2 USING fts4; } |
| 60 |
|
| 61 |
set doc "" |
| 62 |
foreach c1 "a b c d e f g h i j" { |
| 63 |
foreach c2 "a b c d e f g h i j" { |
| 64 |
foreach c3 "a b c d e f g h i j" { |
| 65 |
lappend doc "$c1$c2$c3" |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
set doc [string repeat $doc 10] |
| 70 |
|
| 71 |
foreach {tn am expected} { |
| 72 |
1 {automerge=2} {1 1 2 1 4 1 6 1} |
| 73 |
2 {automerge=4} {1 2 2 1 3 1} |
| 74 |
3 {automerge=8} {0 4 1 3 2 1} |
| 75 |
4 {automerge=1} {0 4 1 3 2 1} |
| 76 |
} { |
| 77 |
foreach {tn2 openclose} {1 {} 2 { db close ; sqlite3 db test.db }} { |
| 78 |
do_test 2.2.$tn.$tn2 { |
| 79 |
execsql { DELETE FROM t2 } |
| 80 |
execsql { INSERT INTO t2(t2) VALUES($am) }; |
| 81 |
|
| 82 |
eval $openclose |
| 83 |
|
| 84 |
for {set i 0} {$i < 100} {incr i} { |
| 85 |
execsql { |
| 86 |
BEGIN; |
| 87 |
INSERT INTO t2 VALUES($doc); |
| 88 |
INSERT INTO t2 VALUES($doc); |
| 89 |
INSERT INTO t2 VALUES($doc); |
| 90 |
INSERT INTO t2 VALUES($doc); |
| 91 |
INSERT INTO t2 VALUES($doc); |
| 92 |
COMMIT; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } |
| 97 |
} [list {*}$expected] |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
sqlite3_enable_shared_cache $::enable_shared_cache |
| 102 |
finish_test |