Skip to content

Commit

Permalink
add sqlite-version-test.js to this legacy version branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Dec 12, 2017
1 parent 4c7b59c commit f23012d
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

###### cordova-sqlite-legacy-express-core 1.0.4-devtest00

TBD

###### cordova-sqlite-legacy-express-core 1.0.3

- Resolve Java 6/7/8 concurrent map compatibility issue reported in litehelpers/Cordova-sqlite-storage#726, THANKS to pointer by @NeoLSN (Jason Yang/楊朝傑) in litehelpers/Cordova-sqlite-storage#727.
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-legacy-express-core",
"version": "1.0.3",
"version": "1.0.4-devtest00",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)",
"cordova": {
"id": "cordova-sqlite-legacy-express-core",
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-legacy-express-core"
version="1.0.3">
version="1.0.4-devtest00">

<name>Cordova sqlite storage plugin - legacy express core version</name>

Expand Down
5 changes: 4 additions & 1 deletion spec/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
<!-- [Cordova] source file(s): -->
<script src="cordova.js"></script>

<!-- spec file(s): -->
<!-- browser startup test: -->
<script src="spec/browser-check-startup.js"></script>

<!-- other spec file(s): -->
<script src="spec/self-test.js"></script>
<script src="spec/sqlite-version-test.js"></script>
<script src="spec/db-tx-string-test.js"></script>
<script src="spec/db-tx-sql-results.js"></script>
<script src="spec/sql-batch-test.js"></script>
Expand Down
123 changes: 123 additions & 0 deletions spec/www/spec/sqlite-version-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* 'use strict'; */

var MYTIMEOUT = 12000;

var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios

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);

// The following openDatabase settings are used for Plugin-implementation-2
// on Android:
// - androidDatabaseImplementation: 2
// - androidLockWorkaround: 1
var scenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',
'HTML5',
'Plugin-implementation-2'
];

var scenarioCount = (!!window.hasWebKitBrowser) ? (isAndroid ? 3 : 2) : 1;

var mytests = function() {

for (var i=0; i<scenarioCount; ++i) {

describe(scenarioList[i] + ': sqlite version test(s)', function() {
var scenarioName = scenarioList[i];
var suiteName = scenarioName + ': ';
var isWebSql = (i === 1);
var isImpl2 = (i === 2);

// NOTE: MUST be defined in proper describe function scope, NOT outer scope:
var openDatabase = function(name, ignored1, ignored2, ignored3) {
if (isImpl2) {
return window.sqlitePlugin.openDatabase({
// prevent reuse of database from default db implementation:
name: 'i2-'+name,
androidDatabaseImplementation: 2,
androidLockWorkaround: 1,
location: 'default'
});
}
if (isWebSql) {
return window.openDatabase(name, "1.0", "Demo", DEFAULT_SIZE);
} else {
return window.sqlitePlugin.openDatabase({name: name, location: 'default'});
}
}

describe(suiteName + 'basic sqlite version test(s)', function() {

it(suiteName + 'Check sqlite version (pattern ONLY for WebKit Web SQL & androidDatabaseImplementation: 2)', function(done) {
var db = openDatabase("check-sqlite-version.db", "1.0", "Demo", DEFAULT_SIZE);

expect(db).toBeDefined();

db.transaction(function(tx) {
expect(tx).toBeDefined();

tx.executeSql('SELECT SQLITE_VERSION() AS myResult', [], function(tx_ignored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
// Check pattern (both Web SQL & plugin)
expect(rs.rows.item(0).myResult).toMatch(/3\.[0-9]+\.[0-9]+/);
// NOT IN THIS VERSION BRANCH:
// Check specific [plugin only]:
// ...

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});
}, function(error) {
// NOT EXPECTED:
expect(false).toBe(true);
expect(error.message).toBe('--');
done();
});
}, MYTIMEOUT);

});

describe(suiteName + 'sqlite encoding test(s)', function() {

it(suiteName + 'Check internal database encoding: UTF-16le for Windows, UTF-8 for others (plugin ONLY)', function(done) {
if (isWebSql) pending('SKIP: NOT SUPPORTED for (WebKit) Web SQL');

var db = openDatabase("Check-sqlite-PRAGMA-encoding.db", "1.0", "Demo", DEFAULT_SIZE);

expect(db).toBeDefined();

db.executeSql('PRAGMA encoding', [], function(rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
if (isWindows)
expect(rs.rows.item(0).encoding).toBe('UTF-16le');
else
expect(rs.rows.item(0).encoding).toBe('UTF-8');

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
}, function(error) {
// NOT EXPECTED:
expect(false).toBe(true);
expect(error.message).toBe('--');
done();
});
}, MYTIMEOUT);

});

});

}

}

if (window.hasBrowser) mytests();
else exports.defineAutoTests = mytests;

/* vim: set expandtab : */

0 comments on commit f23012d

Please sign in to comment.