⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 malloc.test

📁 最新的sqlite3.6.2源代码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
      COMMIT;    }]    if {$rc!="1 {child process exited abnormally}"} {      error "Wrong error message: $rc"    }  } -tclbody {    db eval {ATTACH 'test2.db' as aux;}    set rc [catch {db eval {      SELECT * FROM t1;       SELECT * FROM t2;    }} err]    if {$rc && $err!="no such table: t1"} {      error $err    }  }}if {$tcl_platform(platform)!="windows"} {  do_malloc_test 14 -tclprep {    catch {db close}    sqlite3 db2 test2.db    sqlite3_extended_result_codes db2 1    db2 eval {      PRAGMA synchronous = 0;      CREATE TABLE t1(a, b);      INSERT INTO t1 VALUES(1, 2);      BEGIN;      INSERT INTO t1 VALUES(3, 4);    }    copy_file test2.db test.db    copy_file test2.db-journal test.db-journal    db2 close  } -tclbody {    sqlite3 db test.db    sqlite3_extended_result_codes db 1    db eval {      SELECT * FROM t1;    }    }}proc string_compare {a b} {  return [string compare $a $b]}# Test for malloc() failures in sqlite3_create_collation() and # sqlite3_create_collation16().#ifcapable utf16 {  do_malloc_test 15 -start 4 -tclbody {    db collate string_compare string_compare    if {[catch {add_test_collate db 1 1 1} msg]} {      if {$msg=="SQLITE_NOMEM"} {set msg "out of memory"}      error $msg    }      db complete {SELECT "hello """||'world"' [microsoft], * FROM anicetable;}    db complete {-- Useful comment}      execsql {      CREATE TABLE t1(a, b COLLATE string_compare);      INSERT INTO t1 VALUES(10, 'string');      INSERT INTO t1 VALUES(10, 'string2');    }  }}# Also test sqlite3_complete(). There are (currently) no malloc()# calls in this function, but test anyway against future changes.#do_malloc_test 16 -tclbody {  db complete {SELECT "hello """||'world"' [microsoft], * FROM anicetable;}  db complete {-- Useful comment}  db eval {    SELECT * FROM sqlite_master;  }}# Test handling of malloc() failures in sqlite3_open16().#ifcapable utf16 {  do_malloc_test 17 -tclbody {    set DB2 0    set STMT 0      # open database using sqlite3_open16()    set filename [encoding convertto unicode test.db]    append filename "\x00\x00"    set DB2 [sqlite3_open16 $filename -unused]    if {0==$DB2} {      error "out of memory"    }    sqlite3_extended_result_codes $DB2 1      # Prepare statement    set rc [catch {sqlite3_prepare $DB2 {SELECT * FROM sqlite_master} -1 X} msg]    if {[sqlite3_errcode $DB2] eq "SQLITE_IOERR+12"} {      error "out of memory"    }    if {[regexp ".*automatic extension loading.*" [sqlite3_errmsg $DB2]]} {      error "out of memory"    }    if {$rc} {      error [string range $msg 4 end]    }    set STMT $msg      # Finalize statement    set rc [sqlite3_finalize $STMT]    if {$rc!="SQLITE_OK"} {      error [sqlite3_errmsg $DB2]    }    set STMT 0      # Close database    set rc [sqlite3_close $DB2]    if {$rc!="SQLITE_OK"} {      error [sqlite3_errmsg $DB2]    }    set DB2 0  } -cleanup {    if {$STMT!="0"} {      sqlite3_finalize $STMT    }    if {$DB2!="0"} {      set rc [sqlite3_close $DB2]    }  }}# Test handling of malloc() failures in sqlite3_errmsg16().#ifcapable utf16 {  do_malloc_test 18 -tclprep {    catch {      db eval "SELECT [string repeat longcolumnname 10] FROM sqlite_master"    }  } -tclbody {    set utf16 [sqlite3_errmsg16 [sqlite3_connection_pointer db]]    binary scan $utf16 c* bytes    if {[llength $bytes]==0} {      error "out of memory"    }  }}# This test is aimed at coverage testing. Specificly, it is supposed to# cause a malloc() only used when converting between the two utf-16 # encodings to fail (i.e. little-endian->big-endian). It only actually # hits this malloc() on little-endian hosts.#set static_string "\x00h\x00e\x00l\x00l\x00o"for {set l 0} {$l<10} {incr l} {  append static_string $static_string}append static_string "\x00\x00"do_malloc_test 19 -tclprep {  execsql {    PRAGMA encoding = "UTF16be";    CREATE TABLE abc(a, b, c);  }} -tclbody {  unset -nocomplain ::STMT  set r [catch {    set ::STMT [sqlite3_prepare db {SELECT ?} -1 DUMMY]    sqlite3_bind_text16 -static $::STMT 1 $static_string 112  } msg]  if {$r} {error [string range $msg 4 end]}  set msg} -cleanup {  if {[info exists ::STMT]} {    sqlite3_finalize $::STMT  }}unset static_string# Make sure SQLITE_NOMEM is reported out on an ATTACH failure even# when the malloc failure occurs within the nested parse.#ifcapable attach {  do_malloc_test 20 -tclprep {    db close    file delete -force test2.db test2.db-journal    sqlite3 db test2.db    sqlite3_extended_result_codes db 1    db eval {CREATE TABLE t1(x);}    db close  } -tclbody {    if {[catch {sqlite3 db test.db}]} {      error "out of memory"    }    sqlite3_extended_result_codes db 1  } -sqlbody {    ATTACH DATABASE 'test2.db' AS t2;    SELECT * FROM t1;    DETACH DATABASE t2;  } }# Test malloc failure whilst installing a foreign key.#ifcapable foreignkey {  do_malloc_test 21 -sqlbody {    CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b))  } }# Test malloc failure in an sqlite3_prepare_v2() call.#do_malloc_test 22 -tclbody {  set ::STMT ""  set r [catch {    set ::STMT [      sqlite3_prepare_v2 db "SELECT * FROM sqlite_master" -1 DUMMY    ]  } msg]  if {$r} {error [string range $msg 4 end]}} -cleanup {  if {$::STMT ne ""} {    sqlite3_finalize $::STMT    set ::STMT ""  }}ifcapable {pager_pragmas} {  # This tests a special case - that an error that occurs while the pager  # is trying to recover from error-state in exclusive-access mode works.  #  do_malloc_test 23 -tclprep {    db eval {      PRAGMA cache_size = 10;      PRAGMA locking_mode = exclusive;      BEGIN;      CREATE TABLE abc(a, b, c);      CREATE INDEX abc_i ON abc(a, b, c);      INSERT INTO abc         VALUES(randstr(100,100), randstr(100,100), randstr(100,100));      INSERT INTO abc         SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;      INSERT INTO abc         SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;      INSERT INTO abc         SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;      INSERT INTO abc         SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;      INSERT INTO abc         SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;      COMMIT;    }      # This puts the pager into error state.    #    db eval BEGIN    db eval {UPDATE abc SET a = 0 WHERE oid%2}    set ::sqlite_io_error_pending 10    catch {db eval {ROLLBACK}} msg  } -sqlbody {    SELECT * FROM abc LIMIT 10;  } -cleanup {    set e [db eval {PRAGMA integrity_check}]    if {$e ne "ok"} {error $e}  }}ifcapable compound {  do_malloc_test 24 -sqlprep {    CREATE TABLE t1(a, b, c)  } -sqlbody {    SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1  }}ifcapable view&&trigger {  do_malloc_test 25 -sqlprep {    CREATE TABLE t1(a, b, c);    CREATE VIEW v1 AS SELECT * FROM t1;    CREATE TRIGGER v1t1 INSTEAD OF DELETE ON v1 BEGIN SELECT 1; END;    CREATE TRIGGER v1t2 INSTEAD OF INSERT ON v1 BEGIN SELECT 1; END;    CREATE TRIGGER v1t3 INSTEAD OF UPDATE ON v1 BEGIN SELECT 1; END;  } -sqlbody {    DELETE FROM v1 WHERE a = 1;    INSERT INTO v1 VALUES(1, 2, 3);    UPDATE v1 SET a = 1 WHERE b = 2;  }}do_malloc_test 25 -sqlprep {  CREATE TABLE abc(a, b, c);  CREATE INDEX i1 ON abc(a, b);  INSERT INTO abc VALUES(1, 2, 3);  INSERT INTO abc VALUES(4, 5, 6);} -tclbody {  # For each UPDATE executed, the cursor used for the SELECT statement  # must be "saved". Because the cursor is open on an index, this requires  # a malloc() to allocate space to save the index key. This test case is  # aimed at testing the response of the library to a failure in that  # particular malloc() call.  db eval {SELECT a FROM abc ORDER BY a} {    db eval {UPDATE abc SET b = b - 1 WHERE a = $a}  }}# Ensure that no file descriptors were leaked.do_test malloc-99.X {  catch {db close}  set sqlite_open_file_count} {0}puts open-file-count=$sqlite_open_file_countfinish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -