capi3e.test 2.9 KB

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