Sqlite-Plugin, DB-Copy plugin added und integriert

This commit is contained in:
2016-01-15 00:59:23 +01:00
parent 337215938a
commit 7c683d7450
243 changed files with 308639 additions and 253 deletions

View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no" />
<title>SQLitePlugin Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.2.0/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.2.0/jasmine.css">
<script src="lib/jasmine-2.2.0/jasmine.js"></script>
<script src="lib/jasmine-2.2.0/jasmine-html.js"></script>
<script src="lib/jasmine-2.2.0/boot.js"></script>
<!-- [Cordova] source file(s): -->
<script src="cordova.js"></script>
<!-- Needed for Cordova pre-3.0: -->
<script src="SQLitePlugin.js"></script>
<!-- spec file(s): -->
<script src="spec/browser-check-startup.js"></script>
<script src="spec/simple-test.js"></script>
<script src="spec/legacy.js"></script>
<!-- Slow test(s) disabled by default:
<script src="spec/big-memory-test.js"></script>
-->
</head>
<body>
</body>
</html> <!-- vim: set expandtab : -->

View File

@@ -0,0 +1,121 @@
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
*/
(function() {
/**
* ## Require &amp; Instantiate
*
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);
/**
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
*/
jasmineRequire.html(jasmine);
/**
* Create the Jasmine environment. This is used to run all specs in a project.
*/
var env = jasmine.getEnv();
/**
* ## The Global Interface
*
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
*/
var jasmineInterface = jasmineRequire.interface(jasmine, env);
/**
* Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
*/
if (typeof window == "undefined" && typeof exports == "object") {
extend(exports, jasmineInterface);
} else {
extend(window, jasmineInterface);
}
/**
* ## Runner Parameters
*
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
*/
var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; }
});
var catchingExceptions = queryString.getParam("catch");
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
/**
* ## Reporters
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
*/
var htmlReporter = new jasmine.HtmlReporter({
env: env,
onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
});
/**
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
*/
env.addReporter(jasmineInterface.jsApiReporter);
env.addReporter(htmlReporter);
/**
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
*/
var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam("spec"); }
});
env.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};
/**
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
*/
window.setTimeout = window.setTimeout;
window.setInterval = window.setInterval;
window.clearTimeout = window.clearTimeout;
window.clearInterval = window.clearInterval;
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
env.execute();
};
/**
* Helper function for readability above.
*/
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
}());

View File

@@ -0,0 +1,190 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function getJasmineRequireObj() {
if (typeof module !== 'undefined' && module.exports) {
return exports;
} else {
window.jasmineRequire = window.jasmineRequire || {};
return window.jasmineRequire;
}
}
getJasmineRequireObj().console = function(jRequire, j$) {
j$.ConsoleReporter = jRequire.ConsoleReporter();
};
getJasmineRequireObj().ConsoleReporter = function() {
var noopTimer = {
start: function(){},
elapsed: function(){ return 0; }
};
function ConsoleReporter(options) {
var print = options.print,
showColors = options.showColors || false,
onComplete = options.onComplete || function() {},
timer = options.timer || noopTimer,
specCount,
failureCount,
failedSpecs = [],
pendingCount,
ansi = {
green: '\x1B[32m',
red: '\x1B[31m',
yellow: '\x1B[33m',
none: '\x1B[0m'
},
failedSuites = [];
print('ConsoleReporter is deprecated and will be removed in a future version.');
this.jasmineStarted = function() {
specCount = 0;
failureCount = 0;
pendingCount = 0;
print('Started');
printNewline();
timer.start();
};
this.jasmineDone = function() {
printNewline();
for (var i = 0; i < failedSpecs.length; i++) {
specFailureDetails(failedSpecs[i]);
}
if(specCount > 0) {
printNewline();
var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' +
failureCount + ' ' + plural('failure', failureCount);
if (pendingCount) {
specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount);
}
print(specCounts);
} else {
print('No specs found');
}
printNewline();
var seconds = timer.elapsed() / 1000;
print('Finished in ' + seconds + ' ' + plural('second', seconds));
printNewline();
for(i = 0; i < failedSuites.length; i++) {
suiteFailureDetails(failedSuites[i]);
}
onComplete(failureCount === 0);
};
this.specDone = function(result) {
specCount++;
if (result.status == 'pending') {
pendingCount++;
print(colored('yellow', '*'));
return;
}
if (result.status == 'passed') {
print(colored('green', '.'));
return;
}
if (result.status == 'failed') {
failureCount++;
failedSpecs.push(result);
print(colored('red', 'F'));
}
};
this.suiteDone = function(result) {
if (result.failedExpectations && result.failedExpectations.length > 0) {
failureCount++;
failedSuites.push(result);
}
};
return this;
function printNewline() {
print('\n');
}
function colored(color, str) {
return showColors ? (ansi[color] + str + ansi.none) : str;
}
function plural(str, count) {
return count == 1 ? str : str + 's';
}
function repeat(thing, times) {
var arr = [];
for (var i = 0; i < times; i++) {
arr.push(thing);
}
return arr;
}
function indent(str, spaces) {
var lines = (str || '').split('\n');
var newArr = [];
for (var i = 0; i < lines.length; i++) {
newArr.push(repeat(' ', spaces).join('') + lines[i]);
}
return newArr.join('\n');
}
function specFailureDetails(result) {
printNewline();
print(result.fullName);
for (var i = 0; i < result.failedExpectations.length; i++) {
var failedExpectation = result.failedExpectations[i];
printNewline();
print(indent(failedExpectation.message, 2));
print(indent(failedExpectation.stack, 2));
}
printNewline();
}
function suiteFailureDetails(result) {
for (var i = 0; i < result.failedExpectations.length; i++) {
printNewline();
print(colored('red', 'An error was thrown in an afterAll'));
printNewline();
print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
}
printNewline();
}
}
return ConsoleReporter;
};

View File

@@ -0,0 +1,416 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
jasmineRequire.html = function(j$) {
j$.ResultsNode = jasmineRequire.ResultsNode();
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
j$.QueryString = jasmineRequire.QueryString();
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
};
jasmineRequire.HtmlReporter = function(j$) {
var noopTimer = {
start: function() {},
elapsed: function() { return 0; }
};
function HtmlReporter(options) {
var env = options.env || {},
getContainer = options.getContainer,
createElement = options.createElement,
createTextNode = options.createTextNode,
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
timer = options.timer || noopTimer,
results = [],
specsExecuted = 0,
failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain,
symbols,
failedSuites = [];
this.initialize = function() {
clearPrior();
htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'},
createDom('div', {className: 'banner'},
createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}),
createDom('span', {className: 'version'}, j$.version)
),
createDom('ul', {className: 'symbol-summary'}),
createDom('div', {className: 'alert'}),
createDom('div', {className: 'results'},
createDom('div', {className: 'failures'})
)
);
getContainer().appendChild(htmlReporterMain);
symbols = find('.symbol-summary');
};
var totalSpecsDefined;
this.jasmineStarted = function(options) {
totalSpecsDefined = options.totalSpecsDefined || 0;
timer.start();
};
var summary = createDom('div', {className: 'summary'});
var topResults = new j$.ResultsNode({}, '', null),
currentParent = topResults;
this.suiteStarted = function(result) {
currentParent.addChild(result, 'suite');
currentParent = currentParent.last();
};
this.suiteDone = function(result) {
if (result.status == 'failed') {
failedSuites.push(result);
}
if (currentParent == topResults) {
return;
}
currentParent = currentParent.parent;
};
this.specStarted = function(result) {
currentParent.addChild(result, 'spec');
};
var failures = [];
this.specDone = function(result) {
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
if (result.status != 'disabled') {
specsExecuted++;
}
symbols.appendChild(createDom('li', {
className: noExpectations(result) ? 'empty' : result.status,
id: 'spec_' + result.id,
title: result.fullName
}
));
if (result.status == 'failed') {
failureCount++;
var failure =
createDom('div', {className: 'spec-detail failed'},
createDom('div', {className: 'description'},
createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName)
),
createDom('div', {className: 'messages'})
);
var messages = failure.childNodes[1];
for (var i = 0; i < result.failedExpectations.length; i++) {
var expectation = result.failedExpectations[i];
messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message));
messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack));
}
failures.push(failure);
}
if (result.status == 'pending') {
pendingSpecCount++;
}
};
this.jasmineDone = function() {
var banner = find('.banner');
banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's'));
var alert = find('.alert');
alert.appendChild(createDom('span', { className: 'exceptions' },
createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'),
createDom('input', {
className: 'raise',
id: 'raise-exceptions',
type: 'checkbox'
})
));
var checkbox = find('#raise-exceptions');
checkbox.checked = !env.catchingExceptions();
checkbox.onclick = onRaiseExceptionsClick;
if (specsExecuted < totalSpecsDefined) {
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
alert.appendChild(
createDom('span', {className: 'bar skipped'},
createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage)
)
);
}
var statusBarMessage = '';
var statusBarClassName = 'bar ';
if (totalSpecsDefined > 0) {
statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
statusBarClassName += (failureCount > 0) ? 'failed' : 'passed';
} else {
statusBarClassName += 'skipped';
statusBarMessage += 'No specs found';
}
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage));
for(i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
var errorBarClassName = 'bar errored';
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
}
}
var results = find('.results');
results.appendChild(summary);
summaryList(topResults, summary);
function summaryList(resultsTree, domParent) {
var specListNode;
for (var i = 0; i < resultsTree.children.length; i++) {
var resultNode = resultsTree.children[i];
if (resultNode.type == 'suite') {
var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id},
createDom('li', {className: 'suite-detail'},
createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
)
);
summaryList(resultNode, suiteListNode);
domParent.appendChild(suiteListNode);
}
if (resultNode.type == 'spec') {
if (domParent.getAttribute('class') != 'specs') {
specListNode = createDom('ul', {className: 'specs'});
domParent.appendChild(specListNode);
}
var specDescription = resultNode.result.description;
if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
}
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
}
specListNode.appendChild(
createDom('li', {
className: resultNode.result.status,
id: 'spec-' + resultNode.result.id
},
createDom('a', {href: specHref(resultNode.result)}, specDescription)
)
);
}
}
}
if (failures.length) {
alert.appendChild(
createDom('span', {className: 'menu bar spec-list'},
createDom('span', {}, 'Spec List | '),
createDom('a', {className: 'failures-menu', href: '#'}, 'Failures')));
alert.appendChild(
createDom('span', {className: 'menu bar failure-list'},
createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'),
createDom('span', {}, ' | Failures ')));
find('.failures-menu').onclick = function() {
setMenuModeTo('failure-list');
};
find('.spec-list-menu').onclick = function() {
setMenuModeTo('spec-list');
};
setMenuModeTo('failure-list');
var failureNode = find('.failures');
for (var i = 0; i < failures.length; i++) {
failureNode.appendChild(failures[i]);
}
}
};
return this;
function find(selector) {
return getContainer().querySelector('.jasmine_html-reporter ' + selector);
}
function clearPrior() {
// return the reporter
var oldReporter = find('');
if(oldReporter) {
getContainer().removeChild(oldReporter);
}
}
function createDom(type, attrs, childrenVarArgs) {
var el = createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(createTextNode(child));
} else {
if (child) {
el.appendChild(child);
}
}
}
for (var attr in attrs) {
if (attr == 'className') {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
}
function pluralize(singular, count) {
var word = (count == 1 ? singular : singular + 's');
return '' + count + ' ' + word;
}
function specHref(result) {
return addToExistingQueryString('spec', result.fullName);
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
}
function setMenuModeTo(mode) {
htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
}
function noExpectations(result) {
return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
result.status === 'passed';
}
}
return HtmlReporter;
};
jasmineRequire.HtmlSpecFilter = function() {
function HtmlSpecFilter(options) {
var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
var filterPattern = new RegExp(filterString);
this.matches = function(specName) {
return filterPattern.test(specName);
};
}
return HtmlSpecFilter;
};
jasmineRequire.ResultsNode = function() {
function ResultsNode(result, type, parent) {
this.result = result;
this.type = type;
this.parent = parent;
this.children = [];
this.addChild = function(result, type) {
this.children.push(new ResultsNode(result, type, this));
};
this.last = function() {
return this.children[this.children.length - 1];
};
}
return ResultsNode;
};
jasmineRequire.QueryString = function() {
function QueryString(options) {
this.navigateWithNewParam = function(key, value) {
options.getWindowLocation().search = this.fullStringWithNewParam(key, value);
};
this.fullStringWithNewParam = function(key, value) {
var paramMap = queryStringToParamMap();
paramMap[key] = value;
return toQueryString(paramMap);
};
this.getParam = function(key) {
return queryStringToParamMap()[key];
};
return this;
function toQueryString(paramMap) {
var qStrPairs = [];
for (var prop in paramMap) {
qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop]));
}
return '?' + qStrPairs.join('&');
}
function queryStringToParamMap() {
var paramStr = options.getWindowLocation().search.substring(1),
params = [],
paramMap = {};
if (paramStr.length > 0) {
params = paramStr.split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
var value = decodeURIComponent(p[1]);
if (value === 'true' || value === 'false') {
value = JSON.parse(value);
}
paramMap[decodeURIComponent(p[0])] = value;
}
}
return paramMap;
}
}
return QueryString;
};

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,99 @@
/* 'use strict'; */
// increased timeout for these tests:
var MYTIMEOUT = 120000;
var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios
// FUTURE TBD replace in test(s):
function ok(test, desc) { expect(test).toBe(true); }
function equal(a, b, desc) { expect(a).toEqual(b); } // '=='
function strictEqual(a, b, desc) { expect(a).toBe(b); } // '==='
var isAndroid = /Android/.test(navigator.userAgent);
var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1)
//var isWindows = /Windows NT/.test(navigator.userAgent); // Windows [NT] (8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1)
//var isWindowsPC = /Windows NT/.test(navigator.userAgent); // Windows [NT] (8.1)
//var isWindowsPhone_8_1 = /Windows Phone 8.1/.test(navigator.userAgent); // Windows Phone 8.1
//var isIE = isWindows || isWP8 || isWindowsPhone_8_1;
var isIE = isWindows || isWP8;
var isWebKit = !isIE; // TBD [Android or iOS]
var scenarioList = [ 'Plugin', 'HTML5' ];
var scenarioCount = 1;
// FUTURE:
//var scenarioCount = (!!window.hasWebKitBrowser) ? 2 : 1;
// big memory test(s):
var mytests = function() {
for (var i=0; i<scenarioCount; ++i) {
describe(scenarioList[i] + ': big memory test(s)', function() {
var scenarioName = scenarioList[i];
var suiteName = scenarioName + ': ';
var isWebSql = (i !== 0);
// NOTE: MUST be defined in function scope, NOT outer scope:
var openDatabase = function(name, ignored1, ignored2, ignored3) {
if (isWebSql) {
return window.openDatabase(name, "1.0", "Demo", DEFAULT_SIZE);
} else {
return window.sqlitePlugin.openDatabase(name, "1.0", "Demo", DEFAULT_SIZE);
}
}
// litehelpers/Cordova-sqlite-storage#18 - thanks to @sonalk:
it(suiteName + 'adding a large number of records', function(done) {
if (isWP8) pending('BROKEN for WP(7/8)'); // Hangs on wp8 platform
// remove next line to reproduce crash on Android version:
if (isAndroid && !isWebSql) pending('BROKEN-crashing on Android version of plugin');
var db = openDatabase("add-large-number-of-records.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined()
db.transaction(function(tx) {
expect(tx).toBeDefined()
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql('DROP TABLE IF EXISTS db');
tx.executeSql('CREATE TABLE IF NOT EXISTS db (idd integer primary key, dataa text, data_numm integer)');
tx.executeSql('DROP TABLE IF EXISTS abc');
tx.executeSql('CREATE TABLE IF NOT EXISTS abc (iddd integer primary key, dataaa text, data_nummm integer)');
tx.executeSql('DROP TABLE IF EXISTS abcd');
for (var k = 0; k < 80000; k++) { //loop to add 80000 records
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100]);
tx.executeSql("INSERT INTO db (dataa, data_numm) VALUES (?,?)", ["abc", 100]);
tx.executeSql("INSERT INTO abc (dataaa, data_nummm) VALUES (?,?)", ["abc", 100]);
} ////-for loop ends
//db.transaction ends
}, function (e) {
// not expected:
expect(false).toBe(true);
}, function () {
// expected ok:
expect(true).toBe(true);
done();
});
}, MYTIMEOUT);
});
};
}
if (window.hasBrowser) mytests();
else exports.defineAutoTests = mytests;
/* vim: set expandtab : */

View File

@@ -0,0 +1,33 @@
/* 'use strict'; */
var MYTIMEOUT = 12000;
var isAndroid = /Android/.test(navigator.userAgent);
var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1)
//var isWindows = /Windows NT/.test(navigator.userAgent); // Windows [NT] (8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1)
//var isWindowsPC = /Windows NT/.test(navigator.userAgent); // Windows [NT] (8.1)
//var isWindowsPhone_8_1 = /Windows Phone 8.1/.test(navigator.userAgent); // Windows Phone 8.1
//var isIE = isWindows || isWP8 || isWindowsPhone_8_1;
var isIE = isWindows || isWP8;
var isWebKit = !isIE; // TBD [Android or iOS]
window.hasBrowser = true;
window.hasWebKitBrowser = isWebKit;
describe('check startup', function() {
it('receives deviceready event', function(done) {
expect(true).toBe(true);
document.addEventListener("deviceready", function() {
done();
});
}, MYTIMEOUT);
it('has openDatabase', function() {
if (isWebKit) expect(window.openDatabase).toBeDefined();
expect(window.sqlitePlugin).toBeDefined();
expect(window.sqlitePlugin.openDatabase).toBeDefined();
});
});
/* vim: set expandtab : */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,558 @@
/* 'use strict'; */
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 NT/.test(navigator.userAgent); // Windows [NT] (8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1)
//var isWindowsPC = /Windows NT/.test(navigator.userAgent); // Windows [NT] (8.1)
//var isWindowsPhone_8_1 = /Windows Phone 8.1/.test(navigator.userAgent); // Windows Phone 8.1
//var isIE = isWindows || isWP8 || isWindowsPhone_8_1;
var isIE = isWindows || isWP8;
var isWebKit = !isIE; // TBD [Android or iOS]
var scenarioList = [ isAndroid ? 'Plugin-sqlite-connector' : 'Plugin', 'HTML5', 'Plugin-android.database' ];
//var scenarioCount = isAndroid ? 3 : (isIE ? 1 : 2);
//var scenarioCount = (!!window.hasWebKitBrowser) ? 2 : 1;
var hasAndroidWebKitBrowser = isAndroid && (!!window.hasWebKitBrowser);
var scenarioCount = hasAndroidWebKitBrowser ? 3 : ((!!window.hasWebKitBrowser) ? 2 : 1);
// simple tests:
var mytests = function() {
for (var i=0; i<scenarioCount; ++i) {
describe(scenarioList[i] + ': SIMPLE SQL test(s)', function() {
var scenarioName = scenarioList[i];
var suiteName = scenarioName + ': ';
var isWebSql = (i === 1);
var isOldImpl = (i === 2);
// NOTE: MUST be defined in function scope, NOT outer scope:
var openDatabase = function(name, ignored1, ignored2, ignored3) {
if (isOldImpl) {
return window.sqlitePlugin.openDatabase({name: name, androidDatabaseImplementation: 2});
}
if (isWebSql) {
return window.openDatabase(name, '1.0', 'Test', DEFAULT_SIZE);
} else {
return window.sqlitePlugin.openDatabase(name, '1.0', 'Test', DEFAULT_SIZE);
}
}
it(suiteName + 'US-ASCII String manipulation test',
function(done) {
var db = openDatabase('ASCII-string-test.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql("SELECT UPPER('Some US-ASCII text') AS uppertext", [], function(tx, res) {
console.log('res.rows.item(0).uppertext: ' + res.rows.item(0).uppertext);
expect(res.rows.item(0).uppertext).toEqual('SOME US-ASCII TEXT');
done();
});
});
}, MYTIMEOUT);
// Only test ICU-UNICODE with Android 5.0(+) (Web SQL):
if (isWebSql && /Android [5-9]/.test(navigator.userAgent))
it(suiteName + 'ICU-UNICODE string manipulation test', function(done) {
if ((!isWebSql) && isAndroid) pending('BROKEN for Android version of plugin [with sqlite-connector]');
var db = openDatabase('UNICODE-string-test.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
// 'Some Cyrillic text'
tx.executeSql("SELECT UPPER('Какой-то кириллический текст') AS uppertext", [], function (tx, res) {
console.log('res.rows.item(0).uppertext: ' + res.rows.item(0).uppertext);
expect(res.rows.item(0).uppertext).toEqual('КАКОЙ-ТО КИРИЛЛИЧЕСКИЙ ТЕКСТ');
done();
});
});
});
it(suiteName + 'Simple INSERT test: check insertId & rowsAffected in result', function(done) {
var db = openDatabase('INSERT-test.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql('INSERT INTO test_table (data, data_num) VALUES (?,?)', ['test', 100], function(tx, res) {
expect(res).toBeDefined();
expect(res.insertId).toBeDefined();
expect(res.rowsAffected).toBe(1);
done();
});
});
}, MYTIMEOUT);
it(suiteName + 'db transaction test',
function(done) {
var db = openDatabase('db-trx-test.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
var check = 0;
db.transaction(function(tx) {
// first tx object:
expect(tx).toBeDefined();
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql('INSERT INTO test_table (data, data_num) VALUES (?,?)', ['test', 100], function(tx, res) {
// check tx & res object parameters:
expect(tx).toBeDefined();
expect(res).toBeDefined();
expect(res.insertId).toBeDefined();
expect(res.rowsAffected).toBe(1);
db.transaction(function(tx) {
// second tx object:
expect(tx).toBeDefined();
tx.executeSql('SELECT COUNT(id) AS cnt FROM test_table;', [], function(tx, res) {
++check;
expect(res.rows.length).toBe(1);
expect(res.rows.item(0).cnt).toBe(1);
});
tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, res) {
++check;
expect(res.rows.length).toBe(1);
expect(res.rows.item(0).data_num).toBe(100);
});
tx.executeSql('UPDATE test_table SET data_num = ? WHERE data_num = 100', [101], function(tx, res) {
++check;
expect(res.rowsAffected).toBe(1);
});
tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, res) {
++check;
expect(res.rows.length).toBe(1);
expect(res.rows.item(0).data_num).toBe(101);
});
tx.executeSql("DELETE FROM test_table WHERE data LIKE 'tes%'", [], function(tx, res) {
++check;
expect(res.rowsAffected).toBe(1);
});
tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, res) {
++check;
expect(res.rows.length).toBe(0);
});
}, function(e) {
// not expected:
expect(false).toBe(true);
console.log('ERROR: ' + e.message);
}, function() {
console.log('second tx ok success cb');
expect(check).toBe(6);
done();
});
}, function(e) {
// not expected:
expect(false).toBe(true);
console.log('ERROR: ' + e.message);
});
}, function(e) {
// not expected:
expect(false).toBe(true);
console.log('ERROR: ' + e.message);
done();
}, function() {
console.log('first tx success cb OK');
});
}, MYTIMEOUT);
it(suiteName + 'number values inserted using number bindings',
function(done) {
var db = openDatabase('Value-binding-test.db', '1.0', 'Test', DEFAULT_SIZE);
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data_text1, data_text2, data_int, data_real)');
}, function(err) {
// went wrong:
expect(false).toBe(true);
}, function() {
db.transaction(function(tx) {
// create columns with no type affinity
tx.executeSql('INSERT INTO test_table (data_text1, data_text2, data_int, data_real) VALUES (?,?,?,?)', ['314159', '3.14159', 314159, 3.14159], function(tx, res) {
expect(res.rowsAffected).toBe(1);
tx.executeSql('SELECT * FROM test_table', [], function(tx, res) {
var row = res.rows.item(0);
expect(row.data_text1).toBe('314159'); // data_text1 should have inserted data as text
if (!isWP8) // JSON issue in WP(8) version
expect(row.data_text2).toBe('3.14159'); // data_text2 should have inserted data as text
expect(row.data_int).toBe(314159); // data_int should have inserted data as an integer
expect(Math.abs(row.data_real - 3.14159) < 0.000001).toBe(true); // data_real should have inserted data as a real
done();
});
});
});
});
}, MYTIMEOUT);
/* THANKS to @calebeaires: */
it(suiteName + 'create virtual table using FTS3', function(done) {
if (isWP8) pending('NOT IMPLEMENTED for WP(8)'); // NOT IMPLEMENTED in CSharp-SQLite
var db = openDatabase('virtual-table-using-fts3.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql('CREATE INDEX liv_index ON book (liv, cap);');
tx.executeSql('DROP TABLE IF EXISTS virtual_book');
tx.executeSql('CREATE VIRTUAL TABLE IF NOT EXISTS virtual_book USING FTS3 (liv, cap, ver, tex, tes);', [], function(tx, res) {
// ok:
expect(true).toBe(true);
}, function(err) {
// went wrong:
expect(false).toBe(true);
});
}, function(err) {
// [ignored here]:
//expect(false).toBe(true);
expect(true).toBe(true);
done();
}, function() {
// verify tx was ok:
expect(true).toBe(true);
done();
});
}, MYTIMEOUT);
// NOTE: looking at sqlite3.c, if FTS3 is enabled, FTS4 seems to be working as well!
// (thanks again to @calebeaires for this scenario)
it(suiteName + 'create virtual table using FTS4', function(done) {
if (isWP8) pending('NOT IMPLEMENTED for WP(8)'); // NOT IMPLEMENTED in CSharp-SQLite
var db = openDatabase('virtual-table-using-fts4.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql('CREATE INDEX liv_index ON book (liv, cap);');
tx.executeSql('DROP TABLE IF EXISTS virtual_book');
tx.executeSql('CREATE VIRTUAL TABLE IF NOT EXISTS virtual_book USING FTS4 (liv, cap, ver, tex, tes);', [], function(tx, res) {
// ok:
expect(true).toBe(true);
}, function(err) {
// went wrong:
expect(false).toBe(true);
});
}, function(err) {
// [ignored here]:
//expect(false).toBe(true);
expect(true).toBe(true);
done();
}, function() {
// verify tx was ok:
expect(true).toBe(true);
done();
});
}, MYTIMEOUT);
if (!isWebSql) {
it(suiteName + 'create virtual table using R-Tree', function(done) {
if (isWP8) pending('NOT IMPLEMENTED for WP(8)'); // NOT IMPLEMENTED in CSharp-SQLite
if (isAndroid) pending('NOT IMPLEMENTED for all versions of Android'); // NOT IMPLEMENTED for all versions of Android database (failed in Circle CI)
var db = openDatabase('virtual-table-using-r-tree.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql('DROP TABLE IF EXISTS demo_index');
// from https://www.sqlite.org/rtree.html
tx.executeSql('CREATE VIRTUAL TABLE IF NOT EXISTS demo_index USING rtree (id, minX, maxX, minY, maxY);', [], function(tx, res) {
// ok:
expect(true).toBe(true);
}, function(err) {
// went wrong:
expect(false).toBe(true);
});
}, function(err) {
// [ignored here]:
//expect(false).toBe(true);
expect(true).toBe(true);
done();
}, function() {
// verify tx was ok:
expect(true).toBe(true);
done();
});
}, MYTIMEOUT);
}
/* 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
var db = openDatabase('first-syntax-error-with-no-handler.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
db.transaction(function(tx) {
expect(tx).toBeDefined();
tx.executeSql('DROP TABLE IF EXISTS tt');
tx.executeSql('CREATE TABLE IF NOT EXISTS tt (data unique)');
// 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]:
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);
return false;
});
}, function(err) {
// transaction expected to fail:
expect(true).toBe(true);
done();
}, function() {
// not expected [ignored for now]:
//expect(false).toBe(true);
expect(true).toBe(true);
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
var db = openDatabase('first-syntax-error-handler-returns-true.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
var isFirstErrorHandlerCalled = false; // poor man's spy
var isSecondErrorHandlerCalled = false;
db.transaction(function(tx) {
expect(tx).toBeDefined();
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]:
tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) {
// not expected:
expect(false).toBe(true);
}, function(err) {
// expected ok:
expect(true).toBe(true);
isFirstErrorHandlerCalled = true;
// (should) completely stop transaction:
return true;
});
// second insertion with syntax error with handler that signals explicit recovery [SKIPPED by Web SQL]:
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);
isSecondErrorHandlerCalled = true;
// explicit recovery:
return false;
});
}, function(err) {
// transaction expected to fail:
expect(true).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
// [ignored for now]:
//expect(isSecondErrorHandlerCalled).toBe(false);
done();
}, function() {
// not expected [ignored for now]:
//expect(false).toBe(true);
expect(true).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
// [ignored for now]:
//expect(isSecondErrorHandlerCalled).toBe(false);
done();
});
}, MYTIMEOUT);
// ref: litehelpers/Cordova-sqlite-storage#232
// according to the spec at http://www.w3.org/TR/webdatabase/ the transaction should be
// recovered *only* if the sql error handler returns false.
it(suiteName + 'Recover transaction with callbacks after syntax error handler returns false', function(done) {
var db = openDatabase('recover-if-syntax-error-handler-returns-false.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
var isFirstErrorHandlerCalled = false; // poor man's spy
//var isFirstSuccessHandlerCalled = false; // (not expected)
var isSecondSuccessHandlerCalled = false; // expected ok
//var isSecondErrorHandlerCalled = false; // (not expected)
db.transaction(function(tx) {
expect(tx).toBeDefined();
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]:
tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) {
// not expected:
expect(false).toBe(true);
}, function(err) {
// expected ok:
expect(true).toBe(true);
isFirstErrorHandlerCalled = true;
// [should] recover this transaction:
return false;
});
// second sql ok [NOT SKIPPED by Web SQL]:
tx.executeSql('SELECT 1', [], function(tx, res) {
// expected ok:
isSecondSuccessHandlerCalled = true;
expect(true).toBe(true);
}, function(err) {
// not expected:
expect(false).toBe(true);
//isSecondErrorHandlerCalled = true;
return false;
});
}, function(err) {
// not expected:
expect(false).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
done();
}, function() {
// expected ok:
expect(true).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
expect(isSecondSuccessHandlerCalled).toBe(true);
done();
});
}, MYTIMEOUT);
// 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) {
var db = openDatabase('syntax-error-handler-returns-undefined.db', '1.0', 'Test', DEFAULT_SIZE);
expect(db).toBeDefined();
var isFirstErrorHandlerCalled = false; // poor man's spy
db.transaction(function(tx) {
expect(tx).toBeDefined();
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]:
tx.executeSql('insert into tt (data) VALUES ', [456], function(tx, res) {
// not expected:
expect(false).toBe(true);
}, function(err) {
// expected ok:
expect(true).toBe(true);
isFirstErrorHandlerCalled = true;
// [should] recover this transaction:
//return false;
return undefined;
});
// skip second sql [not relevant for this test, difference plugin vs. Web SQL]:
}, function(err) {
// transaction expected to fail [plugin only]:
expect(true).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
done();
}, function() {
// expected ok for Web SQL ONLY:
if (isWebSql)
expect(true).toBe(true);
else
expect(false).toBe(true);
expect(isFirstErrorHandlerCalled).toBe(true);
done();
});
}, MYTIMEOUT);
// FUTURE TODO ref: litehelpers/Cordova-sqlite-storage#232
// test case of sql error handler returning values such as "true" (string), 1, 0, null
if (!isWebSql) {
// NOTE: this was an issue due to the inconsistency ng cordova documentation and source code which
// triggered problems reported in litehelpers/Cordova-sqlite-storage#246 and
// litehelpers/Cordova-sqlcipher-adapter#5.
// The implementation now avoids this problem *by throwing an exception*.
// It could be nicer to just signal an error in the error callback, if present,
// through throwing an exception does prevent the user from using an invalid db object.
// Brody TBD: check how the Web SQL API would handle this condition?
it(suiteName + 'check that db name is really a string', function(done) {
var p1 = { name: 'my.db.name', location: 1 };
try {
window.sqlitePlugin.openDatabase({ name: p1 }, function(db) {
// not expected:
expect(false).toBe(true);
done();
}, function(error) {
// OK but NOT EXPECTED:
expect(true).toBe(true);
done();
});
} catch (e) {
// stopped by the implementation:
expect(true).toBe(true);
done();
}
}, MYTIMEOUT);
}
});
};
}
if (window.hasBrowser) mytests();
else exports.defineAutoTests = mytests;
/* vim: set expandtab : */