altermalloc.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # 2005 September 19
  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 is testing the ALTER TABLE statement and
  13. # specifically out-of-memory conditions within that command.
  14. #
  15. # $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
  20. ifcapable !altertable||!memdebug {
  21. finish_test
  22. return
  23. }
  24. source $testdir/malloc_common.tcl
  25. do_malloc_test altermalloc-1 -tclprep {
  26. db close
  27. } -tclbody {
  28. if {[catch {sqlite3 db test.db}]} {
  29. error "out of memory"
  30. }
  31. sqlite3_db_config_lookaside db 0 0 0
  32. sqlite3_extended_result_codes db 1
  33. } -sqlbody {
  34. CREATE TABLE t1(a int);
  35. ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
  36. ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
  37. ALTER TABLE t1 RENAME TO t2;
  38. ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD';
  39. }
  40. # Test malloc() failure on an ALTER TABLE on a virtual table.
  41. #
  42. ifcapable vtab {
  43. do_malloc_test altermalloc-vtab -tclprep {
  44. sqlite3 db2 test.db
  45. sqlite3_db_config_lookaside db2 0 0 0
  46. sqlite3_extended_result_codes db2 1
  47. register_echo_module [sqlite3_connection_pointer db2]
  48. db2 eval {
  49. CREATE TABLE t1(a, b VARCHAR, c INTEGER);
  50. CREATE VIRTUAL TABLE t1echo USING echo(t1);
  51. }
  52. db2 close
  53. register_echo_module [sqlite3_connection_pointer db]
  54. } -tclbody {
  55. set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg]
  56. if {$msg eq "vtable constructor failed: t1echo"} {
  57. set msg "out of memory"
  58. }
  59. if {$rc} {
  60. error $msg
  61. }
  62. }
  63. }
  64. finish_test