summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/sql/data/1-creation.js20
-rw-r--r--tests/auto/declarative/sql/data/2-selection.js30
-rw-r--r--tests/auto/declarative/sql/data/3-iteration-item-function.js27
-rw-r--r--tests/auto/declarative/sql/data/5-iteration-iterator.js27
-rw-r--r--tests/auto/declarative/sql/data/6-iteration-efficient.js28
-rw-r--r--tests/auto/declarative/sql/data/README3
-rw-r--r--tests/auto/declarative/sql/data/test1.js18
-rw-r--r--tests/auto/declarative/sql/tst_sql.cpp103
8 files changed, 210 insertions, 46 deletions
diff --git a/tests/auto/declarative/sql/data/1-creation.js b/tests/auto/declarative/sql/data/1-creation.js
new file mode 100644
index 0000000..95fa99e
--- /dev/null
+++ b/tests/auto/declarative/sql/data/1-creation.js
@@ -0,0 +1,20 @@
+var db = openDatabase("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" }
+);
+
+
+function test()
+{
+ return r;
+}
diff --git a/tests/auto/declarative/sql/data/2-selection.js b/tests/auto/declarative/sql/data/2-selection.js
new file mode 100644
index 0000000..3acf686
--- /dev/null
+++ b/tests/auto/declarative/sql/data/2-selection.js
@@ -0,0 +1,30 @@
+var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+var r=0;
+
+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" }
+);
+
+
+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
new file mode 100644
index 0000000..bad9b82
--- /dev/null
+++ b/tests/auto/declarative/sql/data/3-iteration-item-function.js
@@ -0,0 +1,27 @@
+var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+var r=0;
+
+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" }
+);
+
+
+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
new file mode 100644
index 0000000..51f0504
--- /dev/null
+++ b/tests/auto/declarative/sql/data/5-iteration-iterator.js
@@ -0,0 +1,27 @@
+var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+var r=0;
+
+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" }
+);
+
+
+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
new file mode 100644
index 0000000..2222b8a
--- /dev/null
+++ b/tests/auto/declarative/sql/data/6-iteration-efficient.js
@@ -0,0 +1,28 @@
+var db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
+var r=0;
+
+db.transaction(
+ function(tx) {
+ tx.executeSql('SELECT * FROM Greeting', [],
+ function(tx, rs) {
+ var r1=""
+ rs.rows.forwardOnly = true;
+ 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="passed" }
+);
+
+
+function test()
+{
+ if (r == 0) r = "transaction_not_finished";
+ return r;
+}
diff --git a/tests/auto/declarative/sql/data/README b/tests/auto/declarative/sql/data/README
new file mode 100644
index 0000000..7efca3a
--- /dev/null
+++ b/tests/auto/declarative/sql/data/README
@@ -0,0 +1,3 @@
+These tests are executed in sequence - the database persist until the end of the
+testing. This is done to better exercise the persistence of the database, since
+that is how it is used.
diff --git a/tests/auto/declarative/sql/data/test1.js b/tests/auto/declarative/sql/data/test1.js
deleted file mode 100644
index 2ae9988..0000000
--- a/tests/auto/declarative/sql/data/test1.js
+++ /dev/null
@@ -1,18 +0,0 @@
-var db;
-db = openDatabase("QmlTestDB", "", "Test database from Qt autotests", 1000000);
-var r="testerror";
-
-// Asynchronous in WebKit, so must wait before calling test()
-db.transaction(function(tx) {
- r = "passed";
- tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)', [],
- function(tx, rs) { }, function(tx, error) { r="FAILED: "+error.message });
- tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ],
- function(tx, rs) { }, function(tx, error) { r="FAILED: "+error.message });
-}, function(tx, error) { r="TXFAILED: "+error.message }, function(tx, result) { if (r=="testerror") r="passed" });
-
-
-function test()
-{
- return r;
-}
diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp
index 3179c99..10ce6d8 100644
--- a/tests/auto/declarative/sql/tst_sql.cpp
+++ b/tests/auto/declarative/sql/tst_sql.cpp
@@ -17,10 +17,20 @@ public:
tst_sql() {}
private slots:
- void verifyAgainstWebKit_data();
- void verifyAgainstWebKit();
+ void initTestCase();
+
+ void checkDatabasePath();
+
+ void validateAgainstWebkit_data();
+ void validateAgainstWebkit();
+
+ void testQml_data();
+ void testQml();
+
+ void cleanupTestCase();
private:
+ QString dbDir() const;
QmlEngine engine;
};
@@ -28,7 +38,7 @@ class QWebPageWithJavaScriptConsoleMessages : public QWebPage {
public:
void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
{
-qDebug() << sourceID << ":" << lineNumber << ":" << message;
+ qWarning() << sourceID << ":" << lineNumber << ":" << message;
}
};
@@ -44,20 +54,52 @@ void removeRecursive(const QString& dirname)
QDir().rmdir(dirname);
}
+void tst_sql::initTestCase()
+{
+ removeRecursive(dbDir());
+ QDir().mkpath(dbDir());
+}
+
+void tst_sql::cleanupTestCase()
+{
+ removeRecursive(dbDir());
+}
+
+QString tst_sql::dbDir() const
+{
+ return QString(SRCDIR)+"/output";
+}
+
+void tst_sql::checkDatabasePath()
+{
+ // Check default storage path (we can't use it since we don't want to mess with user's data)
+ QVERIFY(engine.offlineStoragePath().contains("Nokia"));
+ QVERIFY(engine.offlineStoragePath().contains("OfflineStorage"));
+}
-void tst_sql::verifyAgainstWebKit_data()
+void tst_sql::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;
+ QTest::newRow("selection") << "data/2-selection.js" << "passed" << 1 << false;
+ QTest::newRow("iteration-item-function") << "data/3-iteration-item-function.js" << "passed" << 1 << false;
+ QTest::newRow("iteration-index") << "data/4-iteration-index.js" << "passed" << 1 << true;
+ QTest::newRow("iteration-iterator") << "data/5-iteration-iterator.js" << "passed" << 1 << true;
+ QTest::newRow("iteration-efficient") << "data/6-iteration-efficient.js" << "passed" << 1 << true;
+}
- QTest::newRow("basic creation") << "data/test1.js" << "passed" << 1;
+void tst_sql::validateAgainstWebkit_data()
+{
+ testQml_data();
}
-void tst_sql::verifyAgainstWebKit()
+void tst_sql::validateAgainstWebkit()
{
- // Tests QML SQL Database support, and tests the same thing against
- // WebKit (HTML5) support to validate the test.
+ // 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_).
@@ -65,32 +107,19 @@ void tst_sql::verifyAgainstWebKit()
QFETCH(QString, jsfile);
QFETCH(QString, result);
QFETCH(int, databases);
+ QFETCH(bool, qmlextension);
- QString tmpdir = QString(SRCDIR)+"/output";
-
- // QML...
- QString qml=
- "import Qt 4.6\n"
- "Text { Script { source: \""+jsfile+"\" } text: test() }";
+ if (qmlextension) // WebKit can't do it (yet?)
+ return;
- // Check default storage path (we can't use it since we don't want to mess with user's data)
- QVERIFY(engine.offlineStoragePath().contains("Nokia"));
- QVERIFY(engine.offlineStoragePath().contains("OfflineStorage"));
- engine.setOfflineStoragePath(tmpdir);
- QmlComponent component(&engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports
- QFxText *text = qobject_cast<QFxText*>(component.create());
- QVERIFY(text != 0);
- QCOMPARE(text->text(),result);
- QCOMPARE(QDir(tmpdir+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), databases*2); // *2 = .ini file + .sqlite file
-
- // WebKit...
QFile f(jsfile);
QVERIFY(f.open(QIODevice::ReadOnly));
QString js=f.readAll();
QWebPageWithJavaScriptConsoleMessages webpage;
- QDir().mkpath(tmpdir);
- webpage.settings()->setOfflineStoragePath(tmpdir);
+ 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);
@@ -98,9 +127,27 @@ void tst_sql::verifyAgainstWebKit()
QWebSecurityOrigin origin = webpage.mainFrame()->securityOrigin();
QList<QWebDatabase> dbs = origin.databases();
QCOMPARE(dbs.count(), databases);
+}
+void tst_sql::testQml()
+{
+ // Tests QML SQL Database support with tests
+ // that have been validated against Webkit.
+ //
+ QFETCH(QString, jsfile);
+ QFETCH(QString, result);
+ QFETCH(int, databases);
- removeRecursive(tmpdir);
+ QString qml=
+ "import Qt 4.6\n"
+ "Text { Script { source: \""+jsfile+"\" } text: test() }";
+
+ engine.setOfflineStoragePath(dbDir());
+ QmlComponent component(&engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports
+ QFxText *text = qobject_cast<QFxText*>(component.create());
+ QVERIFY(text != 0);
+ QCOMPARE(text->text(),result);
+ QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), databases*2); // *2 = .ini file + .sqlite file
}
QTEST_MAIN(tst_sql)