1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Add a completely new testing system for the Bitvec object. The new

testing system uses sqlite3_test_control() instead of unpublished
APIs.  Now provides 100% condition/decision coverage.  Obscure bugs
in Bitvec found and fixed as a result of the enhanced coverage. (CVS 4902)

FossilOrigin-Name: 2498d3ea36ecab6d9c0f04ef1c49d76a7a215a4f
This commit is contained in:
drh
2008-03-21 16:45:47 +00:00
parent 6f332c18d9
commit 3088d59e06
12 changed files with 357 additions and 309 deletions

View File

@@ -13,12 +13,13 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test2.c,v 1.56 2008/03/20 11:04:21 danielk1977 Exp $
** $Id: test2.c,v 1.57 2008/03/21 16:45:48 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
** Interpret an SQLite error number
@@ -561,103 +562,40 @@ static int fake_big_file(
}
#endif
/*
** sqlite3BitvecCreate SIZE
** sqlite3BitvecTest POINTER N
** sqlite3BitvecSet POINTER N
** sqlite3BitvecClear POINTER N
** sqlite3BitvecDestroy POINTER
** sqlite3BitvecBuiltinTest SIZE PROGRAM
**
** Invoke the SQLITE_TESTCTRL_BITVEC_TEST operator on test_control.
** See comments on sqlite3BitvecBuiltinTest() for additional information.
*/
static int testBitvecCreate(
static int testBitvecBuiltinTest(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int size;
Bitvec *p;
char zBuf[100];
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " N\"",
(void*)0);
}
if( Tcl_GetInt(interp, argv[1], &size) ) return TCL_ERROR;
p = sqlite3BitvecCreate(size);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",p);
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
static int testBitvecTest(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int N;
Bitvec *p;
char zBuf[100];
int sz, rc;
int nProg = 0;
int aProg[100];
const char *z;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"",
(void*)0);
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" SIZE PROGRAM\"", (void*)0);
}
p = (Bitvec*)sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3BitvecTest(p,N));
Tcl_AppendResult(interp, zBuf, 0);
if( Tcl_GetInt(interp, argv[1], &sz) ) return TCL_ERROR;
z = argv[2];
while( nProg<99 && *z ){
while( *z && !isdigit(*z) ){ z++; }
if( *z==0 ) break;
aProg[nProg++] = atoi(z);
while( isdigit(*z) ){ z++; }
}
aProg[nProg] = 0;
rc = sqlite3_test_control(SQLITE_TESTCTRL_BITVEC_TEST, sz, aProg);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return TCL_OK;
}
static int testBitvecSet(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int N;
Bitvec *p;
char zBuf[100];
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"",
(void*)0);
}
p = (Bitvec*)sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3BitvecSet(p,N));
Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK;
}
static int testBitvecClear(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
int N;
Bitvec *p;
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"",
(void*)0);
}
p = (Bitvec*)sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
sqlite3BitvecClear(p,N);
return TCL_OK;
}
static int testBitvecDestroy(
void *NotUsed,
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int argc, /* Number of arguments */
const char **argv /* Text of each argument */
){
Bitvec *p;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR\"",
(void*)0);
}
p = (Bitvec*)sqlite3TextToPtr(argv[1]);
sqlite3BitvecDestroy(p);
return TCL_OK;
}
/*
** Register commands with the TCL interpreter.
@@ -693,11 +631,7 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
#ifndef SQLITE_OMIT_DISKIO
{ "fake_big_file", (Tcl_CmdProc*)fake_big_file },
#endif
{ "sqlite3BitvecCreate", (Tcl_CmdProc*)testBitvecCreate },
{ "sqlite3BitvecTest", (Tcl_CmdProc*)testBitvecTest },
{ "sqlite3BitvecSet", (Tcl_CmdProc*)testBitvecSet },
{ "sqlite3BitvecClear", (Tcl_CmdProc*)testBitvecClear },
{ "sqlite3BitvecDestroy", (Tcl_CmdProc*)testBitvecDestroy },
{ "sqlite3BitvecBuiltinTest",(Tcl_CmdProc*)testBitvecBuiltinTest},
};
int i;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){