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 #include "tclsqlite.h"
20 #ifdef SQLITE_VDBE_COVERAGE
22 static u8 aBranchArray
[200000];
24 static void test_vdbe_branch(
27 unsigned char iBranch
,
30 if( iSrc
<sizeof(aBranchArray
) ){
31 aBranchArray
[iSrc
] |= iBranch
;
35 static void appendToList(
41 Tcl_Obj
*pNew
= Tcl_NewObj();
42 Tcl_IncrRefCount(pNew
);
43 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewIntObj(iLine
));
44 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewIntObj(iPath
));
45 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zNever
, -1));
46 Tcl_ListObjAppendElement(0, pList
, pNew
);
47 Tcl_DecrRefCount(pNew
);
51 static int SQLITE_TCLAPI
test_vdbe_coverage(
57 const char *aSub
[] = { "start", "report", "stop", 0 };
60 Tcl_WrongNumArgs(interp
, 1, objv
, "sub-command");
64 if( Tcl_GetIndexFromObj(interp
, objv
[1], aSub
, "sub-command", 0, &iSub
) ){
68 Tcl_ResetResult(interp
);
69 assert( iSub
==0 || iSub
==1 || iSub
==2 );
72 memset(aBranchArray
, 0, sizeof(aBranchArray
));
73 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE
, test_vdbe_branch
, 0);
75 case 1: { /* report */
77 Tcl_Obj
*pRes
= Tcl_NewObj();
78 Tcl_IncrRefCount(pRes
);
79 for(i
=0; i
<sizeof(aBranchArray
); i
++){
80 u8 b
= aBranchArray
[i
];
81 int bFlag
= ((b
>> 4)==4);
84 appendToList(pRes
, i
, 0, bFlag
? "less than" : "falls through");
87 appendToList(pRes
, i
, 1, bFlag
? "equal" : "taken");
90 appendToList(pRes
, i
, 2, bFlag
? "greater-than" : "NULL");
94 Tcl_SetObjResult(interp
, pRes
);
95 Tcl_DecrRefCount(pRes
);
100 sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE
, 0, 0);
107 #endif /* SQLITE_VDBE_COVERAGE */
109 int Sqlitetestvdbecov_Init(Tcl_Interp
*interp
){
110 #ifdef SQLITE_VDBE_COVERAGE
111 Tcl_CreateObjCommand(interp
, "vdbe_coverage", test_vdbe_coverage
, 0, 0);