4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 ******************************************************************************
14 #if SQLITE_TEST /* This file is used for testing only */
17 #include "sqliteInt.h"
18 #if defined(INCLUDE_SQLITE_TCL_H)
19 # include "sqlite_tcl.h"
24 #ifdef SQLITE_VDBE_COVERAGE
26 static u8 aBranchArray
[200000];
28 static void test_vdbe_branch(
31 unsigned char iBranch
,
34 if( iSrc
<sizeof(aBranchArray
) ){
35 aBranchArray
[iSrc
] |= iBranch
;
39 static void appendToList(
45 Tcl_Obj
*pNew
= Tcl_NewObj();
46 Tcl_IncrRefCount(pNew
);
47 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewIntObj(iLine
));
48 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewIntObj(iPath
));
49 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zNever
, -1));
50 Tcl_ListObjAppendElement(0, pList
, pNew
);
51 Tcl_DecrRefCount(pNew
);
55 static int SQLITE_TCLAPI
test_vdbe_coverage(
61 const char *aSub
[] = { "start", "report", "stop", 0 };
64 Tcl_WrongNumArgs(interp
, 1, objv
, "sub-command");
68 if( Tcl_GetIndexFromObj(interp
, objv
[1], aSub
, "sub-command", 0, &iSub
) ){
72 Tcl_ResetResult(interp
);
73 assert( iSub
==0 || iSub
==1 || iSub
==2 );
76 memset(aBranchArray
, 0, sizeof(aBranchArray
));
77 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE
, test_vdbe_branch
, 0);
79 case 1: { /* report */
81 Tcl_Obj
*pRes
= Tcl_NewObj();
82 Tcl_IncrRefCount(pRes
);
83 for(i
=0; i
<sizeof(aBranchArray
); i
++){
84 u8 b
= aBranchArray
[i
];
85 int bFlag
= ((b
>> 4)==4);
88 appendToList(pRes
, i
, 0, bFlag
? "less than" : "falls through");
91 appendToList(pRes
, i
, 1, bFlag
? "equal" : "taken");
94 appendToList(pRes
, i
, 2, bFlag
? "greater-than" : "NULL");
98 Tcl_SetObjResult(interp
, pRes
);
99 Tcl_DecrRefCount(pRes
);
104 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE
, 0, 0);
111 #endif /* SQLITE_VDBE_COVERAGE */
113 int Sqlitetestvdbecov_Init(Tcl_Interp
*interp
){
114 #ifdef SQLITE_VDBE_COVERAGE
115 Tcl_CreateObjCommand(interp
, "vdbe_coverage", test_vdbe_coverage
, 0, 0);