summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-18 04:25:49 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-18 04:25:49 (GMT)
commit27a4decc8f687c81dbd07315ad8d6488cfa4b4a8 (patch)
treed369bffd421bf43fb4339d9be74484c66bc97b79 /tests/auto/declarative
parenta84c87af73058cb9ce7716aa2c9e767c8851369c (diff)
parentdb56fec07c1a8a0a3a6e006ec2613351241cdf54 (diff)
downloadQt-27a4decc8f687c81dbd07315ad8d6488cfa4b4a8.zip
Qt-27a4decc8f687c81dbd07315ad8d6488cfa4b4a8.tar.gz
Qt-27a4decc8f687c81dbd07315ad8d6488cfa4b4a8.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp373
-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.js20
-rw-r--r--tests/auto/declarative/sql/tst_sql.cpp20
10 files changed, 499 insertions, 171 deletions
diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
index 4c8219a..14de1df 100644
--- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
+++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp
@@ -50,29 +50,169 @@ public:
tst_QmlListAccessor() {}
private slots:
+ void invalid();
void qmllist();
- //void qlist();
+ void qlist();
void qstringlist();
+ void qvariantlist();
+ void qobject();
+ void instance();
+ void integer();
};
+void tst_QmlListAccessor::invalid()
+{
+ QmlListAccessor accessor;
+
+ QCOMPARE(accessor.list(), QVariant());
+ QVERIFY(!accessor.isValid());
+ QCOMPARE(accessor.type(), QmlListAccessor::Invalid);
+
+ QCOMPARE(accessor.count(), 0);
+ QCOMPARE(accessor.at(0), QVariant());
+ QCOMPARE(accessor.at(4), QVariant());
+ QVERIFY(!accessor.append(QVariant(10)));
+ QVERIFY(!accessor.insert(0, QVariant(10)));
+ QVERIFY(!accessor.removeAt(0));
+ QVERIFY(!accessor.clear());
+
+ accessor.setList(QVariant());
+
+ QCOMPARE(accessor.list(), QVariant());
+ QVERIFY(!accessor.isValid());
+ QCOMPARE(accessor.type(), QmlListAccessor::Invalid);
+
+ QCOMPARE(accessor.count(), 0);
+ QCOMPARE(accessor.at(0), QVariant());
+ QCOMPARE(accessor.at(4), QVariant());
+ QVERIFY(!accessor.append(QVariant(10)));
+ QVERIFY(!accessor.insert(0, QVariant(10)));
+ QVERIFY(!accessor.removeAt(0));
+ QVERIFY(!accessor.clear());
+}
+
void tst_QmlListAccessor::qmllist()
{
QmlConcreteList<QObject*> list;
- QObject *obj = new QObject;
+ QObject *obj = new QObject(this);
+ QObject *obj2 = new QObject(this);
+ QObject *obj3 = new QObject(this);
+
list.append(obj);
QVERIFY(list.count() == 1);
QCOMPARE(list.at(0), obj);
QmlListAccessor accessor;
accessor.setList(qVariantFromValue((QmlList<QObject*>*)&list));
+ QCOMPARE(accessor.list(), qVariantFromValue((QmlList<QObject*>*)&list));
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::QmlList);
+
+ // isValid
QVERIFY(accessor.isValid());
- QVERIFY(accessor.count() == 1);
- QVariant v = accessor.at(0);
- QCOMPARE(qvariant_cast<QObject*>(v), obj);
+ // count
+ QCOMPARE(accessor.count(), 1);
+
+ // at
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(0)), obj);
+
+ // append
+ accessor.append(qVariantFromValue(obj2));
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 2);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj2);
+ QCOMPARE(list.count(), 2);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj2);
+
+ // insert
+ accessor.insert(1, qVariantFromValue(obj3));
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 3);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj3);
+ QCOMPARE(list.count(), 3);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj3);
+ QCOMPARE(list.at(2), obj2);
+
+ // removeAt
+ accessor.removeAt(1);
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 2);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj2);
+ QCOMPARE(list.count(), 2);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj2);
+ // clear
+ accessor.clear();
QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 0);
+ QCOMPARE(list.count(), 0);
+}
+
+void tst_QmlListAccessor::qlist()
+{
+ QList<QObject*> list;
+ QObject *obj = new QObject(this);
+ QObject *obj2 = new QObject(this);
+ QObject *obj3 = new QObject(this);
+
+ list.append(obj);
+ QVERIFY(list.count() == 1);
+ QCOMPARE(list.at(0), obj);
+
+ QmlListAccessor accessor;
+ accessor.setList(qVariantFromValue((QList<QObject*>*)&list));
+ QCOMPARE(accessor.list(), qVariantFromValue((QList<QObject*>*)&list));
+
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::QListPtr);
+
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QCOMPARE(accessor.count(), 1);
+
+ // at
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(0)), obj);
+
+ // append
+ accessor.append(qVariantFromValue(obj2));
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 2);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj2);
+ QCOMPARE(list.count(), 2);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj2);
+
+ // insert
+ accessor.insert(1, qVariantFromValue(obj3));
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 3);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj3);
+ QCOMPARE(list.count(), 3);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj3);
+ QCOMPARE(list.at(2), obj2);
+
+ // removeAt
+ accessor.removeAt(1);
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 2);
+ QCOMPARE(qvariant_cast<QObject*>(accessor.at(1)), obj2);
+ QCOMPARE(list.count(), 2);
+ QCOMPARE(list.at(0), obj);
+ QCOMPARE(list.at(1), obj2);
+
+ // clear
+ accessor.clear();
+ QVERIFY(accessor.isValid());
+ QCOMPARE(accessor.count(), 0);
+ QCOMPARE(list.count(), 0);
}
void tst_QmlListAccessor::qstringlist()
@@ -85,16 +225,231 @@ void tst_QmlListAccessor::qstringlist()
QmlListAccessor accessor;
accessor.setList(list);
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::StringList);
+
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QVERIFY(accessor.count() == 2);
+
+ // at
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // append
+ QVERIFY(!accessor.append(QVariant("Item3")));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // insert
+ QVERIFY(!accessor.insert(1, QVariant("MiddleItem")));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // removeAt
+ QVERIFY(!accessor.removeAt(1));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // clear
+ QVERIFY(!accessor.clear());
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+}
+
+void tst_QmlListAccessor::qvariantlist()
+{
+ QVariantList list;
+ list.append(QLatin1String("Item1"));
+ list.append(QLatin1String("Item2"));
+ QVERIFY(list.count() == 2);
+
+ QmlListAccessor accessor;
+ accessor.setList(list);
+
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::VariantList);
+
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QVERIFY(accessor.count() == 2);
+
+ // at
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // append
+ QVERIFY(!accessor.append(QVariant("Item3")));
QVERIFY(accessor.isValid());
QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // insert
+ QVERIFY(!accessor.insert(1, QVariant("MiddleItem")));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // removeAt
+ QVERIFY(!accessor.removeAt(1));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+
+ // clear
+ QVERIFY(!accessor.clear());
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 2);
+ QCOMPARE(qvariant_cast<QString>(accessor.at(0)), QLatin1String("Item1"));
+ QCOMPARE(qvariant_cast<QString>(accessor.at(1)), QLatin1String("Item2"));
+}
+
+void tst_QmlListAccessor::qobject()
+{
+ QObject *obj = new QObject(this);
+
+ QmlListAccessor accessor;
+ accessor.setList(qVariantFromValue(obj));
- QVariant v = accessor.at(0);
- QCOMPARE(qvariant_cast<QString>(v), QLatin1String("Item1"));
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::Instance);
- v = accessor.at(1);
- QCOMPARE(qvariant_cast<QString>(v), QLatin1String("Item2"));
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QVERIFY(accessor.count() == 1);
+
+ // at
+ QCOMPARE(accessor.at(0), qVariantFromValue(obj));
+
+ // append
+ QVERIFY(!accessor.append(qVariantFromValue((QObject *)0)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(obj));
+
+ // insert
+ QVERIFY(!accessor.insert(0, qVariantFromValue((QObject *)0)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(obj));
+
+ // removeAt
+ QVERIFY(!accessor.removeAt(0));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(obj));
+
+ // clear
+ QVERIFY(!accessor.clear());
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(obj));
}
+void tst_QmlListAccessor::instance()
+{
+ QRect r;
+
+ QmlListAccessor accessor;
+ accessor.setList(r);
+
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::Instance);
+
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QVERIFY(accessor.count() == 1);
+
+ // at
+ QCOMPARE(accessor.at(0), qVariantFromValue(r));
+
+ // append
+ QVERIFY(!accessor.append(qVariantFromValue(r)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(r));
+
+ // insert
+ QVERIFY(!accessor.insert(0, qVariantFromValue(r)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(r));
+
+ // removeAt
+ QVERIFY(!accessor.removeAt(0));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(r));
+
+ // clear
+ QVERIFY(!accessor.clear());
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 1);
+ QCOMPARE(accessor.at(0), qVariantFromValue(r));
+}
+
+void tst_QmlListAccessor::integer()
+{
+ int r = 13;
+
+ QmlListAccessor accessor;
+ accessor.setList(r);
+
+ // type
+ QCOMPARE(accessor.type(), QmlListAccessor::Integer);
+
+ // isValid
+ QVERIFY(accessor.isValid());
+
+ // count
+ QVERIFY(accessor.count() == 13);
+
+ // at
+ QCOMPARE(accessor.at(4), qVariantFromValue(4));
+
+ // append
+ QVERIFY(!accessor.append(qVariantFromValue(r)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 13);
+ QCOMPARE(accessor.at(4), qVariantFromValue(4));
+
+ // insert
+ QVERIFY(!accessor.insert(0, qVariantFromValue(r)));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 13);
+ QCOMPARE(accessor.at(4), qVariantFromValue(4));
+
+ // removeAt
+ QVERIFY(!accessor.removeAt(0));
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 13);
+ QCOMPARE(accessor.at(4), qVariantFromValue(4));
+
+ // clear
+ QVERIFY(!accessor.clear());
+ QVERIFY(accessor.isValid());
+ QVERIFY(accessor.count() == 13);
+ QCOMPARE(accessor.at(4), qVariantFromValue(4));
+}
QTEST_MAIN(tst_QmlListAccessor)
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
new file mode 100644
index 0000000..65d0c03
--- /dev/null
+++ b/tests/auto/declarative/sql/data/7a-error.js
@@ -0,0 +1,20 @@
+function test() {
+ var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+ var r="transaction_not_finished";
+
+ try {
+ db.transaction(
+ function(tx) {
+ var rs = tx.executeSql('SELECT * FROM NotExists');
+ r = "SHOULD NOT SUCCEED";
+ }
+ );
+ } catch (err) {
+ if (err.message == "no such table: NotExists Unable to execute statement")
+ r = "passed";
+ else
+ r = "WRONG ERROR="+err.message;
+ }
+
+ return r;
+}
diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp
index 973d7b1..cbd14ab 100644
--- a/tests/auto/declarative/sql/tst_sql.cpp
+++ b/tests/auto/declarative/sql/tst_sql.cpp
@@ -144,20 +144,23 @@ void tst_sql::testQml_data()
QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 1 << true; // Some HTML5 documents say to use rows by index, others by item() function
QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 1 << true; // As with previous, WebKit doesn't give an array
QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 1 << true; // It's very inefficient to find the total number of results, here is a solution
+ QTest::newRow("error-a") << "data/7a-error.js" << "passed" << 1 << false;
}
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);
@@ -174,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(200); // 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()