enc4.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # 2010 Sept 29
  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 focus of
  12. # this file is testing the SQLite routines used for converting between the
  13. # various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
  14. # UTF-16be).
  15. #
  16. # $Id: enc4.test,v 1.0 2010/09/29 08:29:32 shaneh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # If UTF16 support is disabled, ignore the tests in this file
  20. #
  21. ifcapable {!utf16} {
  22. finish_test
  23. return
  24. }
  25. db close
  26. # The three unicode encodings understood by SQLite.
  27. set encodings [list UTF-8 UTF-16le UTF-16be]
  28. # initial value to use in SELECT
  29. set inits [list 1 1.0 1. 1e0]
  30. # vals
  31. set vals [list\
  32. "922337203685477580792233720368547758079223372036854775807"\
  33. "100000000000000000000000000000000000000000000000000000000"\
  34. "1.0000000000000000000000000000000000000000000000000000000"\
  35. ]
  36. set i 1
  37. foreach enc $encodings {
  38. forcedelete test.db
  39. sqlite3 db test.db
  40. db eval "PRAGMA encoding = \"$enc\""
  41. do_test enc4-$i.1 {
  42. db eval {PRAGMA encoding}
  43. } $enc
  44. set j 1
  45. foreach init $inits {
  46. do_test enc4-$i.$j.2 {
  47. set S [sqlite3_prepare_v2 db "SELECT $init+?" -1 dummy]
  48. sqlite3_expired $S
  49. } {0}
  50. set k 1
  51. foreach val $vals {
  52. for {set x 1} {$x<16} {incr x} {
  53. set part [expr $init + [string range $val 0 [expr $x-1]]]
  54. do_realnum_test enc4-$i.$j.$k.3.$x {
  55. sqlite3_reset $S
  56. sqlite3_bind_text $S 1 $val $x
  57. sqlite3_step $S
  58. sqlite3_column_text $S 0
  59. } [list $part]
  60. do_realnum_test enc4-$i.$j.$k.4.$x {
  61. sqlite3_reset $S
  62. sqlite3_bind_text16 $S 1 [encoding convertto unicode $val] [expr $x*2]
  63. sqlite3_step $S
  64. sqlite3_column_text $S 0
  65. } [list $part]
  66. }
  67. incr k
  68. }
  69. do_test enc4-$i.$j.5 {
  70. sqlite3_finalize $S
  71. } {SQLITE_OK}
  72. incr j
  73. }
  74. db close
  75. incr i
  76. }
  77. forcedelete test.db
  78. sqlite3 db test.db
  79. do_test enc4-4.1 {
  80. db eval "select 1+1."
  81. } {2.0}
  82. do_test enc4-4.2.1 {
  83. set S [sqlite3_prepare_v2 db "SELECT 1+1." -1 dummy]
  84. sqlite3_step $S
  85. sqlite3_column_text $S 0
  86. } {2.0}
  87. do_test enc4-4.2.2 {
  88. sqlite3_finalize $S
  89. } {SQLITE_OK}
  90. do_test enc4-4.3.1 {
  91. set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy]
  92. sqlite3_bind_text $S 1 "1." 2
  93. sqlite3_step $S
  94. sqlite3_column_text $S 0
  95. } {2.0}
  96. do_test enc4-4.3.2 {
  97. sqlite3_finalize $S
  98. } {SQLITE_OK}
  99. do_test enc4-4.4.1 {
  100. set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy]
  101. sqlite3_bind_text $S 1 "1.0" 2
  102. sqlite3_step $S
  103. sqlite3_column_text $S 0
  104. } {2.0}
  105. do_test enc4-4.4.2 {
  106. sqlite3_finalize $S
  107. } {SQLITE_OK}
  108. db close
  109. finish_test