From 99e16168830f70f5b9da187cd4be75d1ef758769 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Fri, 1 Jul 2016 19:42:22 +0200 Subject: [PATCH] additional testing; remove extra imports from SQLitePlugin.java --- CHANGES.md | 2 +- package.json | 2 +- plugin.xml | 2 +- spec/www/spec/basic-misc-test.js | 150 ++++++++++++++++++++------ spec/www/spec/db-tx-sql-results.js | 29 +++++ spec/www/spec/db-tx-string-test.js | 21 +++- spec/www/spec/sql-batch-test.js | 1 - src/android/io/sqlc/SQLitePlugin.java | 3 - 8 files changed, 171 insertions(+), 39 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 478c9df13..2ab66e238 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Changes -### cordova-sqlite-storage 1.4.4-pre1 +### cordova-sqlite-storage 1.4.4-pre2 - Fix readTransaction to reject modification statements with extra semicolon(s) in the beginning diff --git a/package.json b/package.json index 10ce4a614..284629d9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-sqlite-storage", - "version": "1.4.4-pre1", + "version": "1.4.4-pre2", "description": "Native interface to SQLite for PhoneGap/Cordova", "cordova": { "id": "cordova-sqlite-storage", diff --git a/plugin.xml b/plugin.xml index a88e4e169..0b6ce7834 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.4.4-pre2"> Cordova sqlite storage plugin diff --git a/spec/www/spec/basic-misc-test.js b/spec/www/spec/basic-misc-test.js index 720a0cf9d..cd8b8b3ca 100644 --- a/spec/www/spec/basic-misc-test.js +++ b/spec/www/spec/basic-misc-test.js @@ -389,12 +389,12 @@ var mytests = function() { describe(scenarioList[i] + ': basic tx error semantics test(s)', function() { /* found due to investigation of litehelpers/Cordova-sqlite-storage#226: */ - it(suiteName + 'Skip callbacks after syntax error with no handler', function(done) { - if (!isWebSql) pending('Plugin BROKEN'); // XXX TODO - + it(suiteName + 'SKIP SQL CALLBACKS after syntax error with no handler (REPRODUCE BUG in plugin)', function(done) { var db = openDatabase('first-syntax-error-with-no-handler.db', '1.0', 'Test', DEFAULT_SIZE); expect(db).toBeDefined(); + var isExtraErrorHandlerCalled = false; // poor man's spy + db.transaction(function(tx) { expect(tx).toBeDefined(); tx.executeSql('DROP TABLE IF EXISTS tt'); @@ -403,35 +403,37 @@ var mytests = function() { // This insertion has a sql syntax error-which is not handled: tx.executeSql('insert into tt (data) VALUES ', [123]); - // second insertion with syntax error in transaction ["skipped" by Web SQL]: + // SKIPPED by Web SQL: + // SECOND insertion with syntax error in transaction tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) { - // not expected: + // NOT EXPECTED: expect(false).toBe(true); }, function(err) { - // expected, but then it shows the handling this sql statement is NOT skipped (by the plugin): - expect(false).toBe(true); + // [BUG REPRODUCED] ACTUAL for plugin only + //expect(false).toBe(true); + if (isWebSql) expect('NOT EXPECTED for Web SQL').toBe('--'); + isExtraErrorHandlerCalled = true; + // TRY to RECOVER: return false; }); }, function(err) { - // transaction expected to fail: + // EXPECTED RESULT: expect(true).toBe(true); + if (!isWebSql && !isExtraErrorHandlerCalled) expect('PLUGIN FIXED please update this test').toBe('--'); // Close (plugin only) & finish: (isWebSql) ? done() : db.close(done, done); }, function() { - // not expected [ignored for now]: - //expect(false).toBe(true); - expect(true).toBe(true); + // NOT EXPECTED: + expect(false).toBe(true); // Close (plugin only) & finish: (isWebSql) ? done() : db.close(done, done); }); }, MYTIMEOUT); /* found due to investigation of litehelpers/Cordova-sqlite-storage#226: */ - it(suiteName + 'Skip callbacks after syntax error handler returns true', function(done) { - if (!isWebSql) pending('Plugin BROKEN'); // XXX TODO - + it(suiteName + 'SKIP SQL CALLBACKS after syntax error handler returns true (REPRODUCE BUG in plugin)', function(done) { var db = openDatabase('first-syntax-error-handler-returns-true.db', '1.0', 'Test', DEFAULT_SIZE); expect(db).toBeDefined(); @@ -443,7 +445,7 @@ var mytests = function() { tx.executeSql('DROP TABLE IF EXISTS tt'); tx.executeSql('CREATE TABLE IF NOT EXISTS tt (data unique)'); - // FIRST SQL syntax error with handler that returns undefined [nothing]: + // FIRST SQL syntax error with handler that returns true (should completely stop transaction): tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) { // NOT EXPECTED: expect(false).toBe(true); @@ -455,34 +457,32 @@ var mytests = function() { return true; }); - // SECOND insertion with syntax error with handler that signals explicit recovery [SKIPPED by Web SQL]: + // SKIPPED by Web SQL: + // SECOND insertion with syntax error with handler that signals explicit recovery tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) { // NOT EXPECTED: expect(false).toBe(true); }, function(err) { - // expected, but then it shows the handling this sql statement is NOT skipped (by the plugin): - expect(false).toBe(true); + // [BUG REPRODUCED] ACTUAL for plugin only + //expect(false).toBe(true); + if (isWebSql) expect('NOT EXPECTED for Web SQL').toBe('--'); isSecondErrorHandlerCalled = true; // explicit recovery: return false; }); }, function(err) { - // transaction expected to fail: + // EXPECTED RESULT: expect(true).toBe(true); expect(isFirstErrorHandlerCalled).toBe(true); - // [ignored for now]: - //expect(isSecondErrorHandlerCalled).toBe(false); + if (!isWebSql && !isSecondErrorHandlerCalled) expect('PLUGIN FIXED please update this test').toBe('--'); // Close (plugin only) & finish: (isWebSql) ? done() : db.close(done, done); }, function() { - // not expected [ignored for now]: - //expect(false).toBe(true); - expect(true).toBe(true); + // NOT EXPECTED: + expect(false).toBe(true); expect(isFirstErrorHandlerCalled).toBe(true); - // [ignored for now]: - //expect(isSecondErrorHandlerCalled).toBe(false); // Close (plugin only) & finish: (isWebSql) ? done() : db.close(done, done); }); @@ -548,7 +548,7 @@ var mytests = function() { // NOTE: as discussed in litehelpers/Cordova-sqlite-storage#232 this plugin is correct // according to the spec at http://www.w3.org/TR/webdatabase/ - it(suiteName + 'syntax error handler returns undefined', function(done) { + it(suiteName + 'syntax error handler returns undefined (deviation in WebKit Web SQL implementation)', function(done) { var db = openDatabase('syntax-error-handler-returns-undefined.db', '1.0', 'Test', DEFAULT_SIZE); expect(db).toBeDefined(); @@ -567,8 +567,7 @@ var mytests = function() { // expected ok: expect(true).toBe(true); isFirstErrorHandlerCalled = true; - // [should] recover this transaction: - //return false; + // (should) recover this transaction according to Web SQL spec: return undefined; }); @@ -582,7 +581,7 @@ var mytests = function() { (isWebSql) ? done() : db.close(done, done); }, function() { - // EXPECTED OK for Web SQL ONLY: + // EXPECTED OK for WebKit Web SQL implementation ONLY: if (isWebSql) expect(true).toBe(true); else @@ -593,6 +592,97 @@ var mytests = function() { }); }, MYTIMEOUT); + it(suiteName + 'STOP nested transaction if syntax error handler returns true (REPRODUCE BUG in plugin)', function(done) { + var db = openDatabase('stop-nested-tx-if-syntax-error-handler-returns-true.db', '1.0', 'Test', DEFAULT_SIZE); + expect(db).toBeDefined(); + + // poor man's spy: + var isFirstSuccessHandlerCalled = false; + var isFirstErrorHandlerCalled = false; + var isExtraSuccessHandlerCalled = false; + var isFirstNestedErrorHandlerCalled = false; + var isExtraNestedSuccessHandlerCalled = false; + + db.transaction(function(tx) { + tx.executeSql('SELECT 1', [], function(tx, res) { + // EXPECTED RESULT: + expect(true).toBe(true); + isFirstSuccessHandlerCalled = true; + + // FIRST NESTED: + tx.executeSql('SELCT 1', [], function(tx, res) { + // NOT EXPECTED: + expect(false).toBe(true); + }, function(err) { + // ACTUAL RESULT for plugin ONLY: + //expect(false).toBe(true); + if (isWebSql) expect('NOT EXPECTED for Web SQL').toBe('--'); + isFirstNestedErrorHandlerCalled = true; + // TRY to RECOVER in NESTED: + return true; + }); + + }, function(err) { + // NOT EXPECTED: + expect(false).toBe(true); + return true; + }); + + // FIRST SQL syntax error with handler that returns true (STOP the transaction): + tx.executeSql('SELCT 1', [], function(tx, res) { + // NOT EXPECTED: + expect(false).toBe(true); + }, function(err) { + // EXPECTED RESULT: + expect(true).toBe(true); + isFirstErrorHandlerCalled = true; + // STOP the transaction: + return true; + }); + + // SKIPPED by Web SQL: + tx.executeSql('SELECT 1', [], function(tx, res) { + // ACTUAL RESULT for plugin ONLY: + //expect(false).toBe(true); + if (isWebSql) expect('NOT EXPECTED for Web SQL').toBe('--'); + isExtraSuccessHandlerCalled = true; + + // ACTUAL: EXTRA NESTED (ACTUAL for plugin only): + tx.executeSql('SELECT 1', [], function(tx, res) { + // ACTUAL RESULT for plugin ONLY: + //expect(false).toBe(true); + if (isWebSql) expect('NOT EXPECTED for Web SQL').toBe('--'); + isExtraNestedSuccessHandlerCalled = true; + }, function(err) { + // NOT EXPECTED - error callback for SECOND nested: + expect(false).toBe(true); + }); + + }, function(err) { + // NOT EXPECTED: + expect(false).toBe(true); + return true; + }); + + }, function(err) { + // EXPECTED RESULT: + expect(true).toBe(true); + expect(isFirstErrorHandlerCalled).toBe(true); + if (!isWebSql && !isExtraSuccessHandlerCalled) expect('PLUGIN FIXED please update this test').toBe('--'); + if (!isWebSql && !isExtraNestedSuccessHandlerCalled) expect('PLUGIN FIXED please update this test').toBe('--'); + if (!isWebSql && !isExtraNestedSuccessHandlerCalled) expect('PLUGIN FIXED please update this test').toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + + }, function() { + // NOT EXPECTED: + expect(false).toBe(true); + expect(isFirstErrorHandlerCalled).toBe(true); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + }); describe(scenarioList[i] + ': other tx error handling test(s)', function() { diff --git a/spec/www/spec/db-tx-sql-results.js b/spec/www/spec/db-tx-sql-results.js index ac86b917f..21032d3aa 100644 --- a/spec/www/spec/db-tx-sql-results.js +++ b/spec/www/spec/db-tx-sql-results.js @@ -700,6 +700,35 @@ var mytests = function() { }); }, MYTIMEOUT); + it(suiteName + 'BLOB inserted as a literal', function(done) { + var db = openDatabase('Literal-BLOB-INSERT-test.db', '1.0', 'Test', DEFAULT_SIZE); + + db.transaction(function(tx) { + tx.executeSql('DROP TABLE IF EXISTS TestTable;'); + tx.executeSql('CREATE TABLE TestTable (x);'); + + tx.executeSql("INSERT INTO TestTable VALUES (X'010203')", [], function(ignored1, ignored2) { + tx.executeSql('SELECT HEX(x) AS hex_value FROM TestTable', [], function(ignored, resultSet) { + // EXPECTED: CORRECT RESULT: + expect(resultSet).toBeDefined(); + expect(resultSet.rows).toBeDefined(); + expect(resultSet.rows.length).toBe(1); + expect(resultSet.rows.item(0).hex_value).toBe('010203'); + + // Close (plugin only - always the case in this test) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }); + }, function(e) { + // ERROR RESULT (NOT EXPECTED): + expect(false).toBe(true); + expect(e).toBeDefined(); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + }); } diff --git a/spec/www/spec/db-tx-string-test.js b/spec/www/spec/db-tx-string-test.js index 8134ead58..c61dcda0a 100755 --- a/spec/www/spec/db-tx-string-test.js +++ b/spec/www/spec/db-tx-string-test.js @@ -39,13 +39,13 @@ var mytests = function() { name: 'i2-'+name, androidDatabaseImplementation: 2, androidLockWorkaround: 1, - location: 1 + iosDatabaseLocation: 'Documents' }); } if (isWebSql) { return window.openDatabase(name, "1.0", "Demo", DEFAULT_SIZE); } else { - return window.sqlitePlugin.openDatabase({name: name, location: 0}); + return window.sqlitePlugin.openDatabase({name: name, location: 'default'}); } } @@ -496,6 +496,23 @@ var mytests = function() { }); }, MYTIMEOUT); + it(suiteName + "SELECT HEX(X'010203') [BLOB value test]", function(done) { + var db = openDatabase("SELECT-HEX-BLOB-test.db", "1.0", "Demo", DEFAULT_SIZE); + + db.transaction(function(tx) { + + tx.executeSql("SELECT HEX(X'010203') AS hex_value", [], function(ignored, rs) { + expect(rs).toBeDefined(); + expect(rs.rows).toBeDefined(); + expect(rs.rows.length).toBe(1); + expect(rs.rows.item(0).hex_value).toBe('010203'); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }); + }, MYTIMEOUT); + }); } diff --git a/spec/www/spec/sql-batch-test.js b/spec/www/spec/sql-batch-test.js index b6f881296..7841f0aeb 100644 --- a/spec/www/spec/sql-batch-test.js +++ b/spec/www/spec/sql-batch-test.js @@ -4,7 +4,6 @@ var MYTIMEOUT = 12000; var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios -var isAndroid = /Android/.test(navigator.userAgent); var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1) var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1) var isAndroid = !isWindows && /Android/.test(navigator.userAgent); diff --git a/src/android/io/sqlc/SQLitePlugin.java b/src/android/io/sqlc/SQLitePlugin.java index 04bd2b9cb..684f799e0 100755 --- a/src/android/io/sqlc/SQLitePlugin.java +++ b/src/android/io/sqlc/SQLitePlugin.java @@ -8,7 +8,6 @@ import android.annotation.SuppressLint; -import android.util.Base64; import android.util.Log; import java.io.File; @@ -17,8 +16,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin;