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 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set ::testprefix extension01 18 19load_static_extension db fileio 20do_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}} 31do_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 41do_test 1.2 { 42 db eval { 43 SELECT writefile('./file2.txt', 'A second test line'); 44 } 45} {18} 46do_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 53do_test 1.4 { 54 db eval { 55 SELECT writefile('./file2.txt', NULL); 56 } 57} {0} 58do_test 1.5 { 59 file size ./file2.txt 60} {0} 61 62do_test 1.6 { 63 if {$::tcl_platform(platform)=="unix"} { 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} 72do_test 1.7 { 73 if {$::tcl_platform(platform)=="unix"} { 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 83finish_test 84