| 1 |
# 2013 August 27 |
| 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. The |
| 12 |
# focus of this script is testing the file name handling provided |
| 13 |
# by the "win32-longpath" VFS. |
| 14 |
# |
| 15 |
|
| 16 |
if {$tcl_platform(platform) ne "windows"} return |
| 17 |
|
| 18 |
set testdir [file dirname $argv0] |
| 19 |
source $testdir/tester.tcl |
| 20 |
set testprefix win32longpath |
| 21 |
|
| 22 |
do_test 1.0 { |
| 23 |
file_control_vfsname db |
| 24 |
} win32 |
| 25 |
|
| 26 |
db close |
| 27 |
set rawPath [get_pwd] |
| 28 |
set path [file nativename $rawPath] |
| 29 |
sqlite3 db [file join $path test.db] -vfs win32-longpath |
| 30 |
|
| 31 |
do_test 1.1 { |
| 32 |
file_control_vfsname db |
| 33 |
} win32-longpath |
| 34 |
|
| 35 |
do_test 1.2 { |
| 36 |
db eval { |
| 37 |
BEGIN EXCLUSIVE; |
| 38 |
CREATE TABLE t1(x); |
| 39 |
INSERT INTO t1 VALUES(1); |
| 40 |
INSERT INTO t1 VALUES(2); |
| 41 |
INSERT INTO t1 VALUES(3); |
| 42 |
INSERT INTO t1 VALUES(4); |
| 43 |
SELECT x FROM t1 ORDER BY x; |
| 44 |
COMMIT; |
| 45 |
} |
| 46 |
} {1 2 3 4} |
| 47 |
|
| 48 |
set longPath(1) \\\\?\\$path\\[pid] |
| 49 |
set uriPath(1a) %5C%5C%3F%5C$path\\[pid] |
| 50 |
set uriPath(1b) %5C%5C%3F%5C$rawPath/[pid] |
| 51 |
|
| 52 |
file mkdir $longPath(1) |
| 53 |
|
| 54 |
set longPath(2) $longPath(1)\\[string repeat X 255] |
| 55 |
set uriPath(2a) $uriPath(1a)\\[string repeat X 255] |
| 56 |
set uriPath(2b) $uriPath(1b)/[string repeat X 255] |
| 57 |
|
| 58 |
file mkdir $longPath(2) |
| 59 |
|
| 60 |
set longPath(3) $longPath(2)\\[string repeat Y 255] |
| 61 |
set uriPath(3a) $uriPath(2a)\\[string repeat Y 255] |
| 62 |
set uriPath(3b) $uriPath(2b)/[string repeat Y 255] |
| 63 |
|
| 64 |
file mkdir $longPath(3) |
| 65 |
|
| 66 |
set fileName $longPath(3)\\test.db |
| 67 |
|
| 68 |
set uri(1a) file:$uriPath(3a)\\test.db |
| 69 |
set uri(1b) file:$uriPath(3b)/test.db |
| 70 |
set uri(1c) file:///$uriPath(3a)\\test.db |
| 71 |
set uri(1d) file:///$uriPath(3b)/test.db |
| 72 |
set uri(1e) file://localhost/$uriPath(3a)\\test.db |
| 73 |
set uri(1f) file://localhost/$uriPath(3b)/test.db |
| 74 |
|
| 75 |
do_test 1.3 { |
| 76 |
list [catch {sqlite3 db2 [string range $fileName 4 end]} msg] $msg |
| 77 |
} {1 {unable to open database file}} |
| 78 |
|
| 79 |
sqlite3 db3 $fileName -vfs win32-longpath |
| 80 |
|
| 81 |
do_test 1.4 { |
| 82 |
db3 eval { |
| 83 |
BEGIN EXCLUSIVE; |
| 84 |
CREATE TABLE t1(x); |
| 85 |
INSERT INTO t1 VALUES(5); |
| 86 |
INSERT INTO t1 VALUES(6); |
| 87 |
INSERT INTO t1 VALUES(7); |
| 88 |
INSERT INTO t1 VALUES(8); |
| 89 |
SELECT x FROM t1 ORDER BY x; |
| 90 |
COMMIT; |
| 91 |
} |
| 92 |
} {5 6 7 8} |
| 93 |
|
| 94 |
db3 close |
| 95 |
|
| 96 |
sqlite3 db3 $fileName -vfs win32-longpath |
| 97 |
|
| 98 |
do_test 1.5 { |
| 99 |
db3 eval { |
| 100 |
PRAGMA journal_mode = WAL; |
| 101 |
} |
| 102 |
} {wal} |
| 103 |
|
| 104 |
do_test 1.6 { |
| 105 |
db3 eval { |
| 106 |
BEGIN EXCLUSIVE; |
| 107 |
INSERT INTO t1 VALUES(9); |
| 108 |
INSERT INTO t1 VALUES(10); |
| 109 |
INSERT INTO t1 VALUES(11); |
| 110 |
INSERT INTO t1 VALUES(12); |
| 111 |
SELECT x FROM t1 ORDER BY x; |
| 112 |
COMMIT; |
| 113 |
} |
| 114 |
} {5 6 7 8 9 10 11 12} |
| 115 |
|
| 116 |
db3 close |
| 117 |
|
| 118 |
set lUri [list 1a 1b 1c 1d 1e 1f] |
| 119 |
foreach tn $lUri { |
| 120 |
sqlite3 db3 $uri($tn) -vfs win32-longpath -uri 1 -translatefilename 0 |
| 121 |
|
| 122 |
do_test 1.7.$tn { |
| 123 |
db3 eval { |
| 124 |
SELECT x FROM t1 ORDER BY x; |
| 125 |
} |
| 126 |
} {5 6 7 8 9 10 11 12} |
| 127 |
|
| 128 |
db3 close |
| 129 |
} |
| 130 |
|
| 131 |
# These over-length file and directory names are difficult to delete. |
| 132 |
# The "file delete -force" might not work, depending on the TCL build |
| 133 |
# being used. So first try to delete using the windows rmdir command. |
| 134 |
# |
| 135 |
set fd [open cleanup.bat w] |
| 136 |
puts $fd "rmdir /q /s $longPath(1)" |
| 137 |
close $fd |
| 138 |
if {[catch {exec cleanup.bat} msg]} { |
| 139 |
puts "Command \[cleanup.bat\] returns $msg" |
| 140 |
} |
| 141 |
|
| 142 |
file delete -force $fileName |
| 143 |
file delete -force $longPath(3) |
| 144 |
file delete -force $longPath(2) |
| 145 |
file delete -force $longPath(1) |
| 146 |
|
| 147 |
finish_test |