modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/fts5/test/fts5faultB.test (about)

     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  #
    83  reset_db 
    84  do_execsql_test 3.0 {
    85    CREATE VIRTUAL TABLE x1 USING fts5(z);
    86  }
    87  
    88  do_faultsim_test 3.1 -faults oom* -body {
    89    execsql {
    90      SELECT rowid FROM x1('c') WHERE rowid>1;
    91    }
    92  } -test {
    93    faultsim_test_result {0 {}}
    94  }
    95  
    96  do_execsql_test 3.2 {
    97    INSERT INTO x1 VALUES('a b c');
    98    INSERT INTO x1 VALUES('b c d');
    99    INSERT INTO x1 VALUES('c d e');
   100    INSERT INTO x1 VALUES('d e f');
   101  }
   102  do_faultsim_test 3.3 -faults oom* -body {
   103    execsql {
   104      SELECT rowid FROM x1('c') WHERE rowid>1;
   105    }
   106  } -test {
   107    faultsim_test_result {0 {2 3}}
   108  }
   109  
   110  #-------------------------------------------------------------------------
   111  # Test OOM injection with nested colsets.
   112  #
   113  reset_db
   114  do_execsql_test 4.0 {
   115    CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, d);
   116    INSERT INTO t1 VALUES('a', 'b', 'c', 'd');  -- 1
   117    INSERT INTO t1 VALUES('d', 'a', 'b', 'c');  -- 2
   118    INSERT INTO t1 VALUES('c', 'd', 'a', 'b');  -- 3
   119    INSERT INTO t1 VALUES('b', 'c', 'd', 'a');  -- 4
   120  }
   121  do_faultsim_test 4.1 -faults oom* -body {
   122    execsql { SELECT rowid FROM t1('{a b c} : (b:a AND c:b)'); }
   123  } -test {
   124    faultsim_test_result {0 2}
   125  }
   126  
   127  do_faultsim_test 4.2 -faults oom* -body {
   128    execsql { SELECT rowid FROM t1('{a b c} : (a AND d)') }
   129  } -test {
   130    faultsim_test_result {0 {2 3}}
   131  }
   132  
   133  
   134  finish_test