/ Check-in [8a78050d]
Login

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

Overview
Comment:Improve test coverage of demo code in fts5_test_mi.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8a78050dc0e374a0df0f29716df60250e2c4b4f7
User & Date: dan 2016-02-17 14:11:06
Context
2016-02-17
14:48
Remove the "#ifdef SQLITE_TEST" condition from fts5_test_mi.c. Update fts5_main.c so that if SQLITE_FTS5_TEST_MI is defined when it is built the fts5_test_mi.c entry point is automatically called. This makes it easier to build versions of fts5 that include the matchinfo() demo by default. check-in: 87e6e225 user: dan tags: trunk
14:11
Improve test coverage of demo code in fts5_test_mi.c. check-in: 8a78050d user: dan tags: trunk
13:24
Enhance Lemon to generate more compact and efficient code for yy_reduce(). Update the main SQL grammar to take advantage of the new capabilities. check-in: 53fd040c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/fts5/fts5_test_mi.c.

   240    240         for(iPhrase=0; iPhrase<p->nPhrase; iPhrase++){
   241    241           Fts5PhraseIter iter;
   242    242           int iOff, iCol;
   243    243           for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff); 
   244    244               iOff>=0; 
   245    245               pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
   246    246           ){
   247         -          if( f=='b' ){
   248         -            aOut[iPhrase * ((p->nCol+31)/32) + iCol/32] |= ((u32)1 << iCol%32);
   249         -          }else{
   250    247               aOut[nMul * (iCol + iPhrase * p->nCol)]++;
   251    248             }
   252    249           }
   253         -      }
   254    250   
   255    251         break;
   256    252       }
   257    253   
   258    254       case 'l': {
   259    255         for(i=0; rc==SQLITE_OK && i<p->nCol; i++){
   260    256           int nToken;
................................................................................
   405    401     pApi = fts5_api_from_db(db);
   406    402   
   407    403     /* If fts5_api_from_db() returns NULL, then either FTS5 is not registered
   408    404     ** with this database handle, or an error (OOM perhaps?) has occurred.
   409    405     **
   410    406     ** Also check that the fts5_api object is version 2 or newer.  
   411    407     */ 
   412         -  if( pApi==0 || pApi->iVersion<1 ){
          408  +  if( pApi==0 || pApi->iVersion<2 ){
   413    409       return SQLITE_ERROR;
   414    410     }
   415    411   
   416    412     /* Register the implementation of matchinfo() */
   417    413     rc = pApi->xCreateFunction(pApi, "matchinfo", 0, fts5MatchinfoFunc, 0);
   418    414   
   419    415     return rc;
   420    416   }
   421    417   
   422    418   #endif /* SQLITE_ENABLE_FTS5 */
   423    419   #endif /* SQLITE_TEST */
   424    420   

Added ext/fts5/test/fts5faultB.test.

            1  +# 2016 February 17
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +#
           12  +# This file is focused on OOM errors.
           13  +#
           14  +
           15  +source [file join [file dirname [info script]] fts5_common.tcl]
           16  +source $testdir/malloc_common.tcl
           17  +set testprefix fts5faultB
           18  +
           19  +# If SQLITE_ENABLE_FTS3 is defined, omit this file.
           20  +ifcapable !fts5 {
           21  +  finish_test
           22  +  return
           23  +}
           24  +
           25  +proc mit {blob} {
           26  +  set scan(littleEndian) i*
           27  +  set scan(bigEndian) I*
           28  +  binary scan $blob $scan($::tcl_platform(byteOrder)) r
           29  +  return $r
           30  +}
           31  +db func mit mit
           32  +
           33  +
           34  +#-------------------------------------------------------------------------
           35  +# Errors while registering the matchinfo() demo function.
           36  +#
           37  +do_faultsim_test 1 -faults oom* -prep {
           38  +  sqlite3 db test.db
           39  +} -body {
           40  +  sqlite3_fts5_register_matchinfo db
           41  +} -test {
           42  +  faultsim_test_result {0 {}} {1 SQLITE_ERROR} {1 SQLITE_NOMEM}
           43  +}
           44  +
           45  +
           46  +#-------------------------------------------------------------------------
           47  +# Errors while executing the matchinfo() demo function.
           48  +#
           49  +reset_db
           50  +sqlite3_fts5_register_matchinfo db
           51  +db func mit mit
           52  +do_execsql_test 2 {
           53  +  CREATE VIRTUAL TABLE t1 USING fts5(a, b);
           54  +  INSERT INTO t1 VALUES('x y z', '1 2 3');
           55  +  INSERT INTO t1 VALUES('x', '1 2 3 4 5 6 7');
           56  +}
           57  +
           58  +do_faultsim_test 2.1 -faults oom* -body {
           59  +  execsql { SELECT mit(matchinfo(t1, 'a')) FROM t1('x') }
           60  +} -test {
           61  +  faultsim_test_result {0 {{2 5} {2 5}}} 
           62  +}
           63  +
           64  +do_faultsim_test 2.2 -faults oom* -body {
           65  +  execsql { SELECT mit(matchinfo(t1, 'l')) FROM t1('x') }
           66  +} -test {
           67  +  faultsim_test_result {0 {{3 3} {1 7}}} 
           68  +}
           69  +
           70  +do_execsql_test 2.3 {
           71  +  INSERT INTO t1 VALUES('a b c d e f', 'a b d e f c');
           72  +  INSERT INTO t1 VALUES('l m b c a', 'n o a b c z');
           73  +}
           74  +
           75  +do_faultsim_test 2.4 -faults oom* -body {
           76  +  execsql { SELECT mit(matchinfo(t1, 's')) FROM t1('a b c') }
           77  +} -test {
           78  +  faultsim_test_result {0 {{3 2} {2 3}}} 
           79  +}
           80  +
           81  +
           82  +finish_test
           83  +

Changes to ext/fts5/test/fts5matchinfo.test.

   462    462   
   463    463   do_execsql_test 12.1 {
   464    464     INSERT INTO tt (rowid, c4, c45) VALUES(1, 'abc', 'abc');
   465    465     SELECT mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH 'abc';
   466    466   } [list [list [expr 1<<4] [expr 1<<(45-32)]]]
   467    467   
   468    468   } ;# foreach_detail_mode
          469  +
          470  +#-------------------------------------------------------------------------
          471  +# Test that a bad fts5() return is detected
          472  +#
          473  +reset_db
          474  +proc xyz {} {}
          475  +db func fts5 -argcount 0 xyz
          476  +do_test 13.1 {
          477  +  list [catch { sqlite3_fts5_register_matchinfo db } msg] $msg
          478  +} {1 SQLITE_ERROR}
          479  +
          480  +#-------------------------------------------------------------------------
          481  +# Test that an invalid matchinfo() flag is detected
          482  +#
          483  +reset_db
          484  +sqlite3_fts5_register_matchinfo db
          485  +do_execsql_test 14.1 {
          486  +  CREATE VIRTUAL TABLE x1 USING fts5(z);
          487  +  INSERT INTO x1 VALUES('a b c a b c a b c');
          488  +} {}
          489  +
          490  +do_catchsql_test 14.2 {
          491  +  SELECT matchinfo(x1, 'd') FROM x1('a b c');
          492  +} {1 {unrecognized matchinfo flag: d}}
   469    493   
   470    494   finish_test
   471    495