Skip to content

Commit

Permalink
additional testing; remove extra imports from SQLitePlugin.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Jul 1, 2016
1 parent ade873a commit 99e1616
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-sqlite-storage"
version="1.4.4-pre1">
version="1.4.4-pre2">

<name>Cordova sqlite storage plugin</name>

Expand Down
150 changes: 120 additions & 30 deletions spec/www/spec/basic-misc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();

Expand All @@ -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);
Expand All @@ -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);
});
Expand Down Expand Up @@ -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();

Expand All @@ -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;
});

Expand All @@ -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
Expand All @@ -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() {
Expand Down
29 changes: 29 additions & 0 deletions spec/www/spec/db-tx-sql-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

});

}
Expand Down
21 changes: 19 additions & 2 deletions spec/www/spec/db-tx-string-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
}
}

Expand Down Expand Up @@ -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);

});

}
Expand Down
1 change: 0 additions & 1 deletion spec/www/spec/sql-batch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import android.annotation.SuppressLint;

import android.util.Base64;
import android.util.Log;

import java.io.File;
Expand All @@ -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;
Expand Down

0 comments on commit 99e1616

Please sign in to comment.