Add basic session API JS tests.
FossilOrigin-Name: 64e032602cf420851c8029603c76f5512000d1c9a40fa7a545528d69d6d1d4cc
This commit is contained in:
parent
7d59d90a5b
commit
9d61db1944
@ -1010,7 +1010,12 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
T.assert(P.quota >= 4096)
|
||||
.assert(remaining === P.quota)
|
||||
.mustThrowMatching(()=>P.alloc(0), isAllocErr)
|
||||
.mustThrowMatching(()=>P.alloc(-1), isAllocErr);
|
||||
.mustThrowMatching(()=>P.alloc(-1), isAllocErr)
|
||||
.mustThrowMatching(
|
||||
()=>P.alloc('i33'),
|
||||
(e)=>e instanceof sqlite3.WasmAllocError
|
||||
);
|
||||
;
|
||||
let p1 = P.alloc(12);
|
||||
T.assert(p1 === stack - 16/*8-byte aligned*/)
|
||||
.assert(P.pointer === p1);
|
||||
@ -1029,7 +1034,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
|
||||
T.assert(P.pointer === stack);
|
||||
try {
|
||||
const [p1, p2, p3] = P.allocChunks(3,4);
|
||||
const [p1, p2, p3] = P.allocChunks(3,'i32');
|
||||
T.assert(P.pointer === stack-16/*always rounded to multiple of 8*/)
|
||||
.assert(p2 === p1 + 4)
|
||||
.assert(p3 === p2 + 4);
|
||||
@ -1143,7 +1148,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
T.assert(wasm.isPtr(db.pointer))
|
||||
.mustThrowMatching(()=>db.pointer=1, /read-only/)
|
||||
.assert(0===sqlite3.capi.sqlite3_extended_result_codes(db.pointer,1))
|
||||
@ -1183,7 +1188,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
T.assert(0 === rc);
|
||||
const stack = wasm.pstack.pointer;
|
||||
try {
|
||||
const [pCur, pHi] = wasm.pstack.allocChunks(2,8);
|
||||
const [pCur, pHi] = wasm.pstack.allocChunks(2,'i64');
|
||||
rc = capi.sqlite3_db_status(this.db, capi.SQLITE_DBSTATUS_LOOKASIDE_USED,
|
||||
pCur, pHi, 0);
|
||||
T.assert(0===rc);
|
||||
@ -1729,7 +1734,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
// sqlite3_result_xyz() and return undefined. Both are
|
||||
// functionally equivalent.
|
||||
}
|
||||
});
|
||||
});
|
||||
T.assert(18===db.selectValue('select summerN(1,8,9), summerN(2,3,4)'));
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{
|
||||
@ -1856,7 +1861,6 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
.assert('select 2;' === rc[1])
|
||||
.assert('-- empty\n; select 3' === rc[2]
|
||||
/* Strange but true. */);
|
||||
|
||||
T.mustThrowMatching(()=>{
|
||||
db.exec({sql:'', returnValue: 'nope'});
|
||||
}, /^Invalid returnValue/);
|
||||
@ -2632,6 +2636,78 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
}/*OPFS util sanity checks*/)
|
||||
;/* end OPFS tests */
|
||||
|
||||
T.g('Session API')
|
||||
.t({
|
||||
name: 'Session API sanity checks',
|
||||
predicate: ()=>!!capi.sqlite3changegroup_add,
|
||||
test: function(sqlite3){
|
||||
const db1 = new sqlite3.oo1.DB(), db2 = new sqlite3.oo1.DB();
|
||||
const sqlInit = [
|
||||
"create table t(rowid INTEGER PRIMARY KEY,a,b); ",
|
||||
"insert into t(rowid,a,b) values",
|
||||
"(1,'a1','b1'),",
|
||||
"(2,'a2','b2'),",
|
||||
"(3,'a3','b3');"
|
||||
].join('');
|
||||
db1.exec(sqlInit);
|
||||
db2.exec(sqlInit);
|
||||
T.assert(3 === db1.selectValue("select count(*) from t"))
|
||||
.assert('b3' === db1.selectValue('select b from t where rowid=3'));
|
||||
const stackPtr = wasm.pstack.pointer;
|
||||
try{
|
||||
let ppOut = wasm.pstack.allocPtr();
|
||||
let rc = capi.sqlite3session_create(db1, "main", ppOut);
|
||||
T.assert(0===rc);
|
||||
let pSession = wasm.peekPtr(ppOut);
|
||||
T.assert(pSession && wasm.isPtr(pSession));
|
||||
if(1){
|
||||
capi.sqlite3session_table_filter(pSession, (pCtx, tbl)=>{
|
||||
T.assert('t' === tbl).assert( 99 === pCtx );
|
||||
return 1;
|
||||
}, 99);
|
||||
}else{
|
||||
rc = capi.sqlite3session_attach(pSession, "t");
|
||||
T.assert( 0 === rc );
|
||||
}
|
||||
db1.exec([
|
||||
"update t set b='bTwo' where rowid=2;",
|
||||
"update t set a='aThree' where rowid=3;",
|
||||
"delete from t where rowid=1;",
|
||||
"insert into t(rowid,a,b) values(4,'a4','b4')"
|
||||
]);
|
||||
T.assert('bTwo' === db1.selectValue("select b from t where rowid=2"))
|
||||
.assert(undefined === db1.selectValue('select a from t where rowid=1'))
|
||||
.assert('b4' === db1.selectValue('select b from t where rowid=4'));
|
||||
|
||||
let pnChanges = wasm.pstack.alloc('i32'),
|
||||
ppChanges = wasm.pstack.allocPtr();
|
||||
rc = capi.sqlite3session_changeset(pSession, pnChanges, ppChanges);
|
||||
T.assert( 0 === rc );
|
||||
capi.sqlite3session_delete(pSession);
|
||||
pSession = 0;
|
||||
const pChanges = wasm.peekPtr(ppChanges),
|
||||
nChanges = wasm.peek32(pnChanges);
|
||||
T.assert( pChanges && wasm.isPtr( pChanges ) ).assert( nChanges > 0 );
|
||||
pnChanges = ppChanges = 0;
|
||||
//log("pnChanges =", pnChanges, wasm.peek32(pnChanges), '@', pChanges);
|
||||
rc = capi.sqlite3changeset_apply(
|
||||
db2, nChanges, pChanges, 0, (pCtx, eConflict, pIter)=>{
|
||||
return pCtx ? 1 : 0
|
||||
}, 1
|
||||
);
|
||||
wasm.dealloc( pChanges );
|
||||
T.assert( 0 === rc )
|
||||
.assert( 3 === db2.selectValue('select count(*) from t'))
|
||||
.assert( 'b4' === db2.selectValue('select b from t where rowid=4') );
|
||||
}finally{
|
||||
wasm.pstack.restore(stackPtr);
|
||||
db1.close();
|
||||
db2.close();
|
||||
}
|
||||
}
|
||||
})
|
||||
;/*end of session API group*/;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
log("Loading and initializing sqlite3 WASM module...");
|
||||
if(!self.sqlite3InitModule && !isUIThread()){
|
||||
|
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Add\ssqlite3.wasm.irSizeof()\sand\sextend\scertain\sallocation\sfunctions\sto\smake\suse\sof\sit.
|
||||
D 2022-12-25T20:05:11.134
|
||||
C Add\sbasic\ssession\sAPI\sJS\stests.
|
||||
D 2022-12-25T20:22:20.918
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -555,7 +555,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
|
||||
F ext/wasm/test-opfs-vfs.js f09266873e1a34d9bdb6d3981ec8c9e382f31f215c9fd2f9016d2394b8ae9b7b
|
||||
F ext/wasm/tester1-worker.html d43f3c131d88f10d00aff3e328fed13c858d674ea2ff1ff90225506137f85aa9
|
||||
F ext/wasm/tester1.c-pp.html d34bef3d48e5cbc1c7c06882ad240fec49bf88f5f65696cc2c72c416933aa406
|
||||
F ext/wasm/tester1.c-pp.js 47190277040a6163716c02d11930dc4f028d44a6fcdacb10303010f239ce0a6c
|
||||
F ext/wasm/tester1.c-pp.js a690f82c02d2b0531bad264054a276d09d274487fd1f8aac6bab24f7cfedaa6f
|
||||
F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70
|
||||
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
|
||||
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
|
||||
@ -2067,8 +2067,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 2e8336b6e1cba89dbcc11d6316e39c929bf8b018a18b92efc232abd47e0a5cc6
|
||||
R 63f0c28ba499a3e86a80a83d5b02806d
|
||||
P 1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
|
||||
R e7bca9ee95dfee32728e67001af3a1d6
|
||||
U stephan
|
||||
Z e2479a6e1c7cf91263ea3378ad83cfc4
|
||||
Z 1d08930538afdb25a0799e1e3a67b3c1
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
1cbc7b1875e8611b9db7a747b4c9499501450deaf90c929d212511837d6f72b6
|
||||
64e032602cf420851c8029603c76f5512000d1c9a40fa7a545528d69d6d1d4cc
|
Loading…
Reference in New Issue
Block a user