xref: /sqlite-3.40.0/test/mallocA.test (revision eee4c8ca)
1cf1be45fSdrh# 2007 April 30
2cf1be45fSdrh#
3cf1be45fSdrh# The author disclaims copyright to this source code.  In place of
4cf1be45fSdrh# a legal notice, here is a blessing:
5cf1be45fSdrh#
6cf1be45fSdrh#    May you do good and not evil.
7cf1be45fSdrh#    May you find forgiveness for yourself and forgive others.
8cf1be45fSdrh#    May you share freely, never taking more than you give.
9cf1be45fSdrh#
10cf1be45fSdrh#***********************************************************************
11cf1be45fSdrh# This file contains additional out-of-memory checks (see malloc.tcl).
12cf1be45fSdrh#
13*eee4c8caSdrh# $Id: mallocA.test,v 1.8 2008/02/18 22:24:58 drh Exp $
14cf1be45fSdrh
15cf1be45fSdrhset testdir [file dirname $argv0]
16cf1be45fSdrhsource $testdir/tester.tcl
17*eee4c8caSdrhsource $testdir/malloc_common.tcl
18cf1be45fSdrh
19cf1be45fSdrh# Only run these tests if memory debugging is turned on.
20cf1be45fSdrh#
21*eee4c8caSdrhif {!$MEMDEBUG} {
225a3032b3Sdrh   puts "Skipping mallocA tests: not compiled with -DSQLITE_MEMDEBUG..."
23cf1be45fSdrh   finish_test
24cf1be45fSdrh   return
25cf1be45fSdrh}
26cf1be45fSdrh
27cf1be45fSdrh
28cf1be45fSdrh# Construct a test database
29cf1be45fSdrh#
30cf1be45fSdrhfile delete -force test.db.bu
31cf1be45fSdrhdb eval {
3284f31128Sdrh  CREATE TABLE t1(a COLLATE NOCASE,b,c);
33cf1be45fSdrh  INSERT INTO t1 VALUES(1,2,3);
34cf1be45fSdrh  INSERT INTO t1 VALUES(1,2,4);
35cf1be45fSdrh  INSERT INTO t1 VALUES(2,3,4);
36cf1be45fSdrh  CREATE INDEX t1i1 ON t1(a);
37cf1be45fSdrh  CREATE INDEX t1i2 ON t1(b,c);
38cf1be45fSdrh  CREATE TABLE t2(x,y,z);
39cf1be45fSdrh}
40cf1be45fSdrhdb close
41cf1be45fSdrhfile copy test.db test.db.bu
42cf1be45fSdrh
43cf1be45fSdrh
44a1644fd8Sdanielk1977do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
45cf1be45fSdrh  ANALYZE
46cf1be45fSdrh}
47b8b4bfa0Sdanielk1977do_malloc_test mallocA-1.1 -testdb test.db.bu -sqlbody {
48b8b4bfa0Sdanielk1977  ANALYZE t1
49b8b4bfa0Sdanielk1977}
50b8b4bfa0Sdanielk1977do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody {
51b8b4bfa0Sdanielk1977  ANALYZE main
52b8b4bfa0Sdanielk1977}
53b8b4bfa0Sdanielk1977do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody {
54b8b4bfa0Sdanielk1977  ANALYZE main.t1
55b8b4bfa0Sdanielk1977}
564152e677Sdanielk1977ifcapable reindex {
57a1644fd8Sdanielk1977  do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody {
5884f31128Sdrh    REINDEX;
5984f31128Sdrh  }
60a1644fd8Sdanielk1977  do_malloc_test mallocA-3 -testdb test.db.bu -sqlbody {
6184f31128Sdrh    REINDEX t1;
6284f31128Sdrh  }
63a1644fd8Sdanielk1977  do_malloc_test mallocA-4 -testdb test.db.bu -sqlbody {
6484f31128Sdrh    REINDEX main.t1;
6584f31128Sdrh  }
66a1644fd8Sdanielk1977  do_malloc_test mallocA-5 -testdb test.db.bu -sqlbody {
6784f31128Sdrh    REINDEX nocase;
6884f31128Sdrh  }
694152e677Sdanielk1977}
70cf1be45fSdrh
71cf1be45fSdrh# Ensure that no file descriptors were leaked.
72cf1be45fSdrhdo_test malloc-99.X {
73cf1be45fSdrh  catch {db close}
74cf1be45fSdrh  set sqlite_open_file_count
75cf1be45fSdrh} {0}
76cf1be45fSdrh
77cf1be45fSdrhfile delete -force test.db.bu
78cf1be45fSdrhfinish_test
79