Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Improve test coverage of fts5.c. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fts5 |
Files: | files | file ages | folders |
SHA1: |
add4f4681c648dcbecaa68d08f7b2f4e |
User & Date: | dan 2015-05-01 12:14:23.640 |
Context
2015-05-01
| ||
20:38 | Further improvements to test coverage of fts5 code. (check-in: d4331943df user: dan tags: fts5) | |
12:14 | Improve test coverage of fts5.c. (check-in: add4f4681c user: dan tags: fts5) | |
2015-04-29
| ||
20:54 | Improve fts5 tests. (check-in: c1f07a3aa9 user: dan tags: fts5) | |
Changes
Changes to ext/fts5/fts5.c.
︙ | ︙ | |||
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 | }else{ *pnToken = 0; rc = SQLITE_RANGE; } return rc; } static int fts5ApiSetAuxdata( Fts5Context *pCtx, /* Fts5 context */ void *pPtr, /* Pointer to save as auxdata */ void(*xDelete)(void*) /* Destructor for pPtr (or NULL) */ ){ Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; Fts5Auxdata *pData; for(pData=pCsr->pAuxdata; pData; pData=pData->pNext){ if( pData->pAux==pCsr->pAux ) break; } if( pData ){ if( pData->xDelete ){ pData->xDelete(pData->pPtr); } }else{ | > > > > > > | | < | 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 | }else{ *pnToken = 0; rc = SQLITE_RANGE; } return rc; } /* ** Implementation of the xSetAuxdata() method. */ static int fts5ApiSetAuxdata( Fts5Context *pCtx, /* Fts5 context */ void *pPtr, /* Pointer to save as auxdata */ void(*xDelete)(void*) /* Destructor for pPtr (or NULL) */ ){ Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; Fts5Auxdata *pData; /* Search through the cursors list of Fts5Auxdata objects for one that ** corresponds to the currently executing auxiliary function. */ for(pData=pCsr->pAuxdata; pData; pData=pData->pNext){ if( pData->pAux==pCsr->pAux ) break; } if( pData ){ if( pData->xDelete ){ pData->xDelete(pData->pPtr); } }else{ int rc = SQLITE_OK; pData = (Fts5Auxdata*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Auxdata)); if( pData==0 ){ if( xDelete ) xDelete(pPtr); return rc; } pData->pAux = pCsr->pAux; pData->pNext = pCsr->pAuxdata; pCsr->pAuxdata = pData; } pData->xDelete = xDelete; pData->pPtr = pPtr; |
︙ | ︙ | |||
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 | for(pCsr=pAux->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){ if( pCsr->iCsrId==iCsrId ) break; } if( pCsr==0 ){ char *zErr = sqlite3_mprintf("no such cursor: %lld", iCsrId); sqlite3_result_error(context, zErr, -1); }else{ fts5ApiInvoke(pAux, pCsr, context, argc-1, &argv[1]); } } /* ** Return a "position-list blob" corresponding to the current position of | > | 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 | for(pCsr=pAux->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){ if( pCsr->iCsrId==iCsrId ) break; } if( pCsr==0 ){ char *zErr = sqlite3_mprintf("no such cursor: %lld", iCsrId); sqlite3_result_error(context, zErr, -1); sqlite3_free(zErr); }else{ fts5ApiInvoke(pAux, pCsr, context, argc-1, &argv[1]); } } /* ** Return a "position-list blob" corresponding to the current position of |
︙ | ︙ |
Changes to ext/fts5/fts5_tcl.c.
︙ | ︙ | |||
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | return TCL_OK; } return TCL_ERROR; } /* End of code that accesses the SqliteDb struct. **************************************************************************/ static int f5tDbAndApi( Tcl_Interp *interp, Tcl_Obj *pObj, sqlite3 **ppDb, fts5_api **ppApi ){ | > > > > > > > > > > > > > > > > > > > > > | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | return TCL_OK; } return TCL_ERROR; } /* End of code that accesses the SqliteDb struct. **************************************************************************/ static int f5tResultToErrorCode(const char *zRes){ struct ErrorCode { int rc; const char *zError; } aErr[] = { { SQLITE_DONE, "SQLITE_DONE" }, { SQLITE_ERROR, "SQLITE_ERROR" }, { SQLITE_OK, "SQLITE_OK" }, { SQLITE_OK, "" }, }; int i; for(i=0; i<sizeof(aErr)/sizeof(aErr[0]); i++){ if( 0==sqlite3_stricmp(zRes, aErr[i].zError) ){ return aErr[i].rc; } } return SQLITE_ERROR; } static int f5tDbAndApi( Tcl_Interp *interp, Tcl_Obj *pObj, sqlite3 **ppDb, fts5_api **ppApi ){ |
︙ | ︙ | |||
165 166 167 168 169 170 171 172 173 174 175 176 177 178 | pEval = Tcl_DuplicateObj(p->pScript); Tcl_IncrRefCount(pEval); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zCmd, -1)); rc = Tcl_EvalObjEx(p->interp, pEval, 0); Tcl_DecrRefCount(pEval); Tcl_DeleteCommand(p->interp, zCmd); return rc; } static void xSetAuxdataDestructor(void *p){ F5tAuxData *pData = (F5tAuxData*)p; Tcl_DecrRefCount(pData->pObj); | > > > > | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | pEval = Tcl_DuplicateObj(p->pScript); Tcl_IncrRefCount(pEval); Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zCmd, -1)); rc = Tcl_EvalObjEx(p->interp, pEval, 0); Tcl_DecrRefCount(pEval); Tcl_DeleteCommand(p->interp, zCmd); if( rc==TCL_OK ){ rc = f5tResultToErrorCode(Tcl_GetStringResult(p->interp)); } return rc; } static void xSetAuxdataDestructor(void *p){ F5tAuxData *pData = (F5tAuxData*)p; Tcl_DecrRefCount(pData->pObj); |
︙ | ︙ | |||
191 192 193 194 195 196 197 | Tcl_Obj *CONST objv[] ){ struct Sub { const char *zName; int nArg; const char *zMsg; } aSub[] = { | | | | | | | | | | | | | | | > > | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | Tcl_Obj *CONST objv[] ){ struct Sub { const char *zName; int nArg; const char *zMsg; } aSub[] = { { "xColumnCount", 0, "" }, /* 0 */ { "xRowCount", 0, "" }, /* 1 */ { "xColumnTotalSize", 1, "COL" }, /* 2 */ { "xTokenize", 2, "TEXT SCRIPT" }, /* 3 */ { "xPhraseCount", 0, "" }, /* 4 */ { "xPhraseSize", 1, "PHRASE" }, /* 5 */ { "xInstCount", 0, "" }, /* 6 */ { "xInst", 1, "IDX" }, /* 7 */ { "xRowid", 0, "" }, /* 8 */ { "xColumnText", 1, "COL" }, /* 9 */ { "xColumnSize", 1, "COL" }, /* 10 */ { "xQueryPhrase", 2, "PHRASE SCRIPT" }, /* 11 */ { "xSetAuxdata", 1, "VALUE" }, /* 12 */ { "xGetAuxdata", 1, "CLEAR" }, /* 13 */ { "xSetAuxdataInt", 1, "INTEGER" }, /* 14 */ { "xGetAuxdataInt", 1, "CLEAR" }, /* 15 */ { 0, 0, 0} }; int rc; int iSub = 0; F5tApi *p = (F5tApi*)clientData; |
︙ | ︙ | |||
381 382 383 384 385 386 387 388 389 390 391 392 393 394 | Tcl_SetObjResult(interp, pData->pObj); if( bClear ){ xSetAuxdataDestructor((void*)pData); } } break; } default: assert( 0 ); break; } #undef CASE | > > > > > > > > > > > > > > > > > > > | 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | Tcl_SetObjResult(interp, pData->pObj); if( bClear ){ xSetAuxdataDestructor((void*)pData); } } break; } /* These two - xSetAuxdataInt and xGetAuxdataInt - are similar to the ** xSetAuxdata and xGetAuxdata methods implemented above. The difference ** is that they may only save an integer value as auxiliary data, and ** do not specify a destructor function. */ CASE(14, "xSetAuxdataInt") { int iVal; if( Tcl_GetIntFromObj(interp, objv[2], &iVal) ) return TCL_ERROR; rc = p->pApi->xSetAuxdata(p->pFts, (void*)iVal, 0); break; } CASE(15, "xGetAuxdataInt") { int iVal; int bClear; if( Tcl_GetBooleanFromObj(interp, objv[2], &bClear) ) return TCL_ERROR; iVal = (int)p->pApi->xGetAuxdata(p->pFts, bClear); Tcl_SetObjResult(interp, Tcl_NewIntObj(iVal)); break; } default: assert( 0 ); break; } #undef CASE |
︙ | ︙ |
Changes to ext/fts5/test/fts5aux.test.
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 | SELECT colsize(f1, 2) FROM f1 WHERE f1 MATCH 'two'; } {1 SQLITE_RANGE} do_execsql_test 2.2 { SELECT colsize(f1, 0), colsize(f1, 1) FROM f1 WHERE f1 MATCH 'zero'; } {2 3} finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | SELECT colsize(f1, 2) FROM f1 WHERE f1 MATCH 'two'; } {1 SQLITE_RANGE} do_execsql_test 2.2 { SELECT colsize(f1, 0), colsize(f1, 1) FROM f1 WHERE f1 MATCH 'zero'; } {2 3} #------------------------------------------------------------------------- # Test the xSet and xGetAuxdata APIs with a NULL destructor. # proc prevrowid {add cmd} { set res [$cmd xGetAuxdataInt 0] set r [$cmd xRowid] $cmd xSetAuxdataInt $r return [expr $res + $add] } sqlite3_fts5_create_function db prevrowid [list prevrowid 0] sqlite3_fts5_create_function db prevrowid1 [list prevrowid 1] do_execsql_test 3.0 { CREATE VIRTUAL TABLE e5 USING fts5(x); INSERT INTO e5 VALUES('a b c'); INSERT INTO e5 VALUES('d e f'); INSERT INTO e5 VALUES('a b c'); INSERT INTO e5 VALUES('d e f'); INSERT INTO e5 VALUES('a b c'); } do_execsql_test 3.1 { SELECT prevrowid(e5) || '+' || rowid FROM e5 WHERE e5 MATCH 'c' } {0+1 1+3 3+5} do_execsql_test 3.2 { SELECT prevrowid(e5) || '+' || prevrowid1(e5) || '+' || rowid FROM e5 WHERE e5 MATCH 'e' } {0+1+2 2+3+4} #------------------------------------------------------------------------- # Test that if the xQueryPhrase callback returns other than SQLITE_OK, # the query is abandoned. And that if it returns an error code other than # SQLITE_DONE, the error is propagated back to the caller. # do_execsql_test 4.0 { CREATE VIRTUAL TABLE e7 USING fts5(x); INSERT INTO e7 VALUES('a x a'); INSERT INTO e7 VALUES('b x b'); INSERT INTO e7 VALUES('c x c'); INSERT INTO e7 VALUES('d x d'); INSERT INTO e7 VALUES('e x e'); } proc xCallback {rowid code cmd} { set r [$cmd xRowid] lappend ::cb $r if {$r==$rowid} { return $code } return "" } proc phrasequery {cmd code} { set ::cb [list] $cmd xQueryPhrase 1 [list xCallback [$cmd xRowid] $code] set ::cb } sqlite3_fts5_create_function db phrasequery phrasequery do_execsql_test 4.1 { SELECT phrasequery(e7, 'SQLITE_OK') FROM e7 WHERE e7 MATCH 'c x' } {{1 2 3 4 5}} do_execsql_test 4.2 { SELECT phrasequery(e7, 'SQLITE_DONE') FROM e7 WHERE e7 MATCH 'c x' } {{1 2 3}} do_catchsql_test 4.3 { SELECT phrasequery(e7, 'SQLITE_ERROR') FROM e7 WHERE e7 MATCH 'c x' } {1 SQLITE_ERROR} #------------------------------------------------------------------------- # Auxiliary function calls with many cursors in the global cursor list. # do_execsql_test 5.0 { CREATE VIRTUAL TABLE e9 USING fts5(y); INSERT INTO e9(rowid, y) VALUES(1, 'i iii'); INSERT INTO e9(rowid, y) VALUES(2, 'ii iv'); INSERT INTO e9(rowid, y) VALUES(3, 'ii'); INSERT INTO e9(rowid, y) VALUES(4, 'i iv'); INSERT INTO e9(rowid, y) VALUES(5, 'iii'); } proc my_rowid {cmd} { $cmd xRowid } sqlite3_fts5_create_function db my_rowid my_rowid foreach {var q} { s1 i s2 ii s3 iii s4 iv } { set sql "SELECT my_rowid(e9) FROM e9 WHERE e9 MATCH '$q'" set $var [sqlite3_prepare db $sql -1 dummy] } do_test 5.1.1 { sqlite3_step $s1 ; sqlite3_column_int $s1 0 } 1 do_test 5.1.2 { sqlite3_step $s2 ; sqlite3_column_int $s2 0 } 2 do_test 5.1.3 { sqlite3_step $s3 ; sqlite3_column_int $s3 0 } 1 do_test 5.1.4 { sqlite3_step $s4 ; sqlite3_column_int $s4 0 } 2 do_test 5.2.1 { sqlite3_step $s1 ; sqlite3_column_int $s1 0 } 4 do_test 5.2.2 { sqlite3_step $s2 ; sqlite3_column_int $s2 0 } 3 do_test 5.2.3 { sqlite3_step $s3 ; sqlite3_column_int $s3 0 } 5 do_test 5.2.4 { sqlite3_step $s4 ; sqlite3_column_int $s4 0 } 4 sqlite3_finalize $s1 sqlite3_finalize $s2 sqlite3_finalize $s3 sqlite3_finalize $s4 #------------------------------------------------------------------------- # Passing an invalid first argument to an auxiliary function is detected. # do_execsql_test 6.0 { CREATE VIRTUAL TABLE e11 USING fts5(y, z); INSERT INTO e11(rowid, y, z) VALUES(1, 'a b', 45); INSERT INTO e11(rowid, y, z) VALUES(2, 'b c', 46); } do_catchsql_test 6.1 { SELECT my_rowid(z) FROM e11 WHERE e11 MATCH 'b' } {1 {no such cursor: 45}} do_catchsql_test 6.2 { SELECT my_rowid(y) FROM e11 WHERE e11 MATCH 'b' } {1 {no such cursor: 0}} finish_test |
Changes to ext/fts5/test/fts5fault4.test.
︙ | ︙ | |||
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #------------------------------------------------------------------------- # OOM errors within auxiliary functions. # reset_db do_execsql_test 6.0 { CREATE VIRTUAL TABLE x3 USING fts5(xxx); INSERT INTO x3 VALUES('a b c d c b a'); } do_faultsim_test 6.1 -faults oom-t* -body { db eval { SELECT highlight(x3, 0, '*', '*') FROM x3 WHERE x3 MATCH 'c' } } -test { faultsim_test_result {0 {{a b *c* d *c* b a}}} } proc firstinst {cmd} { foreach {p c o} [$cmd xInst 0] {} expr $c*100 + $o } sqlite3_fts5_create_function db firstinst firstinst do_faultsim_test 6.2 -faults oom-t* -body { db eval { SELECT firstinst(x3) FROM x3 WHERE x3 MATCH 'c' } } -test { faultsim_test_result {0 2} {1 SQLITE_NOMEM} } finish_test | > > > > > > > > > > > > > > > > | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | #------------------------------------------------------------------------- # OOM errors within auxiliary functions. # reset_db do_execsql_test 6.0 { CREATE VIRTUAL TABLE x3 USING fts5(xxx); INSERT INTO x3 VALUES('a b c d c b a'); INSERT INTO x3 VALUES('a a a a a a a'); INSERT INTO x3 VALUES('a a a a a a a'); } do_faultsim_test 6.1 -faults oom-t* -body { db eval { SELECT highlight(x3, 0, '*', '*') FROM x3 WHERE x3 MATCH 'c' } } -test { faultsim_test_result {0 {{a b *c* d *c* b a}}} } proc firstinst {cmd} { foreach {p c o} [$cmd xInst 0] {} expr $c*100 + $o } sqlite3_fts5_create_function db firstinst firstinst do_faultsim_test 6.2 -faults oom-t* -body { db eval { SELECT firstinst(x3) FROM x3 WHERE x3 MATCH 'c' } } -test { faultsim_test_result {0 2} {1 SQLITE_NOMEM} } proc previc {cmd} { set res [$cmd xGetAuxdataInt 0] $cmd xSetAuxdataInt [$cmd xInstCount] return $res } sqlite3_fts5_create_function db previc previc do_faultsim_test 6.2 -faults oom-t* -body { db eval { SELECT previc(x3) FROM x3 WHERE x3 MATCH 'a' } } -test { faultsim_test_result {0 {0 2 7}} {1 SQLITE_NOMEM} } finish_test |