Artifact
3d49c01ef2a1a55f41d73cba2b23b5059ec460fe:
- File
test/capi3e.test
— part of check-in
[9e573198]
at
2014-02-14 00:25:03
on branch trunk
— Revise how the Tcl system encoding is handled by the test suite.
(user:
mistachkin
size: 3151)
[more...]
0000: 23 20 32 30 31 30 20 4e 6f 76 65 6d 65 62 65 72 # 2010 Novemeber
0010: 20 31 38 0a 23 0a 23 20 54 68 65 20 61 75 74 68 18.#.# The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 ource code. In
0050: 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 place of.# a leg
0060: 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 al notice, here
0070: 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 is a blessing:.#
0080: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f .# May you do
0090: 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 good and not ev
00a0: 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 il..# May you
00b0: 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 find forgivenes
00c0: 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 s for yourself a
00d0: 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 nd forgive other
00e0: 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 s..# May you
00f0: 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 share freely, ne
0100: 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 ver taking more
0110: 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 than you give..#
0120: 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .#**************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73 *********.# This
0170: 20 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 file implements
0180: 20 72 65 67 72 65 73 73 69 6f 6e 20 74 65 73 74 regression test
0190: 73 20 66 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 s for SQLite lib
01a0: 72 61 72 79 2e 20 20 54 68 65 0a 23 20 66 6f 63 rary. The.# foc
01b0: 75 73 20 6f 66 20 74 68 69 73 20 73 63 72 69 70 us of this scrip
01c0: 74 20 74 65 73 74 69 6e 67 20 74 68 65 20 63 61 t testing the ca
01d0: 6c 6c 62 61 63 6b 2d 66 72 65 65 20 43 2f 43 2b llback-free C/C+
01e0: 2b 20 41 50 49 2e 0a 23 0a 23 20 24 49 64 3a 20 + API..#.# $Id:
01f0: 63 61 70 69 33 65 2e 74 65 73 74 2c 76 20 31 2e capi3e.test,v 1.
0200: 37 30 20 32 30 30 39 2f 30 31 2f 30 39 20 30 32 70 2009/01/09 02
0210: 3a 34 39 3a 33 32 20 64 72 68 20 45 78 70 20 24 :49:32 drh Exp $
0220: 0a 23 0a 0a 73 65 74 20 74 65 73 74 64 69 72 20 .#..set testdir
0230: 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 24 61 [file dirname $a
0240: 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24 74 65 rgv0].source $te
0250: 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74 63 6c stdir/tester.tcl
0260: 0a 0a 23 20 4d 61 6b 65 20 73 75 72 65 20 74 68 ..# Make sure th
0270: 65 20 73 79 73 74 65 6d 20 65 6e 63 6f 64 69 6e e system encodin
0280: 67 20 69 73 20 75 74 66 2d 38 2e 20 4f 74 68 65 g is utf-8. Othe
0290: 72 77 69 73 65 2c 20 69 66 20 74 68 65 20 73 79 rwise, if the sy
02a0: 73 74 65 6d 20 65 6e 63 6f 64 69 6e 67 0a 23 20 stem encoding.#
02b0: 69 73 20 6f 74 68 65 72 20 74 68 61 6e 20 75 74 is other than ut
02c0: 66 2d 38 2c 20 5b 66 69 6c 65 20 69 73 66 69 6c f-8, [file isfil
02d0: 65 20 24 78 5d 20 6d 61 79 20 6e 6f 74 20 72 65 e $x] may not re
02e0: 66 65 72 20 74 6f 20 74 68 65 20 73 61 6d 65 20 fer to the same
02f0: 66 69 6c 65 0a 23 20 61 73 20 5b 73 71 6c 69 74 file.# as [sqlit
0300: 65 33 20 64 62 20 24 78 5d 2e 0a 23 0a 23 20 54 e3 db $x]..#.# T
0310: 68 69 73 20 69 73 20 6e 6f 20 6c 6f 6e 67 65 72 his is no longer
0320: 20 6e 65 65 64 65 64 20 68 65 72 65 20 62 65 63 needed here bec
0330: 61 75 73 65 20 69 74 20 73 68 6f 75 6c 64 20 62 ause it should b
0340: 65 20 64 6f 6e 65 20 77 69 74 68 69 6e 20 74 68 e done within th
0350: 65 20 74 65 73 74 0a 23 20 66 69 78 74 75 72 65 e test.# fixture
0360: 20 65 78 65 63 75 74 61 62 6c 65 20 69 74 73 65 executable itse
0370: 6c 66 2c 20 76 69 61 20 54 63 6c 5f 53 65 74 53 lf, via Tcl_SetS
0380: 79 73 74 65 6d 45 6e 63 6f 64 69 6e 67 2e 0a 23 ystemEncoding..#
0390: 0a 23 20 65 6e 63 6f 64 69 6e 67 20 73 79 73 74 .# encoding syst
03a0: 65 6d 20 75 74 66 2d 38 0a 0a 23 20 44 6f 20 6e em utf-8..# Do n
03b0: 6f 74 20 75 73 65 20 61 20 63 6f 64 65 63 20 66 ot use a codec f
03c0: 6f 72 20 74 65 73 74 73 20 69 6e 20 74 68 69 73 or tests in this
03d0: 20 66 69 6c 65 2c 20 61 73 20 74 68 65 20 64 61 file, as the da
03e0: 74 61 62 61 73 65 20 66 69 6c 65 20 69 73 0a 23 tabase file is.#
03f0: 20 6d 61 6e 69 70 75 6c 61 74 65 64 20 64 69 72 manipulated dir
0400: 65 63 74 6c 79 20 75 73 69 6e 67 20 74 63 6c 20 ectly using tcl
0410: 73 63 72 69 70 74 73 20 28 75 73 69 6e 67 20 74 scripts (using t
0420: 68 65 20 5b 68 65 78 69 6f 5f 77 72 69 74 65 5d he [hexio_write]
0430: 20 63 6f 6d 6d 61 6e 64 29 2e 0a 23 0a 64 6f 5f command)..#.do_
0440: 6e 6f 74 5f 75 73 65 5f 63 6f 64 65 63 0a 0a 23 not_use_codec..#
0450: 20 52 65 74 75 72 6e 20 74 68 65 20 55 54 46 2d Return the UTF-
0460: 31 36 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 16 representatio
0470: 6e 20 6f 66 20 74 68 65 20 73 75 70 70 6c 69 65 n of the supplie
0480: 64 20 55 54 46 2d 38 20 73 74 72 69 6e 67 20 24 d UTF-8 string $
0490: 73 74 72 2e 0a 23 20 49 66 20 24 6e 74 20 69 73 str..# If $nt is
04a0: 20 74 72 75 65 2c 20 61 70 70 65 6e 64 20 74 77 true, append tw
04b0: 6f 20 30 78 30 30 20 62 79 74 65 73 20 61 73 20 o 0x00 bytes as
04c0: 61 20 6e 75 6c 20 74 65 72 6d 69 6e 61 74 6f 72 a nul terminator
04d0: 2e 0a 70 72 6f 63 20 75 74 66 31 36 20 7b 73 74 ..proc utf16 {st
04e0: 72 20 7b 6e 74 20 31 7d 7d 20 7b 0a 20 20 73 65 r {nt 1}} {. se
04f0: 74 20 72 20 5b 65 6e 63 6f 64 69 6e 67 20 63 6f t r [encoding co
0500: 6e 76 65 72 74 74 6f 20 75 6e 69 63 6f 64 65 20 nvertto unicode
0510: 24 73 74 72 5d 0a 20 20 69 66 20 7b 24 6e 74 7d $str]. if {$nt}
0520: 20 7b 0a 20 20 20 20 61 70 70 65 6e 64 20 72 20 {. append r
0530: 22 5c 78 30 30 5c 78 30 30 22 0a 20 20 7d 0a 20 "\x00\x00". }.
0540: 20 72 65 74 75 72 6e 20 24 72 0a 7d 0a 0a 23 20 return $r.}..#
0550: 52 65 74 75 72 6e 20 74 68 65 20 55 54 46 2d 38 Return the UTF-8
0560: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 representation
0570: 6f 66 20 74 68 65 20 73 75 70 70 6c 69 65 64 20 of the supplied
0580: 55 54 46 2d 31 36 20 73 74 72 69 6e 67 20 24 73 UTF-16 string $s
0590: 74 72 2e 20 0a 70 72 6f 63 20 75 74 66 38 20 7b tr. .proc utf8 {
05a0: 73 74 72 7d 20 7b 0a 20 20 23 20 49 66 20 24 73 str} {. # If $s
05b0: 74 72 20 65 6e 64 73 20 69 6e 20 74 77 6f 20 30 tr ends in two 0
05c0: 78 30 30 20 30 78 30 30 20 62 79 74 65 73 2c 20 x00 0x00 bytes,
05d0: 6b 6e 6f 63 6b 20 74 68 65 73 65 20 6f 66 66 20 knock these off
05e0: 62 65 66 6f 72 65 0a 20 20 23 20 63 6f 6e 76 65 before. # conve
05f0: 72 74 69 6e 67 20 74 6f 20 55 54 46 2d 38 20 75 rting to UTF-8 u
0600: 73 69 6e 67 20 54 43 4c 2e 0a 20 20 62 69 6e 61 sing TCL.. bina
0610: 72 79 20 73 63 61 6e 20 24 73 74 72 20 5c 63 2a ry scan $str \c*
0620: 20 76 61 6c 73 0a 20 20 69 66 20 7b 5b 6c 69 6e vals. if {[lin
0630: 64 65 78 20 24 76 61 6c 73 20 65 6e 64 5d 3d 3d dex $vals end]==
0640: 30 20 26 26 20 5b 6c 69 6e 64 65 78 20 24 76 61 0 && [lindex $va
0650: 6c 73 20 65 6e 64 2d 31 5d 3d 3d 30 7d 20 7b 0a ls end-1]==0} {.
0660: 20 20 20 20 73 65 74 20 73 74 72 20 5b 62 69 6e set str [bin
0670: 61 72 79 20 66 6f 72 6d 61 74 20 5c 63 2a 20 5b ary format \c* [
0680: 6c 72 61 6e 67 65 20 24 76 61 6c 73 20 30 20 65 lrange $vals 0 e
0690: 6e 64 2d 32 5d 5d 0a 20 20 7d 0a 0a 20 20 73 65 nd-2]]. }.. se
06a0: 74 20 72 20 5b 65 6e 63 6f 64 69 6e 67 20 63 6f t r [encoding co
06b0: 6e 76 65 72 74 66 72 6f 6d 20 75 6e 69 63 6f 64 nvertfrom unicod
06c0: 65 20 24 73 74 72 5d 0a 20 20 72 65 74 75 72 6e e $str]. return
06d0: 20 24 72 0a 7d 0a 0a 23 20 54 68 65 73 65 20 74 $r.}..# These t
06e0: 65 73 74 73 20 63 6f 6d 70 6c 65 6d 65 6e 74 20 ests complement
06f0: 74 68 6f 73 65 20 69 6e 20 63 61 70 69 32 2e 74 those in capi2.t
0700: 65 73 74 2e 20 54 68 65 79 20 61 72 65 20 6f 72 est. They are or
0710: 67 61 6e 69 7a 65 64 0a 23 20 61 73 20 66 6f 6c ganized.# as fol
0720: 6c 6f 77 73 3a 0a 23 0a 23 20 63 61 70 69 33 65 lows:.#.# capi3e
0730: 2d 31 2e 2a 3a 20 54 65 73 74 20 73 71 6c 69 74 -1.*: Test sqlit
0740: 65 33 5f 6f 70 65 6e 20 77 69 74 68 20 76 61 72 e3_open with var
0750: 69 6f 75 73 20 55 54 46 38 20 66 69 6c 65 6e 61 ious UTF8 filena
0760: 6d 65 73 0a 23 20 63 61 70 69 33 65 2d 32 2e 2a mes.# capi3e-2.*
0770: 3a 20 54 65 73 74 20 73 71 6c 69 74 65 33 5f 6f : Test sqlite3_o
0780: 70 65 6e 31 36 20 77 69 74 68 20 76 61 72 69 6f pen16 with vario
0790: 75 73 20 55 54 46 38 20 66 69 6c 65 6e 61 6d 65 us UTF8 filename
07a0: 73 0a 23 20 63 61 70 69 33 65 2d 33 2e 2a 3a 20 s.# capi3e-3.*:
07b0: 54 65 73 74 20 41 54 54 41 43 48 20 77 69 74 68 Test ATTACH with
07c0: 20 76 61 72 69 6f 75 73 20 55 54 46 38 20 66 69 various UTF8 fi
07d0: 6c 65 6e 61 6d 65 73 0a 0a 64 62 20 63 6c 6f 73 lenames..db clos
07e0: 65 0a 0a 23 20 68 65 72 65 27 73 20 74 68 65 20 e..# here's the
07f0: 6c 69 73 74 20 6f 66 20 66 69 6c 65 20 6e 61 6d list of file nam
0800: 65 73 20 77 65 27 72 65 20 74 65 73 74 69 6e 67 es we're testing
0810: 0a 73 65 74 20 6e 61 6d 65 73 20 7b 74 20 31 20 .set names {t 1
0820: 74 2e 20 31 2e 20 74 2e 64 20 31 2e 64 20 74 2d t. 1. t.d 1.d t-
0830: 31 20 31 2d 31 20 74 2e 64 62 20 c3 a4 2e 64 62 1 1-1 t.db ...db
0840: 20 c3 ab 2e 64 62 20 c3 b6 2e 64 62 20 c3 bc 2e ...db ...db ...
0850: 64 62 20 c3 bf 2e 64 62 7d 0a 0a 73 65 74 20 69 db ...db}..set i
0860: 20 30 0a 66 6f 72 65 61 63 68 20 6e 61 6d 65 20 0.foreach name
0870: 24 6e 61 6d 65 73 20 7b 0a 20 20 69 6e 63 72 20 $names {. incr
0880: 69 0a 20 20 64 6f 5f 74 65 73 74 20 63 61 70 69 i. do_test capi
0890: 33 65 2d 31 2e 31 2e 24 69 20 7b 0a 20 20 20 20 3e-1.1.$i {.
08a0: 73 65 74 20 64 62 32 20 5b 73 71 6c 69 74 65 33 set db2 [sqlite3
08b0: 5f 6f 70 65 6e 20 24 6e 61 6d 65 20 7b 7d 5d 0a _open $name {}].
08c0: 20 20 20 20 73 71 6c 69 74 65 33 5f 65 72 72 63 sqlite3_errc
08d0: 6f 64 65 20 24 64 62 32 0a 20 20 7d 20 7b 53 51 ode $db2. } {SQ
08e0: 4c 49 54 45 5f 4f 4b 7d 0a 20 20 64 6f 5f 74 65 LITE_OK}. do_te
08f0: 73 74 20 63 61 70 69 33 65 2d 31 2e 32 2e 24 69 st capi3e-1.2.$i
0900: 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 63 {. sqlite3_c
0910: 6c 6f 73 65 20 24 64 62 32 0a 20 20 7d 20 7b 53 lose $db2. } {S
0920: 51 4c 49 54 45 5f 4f 4b 7d 0a 20 20 64 6f 5f 74 QLITE_OK}. do_t
0930: 65 73 74 20 63 61 70 69 33 65 2d 31 2e 33 2e 24 est capi3e-1.3.$
0940: 69 20 7b 0a 20 20 20 20 66 69 6c 65 20 69 73 66 i {. file isf
0950: 69 6c 65 20 24 6e 61 6d 65 0a 20 20 7d 20 7b 31 ile $name. } {1
0960: 7d 0a 7d 0a 0a 69 66 63 61 70 61 62 6c 65 20 7b }.}..ifcapable {
0970: 75 74 66 31 36 7d 20 7b 0a 20 20 73 65 74 20 69 utf16} {. set i
0980: 20 30 0a 20 20 66 6f 72 65 61 63 68 20 6e 61 6d 0. foreach nam
0990: 65 20 24 6e 61 6d 65 73 20 7b 0a 20 20 20 20 69 e $names {. i
09a0: 6e 63 72 20 69 0a 20 20 20 20 64 6f 5f 74 65 73 ncr i. do_tes
09b0: 74 20 63 61 70 69 33 65 2d 32 2e 31 2e 24 69 20 t capi3e-2.1.$i
09c0: 7b 0a 20 20 20 20 20 20 73 65 74 20 64 62 32 20 {. set db2
09d0: 5b 73 71 6c 69 74 65 33 5f 6f 70 65 6e 31 36 20 [sqlite3_open16
09e0: 5b 75 74 66 31 36 20 24 6e 61 6d 65 5d 20 7b 7d [utf16 $name] {}
09f0: 5d 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f ]. sqlite3_
0a00: 65 72 72 63 6f 64 65 20 24 64 62 32 0a 20 20 20 errcode $db2.
0a10: 20 7d 20 7b 53 51 4c 49 54 45 5f 4f 4b 7d 0a 20 } {SQLITE_OK}.
0a20: 20 20 20 64 6f 5f 74 65 73 74 20 63 61 70 69 33 do_test capi3
0a30: 65 2d 32 2e 32 2e 24 69 20 7b 0a 20 20 20 20 20 e-2.2.$i {.
0a40: 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 20 24 sqlite3_close $
0a50: 64 62 32 0a 20 20 20 20 7d 20 7b 53 51 4c 49 54 db2. } {SQLIT
0a60: 45 5f 4f 4b 7d 0a 20 20 20 20 64 6f 5f 74 65 73 E_OK}. do_tes
0a70: 74 20 63 61 70 69 33 65 2d 32 2e 33 2e 24 69 20 t capi3e-2.3.$i
0a80: 7b 0a 20 20 20 20 20 20 66 69 6c 65 20 69 73 66 {. file isf
0a90: 69 6c 65 20 24 6e 61 6d 65 0a 20 20 20 20 7d 20 ile $name. }
0aa0: 7b 31 7d 0a 20 20 7d 0a 7d 0a 0a 69 66 63 61 70 {1}. }.}..ifcap
0ab0: 61 62 6c 65 20 61 74 74 61 63 68 20 7b 0a 20 20 able attach {.
0ac0: 64 6f 5f 74 65 73 74 20 63 61 70 69 33 65 2d 33 do_test capi3e-3
0ad0: 2e 31 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 .1 {. sqlite3
0ae0: 20 64 62 32 20 62 61 73 65 2e 64 62 0a 20 20 7d db2 base.db. }
0af0: 20 7b 7d 0a 20 20 73 65 74 20 69 20 30 0a 20 20 {}. set i 0.
0b00: 66 6f 72 65 61 63 68 20 6e 61 6d 65 20 24 6e 61 foreach name $na
0b10: 6d 65 73 20 7b 0a 20 20 20 20 69 6e 63 72 20 69 mes {. incr i
0b20: 0a 20 20 20 20 64 6f 5f 74 65 73 74 20 63 61 70 . do_test cap
0b30: 69 33 65 2d 33 2e 32 2e 24 69 20 7b 0a 20 20 20 i3e-3.2.$i {.
0b40: 20 20 20 64 62 32 20 65 76 61 6c 20 22 41 54 54 db2 eval "ATT
0b50: 41 43 48 20 44 41 54 41 42 41 53 45 20 27 24 6e ACH DATABASE '$n
0b60: 61 6d 65 27 20 41 53 20 64 62 24 69 3b 22 0a 20 ame' AS db$i;".
0b70: 20 20 20 7d 20 7b 7d 0a 20 20 20 20 64 6f 5f 74 } {}. do_t
0b80: 65 73 74 20 63 61 70 69 33 65 2d 33 2e 33 2e 24 est capi3e-3.3.$
0b90: 69 20 7b 0a 20 20 20 20 20 20 64 62 32 20 65 76 i {. db2 ev
0ba0: 61 6c 20 22 44 45 54 41 43 48 20 44 41 54 41 42 al "DETACH DATAB
0bb0: 41 53 45 20 64 62 24 69 3b 22 0a 20 20 20 20 7d ASE db$i;". }
0bc0: 20 7b 7d 0a 20 20 7d 0a 20 20 64 6f 5f 74 65 73 {}. }. do_tes
0bd0: 74 20 63 61 70 69 33 65 2d 33 2e 34 20 7b 0a 20 t capi3e-3.4 {.
0be0: 20 20 20 64 62 32 20 63 6c 6f 73 65 0a 20 20 7d db2 close. }
0bf0: 20 7b 7d 0a 7d 0a 0a 23 20 63 6c 65 61 6e 20 75 {}.}..# clean u
0c00: 70 0a 66 6f 72 63 65 64 65 6c 65 74 65 20 62 61 p.forcedelete ba
0c10: 73 65 2e 64 62 0a 66 6f 72 65 61 63 68 20 6e 61 se.db.foreach na
0c20: 6d 65 20 24 6e 61 6d 65 73 20 7b 0a 20 20 66 6f me $names {. fo
0c30: 72 63 65 64 65 6c 65 74 65 20 24 6e 61 6d 65 0a rcedelete $name.
0c40: 7d 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a }..finish_test.