diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-09-24 05:53:38 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-09-24 05:53:38 (GMT) |
commit | 64279c11f2092a5e6e03f1b7e4bfc7a9065807f8 (patch) | |
tree | 9b109ecb4d81b9c9facaffa1bddb390ca73e921e /tests | |
parent | 74a66e291be2f216f88491e518add9ef72a730f2 (diff) | |
download | Qt-64279c11f2092a5e6e03f1b7e4bfc7a9065807f8.zip Qt-64279c11f2092a5e6e03f1b7e4bfc7a9065807f8.tar.gz Qt-64279c11f2092a5e6e03f1b7e4bfc7a9065807f8.tar.bz2 |
More testing, validate tests before running them.
Run all WebKit validations first (no point testing QML if the test are wrong).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/sql/data/README | 3 | ||||
-rw-r--r-- | tests/auto/declarative/sql/data/test2.js | 30 | ||||
-rw-r--r-- | tests/auto/declarative/sql/tst_sql.cpp | 92 |
3 files changed, 97 insertions, 28 deletions
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/test2.js b/tests/auto/declarative/sql/data/test2.js new file mode 100644 index 0000000..3acf686 --- /dev/null +++ b/tests/auto/declarative/sql/data/test2.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/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index b0a6021..cb13427 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,47 @@ 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::newRow("basic creation") << "data/test1.js" << "passed" << 1; + QTest::newRow("basic select") << "data/test2.js" << "passed" << 1; } -void tst_sql::verifyAgainstWebKit() +void tst_sql::validateAgainstWebkit_data() { - // Tests QML SQL Database support, and tests the same thing against - // WebKit (HTML5) support to validate the test. + testQml_data(); +} + +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_). @@ -66,31 +103,12 @@ void tst_sql::verifyAgainstWebKit() QFETCH(QString, result); QFETCH(int, databases); - QString tmpdir = QString(SRCDIR)+"/output"; - - // QML... - QString qml= - "import Qt 4.6\n" - "Text { Script { source: \""+jsfile+"\" } text: test() }"; - - // 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); @@ -100,9 +118,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); + QString qml= + "import Qt 4.6\n" + "Text { Script { source: \""+jsfile+"\" } text: test() }"; - removeRecursive(tmpdir); + 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) |