summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/sql/data/1-creation.js27
-rw-r--r--tests/auto/declarative/sql/data/2-selection-bindnames.js32
-rw-r--r--tests/auto/declarative/sql/data/2-selection.js41
-rw-r--r--tests/auto/declarative/sql/data/3-iteration-item-function.js38
-rw-r--r--tests/auto/declarative/sql/data/4-iteration-index.js38
-rw-r--r--tests/auto/declarative/sql/data/5-iteration-iterator.js38
-rw-r--r--tests/auto/declarative/sql/data/6-iteration-efficient.js43
-rw-r--r--tests/auto/declarative/sql/data/7a-error.js32
-rw-r--r--tests/auto/declarative/sql/tst_sql.cpp19
9 files changed, 127 insertions, 181 deletions
diff --git a/tests/auto/declarative/sql/data/1-creation.js b/tests/auto/declarative/sql/data/1-creation.js
index 95fa99e..aab9b5d 100644
--- a/tests/auto/declarative/sql/data/1-creation.js
+++ b/tests/auto/declarative/sql/data/1-creation.js
@@ -1,20 +1,15 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r="transaction_not_finished";
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-// Asynchronous in WebKit, so must wait before calling test()
-db.transaction(
- function(tx) {
- tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', [],
- function(tx, rs) { }, function(tx, error) { r="CREATE FAILED: "+error.message });
- tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ],
- function(tx, rs) { }, function(tx, error) { r="INSERT FAILED: "+error.message });
- },
- function(tx, error) { r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r=="transaction_not_finished") r="passed" }
-);
+ // Asynchronous in WebKit, so must wait before calling test()
+ db.transaction(
+ function(tx) {
+ tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
+ tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
+ r = "passed";
+ }
+ );
-
-function test()
-{
return r;
}
diff --git a/tests/auto/declarative/sql/data/2-selection-bindnames.js b/tests/auto/declarative/sql/data/2-selection-bindnames.js
index c00acc14..21f34db 100644
--- a/tests/auto/declarative/sql/data/2-selection-bindnames.js
+++ b/tests/auto/declarative/sql/data/2-selection-bindnames.js
@@ -1,24 +1,16 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM Greeting WHERE salutation=:p2 AND salutee=:p1', {':p1':'world', ':p2':'hello'},
- function(tx, rs) {
- if ( rs.rows.length != 4 ) {
- if (r==0) r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1)
- }
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="passed" }
-);
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM Greeting WHERE salutation=:p2 AND salutee=:p1', {':p1':'world', ':p2':'hello'});
+ if ( rs.rows.length != 4 )
+ r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1)
+ else
+ r = "passed";
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/2-selection.js b/tests/auto/declarative/sql/data/2-selection.js
index 3acf686..f141d2c 100644
--- a/tests/auto/declarative/sql/data/2-selection.js
+++ b/tests/auto/declarative/sql/data/2-selection.js
@@ -1,30 +1,19 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ],
- function(tx, rs) { }, function(tx, error) { if (r==0) r="INSERT 1 FAILED: "+error.message });
- tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ],
- function(tx, rs) { }, function(tx, error) { if (r==0) r="INSERT 2 FAILED: "+error.message });
- tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ],
- function(tx, rs) { }, function(tx, error) { if (r==0) r="INSERT 3 FAILED: "+error.message });
- tx.executeSql('SELECT * FROM Greeting', [],
- function(tx, rs) {
- if ( rs.rows.length != 4 ) { // 1 from test1, 3 from this test.
- if (r==0) r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1]
- }
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="passed" }
-);
+ db.transaction(
+ function(tx) {
+ tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
+ tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
+ tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
+ var rs = tx.executeSql('SELECT * FROM Greeting');
+ if ( rs.rows.length != 4 ) // 1 from test1, 3 from this test.
+ r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1]
+ else
+ r = "passed";
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/3-iteration-item-function.js b/tests/auto/declarative/sql/data/3-iteration-item-function.js
index bad9b82..57c8a17 100644
--- a/tests/auto/declarative/sql/data/3-iteration-item-function.js
+++ b/tests/auto/declarative/sql/data/3-iteration-item-function.js
@@ -1,27 +1,19 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM Greeting', [],
- function(tx, rs) {
- var r1=""
- for(var i = 0; i < rs.rows.length; i++) {
- r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";"
- }
- if (r1 != "hello, world;hello, world;hello, world;hello, world;")
- r = "SELECTED DATA WRONG: "+r1;
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="passed" }
-);
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM Greeting');
+ var r1=""
+ for(var i = 0; i < rs.rows.length; i++)
+ r1 += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + ";"
+ if (r1 != "hello, world;hello, world;hello, world;hello, world;")
+ r = "SELECTED DATA WRONG: "+r1;
+ else
+ r = "passed";
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/4-iteration-index.js b/tests/auto/declarative/sql/data/4-iteration-index.js
index 298737d..512cf8d 100644
--- a/tests/auto/declarative/sql/data/4-iteration-index.js
+++ b/tests/auto/declarative/sql/data/4-iteration-index.js
@@ -1,27 +1,19 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM Greeting', [],
- function(tx, rs) {
- var r1=""
- for(var i = 0; i < rs.rows.length; i++) {
- r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";"
- }
- if (r1 != "hello, world;hello, world;hello, world;hello, world;")
- r = "SELECTED DATA WRONG: "+r1;
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="passed" }
-);
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM Greeting');
+ var r1=""
+ for(var i = 0; i < rs.rows.length; i++)
+ r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";"
+ if (r1 != "hello, world;hello, world;hello, world;hello, world;")
+ r = "SELECTED DATA WRONG: "+r1;
+ else
+ r = "passed";
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/5-iteration-iterator.js b/tests/auto/declarative/sql/data/5-iteration-iterator.js
index 51f0504..ae4fd34 100644
--- a/tests/auto/declarative/sql/data/5-iteration-iterator.js
+++ b/tests/auto/declarative/sql/data/5-iteration-iterator.js
@@ -1,27 +1,19 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM Greeting', [],
- function(tx, rs) {
- var r1=""
- for(var i in rs.rows) {
- r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";"
- }
- if (r1 != "hello, world;hello, world;hello, world;hello, world;")
- r = "SELECTED DATA WRONG: "+r1;
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="passed" }
-);
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM Greeting')
+ var r1=""
+ for(var i in rs.rows)
+ r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";"
+ if (r1 != "hello, world;hello, world;hello, world;hello, world;")
+ r = "SELECTED DATA WRONG: "+r1;
+ else
+ r = "passed";
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/6-iteration-efficient.js b/tests/auto/declarative/sql/data/6-iteration-efficient.js
index 6711fb0..fe0acfc 100644
--- a/tests/auto/declarative/sql/data/6-iteration-efficient.js
+++ b/tests/auto/declarative/sql/data/6-iteration-efficient.js
@@ -1,32 +1,29 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
-var fbefore="FORWARD WRONG"
-var fafter="FORWARD WRONG"
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM Greeting', [],
- function(tx, rs) {
- var r1=""
- if (!rs.rows.forwardOnly) fbefore=""
- rs.rows.forwardOnly = true;
- if (rs.rows.forwardOnly) fafter="";
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM Greeting');
+ var r1=""
+ var fbefiore = rs.rows.forwardOnly;
+ rs.rows.forwardOnly = true;
+ var fafter = rs.rows.forwardOnly;
+ if (fbefore)
+ r = "forward wrong before";
+ else if (!fafter)
+ r = "forward wrong after";
+ else {
for(var i=0; rs.rows[i]; ++i) {
r1 += rs.rows[i].salutation + ", " + rs.rows[i].salutee + ";"
}
if (r1 != "hello, world;hello, world;hello, world;hello, world;")
r = "SELECTED DATA WRONG: "+r1;
- },
- function(tx, error) { if (r==0) r="SELECT FAILED: "+error.message }
- );
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r=fbefore+"passed"+fafter }
-);
+ else
+ r = "passed";
+ }
+ }
+ );
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/data/7a-error.js b/tests/auto/declarative/sql/data/7a-error.js
index 0bb39ef..65d0c03 100644
--- a/tests/auto/declarative/sql/data/7a-error.js
+++ b/tests/auto/declarative/sql/data/7a-error.js
@@ -1,26 +1,20 @@
-var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r=0;
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
-db.transaction(
- function(tx) {
- tx.executeSql('SELECT * FROM NotExists', [],
- function(tx, rs) {
+ try {
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM NotExists');
r = "SHOULD NOT SUCCEED";
- },
- function(tx, error) {
- if (error.message == "no such table: NotExists Unable to execute statement" // QML
- || error.message == "no such table: NotExists") r="passed" // WebKit
- else r="WRONG ERROR:"+error.message
}
);
- },
- function(tx, error) { if (r==0) r="TRANSACTION FAILED: "+error.message },
- function(tx, result) { if (r==0) r="SHOULD NOT SUCCEED2" }
-);
+ } catch (err) {
+ if (err.message == "no such table: NotExists Unable to execute statement")
+ r = "passed";
+ else
+ r = "WRONG ERROR="+err.message;
+ }
-
-function test()
-{
- if (r == 0) r = "transaction_not_finished";
return r;
}
diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp
index a929aba..cbd14ab 100644
--- a/tests/auto/declarative/sql/tst_sql.cpp
+++ b/tests/auto/declarative/sql/tst_sql.cpp
@@ -149,16 +149,18 @@ void tst_sql::testQml_data()
void tst_sql::validateAgainstWebkit_data()
{
- testQml_data();
+ QTest::addColumn<QString>("jsfile"); // The input file
+ QTest::addColumn<QString>("result"); // The required output from the js test() function
+ QTest::addColumn<int>("databases"); // The number of databases that should have been created
+ QTest::addColumn<bool>("qmlextension"); // Things WebKit can't do
+ QTest::newRow("creation") << "data/1-creation.js" << "passed" << 1 << false;
}
void tst_sql::validateAgainstWebkit()
{
// Validates tests against WebKit (HTML5) support.
//
- // WebKit SQL is asynchronous, so tests are divided into code plus a test()
- // function which is executed "later" (via QTRY_).
- //
+
QFETCH(QString, jsfile);
QFETCH(QString, result);
QFETCH(int, databases);
@@ -175,14 +177,15 @@ void tst_sql::validateAgainstWebkit()
webpage.settings()->setOfflineStoragePath(dbDir());
webpage.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
- webpage.mainFrame()->evaluateJavaScript(js);
- QTest::qWait(200); // WebKit db access is asynchronous
- QTRY_COMPARE(webpage.mainFrame()->evaluateJavaScript("test()").toString(),result);
- QTest::qWait(1000); // WebKit crashes if you quit it too fast
+ QEXPECT_FAIL("","WebKit doesn't support openDatabaseSync yet", Continue);
+ QCOMPARE(webpage.mainFrame()->evaluateJavaScript(js).toString(),result);
+ /*
+ QTest::qWait(100); // WebKit crashes if you quit it too fast
QWebSecurityOrigin origin = webpage.mainFrame()->securityOrigin();
QList<QWebDatabase> dbs = origin.databases();
QCOMPARE(dbs.count(), databases);
+ */
}
void tst_sql::testQml()