diff options
Diffstat (limited to 'tests/auto/declarative/sql')
21 files changed, 325 insertions, 123 deletions
diff --git a/tests/auto/declarative/sql/data/2-selection-bindnames.js b/tests/auto/declarative/sql/data/2-selection-bindnames.js deleted file mode 100644 index 21f34db..0000000 --- a/tests/auto/declarative/sql/data/2-selection-bindnames.js +++ /dev/null @@ -1,16 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/4-iteration-index.js b/tests/auto/declarative/sql/data/4-iteration-index.js deleted file mode 100644 index 512cf8d..0000000 --- a/tests/auto/declarative/sql/data/4-iteration-index.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/5-iteration-iterator.js b/tests/auto/declarative/sql/data/5-iteration-iterator.js deleted file mode 100644 index ae4fd34..0000000 --- a/tests/auto/declarative/sql/data/5-iteration-iterator.js +++ /dev/null @@ -1,19 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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"; - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/6-iteration-efficient.js b/tests/auto/declarative/sql/data/6-iteration-efficient.js deleted file mode 100644 index fe0acfc..0000000 --- a/tests/auto/declarative/sql/data/6-iteration-efficient.js +++ /dev/null @@ -1,29 +0,0 @@ -function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); - var r="transaction_not_finished"; - - 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; - else - r = "passed"; - } - } - ); - - return r; -} diff --git a/tests/auto/declarative/sql/data/changeversion.js b/tests/auto/declarative/sql/data/changeversion.js new file mode 100644 index 0000000..680d7a6 --- /dev/null +++ b/tests/auto/declarative/sql/data/changeversion.js @@ -0,0 +1,53 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000, + function(db) { + db.changeVersion("","1.0") + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + }) + }); + + db.transaction(function(tx){ + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + }); + + + db = openDatabaseSync("QmlTestDB-changeversion", "", "Test database from Qt autotests", 1000000); + + if (db.version == "1.0") + db.changeVersion("1.0","2.0",function(tx) + { + tx.executeSql('CREATE TABLE Utterance(type TEXT, phrase TEXT)') + var rs = tx.executeSql('SELECT * FROM Greeting'); + for (var i=0; i<rs.rows.length; ++i) { + var type = "Greeting"; + var phrase = rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee; + if (rs.rows.item(i).salutation == "Goodbye" + || rs.rows.item(i).salutation == "Farewell" + || rs.rows.item(i).salutation == "Good-bye") type = "Valediction"; + var ins = tx.executeSql('INSERT INTO Utterance VALUES(?,?)',[type,phrase]); + } + tx.executeSql('DROP TABLE Greeting'); + }); + else + return "db.version should be 1.0, but is " + db.version; + + var db = openDatabaseSync("QmlTestDB-changeversion", "2.0", "Test database from Qt autotests", 1000000); + + db.transaction(function(tx){ + var rs = tx.executeSql('SELECT * FROM Utterance'); + r = "" + for (var i=0; i<rs.rows.length; ++i) { + r += "(" + rs.rows.item(i).type + ": " + rs.rows.item(i).phrase + ")"; + } + if (r == "(Greeting: Hello, world)(Valediction: Goodbye, cruel world)") + r = "passed" + else + r = "WRONG DATA: " + r; + }) + + return r; +} diff --git a/tests/auto/declarative/sql/data/creation-a.js b/tests/auto/declarative/sql/data/creation-a.js new file mode 100644 index 0000000..bd7d5c5 --- /dev/null +++ b/tests/auto/declarative/sql/data/creation-a.js @@ -0,0 +1,18 @@ +function test() { + var r="transaction_not_finished"; + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + db.transaction(function(tx){ + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + r = "passed"; + }) + }); + + var db = openDatabaseSync("QmlTestDB-creation-a", "1.0", "Test database from Qt autotests", 1000000, + function(db) { + r = "FAILED: should have already been created"; + }); + + return r; +} diff --git a/tests/auto/declarative/sql/data/1-creation.js b/tests/auto/declarative/sql/data/creation.js index aab9b5d..317b4c1 100644 --- a/tests/auto/declarative/sql/data/1-creation.js +++ b/tests/auto/declarative/sql/data/creation.js @@ -1,8 +1,7 @@ function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-creation", "1.0", "Test database from Qt autotests", 1000000); - // 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)'); diff --git a/tests/auto/declarative/sql/data/7a-error.js b/tests/auto/declarative/sql/data/error-a.js index 65d0c03..10a23f6 100644 --- a/tests/auto/declarative/sql/data/7a-error.js +++ b/tests/auto/declarative/sql/data/error-a.js @@ -1,5 +1,5 @@ function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); + var db = openDatabaseSync("QmlTestDB-error-a", "1.0", "Test database from Qt autotests", 1000000); var r="transaction_not_finished"; try { diff --git a/tests/auto/declarative/sql/data/error-b.js b/tests/auto/declarative/sql/data/error-b.js new file mode 100644 index 0000000..4dd0ecf --- /dev/null +++ b/tests/auto/declarative/sql/data/error-b.js @@ -0,0 +1,13 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-error-b", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES("junk","junk")'); + notexist[123] = "oops" + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/error-creation.js b/tests/auto/declarative/sql/data/error-creation.js new file mode 100644 index 0000000..92245fd --- /dev/null +++ b/tests/auto/declarative/sql/data/error-creation.js @@ -0,0 +1,12 @@ +function test() { + var r="transaction_not_finished"; + try { + var db = openDatabaseSync("QmlTestDB-creation", "2.0", "Test database from Qt autotests", 1000000); + } catch (err) { + if (err.message == "SQL: database version mismatch") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + return r; +} diff --git a/tests/auto/declarative/sql/data/error-notransaction.js b/tests/auto/declarative/sql/data/error-notransaction.js new file mode 100644 index 0000000..b9cc647 --- /dev/null +++ b/tests/auto/declarative/sql/data/error-notransaction.js @@ -0,0 +1,15 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-data/error-notransaction", "1.0", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + try { + db.transaction(); + } catch (err) { + if (err.message == "transaction: missing callback") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/iteration-forwardonly.js b/tests/auto/declarative/sql/data/iteration-forwardonly.js new file mode 100644 index 0000000..45947c0 --- /dev/null +++ b/tests/auto/declarative/sql/data/iteration-forwardonly.js @@ -0,0 +1,29 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-iteration-forwardonly", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + rs.forwardOnly = !rs.forwardOnly + 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;") + if (r1 != "Hello, world;Goodbye, cruel world;") + r = "SELECTED DATA WRONG: "+r1; + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/3-iteration-item-function.js b/tests/auto/declarative/sql/data/iteration.js index 57c8a17..c34cbbb 100644 --- a/tests/auto/declarative/sql/data/3-iteration-item-function.js +++ b/tests/auto/declarative/sql/data/iteration.js @@ -1,14 +1,23 @@ function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); + var db = openDatabaseSync("QmlTestDB-iteration", "", "Test database from Qt autotests", 1000000); var r="transaction_not_finished"; db.transaction( function(tx) { + tx.executeSql('CREATE TABLE Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES ("Hello", "world")'); + tx.executeSql('INSERT INTO Greeting VALUES ("Goodbye", "cruel world")'); + } + ) + + 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;") + if (r1 != "Hello, world;Goodbye, cruel world;") r = "SELECTED DATA WRONG: "+r1; else r = "passed"; diff --git a/tests/auto/declarative/sql/data/readonly-error.js b/tests/auto/declarative/sql/data/readonly-error.js new file mode 100644 index 0000000..ab82712 --- /dev/null +++ b/tests/auto/declarative/sql/data/readonly-error.js @@ -0,0 +1,28 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly-error", "1.0", "Test database from Qt autotests", 1000000); + + 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"; + } + ); + + try { + db.readTransaction( + function(tx) { + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + r = "FAILED"; + } + ); + } catch (err) { + if (err.message == "Read-only Transaction") + r = "passed"; + else + r = "WRONG ERROR="+err.message; + } + + return r; +} diff --git a/tests/auto/declarative/sql/data/readonly.js b/tests/auto/declarative/sql/data/readonly.js new file mode 100644 index 0000000..5ee862c --- /dev/null +++ b/tests/auto/declarative/sql/data/readonly.js @@ -0,0 +1,24 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-readonly", "1.0", "Test database from Qt autotests", 1000000); + + 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"; + } + ); + + db.readTransaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/reopen1.js b/tests/auto/declarative/sql/data/reopen1.js new file mode 100644 index 0000000..c1a8157 --- /dev/null +++ b/tests/auto/declarative/sql/data/reopen1.js @@ -0,0 +1,14 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + 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"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/reopen2.js b/tests/auto/declarative/sql/data/reopen2.js new file mode 100644 index 0000000..4f7248f --- /dev/null +++ b/tests/auto/declarative/sql/data/reopen2.js @@ -0,0 +1,16 @@ +function test() { + var r="transaction_not_finished"; + var db = openDatabaseSync("QmlTestDB-reopen", "1.0", "Test database from Qt autotests", 1000000); + + db.transaction( + function(tx) { + var rs = tx.executeSql('SELECT * FROM Greeting'); + if (rs.rows.item(0).salutation == 'hello') + r = "passed"; + else + r = "FAILED"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/selection-bindnames.js b/tests/auto/declarative/sql/data/selection-bindnames.js new file mode 100644 index 0000000..9786821 --- /dev/null +++ b/tests/auto/declarative/sql/data/selection-bindnames.js @@ -0,0 +1,26 @@ +function test() { + var db = openDatabaseSync("QmlTestDB-bindnames", "", "Test database from Qt autotests", 1000000); + var r="transaction_not_finished"; + + db.transaction( + function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'goodbye', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'there' ]); + } + ); + + 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 != 2 ) + r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows.item(0)+rs.rows.item(1) + else + r = "passed"; + } + ); + + return r; +} diff --git a/tests/auto/declarative/sql/data/2-selection.js b/tests/auto/declarative/sql/data/selection.js index f141d2c..f116eff 100644 --- a/tests/auto/declarative/sql/data/2-selection.js +++ b/tests/auto/declarative/sql/data/selection.js @@ -1,14 +1,21 @@ function test() { - var db = openDatabaseSync("QmlTestDB", "", "Test database from Qt autotests", 1000000); + var db = openDatabaseSync("QmlTestDB-selection", "", "Test database from Qt autotests", 1000000); var r="transaction_not_finished"; db.transaction( function(tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)'); tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]); + } + ); + + db.transaction( + function(tx) { + 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. + if ( rs.rows.length != 4 ) r = "SELECT RETURNED WRONG VALUE "+rs.rows.length+rs.rows[0]+rs.rows[1] else r = "passed"; diff --git a/tests/auto/declarative/sql/sql.pro b/tests/auto/declarative/sql/sql.pro index 48e06a2..875e9d8 100644 --- a/tests/auto/declarative/sql/sql.pro +++ b/tests/auto/declarative/sql/sql.pro @@ -1,5 +1,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative +QT += script macx:CONFIG -= app_bundle SOURCES += tst_sql.cpp diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index cbd14ab..4296279 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -43,10 +43,13 @@ #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> #include <private/qmlgraphicstext_p.h> +#include <private/qmlengine_p.h> +#include <QtCore/qcryptographichash.h> #include <QtWebKit/qwebpage.h> #include <QtWebKit/qwebframe.h> #include <QtWebKit/qwebdatabase.h> #include <QtWebKit/qwebsecurityorigin.h> +#include <QtSql/qsqldatabase.h> #include <QtCore/qdir.h> #include <QtCore/qfile.h> @@ -72,11 +75,11 @@ private slots: void checkDatabasePath(); - void validateAgainstWebkit_data(); - void validateAgainstWebkit(); - void testQml_data(); void testQml(); + void testQml_cleanopen_data(); + void testQml_cleanopen(); + void totalDatabases(); void cleanupTestCase(); @@ -130,44 +133,40 @@ void tst_sql::checkDatabasePath() QVERIFY(engine->offlineStoragePath().contains("OfflineStorage")); } +static const int total_databases_created_by_tests = 12; 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("selection-bindnames") << "data/2-selection-bindnames.js" << "passed" << 1 << true; // WebKit somehow breaks named parameters - 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; // 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() -{ - 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; + // Each test should use a newly named DB to avoid inter-test dependencies + QTest::newRow("creation") << "data/creation.js"; + QTest::newRow("creation-a") << "data/creation-a.js"; + QTest::newRow("creation") << "data/creation.js"; + QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses above DB + QTest::newRow("changeversion") << "data/changeversion.js"; + QTest::newRow("readonly") << "data/readonly.js"; + QTest::newRow("readonly-error") << "data/readonly-error.js"; + QTest::newRow("selection") << "data/selection.js"; + QTest::newRow("selection-bindnames") << "data/selection-bindnames.js"; + QTest::newRow("iteration") << "data/iteration.js"; + QTest::newRow("iteration-forwardonly") << "data/iteration-forwardonly.js"; + QTest::newRow("error-a") << "data/error-a.js"; + QTest::newRow("error-notransaction") << "data/error-notransaction.js"; + QTest::newRow("reopen1") << "data/reopen1.js"; + QTest::newRow("reopen2") << "data/reopen2.js"; // re-uses above DB + + // If you add a test, you should usually use a new database in the + // test - in which case increment total_databases_created_by_tests above. } +/* void tst_sql::validateAgainstWebkit() { // Validates tests against WebKit (HTML5) support. // - QFETCH(QString, jsfile); QFETCH(QString, result); QFETCH(int, databases); - QFETCH(bool, qmlextension); - - if (qmlextension) // WebKit can't do it (yet?) - return; QFile f(jsfile); QVERIFY(f.open(QIODevice::ReadOnly)); @@ -179,14 +178,14 @@ void tst_sql::validateAgainstWebkit() 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() { @@ -194,8 +193,6 @@ void tst_sql::testQml() // that have been validated against Webkit. // QFETCH(QString, jsfile); - QFETCH(QString, result); - QFETCH(int, databases); QString qml= "import Qt 4.6\n" @@ -205,8 +202,32 @@ void tst_sql::testQml() QmlComponent component(engine, qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports QmlGraphicsText *text = qobject_cast<QmlGraphicsText*>(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 + QCOMPARE(text->text(),QString("passed")); +} + +void tst_sql::testQml_cleanopen_data() +{ + QTest::addColumn<QString>("jsfile"); // The input file + QTest::newRow("reopen1") << "data/reopen1.js"; + QTest::newRow("reopen2") << "data/reopen2.js"; + QTest::newRow("error-creation") << "data/error-creation.js"; // re-uses creation DB +} + +void tst_sql::testQml_cleanopen() +{ + // Same as testQml, but clean connections between tests, + // making it more like the tests are running in new processes. + testQml(); + + QmlEnginePrivate::getScriptEngine(engine)->collectGarbage(); // close databases + foreach (QString dbname, QSqlDatabase::connectionNames()) { + QSqlDatabase::removeDatabase(dbname); + } +} + +void tst_sql::totalDatabases() +{ + QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), total_databases_created_by_tests*2); } QTEST_MAIN(tst_sql) |