mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
FTS-related JNI refactoring. Move FTS-specific tests into their own class and dynamically load it, if possible, from the main test app.
FossilOrigin-Name: b7a8428fcd969e7a29a23c2dae61883f69501094f2de0f79bbee3c02c672cbf5
This commit is contained in:
@@ -69,11 +69,12 @@ ifeq (1,$(enable.fts5))
|
|||||||
Fts5Context.java \
|
Fts5Context.java \
|
||||||
Fts5ExtensionApi.java \
|
Fts5ExtensionApi.java \
|
||||||
Fts5Function.java \
|
Fts5Function.java \
|
||||||
|
TesterFts5.java \
|
||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
CLASS_FILES :=
|
CLASS_FILES :=
|
||||||
define DOTCLASS_DEPS
|
define DOTCLASS_DEPS
|
||||||
$(1).class: $(1).java
|
$(1).class: $(1).java $(MAKEFILE)
|
||||||
all: $(1).class
|
all: $(1).class
|
||||||
CLASS_FILES += $(1).class
|
CLASS_FILES += $(1).class
|
||||||
endef
|
endef
|
||||||
|
@@ -206,6 +206,7 @@ static const struct {
|
|||||||
#ifdef SQLITE_ENABLE_FTS5
|
#ifdef SQLITE_ENABLE_FTS5
|
||||||
const char * const Fts5Context;
|
const char * const Fts5Context;
|
||||||
const char * const Fts5ExtensionApi;
|
const char * const Fts5ExtensionApi;
|
||||||
|
const char * const fts5_api;
|
||||||
#endif
|
#endif
|
||||||
} S3ClassNames = {
|
} S3ClassNames = {
|
||||||
"org/sqlite/jni/sqlite3",
|
"org/sqlite/jni/sqlite3",
|
||||||
@@ -216,7 +217,7 @@ static const struct {
|
|||||||
"org/sqlite/jni/OutputPointer$Int64",
|
"org/sqlite/jni/OutputPointer$Int64",
|
||||||
#ifdef SQLITE_ENABLE_FTS5
|
#ifdef SQLITE_ENABLE_FTS5
|
||||||
"org/sqlite/jni/Fts5Context",
|
"org/sqlite/jni/Fts5Context",
|
||||||
"org/sqlite/jni/Fts5ExtensionApi"
|
"org/sqlite/jni/Fts5ExtensionApi",
|
||||||
"org/sqlite/jni/fts5_api"
|
"org/sqlite/jni/fts5_api"
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -959,6 +960,7 @@ static void setOutputInt32(JNIEnv * env, jobject jOut, int v){
|
|||||||
EXCEPTION_IS_FATAL("Cannot set OutputPointer.Int32.value");
|
EXCEPTION_IS_FATAL("Cannot set OutputPointer.Int32.value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SQLITE_ENABLE_FTS5
|
||||||
/* Sets a native int64 value in OutputPointer.Int64 object jOut. */
|
/* Sets a native int64 value in OutputPointer.Int64 object jOut. */
|
||||||
static void setOutputInt64(JNIEnv * env, jobject jOut, jlong v){
|
static void setOutputInt64(JNIEnv * env, jobject jOut, jlong v){
|
||||||
jfieldID setter = 0;
|
jfieldID setter = 0;
|
||||||
@@ -977,6 +979,7 @@ static void setOutputInt64(JNIEnv * env, jobject jOut, jlong v){
|
|||||||
(*env)->SetIntField(env, jOut, setter, (jint)v);
|
(*env)->SetIntField(env, jOut, setter, (jint)v);
|
||||||
EXCEPTION_IS_FATAL("Cannot set OutputPointer.Int64.value");
|
EXCEPTION_IS_FATAL("Cannot set OutputPointer.Int64.value");
|
||||||
}
|
}
|
||||||
|
#endif /* SQLITE_ENABLE_FTS5 */
|
||||||
|
|
||||||
static int encodingTypeIsValid(int eTextRep){
|
static int encodingTypeIsValid(int eTextRep){
|
||||||
switch(eTextRep){
|
switch(eTextRep){
|
||||||
|
@@ -909,10 +909,19 @@ public class Tester1 {
|
|||||||
sqlite3_close_v2(db);
|
sqlite3_close_v2(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testFts1(){
|
@SuppressWarnings("unchecked")
|
||||||
Fts5ExtensionApi fea = Fts5ExtensionApi.getInstance();
|
private static void testFts5(){
|
||||||
affirm( null != fea );
|
try {
|
||||||
affirm( fea.getNativePointer() != 0 );
|
Class t = Class.forName("org.sqlite.jni.TesterFts5");
|
||||||
|
java.lang.reflect.Constructor ctor = t.getConstructor();
|
||||||
|
ctor.newInstance();
|
||||||
|
}catch(ClassNotFoundException e){
|
||||||
|
outln("FTS5 classes not loaded. Skipping FTS tests.");
|
||||||
|
}catch(NoSuchMethodException e){
|
||||||
|
outln("FTS5 tester ctor not found. Skipping FTS tests.");
|
||||||
|
}catch(Exception e){
|
||||||
|
outln("FTS5 tester cannot be instantiated. Skipping FTS tests.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testSleep(){
|
private static void testSleep(){
|
||||||
@@ -947,6 +956,7 @@ public class Tester1 {
|
|||||||
testCommitHook();
|
testCommitHook();
|
||||||
testRollbackHook();
|
testRollbackHook();
|
||||||
testUpdateHook();
|
testUpdateHook();
|
||||||
|
testFts5();
|
||||||
//testSleep();
|
//testSleep();
|
||||||
if(liArgs.indexOf("-v")>0){
|
if(liArgs.indexOf("-v")>0){
|
||||||
sqlite3_do_something_for_developer();
|
sqlite3_do_something_for_developer();
|
||||||
|
101
ext/jni/src/org/sqlite/jni/TesterFts5.java
Normal file
101
ext/jni/src/org/sqlite/jni/TesterFts5.java
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
** 2023-08-04
|
||||||
|
**
|
||||||
|
** The author disclaims copyright to this source code. In place of
|
||||||
|
** a legal notice, here is a blessing:
|
||||||
|
**
|
||||||
|
** May you do good and not evil.
|
||||||
|
** May you find forgiveness for yourself and forgive others.
|
||||||
|
** May you share freely, never taking more than you give.
|
||||||
|
**
|
||||||
|
*************************************************************************
|
||||||
|
** This file contains a set of tests for the sqlite3 JNI bindings.
|
||||||
|
*/
|
||||||
|
package org.sqlite.jni;
|
||||||
|
import static org.sqlite.jni.SQLite3Jni.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class TesterFts5 {
|
||||||
|
|
||||||
|
private static <T> void out(T val){
|
||||||
|
System.out.print(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> void outln(T val){
|
||||||
|
System.out.println(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int affirmCount = 0;
|
||||||
|
private static void affirm(Boolean v){
|
||||||
|
++affirmCount;
|
||||||
|
if( !v ) throw new RuntimeException("Assertion failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void execSql(sqlite3 db, String[] sql){
|
||||||
|
execSql(db, String.join("", sql));
|
||||||
|
}
|
||||||
|
private static int execSql(sqlite3 db, boolean throwOnError, String sql){
|
||||||
|
OutputPointer.Int32 oTail = new OutputPointer.Int32();
|
||||||
|
final byte[] sqlUtf8 = sql.getBytes(StandardCharsets.UTF_8);
|
||||||
|
int pos = 0, n = 1;
|
||||||
|
byte[] sqlChunk = sqlUtf8;
|
||||||
|
sqlite3_stmt stmt = new sqlite3_stmt();
|
||||||
|
int rc = 0;
|
||||||
|
while(pos < sqlChunk.length){
|
||||||
|
if(pos > 0){
|
||||||
|
sqlChunk = Arrays.copyOfRange(sqlChunk, pos,
|
||||||
|
sqlChunk.length);
|
||||||
|
}
|
||||||
|
if( 0==sqlChunk.length ) break;
|
||||||
|
rc = sqlite3_prepare_v2(db, sqlChunk, stmt, oTail);
|
||||||
|
affirm(0 == rc);
|
||||||
|
pos = oTail.getValue();
|
||||||
|
affirm(0 != stmt.getNativePointer());
|
||||||
|
rc = sqlite3_step(stmt);
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
affirm(0 == stmt.getNativePointer());
|
||||||
|
if(0!=rc && SQLITE_ROW!=rc && SQLITE_DONE!=rc){
|
||||||
|
if(throwOnError){
|
||||||
|
throw new RuntimeException("db op failed with rc="+rc);
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(SQLITE_ROW==rc || SQLITE_DONE==rc) rc = 0;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
private static void execSql(sqlite3 db, String sql){
|
||||||
|
execSql(db, true, sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static sqlite3 createNewDb(){
|
||||||
|
sqlite3 db = new sqlite3();
|
||||||
|
affirm(0 == db.getNativePointer());
|
||||||
|
int rc = sqlite3_open(":memory:", db);
|
||||||
|
affirm(0 == rc);
|
||||||
|
affirm(0 != db.getNativePointer());
|
||||||
|
rc = sqlite3_busy_timeout(db, 2000);
|
||||||
|
affirm( 0 == rc );
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void test1(){
|
||||||
|
Fts5ExtensionApi fea = Fts5ExtensionApi.getInstance();
|
||||||
|
affirm( null != fea );
|
||||||
|
affirm( fea.getNativePointer() != 0 );
|
||||||
|
affirm( fea == Fts5ExtensionApi.getInstance() )/*singleton*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TesterFts5(){
|
||||||
|
final long timeStart = System.nanoTime();
|
||||||
|
test1();
|
||||||
|
final long timeEnd = System.nanoTime();
|
||||||
|
outln("FTS5 Tests done. Metrics:");
|
||||||
|
outln("\tAssertions checked: "+affirmCount);
|
||||||
|
outln("\tTotal time = "
|
||||||
|
+((timeEnd - timeStart)/1000000.0)+"ms");
|
||||||
|
}
|
||||||
|
}
|
17
manifest
17
manifest
@@ -1,5 +1,5 @@
|
|||||||
C More\swork\stowards\sbinding\sFTS5\scustomization\sto\sJNI.\sAdd\sFts*.java\sfiles\smissing\sfrom\sprevious\scheckin.
|
C FTS-related\sJNI\srefactoring.\sMove\sFTS-specific\stests\sinto\stheir\sown\sclass\sand\sdynamically\sload\sit,\sif\spossible,\sfrom\sthe\smain\stest\sapp.
|
||||||
D 2023-08-04T12:44:06.920
|
D 2023-08-04T13:03:31.867
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@@ -230,9 +230,9 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c
|
|||||||
F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9
|
F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9
|
||||||
F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
|
F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
|
||||||
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
|
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
|
||||||
F ext/jni/GNUmakefile ff5c539c686b79598c9703822343a3b3117b2153ccebde0935f805f760de0847
|
F ext/jni/GNUmakefile 83f8f1c5a76714b3034815631587336c9b5bb345a325bde118a6909e2f18b16f
|
||||||
F ext/jni/README.md 6ff7e1f4100dee980434a6ee37a199b653bceec62e233a6e2ccde6e7ae0c58bf
|
F ext/jni/README.md 6ff7e1f4100dee980434a6ee37a199b653bceec62e233a6e2ccde6e7ae0c58bf
|
||||||
F ext/jni/src/c/sqlite3-jni.c 8ec2c1cc63af05bc84965c73e0dacb39474f5efd9fa712c780a24a44237c5e4b
|
F ext/jni/src/c/sqlite3-jni.c d3f98fa1b76d2ee810984ace183459d893d322f8c78bdf44d2bacf2b5e465cf6
|
||||||
F ext/jni/src/c/sqlite3-jni.h ed03612024e9fe06a9e0655ccfe9f9f7bd899c7e68badad636c7d9833682655b
|
F ext/jni/src/c/sqlite3-jni.h ed03612024e9fe06a9e0655ccfe9f9f7bd899c7e68badad636c7d9833682655b
|
||||||
F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c
|
F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c
|
||||||
F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1
|
F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1
|
||||||
@@ -247,7 +247,8 @@ F ext/jni/src/org/sqlite/jni/ProgressHandler.java 5979450e996416d28543f1d42634d3
|
|||||||
F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564
|
F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564
|
||||||
F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46
|
F ext/jni/src/org/sqlite/jni/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46
|
||||||
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 78496a02c7cc65a2238f54e935af070acf4e2dbef95d7cc1ff46938c440848a4
|
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 78496a02c7cc65a2238f54e935af070acf4e2dbef95d7cc1ff46938c440848a4
|
||||||
F ext/jni/src/org/sqlite/jni/Tester1.java fed44197213929cb16edbb59d68f057d0b851cb35c4b52366b021e158ded304b
|
F ext/jni/src/org/sqlite/jni/Tester1.java 983d6eda3c5f5c48983b4dd972c59a18b51041c304918b8e697a9e133ea02821
|
||||||
|
F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d258f7c252bb509b424095a02a54e18e63aaf6830702d929a609d63cae4a13e
|
||||||
F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d
|
F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d
|
||||||
F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d
|
F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d
|
||||||
F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee
|
F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee
|
||||||
@@ -2075,8 +2076,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P abaf5edd0430e3301a11bd0acb9ce4b81b310237e1799701411db56ef7605e01
|
P 91263178f463ca4623dd0203696eff6bcfd68abde5d2471be3f5a3edd791c52a
|
||||||
R 0ce682e16f3279fc573892c09d1e8907
|
R b273b1d0d422a8c3553d79602f5aa670
|
||||||
U stephan
|
U stephan
|
||||||
Z cb3ae8248e37b24a50f177e201f5ab44
|
Z 5f6d6f36a9720080751b0cf982852db5
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
@@ -1 +1 @@
|
|||||||
91263178f463ca4623dd0203696eff6bcfd68abde5d2471be3f5a3edd791c52a
|
b7a8428fcd969e7a29a23c2dae61883f69501094f2de0f79bbee3c02c672cbf5
|
Reference in New Issue
Block a user