Annotation of embedaddon/sqlite3/test/capi3e.test, revision 1.1.1.1

1.1       misho       1: # 2010 Novemeber 18
                      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: # This file implements regression tests for SQLite library.  The
                     12: # focus of this script testing the callback-free C/C++ API.
                     13: #
                     14: # $Id: capi3e.test,v 1.70 2009/01/09 02:49:32 drh Exp $
                     15: #
                     16: 
                     17: set testdir [file dirname $argv0]
                     18: source $testdir/tester.tcl
                     19: 
                     20: # Make sure the system encoding is utf-8. Otherwise, if the system encoding
                     21: # is other than utf-8, [file isfile $x] may not refer to the same file
                     22: # as [sqlite3 db $x].
                     23: encoding system utf-8
                     24: 
                     25: # Do not use a codec for tests in this file, as the database file is
                     26: # manipulated directly using tcl scripts (using the [hexio_write] command).
                     27: #
                     28: do_not_use_codec
                     29: 
                     30: # Return the UTF-16 representation of the supplied UTF-8 string $str.
                     31: # If $nt is true, append two 0x00 bytes as a nul terminator.
                     32: proc utf16 {str {nt 1}} {
                     33:   set r [encoding convertto unicode $str]
                     34:   if {$nt} {
                     35:     append r "\x00\x00"
                     36:   }
                     37:   return $r
                     38: }
                     39: 
                     40: # Return the UTF-8 representation of the supplied UTF-16 string $str. 
                     41: proc utf8 {str} {
                     42:   # If $str ends in two 0x00 0x00 bytes, knock these off before
                     43:   # converting to UTF-8 using TCL.
                     44:   binary scan $str \c* vals
                     45:   if {[lindex $vals end]==0 && [lindex $vals end-1]==0} {
                     46:     set str [binary format \c* [lrange $vals 0 end-2]]
                     47:   }
                     48: 
                     49:   set r [encoding convertfrom unicode $str]
                     50:   return $r
                     51: }
                     52: 
                     53: # These tests complement those in capi2.test. They are organized
                     54: # as follows:
                     55: #
                     56: # capi3e-1.*: Test sqlite3_open with various UTF8 filenames
                     57: # capi3e-2.*: Test sqlite3_open16 with various UTF8 filenames
                     58: # capi3e-3.*: Test ATTACH with various UTF8 filenames
                     59: 
                     60: db close
                     61: 
                     62: # here's the list of file names we're testing
                     63: set names {t 1 t. 1. t.d 1.d t-1 1-1 t.db ä.db ë.db ö.db ü.db ÿ.db}
                     64: 
                     65: set i 0
                     66: foreach name $names {
                     67:   incr i
                     68:   do_test capi3e-1.1.$i {
                     69:     set db2 [sqlite3_open $name {}]
                     70:     sqlite3_errcode $db2
                     71:   } {SQLITE_OK}
                     72:   do_test capi3e-1.2.$i {
                     73:     sqlite3_close $db2
                     74:   } {SQLITE_OK}
                     75:   do_test capi3e-1.3.$i {
                     76:     file isfile $name
                     77:   } {1}
                     78: }
                     79: 
                     80: ifcapable {utf16} {
                     81:   set i 0
                     82:   foreach name $names {
                     83:     incr i
                     84:     do_test capi3e-2.1.$i {
                     85:       set db2 [sqlite3_open16 [utf16 $name] {}]
                     86:       sqlite3_errcode $db2
                     87:     } {SQLITE_OK}
                     88:     do_test capi3e-2.2.$i {
                     89:       sqlite3_close $db2
                     90:     } {SQLITE_OK}
                     91:     do_test capi3e-2.3.$i {
                     92:       file isfile $name
                     93:     } {1}
                     94:   }
                     95: }
                     96: 
                     97: ifcapable attach {
                     98:   do_test capi3e-3.1 {
                     99:     sqlite3 db2 base.db
                    100:   } {}
                    101:   set i 0
                    102:   foreach name $names {
                    103:     incr i
                    104:     do_test capi3e-3.2.$i {
                    105:       db2 eval "ATTACH DATABASE '$name' AS db$i;"
                    106:     } {}
                    107:     do_test capi3e-3.3.$i {
                    108:       db2 eval "DETACH DATABASE db$i;"
                    109:     } {}
                    110:   }
                    111:   do_test capi3e-3.4 {
                    112:     db2 close
                    113:   } {}
                    114: }
                    115: 
                    116: # clean up
                    117: forcedelete base.db
                    118: foreach name $names {
                    119:   forcedelete $name
                    120: }
                    121: 
                    122: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>