From 35afac3d3a275aa69c74e174cfeb5e411816e94a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 14 Apr 2010 14:53:13 +1000 Subject: Rename "sql" test so autotester doesn't get confused. --- tests/auto/declarative/declarative.pro | 2 +- .../qdeclarativesqldatabase/data/README | 3 + .../qdeclarativesqldatabase/data/changeversion.js | 53 +++++ .../qdeclarativesqldatabase/data/creation-a.js | 18 ++ .../qdeclarativesqldatabase/data/creation.js | 14 ++ .../qdeclarativesqldatabase/data/error-a.js | 20 ++ .../qdeclarativesqldatabase/data/error-b.js | 13 ++ .../qdeclarativesqldatabase/data/error-creation.js | 14 ++ .../data/error-notransaction.js | 15 ++ .../data/error-outsidetransaction.js | 17 ++ .../data/iteration-forwardonly.js | 29 +++ .../qdeclarativesqldatabase/data/iteration.js | 28 +++ .../qdeclarativesqldatabase/data/readonly-error.js | 27 +++ .../qdeclarativesqldatabase/data/readonly.js | 24 +++ .../qdeclarativesqldatabase/data/reopen1.js | 14 ++ .../qdeclarativesqldatabase/data/reopen2.js | 16 ++ .../data/selection-bindnames.js | 26 +++ .../qdeclarativesqldatabase/data/selection.js | 26 +++ .../qdeclarativesqldatabase.pro | 12 ++ .../tst_qdeclarativesqldatabase.cpp | 239 +++++++++++++++++++++ tests/auto/declarative/sql/data/README | 3 - tests/auto/declarative/sql/data/changeversion.js | 53 ----- tests/auto/declarative/sql/data/creation-a.js | 18 -- tests/auto/declarative/sql/data/creation.js | 14 -- tests/auto/declarative/sql/data/error-a.js | 20 -- tests/auto/declarative/sql/data/error-b.js | 13 -- tests/auto/declarative/sql/data/error-creation.js | 14 -- .../declarative/sql/data/error-notransaction.js | 15 -- .../sql/data/error-outsidetransaction.js | 17 -- .../declarative/sql/data/iteration-forwardonly.js | 29 --- tests/auto/declarative/sql/data/iteration.js | 28 --- tests/auto/declarative/sql/data/readonly-error.js | 27 --- tests/auto/declarative/sql/data/readonly.js | 24 --- tests/auto/declarative/sql/data/reopen1.js | 14 -- tests/auto/declarative/sql/data/reopen2.js | 16 -- .../declarative/sql/data/selection-bindnames.js | 26 --- tests/auto/declarative/sql/data/selection.js | 26 --- tests/auto/declarative/sql/sql.pro | 12 -- tests/auto/declarative/sql/tst_sql.cpp | 239 --------------------- 39 files changed, 609 insertions(+), 609 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/README create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/changeversion.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/creation-a.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/creation.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/error-a.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/error-b.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/error-creation.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/error-notransaction.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/error-outsidetransaction.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/iteration-forwardonly.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/iteration.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/readonly-error.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/readonly.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/reopen1.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/reopen2.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/selection-bindnames.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/data/selection.js create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/qdeclarativesqldatabase.pro create mode 100644 tests/auto/declarative/qdeclarativesqldatabase/tst_qdeclarativesqldatabase.cpp delete mode 100644 tests/auto/declarative/sql/data/README delete mode 100644 tests/auto/declarative/sql/data/changeversion.js delete mode 100644 tests/auto/declarative/sql/data/creation-a.js delete mode 100644 tests/auto/declarative/sql/data/creation.js delete mode 100644 tests/auto/declarative/sql/data/error-a.js delete mode 100644 tests/auto/declarative/sql/data/error-b.js delete mode 100644 tests/auto/declarative/sql/data/error-creation.js delete mode 100644 tests/auto/declarative/sql/data/error-notransaction.js delete mode 100644 tests/auto/declarative/sql/data/error-outsidetransaction.js delete mode 100644 tests/auto/declarative/sql/data/iteration-forwardonly.js delete mode 100644 tests/auto/declarative/sql/data/iteration.js delete mode 100644 tests/auto/declarative/sql/data/readonly-error.js delete mode 100644 tests/auto/declarative/sql/data/readonly.js delete mode 100644 tests/auto/declarative/sql/data/reopen1.js delete mode 100644 tests/auto/declarative/sql/data/reopen2.js delete mode 100644 tests/auto/declarative/sql/data/selection-bindnames.js delete mode 100644 tests/auto/declarative/sql/data/selection.js delete mode 100644 tests/auto/declarative/sql/sql.pro delete mode 100644 tests/auto/declarative/sql/tst_sql.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 5441311..7834650 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -62,7 +62,7 @@ SUBDIRS += \ qdeclarativexmlhttprequest \ # Cover qdeclarativeimageprovider \ # Cover qdeclarativestyledtext \ # Cover - sql \ # Cover + qdeclarativesqldatabase \ # Cover qmlvisual # Cover contains(QT_CONFIG, webkit) { diff --git a/tests/auto/declarative/qdeclarativesqldatabase/data/README b/tests/auto/declarative/qdeclarativesqldatabase/data/README new file mode 100644 index 0000000..7efca3a --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/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/qdeclarativesqldatabase/data/changeversion.js b/tests/auto/declarative/qdeclarativesqldatabase/data/changeversion.js new file mode 100644 index 0000000..680d7a6 --- /dev/null +++ b/tests/auto/declarative/qdeclarativesqldatabase/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 +#include "../../../shared/util.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_qdeclarativesqldatabase : public QObject +{ + Q_OBJECT +public: + tst_qdeclarativesqldatabase() + { + qApp->setApplicationName("tst_qdeclarativesqldatabase"); + qApp->setOrganizationName("Nokia"); + qApp->setOrganizationDomain("nokia.com"); + engine = new QDeclarativeEngine; + } + + ~tst_qdeclarativesqldatabase() + { + delete engine; + } + +private slots: + void initTestCase(); + + void checkDatabasePath(); + + void testQml_data(); + void testQml(); + void testQml_cleanopen_data(); + void testQml_cleanopen(); + void totalDatabases(); + + void cleanupTestCase(); + +private: + QString dbDir() const; + QDeclarativeEngine *engine; +}; + +class QWebPageWithJavaScriptConsoleMessages : public QWebPage { +public: + void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) + { + qWarning() << sourceID << ":" << lineNumber << ":" << message; + } +}; + +void removeRecursive(const QString& dirname) +{ + QDir dir(dirname); + QFileInfoList entries(dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot)); + for (int i = 0; i < entries.count(); ++i) + if (entries[i].isDir()) + removeRecursive(entries[i].filePath()); + else + dir.remove(entries[i].fileName()); + QDir().rmdir(dirname); +} + +void tst_qdeclarativesqldatabase::initTestCase() +{ + removeRecursive(dbDir()); + QDir().mkpath(dbDir()); +} + +void tst_qdeclarativesqldatabase::cleanupTestCase() +{ + removeRecursive(dbDir()); +} + +QString tst_qdeclarativesqldatabase::dbDir() const +{ + static QString tmpd = QDir::tempPath()+"/tst_qdeclarativesqldatabase_output-" + + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); + return tmpd; +} + +void tst_qdeclarativesqldatabase::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("tst_qdeclarativesqldatabase")); + QVERIFY(engine->offlineStoragePath().contains("OfflineStorage")); +} + +static const int total_databases_created_by_tests = 12; +void tst_qdeclarativesqldatabase::testQml_data() +{ + QTest::addColumn("jsfile"); // The input file + + // 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("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above + 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_qdeclarativesqldatabase::validateAgainstWebkit() +{ + // Validates tests against WebKit (HTML5) support. + // + QFETCH(QString, jsfile); + QFETCH(QString, result); + QFETCH(int, databases); + + QFile f(jsfile); + QVERIFY(f.open(QIODevice::ReadOnly)); + QString js=f.readAll(); + + QWebPageWithJavaScriptConsoleMessages webpage; + webpage.settings()->setOfflineStoragePath(dbDir()); + webpage.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); + + 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 dbs = origin.databases(); + QCOMPARE(dbs.count(), databases); +} +*/ + +void tst_qdeclarativesqldatabase::testQml() +{ + // Tests QML SQL Database support with tests + // that have been validated against Webkit. + // + QFETCH(QString, jsfile); + + QString qml= + "import Qt 4.7\n" + "import \""+jsfile+"\" as JS\n" + "Text { text: JS.test() }"; + + engine->setOfflineStoragePath(dbDir()); + QDeclarativeComponent component(engine); + component.setData(qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports + QVERIFY(!component.isError()); + QDeclarativeText *text = qobject_cast(component.create()); + QVERIFY(text != 0); + QCOMPARE(text->text(),QString("passed")); +} + +void tst_qdeclarativesqldatabase::testQml_cleanopen_data() +{ + QTest::addColumn("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_qdeclarativesqldatabase::testQml_cleanopen() +{ + // Same as testQml, but clean connections between tests, + // making it more like the tests are running in new processes. + testQml(); + + QDeclarativeEnginePrivate::getScriptEngine(engine)->collectGarbage(); // close databases + foreach (QString dbname, QSqlDatabase::connectionNames()) { + QSqlDatabase::removeDatabase(dbname); + } +} + +void tst_qdeclarativesqldatabase::totalDatabases() +{ + QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), total_databases_created_by_tests*2); +} + +QTEST_MAIN(tst_qdeclarativesqldatabase) + +#include "tst_qdeclarativesqldatabase.moc" diff --git a/tests/auto/declarative/sql/data/README b/tests/auto/declarative/sql/data/README deleted file mode 100644 index 7efca3a..0000000 --- a/tests/auto/declarative/sql/data/README +++ /dev/null @@ -1,3 +0,0 @@ -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/changeversion.js b/tests/auto/declarative/sql/data/changeversion.js deleted file mode 100644 index 680d7a6..0000000 --- a/tests/auto/declarative/sql/data/changeversion.js +++ /dev/null @@ -1,53 +0,0 @@ -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 -#include "../../../shared/util.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_sql : public QObject -{ - Q_OBJECT -public: - tst_sql() - { - qApp->setApplicationName("tst_sql"); - qApp->setOrganizationName("Nokia"); - qApp->setOrganizationDomain("nokia.com"); - engine = new QDeclarativeEngine; - } - - ~tst_sql() - { - delete engine; - } - -private slots: - void initTestCase(); - - void checkDatabasePath(); - - void testQml_data(); - void testQml(); - void testQml_cleanopen_data(); - void testQml_cleanopen(); - void totalDatabases(); - - void cleanupTestCase(); - -private: - QString dbDir() const; - QDeclarativeEngine *engine; -}; - -class QWebPageWithJavaScriptConsoleMessages : public QWebPage { -public: - void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) - { - qWarning() << sourceID << ":" << lineNumber << ":" << message; - } -}; - -void removeRecursive(const QString& dirname) -{ - QDir dir(dirname); - QFileInfoList entries(dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot)); - for (int i = 0; i < entries.count(); ++i) - if (entries[i].isDir()) - removeRecursive(entries[i].filePath()); - else - dir.remove(entries[i].fileName()); - QDir().rmdir(dirname); -} - -void tst_sql::initTestCase() -{ - removeRecursive(dbDir()); - QDir().mkpath(dbDir()); -} - -void tst_sql::cleanupTestCase() -{ - removeRecursive(dbDir()); -} - -QString tst_sql::dbDir() const -{ - static QString tmpd = QDir::tempPath()+"/tst_sql_output-" - + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); - return tmpd; -} - -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("tst_sql")); - QVERIFY(engine->offlineStoragePath().contains("OfflineStorage")); -} - -static const int total_databases_created_by_tests = 12; -void tst_sql::testQml_data() -{ - QTest::addColumn("jsfile"); // The input file - - // 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("error-outsidetransaction") << "data/error-outsidetransaction.js"; // reuse above - 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); - - QFile f(jsfile); - QVERIFY(f.open(QIODevice::ReadOnly)); - QString js=f.readAll(); - - QWebPageWithJavaScriptConsoleMessages webpage; - webpage.settings()->setOfflineStoragePath(dbDir()); - webpage.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); - - 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 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); - - QString qml= - "import Qt 4.7\n" - "import \""+jsfile+"\" as JS\n" - "Text { text: JS.test() }"; - - engine->setOfflineStoragePath(dbDir()); - QDeclarativeComponent component(engine); - component.setData(qml.toUtf8(), QUrl::fromLocalFile(SRCDIR "/empty.qml")); // just a file for relative local imports - QVERIFY(!component.isError()); - QDeclarativeText *text = qobject_cast(component.create()); - QVERIFY(text != 0); - QCOMPARE(text->text(),QString("passed")); -} - -void tst_sql::testQml_cleanopen_data() -{ - QTest::addColumn("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(); - - QDeclarativeEnginePrivate::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) - -#include "tst_sql.moc" -- cgit v0.12