Merge branch 'prerelease' of ssh://git.zetetic.net/sqlcipher into prerelease
[sqlcipher.git] / test / symlink2.test
blob4123092deb10801c97423f23122aefe6a46ce1db
1 # 2019 November 18
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this file is testing that SQLite can follow symbolic links.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix symlink2
19 # This only runs on Windows.
20 if {$::tcl_platform(platform)!="windows"} {
21   finish_test
22   return
25 proc createWin32Symlink { link target } {
26   exec -- $::env(ComSpec) /c mklink \
27       [file nativename $link] [file nativename $target]
28   return ""
31 proc deleteWin32Symlink { link } {
32   exec -- $::env(ComSpec) /c del [file nativename $link]
33   return ""
36 proc canCreateWin32Symlink {} {
37   set link [file join $::testdir lnk[pid].sym]
38   if {[file exists $link]} { return 0 }
39   set target [info nameofexecutable]
40   if {[catch {createWin32Symlink $link $target}] == 0} {
41     deleteWin32Symlink $link
42     return 1
43   }
44   return 0
47 # Creating symlinks may require administrator privileges on Windows.
48 if {![canCreateWin32Symlink]} {
49   finish_test
50   return
53 # Ensure that test.db has been created.
55 do_execsql_test 1.0 {
56   CREATE TABLE t1(x, y);
57   INSERT INTO t1 VALUES(1,9999);
60 do_test 2.0 {
61   createWin32Symlink link.db test.db
62 } {}
64 do_test 2.1 {
65   file exists test.db
66 } {1}
68 do_test 2.2 {
69   file exists link.db
70 } {1}
72 do_test 3.1 {
73   execsql { SELECT x, y FROM t1; } db
74 } {1 9999}
76 do_test 3.2 {
77   sqlite3 db2 link.db
78   execsql { SELECT x, y FROM t1; } db2
79 } {1 9999}
81 do_test 3.3 {
82   sqlite3 db3 test.db -nofollow true
83   execsql { SELECT x, y FROM t1; } db3
84 } {1 9999}
86 do_test 3.4 {
87   db3 close
88 } {}
90 do_test 3.5 {
91   list [catch {
92     sqlite3 db4 link.db -nofollow true
93     execsql { SELECT x, y FROM t1; } db4
94   } res] $res
95 } {1 {unable to open database file}}
97 catch {db4 close}
99 do_test 4.0 {
100   db2 close
101   deleteWin32Symlink link.db
102 } {}
104 do_test 4.1 {
105   file exists test.db
106 } {1}
108 do_test 4.2 {
109   file exists link.db
110 } {0}
112 do_test 5.1 {
113   execsql { SELECT x, y FROM t1; } db
114 } {1 9999}
116 finish_test