| 1 |
# 2014-06-16 |
| 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 |
# This file implements tests for various small extensions. |
| 13 |
# |
| 14 |
|
| 15 |
set testdir [file dirname $argv0] |
| 16 |
source $testdir/tester.tcl |
| 17 |
set ::testprefix extension01 |
| 18 |
|
| 19 |
load_static_extension db fileio |
| 20 |
do_test 1.0 { |
| 21 |
forcedelete file1.txt |
| 22 |
set out [open ./file1.txt wb] |
| 23 |
puts -nonewline $out "This is a text file without a line ending" |
| 24 |
close $out |
| 25 |
db eval { |
| 26 |
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); |
| 27 |
INSERT INTO t1 VALUES(1, readfile('./file1.txt')); |
| 28 |
SELECT * FROM t1; |
| 29 |
} |
| 30 |
} {1 {This is a text file without a line ending}} |
| 31 |
do_test 1.1 { |
| 32 |
forcedelete file2.txt |
| 33 |
db nullvalue nil |
| 34 |
db eval { |
| 35 |
DELETE FROM t1; |
| 36 |
INSERT INTO t1 VALUES(2, readfile(NULL)),(3, readfile('file2.txt')); |
| 37 |
SELECT a, b, typeof(b) FROM t1; |
| 38 |
} |
| 39 |
} {2 nil null 3 nil null} |
| 40 |
|
| 41 |
do_test 1.2 { |
| 42 |
db eval { |
| 43 |
SELECT writefile('./file2.txt', 'A second test line'); |
| 44 |
} |
| 45 |
} {18} |
| 46 |
do_test 1.3 { |
| 47 |
set in [open ./file2.txt rb] |
| 48 |
set x [read $in] |
| 49 |
close $in |
| 50 |
list $x [file size file2.txt] |
| 51 |
} {{A second test line} 18} |
| 52 |
|
| 53 |
do_test 1.4 { |
| 54 |
db eval { |
| 55 |
SELECT writefile('./file2.txt', NULL); |
| 56 |
} |
| 57 |
} {0} |
| 58 |
do_test 1.5 { |
| 59 |
file size ./file2.txt |
| 60 |
} {0} |
| 61 |
|
| 62 |
do_test 1.6 { |
| 63 |
if {$::tcl_platform(os) ne "Windows NT"} { |
| 64 |
file attributes ./file2.txt -permissions r--r--r-- |
| 65 |
} else { |
| 66 |
file attributes ./file2.txt -readonly 1 |
| 67 |
} |
| 68 |
db eval { |
| 69 |
SELECT writefile('./file2.txt', 'Another test'); |
| 70 |
} |
| 71 |
} {nil} |
| 72 |
do_test 1.7 { |
| 73 |
if {$::tcl_platform(os) ne "Windows NT"} { |
| 74 |
file attributes ./file2.txt -permissions rw-r--r-- |
| 75 |
} else { |
| 76 |
file attributes ./file2.txt -readonly 0 |
| 77 |
} |
| 78 |
db eval { |
| 79 |
SELECT writefile(NULL, 'Another test'); |
| 80 |
} |
| 81 |
} {nil} |
| 82 |
|
| 83 |
finish_test |