malloc8.test 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # 2007 April 25
  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 contains additional out-of-memory checks (see malloc.tcl)
  12. # added to expose a bug in out-of-memory handling for sqlite3_value_text()
  13. #
  14. # $Id: malloc8.test,v 1.7 2008/02/18 22:24:58 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. source $testdir/malloc_common.tcl
  18. # Only run these tests if memory debugging is turned on.
  19. #
  20. if {!$MEMDEBUG} {
  21. puts "Skipping malloc8 tests: not compiled with -DSQLITE_MEMDEBUG..."
  22. finish_test
  23. return
  24. }
  25. # The setup is a database with UTF-16 encoding that contains a single
  26. # large string. We will be running lots of queries against this
  27. # database. Because we will be extracting the string as UTF-8, there
  28. # is a type conversion that occurs and thus an opportunity for malloc()
  29. # to fail and for sqlite3_value_text() to return 0 even though
  30. # sqlite3_value_type() returns SQLITE_TEXT.
  31. #
  32. do_malloc_test malloc8-1 -sqlprep {
  33. PRAGMA encoding='UTF-16';
  34. CREATE TABLE t1(a);
  35. INSERT INTO t1
  36. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  37. } -sqlbody {
  38. SELECT lower(a), upper(a), quote(a), trim(a), trim('x',a) FROM t1;
  39. }
  40. do_malloc_test malloc8-2 -sqlprep {
  41. PRAGMA encoding='UTF-16';
  42. CREATE TABLE t1(a);
  43. INSERT INTO t1
  44. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  45. } -sqlbody {
  46. SELECT replace(a,'x','y'), replace('x',a,'y'), replace('x','y',a)
  47. FROM t1;
  48. }
  49. do_malloc_test malloc8-3 -sqlprep {
  50. PRAGMA encoding='UTF-16';
  51. CREATE TABLE t1(a);
  52. INSERT INTO t1
  53. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  54. } -sqlbody {
  55. SELECT length(a), substr(a, 4, 4) FROM t1;
  56. }
  57. ifcapable datetime {
  58. do_malloc_test malloc8-4 -sqlprep {
  59. PRAGMA encoding='UTF-16';
  60. CREATE TABLE t1(a);
  61. INSERT INTO t1
  62. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  63. } -sqlbody {
  64. SELECT julianday(a,a) FROM t1;
  65. }
  66. }
  67. do_malloc_test malloc8-5 -sqlprep {
  68. PRAGMA encoding='UTF-16';
  69. CREATE TABLE t1(a);
  70. INSERT INTO t1
  71. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  72. } -sqlbody {
  73. SELECT 1 FROM t1 WHERE a LIKE 'hello' ESCAPE NULL;
  74. }
  75. do_malloc_test malloc8-6 -sqlprep {
  76. PRAGMA encoding='UTF-16';
  77. CREATE TABLE t1(a);
  78. INSERT INTO t1
  79. VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
  80. } -sqlbody {
  81. SELECT hex(randomblob(100));
  82. }
  83. # Ensure that no file descriptors were leaked.
  84. do_test malloc-99.X {
  85. catch {db close}
  86. set sqlite_open_file_count
  87. } {0}
  88. finish_test