Extra tests for java Fts5ExtensionApi interface.

FossilOrigin-Name: c923893f3604b278277de1bb919ef713bf7a4296b7ff71451cfe19bc2ff03190
This commit is contained in:
dan 2023-09-18 18:12:03 +00:00
parent 38119058aa
commit 876f09b560
4 changed files with 292 additions and 12 deletions

View File

@ -1288,7 +1288,7 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1data_1count
* Method: sqlite3_db_config
* Signature: (Lorg/sqlite/jni/sqlite3;IILorg/sqlite/jni/OutputPointer/Int32;)I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_Int32_2
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPointer_00024Int32_2
(JNIEnv *, jclass, jobject, jint, jint, jobject);
/*

View File

@ -275,7 +275,185 @@ public class TesterFts5 {
public void xDestroy(){ }
};
fts5_aux fts5_aux1 = new fts5_aux();
/*
** fts5_inst(<fts>);
**
** This is used to test the xInstCount() and xInst() APIs. It returns a
** text value containing a Tcl list with xInstCount() elements. Each
** element is itself a list of 3 integers - the phrase number, column
** number and token offset returned by each call to xInst().
*/
fts5_extension_function fts5_inst = new fts5_extension_function(){
@Override public void call(
Fts5ExtensionApi ext,
Fts5Context fCx,
sqlite3_context pCx,
sqlite3_value argv[]
){
if( argv.length!=0 ){
throw new RuntimeException("fts5_inst: wrong number of args");
}
OutputPointer.Int32 pnInst = new OutputPointer.Int32();
OutputPointer.Int32 piPhrase = new OutputPointer.Int32();
OutputPointer.Int32 piCol = new OutputPointer.Int32();
OutputPointer.Int32 piOff = new OutputPointer.Int32();
String ret = new String();
int rc = ext.xInstCount(fCx, pnInst);
int nInst = pnInst.get();
int ii;
for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
ext.xInst(fCx, ii, piPhrase, piCol, piOff);
if( ii>0 ) ret += " ";
ret += "{"+piPhrase.get()+" "+piCol.get()+" "+piOff.get()+"}";
}
sqlite3_result_text(pCx, ret);
}
public void xDestroy(){ }
};
/*
** fts5_pinst(<fts>);
**
** Like SQL function fts5_inst(), except using the following
**
** xPhraseCount
** xPhraseFirst
** xPhraseNext
*/
fts5_extension_function fts5_pinst = new fts5_extension_function(){
@Override public void call(
Fts5ExtensionApi ext,
Fts5Context fCx,
sqlite3_context pCx,
sqlite3_value argv[]
){
if( argv.length!=0 ){
throw new RuntimeException("fts5_pinst: wrong number of args");
}
OutputPointer.Int32 piCol = new OutputPointer.Int32();
OutputPointer.Int32 piOff = new OutputPointer.Int32();
String ret = new String();
int rc = SQLITE_OK;
int nPhrase = ext.xPhraseCount(fCx);
int ii;
for(ii=0; rc==SQLITE_OK && ii<nPhrase; ii++){
Fts5PhraseIter pIter = new Fts5PhraseIter();
for(rc = ext.xPhraseFirst(fCx, ii, pIter, piCol, piOff);
rc==SQLITE_OK && piCol.get()>=0;
ext.xPhraseNext(fCx, pIter, piCol, piOff)
){
if( !ret.equals("") ) ret += " ";
ret += "{"+ii+" "+piCol.get()+" "+piOff.get()+"}";
}
}
if( rc!=SQLITE_OK ){
throw new RuntimeException("fts5_pinst: rc=" + rc);
}else{
sqlite3_result_text(pCx, ret);
}
}
public void xDestroy(){ }
};
/*
** fts5_pcolinst(<fts>);
**
** Like SQL function fts5_pinst(), except using the following
**
** xPhraseFirstColumn
** xPhraseNextColumn
*/
fts5_extension_function fts5_pcolinst = new fts5_extension_function(){
@Override public void call(
Fts5ExtensionApi ext,
Fts5Context fCx,
sqlite3_context pCx,
sqlite3_value argv[]
){
if( argv.length!=0 ){
throw new RuntimeException("fts5_pcolinst: wrong number of args");
}
OutputPointer.Int32 piCol = new OutputPointer.Int32();
String ret = new String();
int rc = SQLITE_OK;
int nPhrase = ext.xPhraseCount(fCx);
int ii;
for(ii=0; rc==SQLITE_OK && ii<nPhrase; ii++){
Fts5PhraseIter pIter = new Fts5PhraseIter();
for(rc = ext.xPhraseFirstColumn(fCx, ii, pIter, piCol);
rc==SQLITE_OK && piCol.get()>=0;
ext.xPhraseNextColumn(fCx, pIter, piCol)
){
if( !ret.equals("") ) ret += " ";
ret += "{"+ii+" "+piCol.get()+"}";
}
}
if( rc!=SQLITE_OK ){
throw new RuntimeException("fts5_pcolinst: rc=" + rc);
}else{
sqlite3_result_text(pCx, ret);
}
}
public void xDestroy(){ }
};
/*
** fts5_rowcount(<fts>);
*/
fts5_extension_function fts5_rowcount = new fts5_extension_function(){
@Override public void call(
Fts5ExtensionApi ext,
Fts5Context fCx,
sqlite3_context pCx,
sqlite3_value argv[]
){
if( argv.length!=0 ){
throw new RuntimeException("fts5_rowcount: wrong number of args");
}
OutputPointer.Int64 pnRow = new OutputPointer.Int64();
int rc = ext.xRowCount(fCx, pnRow);
if( rc==SQLITE_OK ){
sqlite3_result_int64(pCx, pnRow.get());
}else{
throw new RuntimeException("fts5_rowcount: rc=" + rc);
}
}
public void xDestroy(){ }
};
/*
** fts5_phrasesize(<fts>);
*/
fts5_extension_function fts5_phrasesize = new fts5_extension_function(){
@Override public void call(
Fts5ExtensionApi ext,
Fts5Context fCx,
sqlite3_context pCx,
sqlite3_value argv[]
){
if( argv.length!=1 ){
throw new RuntimeException("fts5_phrasesize: wrong number of args");
}
int iPhrase = sqlite3_value_int(argv[0]);
int sz = ext.xPhraseSize(fCx, iPhrase);
sqlite3_result_int(pCx, sz);
}
public void xDestroy(){ }
};
fts5_api api = fts5_api.getInstanceForDb(db);
api.xCreateFunction("fts5_rowid", fts5_rowid);
@ -286,8 +464,13 @@ public class TesterFts5 {
api.xCreateFunction("fts5_aux1", new fts5_aux());
api.xCreateFunction("fts5_aux2", new fts5_aux());
}
api.xCreateFunction("fts5_inst", fts5_inst);
api.xCreateFunction("fts5_pinst", fts5_pinst);
api.xCreateFunction("fts5_pcolinst", fts5_pcolinst);
api.xCreateFunction("fts5_rowcount", fts5_rowcount);
api.xCreateFunction("fts5_phrasesize", fts5_phrasesize);
}
/*
** Test of various Fts5ExtensionApi methods
*/
@ -381,6 +564,11 @@ public class TesterFts5 {
affirm( e.getMessage().matches(".*column index out of range") );
}
do_execsql_test(db,
"SELECT rowid, fts5_rowcount(ft) FROM ft('z')",
"[1, 6, 2, 6, 3, 6]"
);
sqlite3_close_v2(db);
}
@ -417,13 +605,105 @@ public class TesterFts5 {
"SELECT fts5_aux1(ft, b), fts5_aux1(ft) FROM ft('the')",
"[null, 1, 1, 2, 2, 3, 3, null]"
);
}
/*
** Test of various Fts5ExtensionApi methods
*/
private static void test4(){
/* Open db and populate an fts5 table */
sqlite3 db = createNewDb();
create_test_functions(db);
do_execsql_test(db,
"CREATE VIRTUAL TABLE ft USING fts5(a, b);" +
"INSERT INTO ft(a, b) VALUES('one two three', 'two three four');" +
"INSERT INTO ft(a, b) VALUES('two three four', 'three four five');" +
"INSERT INTO ft(a, b) VALUES('three four five', 'four five six');"
);
do_execsql_test(db,
"SELECT fts5_inst(ft) FROM ft('two')",
"[{0 0 1} {0 1 0}, {0 0 0}]"
);
do_execsql_test(db,
"SELECT fts5_inst(ft) FROM ft('four')",
"[{0 1 2}, {0 0 2} {0 1 1}, {0 0 1} {0 1 0}]"
);
do_execsql_test(db,
"SELECT fts5_inst(ft) FROM ft('a OR b OR four')",
"[{2 1 2}, {2 0 2} {2 1 1}, {2 0 1} {2 1 0}]"
);
do_execsql_test(db,
"SELECT fts5_inst(ft) FROM ft('two four')",
"[{0 0 1} {0 1 0} {1 1 2}, {0 0 0} {1 0 2} {1 1 1}]"
);
do_execsql_test(db,
"SELECT fts5_pinst(ft) FROM ft('two')",
"[{0 0 1} {0 1 0}, {0 0 0}]"
);
do_execsql_test(db,
"SELECT fts5_pinst(ft) FROM ft('four')",
"[{0 1 2}, {0 0 2} {0 1 1}, {0 0 1} {0 1 0}]"
);
do_execsql_test(db,
"SELECT fts5_pinst(ft) FROM ft('a OR b OR four')",
"[{2 1 2}, {2 0 2} {2 1 1}, {2 0 1} {2 1 0}]"
);
do_execsql_test(db,
"SELECT fts5_pinst(ft) FROM ft('two four')",
"[{0 0 1} {0 1 0} {1 1 2}, {0 0 0} {1 0 2} {1 1 1}]"
);
do_execsql_test(db,
"SELECT fts5_pcolinst(ft) FROM ft('two')",
"[{0 0} {0 1}, {0 0}]"
);
do_execsql_test(db,
"SELECT fts5_pcolinst(ft) FROM ft('four')",
"[{0 1}, {0 0} {0 1}, {0 0} {0 1}]"
);
do_execsql_test(db,
"SELECT fts5_pcolinst(ft) FROM ft('a OR b OR four')",
"[{2 1}, {2 0} {2 1}, {2 0} {2 1}]"
);
do_execsql_test(db,
"SELECT fts5_pcolinst(ft) FROM ft('two four')",
"[{0 0} {0 1} {1 1}, {0 0} {1 0} {1 1}]"
);
sqlite3_close_v2(db);
}
private static void test5(){
/* Open db and populate an fts5 table */
sqlite3 db = createNewDb();
create_test_functions(db);
do_execsql_test(db,
"CREATE VIRTUAL TABLE ft USING fts5(x, b);" +
"INSERT INTO ft(x) VALUES('one two three four five six seven eight');"
);
do_execsql_test(db,
"SELECT fts5_phrasesize(ft, 0) FROM ft('four five six');",
"[1]"
);
do_execsql_test(db,
"SELECT fts5_phrasesize(ft, 0) FROM ft('four + five + six');",
"[3]"
);
sqlite3_close_v2(db);
}
private static synchronized void runTests(){
test1();
test2();
test3();
test4();
}
public TesterFts5(){

View File

@ -1,5 +1,5 @@
C Remove\sa\sNEVER()\sin\sbtree.c\sthat\scould\sactually\sbe\sreached,\swith\sthe\sapproriate\ndatabase\scorruption.
D 2023-09-17T16:36:22.899
C Extra\stests\sfor\sjava\sFts5ExtensionApi\sinterface.
D 2023-09-18T18:12:03.235
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -239,7 +239,7 @@ F ext/jni/GNUmakefile 42e00052401b6dd41c0cdd53b31450606ea37486283abdb038dff9be74
F ext/jni/README.md 9fceaeb17cecdc5d699dfc83c0cbc3a03fdb3b86bf676381894166c73375ee75
F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
F ext/jni/src/c/sqlite3-jni.c 24b620de024b1763c094dcfef978c78a1b417cb90210f6fe51b04b45e492496b
F ext/jni/src/c/sqlite3-jni.h 5e093f65c01050e6fe0988f559145f3b61a15c734aa3100a2b98d2a4b9d4c57a
F ext/jni/src/c/sqlite3-jni.h c934b646b62c0fd13dfceea7a54d8fc0d1274d0520d0edc58ad220753f4c4f7d
F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436
F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4
F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38
@ -276,7 +276,7 @@ F ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java 7058da97059b8e156c17561a47ecd
F ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java b1b23431ece266c3308c1089d4cc3d2762a36ff4ea720196be1bcd75577abb9a
F ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java 2a7f3d76a1206e6a43d4c4ed9609b294d5431cc7d8fb875d8419f76efa6e56dc
F ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java cc9a53846a168a215238af224c31cef0e8379780e36e8a5e743b00c08145cf19
F ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java 29899c85710b6210f34beccf97fa853369c87dec25c66f289b7c620f4340ed8d
F ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java 499cd66c4a291a12e8224fa627bf105167fe5a3879bf70ae3eb06f1c3abb4c08
F ext/jni/src/org/sqlite/jni/fts5/XTokenizeCallback.java 1efd1220ea328a32f2d2a1b16c735864159e929480f71daad4de9d5944839167
F ext/jni/src/org/sqlite/jni/fts5/fts5_api.java 6071bf76c2c6a0f035b99adc76715b0324f540a441452b4ff6b94d9360a6a83d
F ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java 1fe0f5692c1d67475d12b067f0469949073446f18c56eba5ee5da6ddd06db9b9
@ -2121,8 +2121,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 37ec43d92bde13efc71fa57ff5e59c4a95b9054c298f844aefeb06d4a91ad0d4
R 2dff3eedf66e26de6ca89861ec866225
U drh
Z a50c6507545030243bec0cded72fd45a
P d1fd00e0875f881cacdc581a75215ec1872a81969ac07b8ebe3aaa707a9a3640
R 1fefa695fa4390af83beddaf788f1e81
U dan
Z 8321aa821a44435aa878fc82bc41dc27
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
d1fd00e0875f881cacdc581a75215ec1872a81969ac07b8ebe3aaa707a9a3640
c923893f3604b278277de1bb919ef713bf7a4296b7ff71451cfe19bc2ff03190