xref: /sqlite-3.40.0/test/extension01.test (revision a2412c16)
151ed2983Sdrh# 2014-06-16
251ed2983Sdrh#
351ed2983Sdrh# The author disclaims copyright to this source code.  In place of
451ed2983Sdrh# a legal notice, here is a blessing:
551ed2983Sdrh#
651ed2983Sdrh#    May you do good and not evil.
751ed2983Sdrh#    May you find forgiveness for yourself and forgive others.
851ed2983Sdrh#    May you share freely, never taking more than you give.
951ed2983Sdrh#
1051ed2983Sdrh#***********************************************************************
1151ed2983Sdrh#
1251ed2983Sdrh# This file implements tests for various small extensions.
1351ed2983Sdrh#
1451ed2983Sdrh
1551ed2983Sdrhset testdir [file dirname $argv0]
1651ed2983Sdrhsource $testdir/tester.tcl
1751ed2983Sdrhset ::testprefix extension01
1851ed2983Sdrh
1951ed2983Sdrhload_static_extension db fileio
2051ed2983Sdrhdo_test 1.0 {
2151ed2983Sdrh  forcedelete file1.txt
2251ed2983Sdrh  set out [open ./file1.txt wb]
2351ed2983Sdrh  puts -nonewline $out "This is a text file without a line ending"
2451ed2983Sdrh  close $out
2551ed2983Sdrh  db eval {
2651ed2983Sdrh    CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
2751ed2983Sdrh    INSERT INTO t1 VALUES(1, readfile('./file1.txt'));
2851ed2983Sdrh    SELECT * FROM t1;
2951ed2983Sdrh  }
3051ed2983Sdrh} {1 {This is a text file without a line ending}}
3151ed2983Sdrhdo_test 1.1 {
3251ed2983Sdrh  forcedelete file2.txt
3351ed2983Sdrh  db nullvalue nil
3451ed2983Sdrh  db eval {
3551ed2983Sdrh    DELETE FROM t1;
3651ed2983Sdrh    INSERT INTO t1 VALUES(2, readfile(NULL)),(3, readfile('file2.txt'));
3751ed2983Sdrh    SELECT a, b, typeof(b) FROM t1;
3851ed2983Sdrh  }
3951ed2983Sdrh} {2 nil null 3 nil null}
4051ed2983Sdrh
4151ed2983Sdrhdo_test 1.2 {
4251ed2983Sdrh  db eval {
4351ed2983Sdrh    SELECT writefile('./file2.txt', 'A second test line');
4451ed2983Sdrh  }
4551ed2983Sdrh} {18}
4651ed2983Sdrhdo_test 1.3 {
4751ed2983Sdrh  set in [open ./file2.txt rb]
4851ed2983Sdrh  set x [read $in]
4951ed2983Sdrh  close $in
5051ed2983Sdrh  list $x [file size file2.txt]
5151ed2983Sdrh} {{A second test line} 18}
5251ed2983Sdrh
5351ed2983Sdrhdo_test 1.4 {
5451ed2983Sdrh  db eval {
5551ed2983Sdrh    SELECT writefile('./file2.txt', NULL);
5651ed2983Sdrh  }
5751ed2983Sdrh} {0}
5851ed2983Sdrhdo_test 1.5 {
5951ed2983Sdrh  file size ./file2.txt
6051ed2983Sdrh} {0}
6151ed2983Sdrh
6251ed2983Sdrhdo_test 1.6 {
63*a2412c16Sdrh  if {$::tcl_platform(platform)=="unix"} {
6451ed2983Sdrh    file attributes ./file2.txt -permissions r--r--r--
65*a2412c16Sdrh  } else {
66*a2412c16Sdrh    file attributes ./file2.txt -readonly 1
67*a2412c16Sdrh  }
6851ed2983Sdrh  db eval {
6951ed2983Sdrh    SELECT writefile('./file2.txt', 'Another test');
7051ed2983Sdrh  }
7151ed2983Sdrh} {nil}
7251ed2983Sdrhdo_test 1.7 {
73*a2412c16Sdrh  if {$::tcl_platform(platform)=="unix"} {
7451ed2983Sdrh    file attributes ./file2.txt -permissions rw-r--r--
75*a2412c16Sdrh  } else {
76*a2412c16Sdrh    file attributes ./file2.txt -readonly 0
77*a2412c16Sdrh  }
7851ed2983Sdrh  db eval {
7951ed2983Sdrh    SELECT writefile(NULL, 'Another test');
8051ed2983Sdrh  }
8151ed2983Sdrh} {nil}
8251ed2983Sdrh
8351ed2983Sdrhfinish_test
84