From 622c9902e749a60b56c6537cc76d7d084da00a1d Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 22 Jan 2018 17:15:55 -0500 Subject: [PATCH] quick test of u2013 / u2019 BOTH INLINE & parameter testing ref: litehelpers/Cordova-sqlite-storage#739 --- spec/www/spec/db-tx-string-test.js | 258 +++++++++++++++++++++ spec/www/spec/db-tx-value-bindings-test.js | 144 ++++++++++++ 2 files changed, 402 insertions(+) diff --git a/spec/www/spec/db-tx-string-test.js b/spec/www/spec/db-tx-string-test.js index fbfc713e6..5b7fb6559 100755 --- a/spec/www/spec/db-tx-string-test.js +++ b/spec/www/spec/db-tx-string-test.js @@ -563,6 +563,80 @@ var mytests = function() { }); }, MYTIMEOUT); + it(suiteName + "INLINE UNICODE \\u2013 test", function(done) { + var db = openDatabase("String-u2013-test.db", "1.0", "Demo", DEFAULT_SIZE); + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql("SELECT UPPER('First\u2013Second') AS uppertext", [], function(tx_ignored, rs1) { + // Check INLINE string result: + expect(rs1).toBeDefined(); + expect(rs1.rows).toBeDefined(); + expect(rs1.rows.length).toBe(1); + expect(rs1.rows.item(0).uppertext).toBe('FIRST\u2013SECOND'); + + // Check value binding & HEX result: + tx.executeSql("SELECT HEX('1\u2013') AS myResult", null, function(tx_ignored, rs2) { + expect(rs2).toBeDefined(); + expect(rs2.rows).toBeDefined(); + expect(rs2.rows.length).toBe(1); + if (isWindows) + expect(rs2.rows.item(0).myResult).toBe('410008003100'); // (UTF-16le) + else + expect(rs2.rows.item(0).myResult).toBe('31E28093'); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + "INLINE UNICODE \\u2019 test", function(done) { + var db = openDatabase("String-u2019-test.db", "1.0", "Demo", DEFAULT_SIZE); + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql("SELECT UPPER('First\u2019Second') AS uppertext", [], function(tx_ignored, rs1) { + // Check INLINE string result: + expect(rs1).toBeDefined(); + expect(rs1.rows).toBeDefined(); + expect(rs1.rows.length).toBe(1); + expect(rs1.rows.item(0).uppertext).toBe('FIRST\u2019SECOND'); + + // Check value binding & HEX result: + tx.executeSql("SELECT HEX('1\u2019') AS myResult", null, function(tx_ignored, rs2) { + expect(rs2).toBeDefined(); + expect(rs2.rows).toBeDefined(); + expect(rs2.rows.length).toBe(1); + if (isWindows) + expect(rs2.rows.item(0).myResult).toBe('410008003100'); // (UTF-16le) + else + expect(rs2.rows.item(0).myResult).toBe('31E28099'); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + }); describe(suiteName + 'UTF-8 multiple octet character string binding/manipulation tests [default sqlite encoding: UTF-16le on Windows, UTF-8 encoding on others]', function() { @@ -901,6 +975,190 @@ var mytests = function() { }); }, MYTIMEOUT); + // NOTE: the next 3 tests repeat the above for UNICODE \u2029 paragraph separator + // on iOS/macOS/Android: + // XXX XXX + + it(suiteName + "UNICODE \\u2013 xxx string length", function(done) { + if (isWP8) pending('BROKEN on WP(8)'); // [BUG #202] Certain UNICODE characters not working with WP(8) + + // NOTE: this test verifies that the UNICODE xxx (\u2013) + // is seen by the sqlite implementation OK: + var db = openDatabase("UNICODE-paragraph-separator-string-length.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + var text = 'Abcd\u20191234'; + tx.executeSql("select length(?) AS stringlength", ['First\u2013Second'], function (tx_ignored, rs) { + expect(rs.rows.item(0).stringlength).toBe(12); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + 'HEX value of string with UNICODE \\u2013 xxx', function(done) { + // NOTE: this test verifies that the UNICODE xxx (\u2013) + // is seen by the sqlite implementation OK: + var db = openDatabase("UNICODE-u2013-hex-value-test.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql('SELECT HEX(?) AS myresult', ['1\u2013'], function (tx_ignored, rs) { + if (isWindows) + expect(rs.rows.item(0).myresult).toBe('31002920'); // (UTF-16le) + else + expect(rs.rows.item(0).myresult).toBe('31E28093'); // (UTF-8) + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + ' handles UNICODE \\u2013 xxx correctly [string test]', function (done) { + if (isWP8) pending('BROKEN on WP(8)'); // [BUG #202] UNICODE characters not working with WP(8) + //if (!isWebSql && !isWindows && isAndroid) pending('SKIP for Android plugin (cordova-android 6.x BUG: cordova/cordova-discuss#57)'); + //if (!isWebSql && !isWindows && !isAndroid && !isWP8) pending('SKIP for iOS/macOS plugin (Cordova BUG: CB-9435)'); + + // NOTE: since the above test shows the UNICODE xxx (\u2013) + // is seen by the sqlite implementation OK, it is now concluded that + // the failure is caused by the native JSON result encoding. + var db = openDatabase("UNICODE-paragraph-separator-string-lowertext.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql("SELECT LOWER(?) AS lowertext", ['First\u2013Second'], function (tx_ignored, rs) { + expect(rs).toBeDefined(); + expect(rs.rows.item(0).lowertext).toBe("first\u2013second"); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + // NOTE: the next 3 tests show that for iOS/macOS/Android: + // XXX XXX + + it(suiteName + "UNICODE \\u2019 xxx string length", function(done) { + if (isWP8) pending('BROKEN on WP(8)'); // [BUG #202] Certain UNICODE characters not working with WP(8) + + // NOTE: this test verifies that the UNICODE xxx (\u2019) + // is seen by the sqlite implementation OK: + var db = openDatabase("UNICODE-line-separator-string-length.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql("select length(?) AS stringlength", ['First\u2019Second'], function (tx_ignored, rs) { + expect(rs).toBeDefined(); + expect(rs.rows).toBeDefined(); + expect(rs.rows.length).toBe(1); + expect(rs.rows.item(0).stringlength).toBe(12); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + 'HEX value of string with UNICODE \\u2019 xxx', function(done) { + // NOTE: this test verifies that the UNICODE xxx (\u2019) + // is seen by the sqlite implementation OK: + var db = openDatabase("UNICODE-line-separator-hex-value-test.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql('SELECT HEX(?) AS myresult', ['1\u2019'], function (tx_ignored, rs) { + if (isWindows) + expect(rs.rows.item(0).myresult).toBe('31002820'); // (UTF-16le) + else + expect(rs.rows.item(0).myresult).toBe('31E28099'); // (UTF-8) + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + ' handles UNICODE \\u2019 xxx correctly [string test]', function (done) { + if (isWP8) pending('BROKEN on WP(8)'); // [BUG #202] UNICODE characters not working with WP(8) + //if (!isWebSql && !isWindows && isAndroid) pending('SKIP for Android plugin (cordova-android 6.x BUG: cordova/cordova-discuss#57)'); + //if (!isWebSql && !isWindows && !isAndroid && !isWP8) pending('SKIP for iOS/macOS plugin (Cordova BUG: CB-9435)'); + //if (isWebSql && !isWindows && isAndroid) pending('SKIP for Android Web SQL'); // TBD SKIP for Android Web for now + + // NOTE: since the above test shows the UNICODE xxx (\u2019) + // is seen by the sqlite implementation OK, it is now concluded that + // the failure is caused by the native JSON result encoding. + var db = openDatabase("UNICODE-line-separator-string-lowertext.db", "1.0", "Demo", DEFAULT_SIZE); + + expect(db).toBeDefined(); + + db.transaction(function(tx) { + expect(tx).toBeDefined(); + + tx.executeSql("SELECT LOWER(?) AS lowertext", ['First\u2019Second'], function (tx_ignored, rs) { + expect(rs).toBeDefined(); + expect(rs.rows.item(0).lowertext).toBe("first\u2019second"); + + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('--'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + // NOTE: the next 3 tests repeat the above for UNICODE \u2029 paragraph separator // on iOS/macOS/Android: // - UNICODE \u2029 paragraph separator from JavaScript to native (Objective-C/Java) is working OK diff --git a/spec/www/spec/db-tx-value-bindings-test.js b/spec/www/spec/db-tx-value-bindings-test.js index 76315b5f5..4589fd6fc 100755 --- a/spec/www/spec/db-tx-value-bindings-test.js +++ b/spec/www/spec/db-tx-value-bindings-test.js @@ -1396,6 +1396,150 @@ var mytests = function() { }); }, MYTIMEOUT); + it(suiteName + + ' handles UNICODE \\u2013 INLINE correctly in database', function (done) { + var db = openDatabase('INLINE-u2013-INSERT-test.db'); + + var check1 = false; + + db.transaction(function (tx) { + tx.executeSql('DROP TABLE IF EXISTS test', [], function () { + tx.executeSql('CREATE TABLE test (name, id)', [], function() { + tx.executeSql("INSERT INTO test VALUES ('hello\u2013world', 'id1')", null, function () { + tx.executeSql('SELECT name FROM test', [], function (tx_ignored, rs) { + var name = rs.rows.item(0).name; + + expect(name.length).toBe(11); + expect(name).toBe('hello\u2013world'); + + check1 = true; + }); + }); + }); + }); + + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('---'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + + }, function() { + expect(check1).toBe(true); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + + ' handles UNICODE \\u2019 INLINE correctly in database', function (done) { + var db = openDatabase('INLINE-u2019-INSERT-test.db'); + + var check1 = false; + + db.transaction(function (tx) { + tx.executeSql('DROP TABLE IF EXISTS test', [], function () { + tx.executeSql('CREATE TABLE test (name, id)', [], function() { + tx.executeSql("INSERT INTO test VALUES ('hello\u2019world', 'id1')", null, function () { + tx.executeSql('SELECT name FROM test', [], function (tx_ignored, rs) { + var name = rs.rows.item(0).name; + + expect(name.length).toBe(11); + expect(name).toBe('hello\u2019world'); + + check1 = true; + }); + }); + }); + }); + + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('---'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + + }, function() { + expect(check1).toBe(true); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + + ' handles UNICODE \\u2013 xxx correctly in database', function (done) { + var db = openDatabase('UNICODE-u2013-INSERT-test.db'); + + var check1 = false; + + db.transaction(function (tx) { + tx.executeSql('DROP TABLE IF EXISTS test', [], function () { + tx.executeSql('CREATE TABLE test (name, id)', [], function() { + tx.executeSql('INSERT INTO test VALUES (?, "id1")', ['hello\u2013world'], function () { + tx.executeSql('SELECT name FROM test', [], function (tx_ignored, rs) { + var name = rs.rows.item(0).name; + + expect(name.length).toBe(11); + expect(name).toBe('hello\u2013world'); + + check1 = true; + }); + }); + }); + }); + + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('---'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + + }, function() { + expect(check1).toBe(true); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + + it(suiteName + + ' handles UNICODE \\u2019 xxx correctly in database', function (done) { + var db = openDatabase('UNICODE-u2019-INSERT-test.db'); + + var check1 = false; + + db.transaction(function (tx) { + tx.executeSql('DROP TABLE IF EXISTS test', [], function () { + tx.executeSql('CREATE TABLE test (name, id)', [], function() { + tx.executeSql('INSERT INTO test VALUES (?, "id1")', ['hello\u2019world'], function () { + tx.executeSql('SELECT name FROM test', [], function (tx_ignored, rs) { + var name = rs.rows.item(0).name; + + expect(name.length).toBe(11); + expect(name).toBe('hello\u2019world'); + + check1 = true; + }); + }); + }); + }); + + }, function(error) { + // NOT EXPECTED: + expect(false).toBe(true); + expect(error.message).toBe('---'); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + + }, function() { + expect(check1).toBe(true); + // Close (plugin only) & finish: + (isWebSql) ? done() : db.close(done, done); + }); + }, MYTIMEOUT); + }); });