mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Eliminate code duplication in the two JNI tester classes.
FossilOrigin-Name: 63e7bbe3d5fcfb531f9d7fa88398c1191570e69b5d11adcb9c5e64b8345b4e6c
This commit is contained in:
@ -23,16 +23,16 @@ public class Tester1 {
|
||||
|
||||
static final Metrics metrics = new Metrics();
|
||||
|
||||
private static <T> void out(T val){
|
||||
public static <T> void out(T val){
|
||||
System.out.print(val);
|
||||
}
|
||||
|
||||
private static <T> void outln(T val){
|
||||
public static <T> void outln(T val){
|
||||
System.out.println(val);
|
||||
}
|
||||
|
||||
private static int affirmCount = 0;
|
||||
private static void affirm(Boolean v){
|
||||
static int affirmCount = 0;
|
||||
public static void affirm(Boolean v){
|
||||
++affirmCount;
|
||||
if( !v ) throw new RuntimeException("Assertion failed.");
|
||||
}
|
||||
@ -50,21 +50,23 @@ public class Tester1 {
|
||||
affirm(SQLITE_MAX_TRIGGER_DEPTH>0);
|
||||
}
|
||||
|
||||
private static void testCompileOption(){
|
||||
int i = 0;
|
||||
String optName;
|
||||
outln("compile options:");
|
||||
for( ; null != (optName = sqlite3_compileoption_get(i)); ++i){
|
||||
outln("\t"+optName+"\t (used="+
|
||||
sqlite3_compileoption_used(optName)+")");
|
||||
}
|
||||
|
||||
public static sqlite3 createNewDb(){
|
||||
sqlite3 db = new sqlite3();
|
||||
affirm(0 == db.getNativePointer());
|
||||
int rc = sqlite3_open(":memory:", db);
|
||||
++metrics.dbOpen;
|
||||
affirm(0 == rc);
|
||||
affirm(0 != db.getNativePointer());
|
||||
rc = sqlite3_busy_timeout(db, 2000);
|
||||
affirm( 0 == rc );
|
||||
return db;
|
||||
}
|
||||
|
||||
private static void execSql(sqlite3 db, String[] sql){
|
||||
public static void execSql(sqlite3 db, String[] sql){
|
||||
execSql(db, String.join("", sql));
|
||||
}
|
||||
private static int execSql(sqlite3 db, boolean throwOnError, String sql){
|
||||
|
||||
public 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;
|
||||
@ -95,9 +97,11 @@ public class Tester1 {
|
||||
if(SQLITE_ROW==rc || SQLITE_DONE==rc) rc = 0;
|
||||
return rc;
|
||||
}
|
||||
private static void execSql(sqlite3 db, String sql){
|
||||
|
||||
public static void execSql(sqlite3 db, String sql){
|
||||
execSql(db, true, sql);
|
||||
}
|
||||
|
||||
private static void testOpenDb1(){
|
||||
sqlite3 db = new sqlite3();
|
||||
affirm(0 == db.getNativePointer());
|
||||
@ -109,6 +113,17 @@ public class Tester1 {
|
||||
affirm(0 == db.getNativePointer());
|
||||
}
|
||||
|
||||
private static void testCompileOption(){
|
||||
int i = 0;
|
||||
String optName;
|
||||
outln("compile options:");
|
||||
for( ; null != (optName = sqlite3_compileoption_get(i)); ++i){
|
||||
outln("\t"+optName+"\t (used="+
|
||||
sqlite3_compileoption_used(optName)+")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void testOpenDb2(){
|
||||
sqlite3 db = new sqlite3();
|
||||
affirm(0 == db.getNativePointer());
|
||||
@ -122,18 +137,6 @@ public class Tester1 {
|
||||
affirm(0 == db.getNativePointer());
|
||||
}
|
||||
|
||||
private static sqlite3 createNewDb(){
|
||||
sqlite3 db = new sqlite3();
|
||||
affirm(0 == db.getNativePointer());
|
||||
int rc = sqlite3_open(":memory:", db);
|
||||
++metrics.dbOpen;
|
||||
affirm(0 == rc);
|
||||
affirm(0 != db.getNativePointer());
|
||||
rc = sqlite3_busy_timeout(db, 2000);
|
||||
affirm( 0 == rc );
|
||||
return db;
|
||||
}
|
||||
|
||||
private static void testPrepare123(){
|
||||
sqlite3 db = createNewDb();
|
||||
int rc;
|
||||
|
@ -13,75 +13,10 @@
|
||||
*/
|
||||
package org.sqlite.jni;
|
||||
import static org.sqlite.jni.SQLite3Jni.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import static org.sqlite.jni.Tester1.*;
|
||||
|
||||
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 );
|
||||
@ -90,12 +25,15 @@ public class TesterFts5 {
|
||||
}
|
||||
|
||||
public TesterFts5(){
|
||||
int oldAffirmCount = Tester1.affirmCount;
|
||||
Tester1.affirmCount = 0;
|
||||
final long timeStart = System.nanoTime();
|
||||
test1();
|
||||
final long timeEnd = System.nanoTime();
|
||||
outln("FTS5 Tests done. Metrics:");
|
||||
outln("\tAssertions checked: "+affirmCount);
|
||||
outln("\tAssertions checked: "+Tester1.affirmCount);
|
||||
outln("\tTotal time = "
|
||||
+((timeEnd - timeStart)/1000000.0)+"ms");
|
||||
Tester1.affirmCount = oldAffirmCount;
|
||||
}
|
||||
}
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
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-04T13:03:31.867
|
||||
C Eliminate\scode\sduplication\sin\sthe\stwo\sJNI\stester\sclasses.
|
||||
D 2023-08-04T13:27:45.190
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -247,8 +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/SQLFunction.java 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46
|
||||
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 78496a02c7cc65a2238f54e935af070acf4e2dbef95d7cc1ff46938c440848a4
|
||||
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/Tester1.java 70df1ad81d9740cd5c10dd2c82955b861be33434ddb722fd9b67c35f7ae6fdab
|
||||
F ext/jni/src/org/sqlite/jni/TesterFts5.java b6952f742c968d57f6bc98c0e9c635a31cbcf0b0357f49b9d01e9b56895cf9ab
|
||||
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/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee
|
||||
@ -2076,8 +2076,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 91263178f463ca4623dd0203696eff6bcfd68abde5d2471be3f5a3edd791c52a
|
||||
R b273b1d0d422a8c3553d79602f5aa670
|
||||
P b7a8428fcd969e7a29a23c2dae61883f69501094f2de0f79bbee3c02c672cbf5
|
||||
R 59dc3fb86d2e5c0f507a4fc5e8173e50
|
||||
U stephan
|
||||
Z 5f6d6f36a9720080751b0cf982852db5
|
||||
Z e13f8a71cd8f22ed593837a52fb2f248
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
b7a8428fcd969e7a29a23c2dae61883f69501094f2de0f79bbee3c02c672cbf5
|
||||
63e7bbe3d5fcfb531f9d7fa88398c1191570e69b5d11adcb9c5e64b8345b4e6c
|
Reference in New Issue
Block a user