1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-01-06 08:01:16 +03:00
Files
sqlite/test/ctime.test
shaneh 915c8bdbbd Changes to compile time option diags to report values for some defines.
Added test cases to TCL test suite (ctime.test).

FossilOrigin-Name: dd480f62afa56ff85c2dd57ee7a16eee427e823f
2010-02-24 19:36:10 +00:00

240 lines
5.1 KiB
Plaintext

# 2009 February 24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the compile time diagnostic
# functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Test organization:
#
# ctime-1.*: Test pragma support.
# ctime-2.*: Test function support.
#
ifcapable !pragma||!compileoption_diags {
finish_test
return
}
#####################
# ctime-1.*: Test pragma support.
do_test ctime-1.1.1 {
catchsql {
PRAGMA compile_options();
}
} {1 {near ")": syntax error}}
do_test ctime-1.1.2 {
catchsql {
PRAGMA compile_options(NULL);
}
} {1 {near "NULL": syntax error}}
do_test ctime-1.1.3 {
catchsql {
PRAGMA compile_options *;
}
} {1 {near "*": syntax error}}
do_test ctime-1.2.1 {
set ans [ catchsql {
PRAGMA compile_options;
} ]
list [ lindex $ans 0 ]
} {0}
# the results should be in sorted order already
do_test ctime-1.2.2 {
set ans [ catchsql {
PRAGMA compile_options;
} ]
list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ]
} {0 1}
do_test ctime-1.3.1 {
catchsql {
PRAGMA compile_option();
}
} {1 {near ")": syntax error}}
do_test ctime-1.3.2 {
catchsql {
PRAGMA compile_option(NULL);
}
} {1 {near "NULL": syntax error}}
do_test ctime-1.3.3 {
catchsql {
PRAGMA compile_option foo;
}
} {1 {near "foo": syntax error}}
do_test ctime-1.3.4 {
catchsql {
PRAGMA compile_option 'foo';
}
} {1 {near "'foo'": syntax error}}
# SQLITE_THREADSAFE should pretty much always be defined
# one way or the other, and it must have a value of 0 or 1.
do_test ctime-1.4.1 {
catchsql {
PRAGMA compile_option('SQLITE_THREADSAFE');
}
} {0 1}
do_test ctime-1.4.2 {
catchsql {
PRAGMA compile_option('THREADSAFE');
}
} {0 1}
do_test ctime-1.4.3 {
catchsql {
PRAGMA compile_option("THREADSAFE");
}
} {0 1}
do_test ctime-1.4.4 {
catchsql {
PRAGMA compile_option='THREADSAFE';
}
} {0 1}
do_test ctime-1.4.5 {
catchsql {
PRAGMA compile_option="THREADSAFE";
}
} {0 1}
do_test ctime-1.4 {
set ans1 [ catchsql {
PRAGMA compile_option('THREADSAFE=0');
} ]
set ans2 [ catchsql {
PRAGMA compile_option('THREADSAFE=1');
} ]
lsort [ list $ans1 $ans2 ]
} {{0 0} {0 1}}
do_test ctime-1.5 {
execsql {
PRAGMA compile_option('THREADSAFE=');
}
} {0}
do_test ctime-1.6 {
execsql {
PRAGMA compile_option('SQLITE_OMIT_COMPILEOPTION_DIAGS');
}
} {0}
do_test ctime-1.7 {
execsql {
PRAGMA compile_option('OMIT_COMPILEOPTION_DIAGS');
}
} {0}
#####################
# ctime-2.*: Test function support.
do_test ctime-2.1.1 {
catchsql {
SELECT sqlite_compile_option_used();
}
} {1 {wrong number of arguments to function sqlite_compile_option_used()}}
do_test ctime-2.1.2 {
catchsql {
SELECT sqlite_compile_option_used(NULL);
}
} {0 {{}}}
do_test ctime-2.1.3 {
catchsql {
SELECT sqlite_compile_option_used("");
}
} {0 0}
do_test ctime-2.1.4 {
catchsql {
SELECT sqlite_compile_option_used('');
}
} {0 0}
do_test ctime-2.1.5 {
catchsql {
SELECT sqlite_compile_option_used(foo);
}
} {1 {no such column: foo}}
do_test ctime-2.1.6 {
catchsql {
SELECT sqlite_compile_option_used('THREADSAFE', 0);
}
} {1 {wrong number of arguments to function sqlite_compile_option_used()}}
do_test ctime-2.2.1 {
catchsql {
SELECT sqlite_compile_option_get();
}
} {1 {wrong number of arguments to function sqlite_compile_option_get()}}
do_test ctime-2.2.2 {
catchsql {
SELECT sqlite_compile_option_get(0, 0);
}
} {1 {wrong number of arguments to function sqlite_compile_option_get()}}
# This assumes there is at least 1 compile time option
# (see SQLITE_THREADSAFE above).
do_test ctime-2.3 {
catchsql {
SELECT sqlite_compile_option_used(sqlite_compile_option_get(0));
}
} {0 1}
# This assumes there is at least 1 compile time option
# (see SQLITE_THREADSAFE above).
do_test ctime-2.4 {
set res [ catchsql {
SELECT sqlite_compile_option_get(0);
} ]
list [lindex $res 0]
} {0}
# Get the list of defines using the pragma,
# then try querying each one with the functions.
set ans [ catchsql {
PRAGMA compile_options;
} ]
set opts [ lindex $ans 1 ]
set tc 1
foreach opt $opts {
do_test ctime-2.5.$tc {
set N [ expr {$tc-1} ]
set ans1 [ catchsql {
SELECT sqlite_compile_option_get($N);
} ]
set ans2 [ catchsql {
SELECT sqlite_compile_option_used($opt);
} ]
list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \
[ expr { $ans2 } ]
} {0 1 {0 1}}
incr tc 1
}
# test 1 past array bounds
do_test ctime-2.5.$tc {
set N [ expr {$tc-1} ]
set ans [ catchsql {
SELECT sqlite_compile_option_get($N);
} ]
} {0 {{}}}
incr tc 1
# test 1 before array bounds (N=-1)
do_test ctime-2.5.$tc {
set N -1
set ans [ catchsql {
SELECT sqlite_compile_option_get($N);
} ]
} {0 {{}}}
finish_test