SQLite

Check-in [19fc3d7896]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Extra test cases to improve coverage of main.c. (CVS 3755)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 19fc3d78962d225d42372b9298be5921ec1fc8a1
User & Date: danielk1977 2007-03-30 07:10:51.000
Context
2007-03-30
09:13
Test coverage a few extra lines in where.c. (CVS 3756) (check-in: ea49ddf64a user: danielk1977 tags: trunk)
07:10
Extra test cases to improve coverage of main.c. (CVS 3755) (check-in: 19fc3d7896 user: danielk1977 tags: trunk)
2007-03-29
20:19
Assume any return code from fcntl() other than -1 is success. Formerly we only assumed that 0 was success. Ticket #2173. (CVS 3754) (check-in: 8d0073c0e8 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/main.c.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.363 2007/03/29 15:00:53 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.364 2007/03/30 07:10:51 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** The following constant value is used by the SQLITE_BIGENDIAN and
132
133
134
135
136
137
138



139
140
141
142
143
144
145
  }
  assert( !sqlite3SafetyCheck(db) );

  /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database
  ** cannot be opened for some reason. So this routine needs to run in
  ** that case. But maybe there should be an extra magic value for the
  ** "failed to open" state.



  */
  if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){
    /* printf("DID NOT CLOSE\n"); fflush(stdout); */
    return SQLITE_ERROR;
  }

  sqlite3VtabRollback(db);







>
>
>







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  }
  assert( !sqlite3SafetyCheck(db) );

  /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database
  ** cannot be opened for some reason. So this routine needs to run in
  ** that case. But maybe there should be an extra magic value for the
  ** "failed to open" state.
  **
  ** TODO: Coverage tests do not test the case where this condition is
  ** true. It's hard to see how to cause it without messing with threads.
  */
  if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){
    /* printf("DID NOT CLOSE\n"); fflush(stdout); */
    return SQLITE_ERROR;
  }

  sqlite3VtabRollback(db);
Changes to test/malloc.test.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.39 2007/03/29 17:07:53 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.40 2007/03/30 07:10:52 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  }
} -sqlbody {
  ATTACH DATABASE 'test2.db' AS t2;
  SELECT * FROM t1;
  DETACH DATABASE t2;
} 

# Test malloc failure whilst installing a foriegn key.
#
do_malloc_test 21 -sqlbody {
  CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b))
} 


# 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_count
sqlite_malloc_fail 0
finish_test







|




<










542
543
544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563
  }
} -sqlbody {
  ATTACH DATABASE 'test2.db' AS t2;
  SELECT * FROM t1;
  DETACH DATABASE t2;
} 

# Test malloc failure whilst installing a foreign key.
#
do_malloc_test 21 -sqlbody {
  CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b))
} 


# 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_count
sqlite_malloc_fail 0
finish_test
Changes to test/misc7.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2006 September 4
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: misc7.test,v 1.2 2007/03/29 17:07:53 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test misc7-1 {
  c_misuse_test
} {}












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2006 September 4
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: misc7.test,v 1.3 2007/03/30 07:10:52 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test misc7-1 {
  c_misuse_test
} {}
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  }
  return $ret
}

execsql { CREATE TABLE abc(a PRIMARY KEY, b, c); }
db close
set fd_list [use_up_files]

set ::go 1
set ::n 1
while {$::go} {
  catch {db close}
  do_test misc7-6.$::n {
    set rc [catch {
      sqlite db test.db







<







64
65
66
67
68
69
70

71
72
73
74
75
76
77
  }
  return $ret
}

execsql { CREATE TABLE abc(a PRIMARY KEY, b, c); }
db close
set fd_list [use_up_files]

set ::go 1
set ::n 1
while {$::go} {
  catch {db close}
  do_test misc7-6.$::n {
    set rc [catch {
      sqlite db test.db
92
93
94
95
96
97
98

99




















































100
101
  close [lindex $fd_list 0]
  set fd_list [lrange $fd_list 1 end]
  incr ::n
}
foreach fd $fd_list {
  close $fd
}






















































finish_test








>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  close [lindex $fd_list 0]
  set fd_list [lrange $fd_list 1 end]
  incr ::n
}
foreach fd $fd_list {
  close $fd
}
db close
#
# End of tests for out-of-file-descriptors condition.
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# Test that the sqlite3_busy_timeout call seems to delay approximately
# the right amount of time.
#
do_test misc7-6 {
  sqlite3 db2 test.db
  sqlite3 db test.db
  sqlite3_busy_timeout [sqlite3_connection_pointer db] 2000
  execsql {
    BEGIN EXCLUSIVE;
  } db2

  # Now db2 has an exclusive lock on the database file, and db has
  # a busy-timeout of 2000 milliseconds. So check that trying to
  # access the database using connection db delays for at least 1500 ms.
  #
  set c1 [clock clicks -milliseconds]
  catchsql {
    SELECT * FROM sqlite_master;
  } db
  expr {([clock clicks -milliseconds]-$c1) > 1500 ? 1 : 0}
} {1}
db2 close

#--------------------------------------------------------------------
# Test that nothing goes horribly wrong when attaching a database
# after the omit_readlock pragma has been exercised.
#
do_test misc7-7 {
  file delete -force test2.db
  file delete -force test2.db-journal
  execsql {
    PRAGMA omit_readlock = 1;
    ATTACH 'test2.db' AS aux;
    CREATE TABLE aux.hello(world);
    SELECT name FROM aux.sqlite_master;
  }
} {hello}

# Test malloc failure whilst installing a foriegn key.
#
ifcapable utf16 {
  do_test misc7-8 {
    encoding convertfrom unicode [sqlite3_errmsg16 0x00000000]
  } {out of memory}
}



finish_test