19fc47111Sshaneh# 2010 Sept 29 29fc47111Sshaneh# 39fc47111Sshaneh# The author disclaims copyright to this source code. In place of 49fc47111Sshaneh# a legal notice, here is a blessing: 59fc47111Sshaneh# 69fc47111Sshaneh# May you do good and not evil. 79fc47111Sshaneh# May you find forgiveness for yourself and forgive others. 89fc47111Sshaneh# May you share freely, never taking more than you give. 99fc47111Sshaneh# 109fc47111Sshaneh#*********************************************************************** 119fc47111Sshaneh# This file implements regression tests for SQLite library. The focus of 129fc47111Sshaneh# this file is testing the SQLite routines used for converting between the 139fc47111Sshaneh# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and 149fc47111Sshaneh# UTF-16be). 159fc47111Sshaneh# 169fc47111Sshaneh# $Id: enc4.test,v 1.0 2010/09/29 08:29:32 shaneh Exp $ 179fc47111Sshaneh 189fc47111Sshanehset testdir [file dirname $argv0] 199fc47111Sshanehsource $testdir/tester.tcl 209fc47111Sshaneh 219fc47111Sshaneh# If UTF16 support is disabled, ignore the tests in this file 229fc47111Sshaneh# 239fc47111Sshanehifcapable {!utf16} { 249fc47111Sshaneh finish_test 259fc47111Sshaneh return 269fc47111Sshaneh} 279fc47111Sshaneh 289fc47111Sshanehdb close 299fc47111Sshaneh 309fc47111Sshaneh# The three unicode encodings understood by SQLite. 319fc47111Sshanehset encodings [list UTF-8 UTF-16le UTF-16be] 329fc47111Sshaneh 339fc47111Sshaneh# initial value to use in SELECT 340246dcedSshanehset inits [list 1 1.0 1. 1e0] 359fc47111Sshaneh 369fc47111Sshaneh# vals 379fc47111Sshanehset vals [list\ 389fc47111Sshaneh"922337203685477580792233720368547758079223372036854775807"\ 399fc47111Sshaneh"100000000000000000000000000000000000000000000000000000000"\ 409fc47111Sshaneh"1.0000000000000000000000000000000000000000000000000000000"\ 419fc47111Sshaneh] 429fc47111Sshaneh 439fc47111Sshanehset i 1 449fc47111Sshanehforeach enc $encodings { 459fc47111Sshaneh 46*fda06befSmistachkin forcedelete test.db 479fc47111Sshaneh sqlite3 db test.db 489fc47111Sshaneh db eval "PRAGMA encoding = \"$enc\"" 499fc47111Sshaneh 509fc47111Sshaneh do_test enc4-$i.1 { 519fc47111Sshaneh db eval {PRAGMA encoding} 529fc47111Sshaneh } $enc 539fc47111Sshaneh 549fc47111Sshaneh set j 1 559fc47111Sshaneh foreach init $inits { 569fc47111Sshaneh 579fc47111Sshaneh do_test enc4-$i.$j.2 { 589fc47111Sshaneh set S [sqlite3_prepare_v2 db "SELECT $init+?" -1 dummy] 599fc47111Sshaneh sqlite3_expired $S 609fc47111Sshaneh } {0} 619fc47111Sshaneh 629fc47111Sshaneh set k 1 639fc47111Sshaneh foreach val $vals { 644f529e87Sshaneh for {set x 1} {$x<16} {incr x} { 659fc47111Sshaneh set part [expr $init + [string range $val 0 [expr $x-1]]] 669fc47111Sshaneh 674f529e87Sshaneh do_realnum_test enc4-$i.$j.$k.3.$x { 689fc47111Sshaneh sqlite3_reset $S 699fc47111Sshaneh sqlite3_bind_text $S 1 $val $x 709fc47111Sshaneh sqlite3_step $S 719fc47111Sshaneh sqlite3_column_text $S 0 729fc47111Sshaneh } [list $part] 739fc47111Sshaneh 744f529e87Sshaneh do_realnum_test enc4-$i.$j.$k.4.$x { 759fc47111Sshaneh sqlite3_reset $S 769fc47111Sshaneh sqlite3_bind_text16 $S 1 [encoding convertto unicode $val] [expr $x*2] 779fc47111Sshaneh sqlite3_step $S 789fc47111Sshaneh sqlite3_column_text $S 0 799fc47111Sshaneh } [list $part] 809fc47111Sshaneh } 819fc47111Sshaneh 829fc47111Sshaneh incr k 839fc47111Sshaneh } 849fc47111Sshaneh 859fc47111Sshaneh do_test enc4-$i.$j.5 { 869fc47111Sshaneh sqlite3_finalize $S 879fc47111Sshaneh } {SQLITE_OK} 889fc47111Sshaneh 899fc47111Sshaneh incr j 909fc47111Sshaneh } 919fc47111Sshaneh 929fc47111Sshaneh db close 939fc47111Sshaneh incr i 949fc47111Sshaneh} 959fc47111Sshaneh 96*fda06befSmistachkinforcedelete test.db 979fc47111Sshanehsqlite3 db test.db 989fc47111Sshaneh 999fc47111Sshanehdo_test enc4-4.1 { 1009fc47111Sshaneh db eval "select 1+1." 1019fc47111Sshaneh} {2.0} 1029fc47111Sshaneh 1030246dcedSshanehdo_test enc4-4.2.1 { 1049fc47111Sshaneh set S [sqlite3_prepare_v2 db "SELECT 1+1." -1 dummy] 1059fc47111Sshaneh sqlite3_step $S 1069fc47111Sshaneh sqlite3_column_text $S 0 1079fc47111Sshaneh} {2.0} 1089fc47111Sshaneh 1090246dcedSshanehdo_test enc4-4.2.2 { 1100246dcedSshaneh sqlite3_finalize $S 1110246dcedSshaneh} {SQLITE_OK} 1120246dcedSshaneh 1130246dcedSshanehdo_test enc4-4.3.1 { 1149fc47111Sshaneh set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] 1159fc47111Sshaneh sqlite3_bind_text $S 1 "1." 2 1169fc47111Sshaneh sqlite3_step $S 1179fc47111Sshaneh sqlite3_column_text $S 0 1189fc47111Sshaneh} {2.0} 1199fc47111Sshaneh 1200246dcedSshanehdo_test enc4-4.3.2 { 1210246dcedSshaneh sqlite3_finalize $S 1220246dcedSshaneh} {SQLITE_OK} 1230246dcedSshaneh 1240246dcedSshanehdo_test enc4-4.4.1 { 1259fc47111Sshaneh set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] 1269fc47111Sshaneh sqlite3_bind_text $S 1 "1.0" 2 1279fc47111Sshaneh sqlite3_step $S 1289fc47111Sshaneh sqlite3_column_text $S 0 1299fc47111Sshaneh} {2.0} 1309fc47111Sshaneh 1310246dcedSshanehdo_test enc4-4.4.2 { 1320246dcedSshaneh sqlite3_finalize $S 1330246dcedSshaneh} {SQLITE_OK} 1340246dcedSshaneh 1350246dcedSshanehdb close 1369fc47111Sshaneh 1379fc47111Sshanehfinish_test 138