ctime.test 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # 2009 February 24
  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.
  12. #
  13. # This file implements tests for the compile time diagnostic
  14. # functions.
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Test organization:
  19. #
  20. # ctime-1.*: Test pragma support.
  21. # ctime-2.*: Test function support.
  22. #
  23. ifcapable !pragma||!compileoption_diags {
  24. finish_test
  25. return
  26. }
  27. #####################
  28. # ctime-1.*: Test pragma support.
  29. do_test ctime-1.1.1 {
  30. catchsql {
  31. PRAGMA compile_options();
  32. }
  33. } {1 {near ")": syntax error}}
  34. do_test ctime-1.1.2 {
  35. catchsql {
  36. PRAGMA compile_options(NULL);
  37. }
  38. } {1 {near "NULL": syntax error}}
  39. do_test ctime-1.1.3 {
  40. catchsql {
  41. PRAGMA compile_options *;
  42. }
  43. } {1 {near "*": syntax error}}
  44. do_test ctime-1.2.1 {
  45. set ans [ catchsql {
  46. PRAGMA compile_options;
  47. } ]
  48. list [ lindex $ans 0 ]
  49. } {0}
  50. # the results should be in sorted order already
  51. do_test ctime-1.2.2 {
  52. set ans [ catchsql {
  53. PRAGMA compile_options;
  54. } ]
  55. list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ]
  56. } {0 1}
  57. # SQLITE_THREADSAFE should pretty much always be defined
  58. # one way or the other, and it must have a value of 0 or 1.
  59. do_test ctime-1.4.1 {
  60. catchsql {
  61. SELECT sqlite_compileoption_used('SQLITE_THREADSAFE');
  62. }
  63. } {0 1}
  64. do_test ctime-1.4.2 {
  65. catchsql {
  66. SELECT sqlite_compileoption_used('THREADSAFE');
  67. }
  68. } {0 1}
  69. do_test ctime-1.4.3 {
  70. catchsql {
  71. SELECT sqlite_compileoption_used("THREADSAFE");
  72. }
  73. } {0 1}
  74. do_test ctime-1.5 {
  75. set ans1 [ catchsql {
  76. SELECT sqlite_compileoption_used('THREADSAFE=0');
  77. } ]
  78. set ans2 [ catchsql {
  79. SELECT sqlite_compileoption_used('THREADSAFE=1');
  80. } ]
  81. set ans3 [ catchsql {
  82. SELECT sqlite_compileoption_used('THREADSAFE=2');
  83. } ]
  84. lsort [ list $ans1 $ans2 $ans3 ]
  85. } {{0 0} {0 0} {0 1}}
  86. do_test ctime-1.6 {
  87. execsql {
  88. SELECT sqlite_compileoption_used('THREADSAFE=');
  89. }
  90. } {0}
  91. do_test ctime-1.7.1 {
  92. execsql {
  93. SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS');
  94. }
  95. } {0}
  96. do_test ctime-1.7.2 {
  97. execsql {
  98. SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS');
  99. }
  100. } {0}
  101. #####################
  102. # ctime-2.*: Test function support.
  103. do_test ctime-2.1.1 {
  104. catchsql {
  105. SELECT sqlite_compileoption_used();
  106. }
  107. } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
  108. do_test ctime-2.1.2 {
  109. catchsql {
  110. SELECT sqlite_compileoption_used(NULL);
  111. }
  112. } {0 {{}}}
  113. do_test ctime-2.1.3 {
  114. catchsql {
  115. SELECT sqlite_compileoption_used("");
  116. }
  117. } {0 0}
  118. do_test ctime-2.1.4 {
  119. catchsql {
  120. SELECT sqlite_compileoption_used('');
  121. }
  122. } {0 0}
  123. do_test ctime-2.1.5 {
  124. catchsql {
  125. SELECT sqlite_compileoption_used(foo);
  126. }
  127. } {1 {no such column: foo}}
  128. do_test ctime-2.1.6 {
  129. catchsql {
  130. SELECT sqlite_compileoption_used('THREADSAFE', 0);
  131. }
  132. } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
  133. do_test ctime-2.1.7 {
  134. catchsql {
  135. SELECT sqlite_compileoption_used(0);
  136. }
  137. } {0 0}
  138. do_test ctime-2.1.8 {
  139. catchsql {
  140. SELECT sqlite_compileoption_used('0');
  141. }
  142. } {0 0}
  143. do_test ctime-2.1.9 {
  144. catchsql {
  145. SELECT sqlite_compileoption_used(1.0);
  146. }
  147. } {0 0}
  148. do_test ctime-2.2.1 {
  149. catchsql {
  150. SELECT sqlite_compileoption_get();
  151. }
  152. } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
  153. do_test ctime-2.2.2 {
  154. catchsql {
  155. SELECT sqlite_compileoption_get(0, 0);
  156. }
  157. } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
  158. # This assumes there is at least 1 compile time option
  159. # (see SQLITE_THREADSAFE above).
  160. do_test ctime-2.3 {
  161. catchsql {
  162. SELECT sqlite_compileoption_used(sqlite_compileoption_get(0));
  163. }
  164. } {0 1}
  165. # This assumes there is at least 1 compile time option
  166. # (see SQLITE_THREADSAFE above).
  167. do_test ctime-2.4 {
  168. set ans [ catchsql {
  169. SELECT sqlite_compileoption_get(0);
  170. } ]
  171. list [lindex $ans 0]
  172. } {0}
  173. # Get the list of defines using the pragma,
  174. # then try querying each one with the functions.
  175. set ans [ catchsql {
  176. PRAGMA compile_options;
  177. } ]
  178. set opts [ lindex $ans 1 ]
  179. set tc 1
  180. foreach opt $opts {
  181. do_test ctime-2.5.$tc {
  182. set N [ expr {$tc-1} ]
  183. set ans1 [ catchsql {
  184. SELECT sqlite_compileoption_get($N);
  185. } ]
  186. set ans2 [ catchsql {
  187. SELECT sqlite_compileoption_used($opt);
  188. } ]
  189. list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \
  190. [ expr { $ans2 } ]
  191. } {0 1 {0 1}}
  192. incr tc 1
  193. }
  194. # test 1 past array bounds
  195. do_test ctime-2.5.$tc {
  196. set N [ expr {$tc-1} ]
  197. set ans [ catchsql {
  198. SELECT sqlite_compileoption_get($N);
  199. } ]
  200. } {0 {{}}}
  201. incr tc 1
  202. # test 1 before array bounds (N=-1)
  203. do_test ctime-2.5.$tc {
  204. set N -1
  205. set ans [ catchsql {
  206. SELECT sqlite_compileoption_get($N);
  207. } ]
  208. } {0 {{}}}
  209. finish_test