diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-10-06 03:49:48 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-10-06 03:49:48 (GMT) |
commit | 6ddff0d80fb360a7b3296e039150c97729fb8d10 (patch) | |
tree | ca6fe14e74f3b51652f5a339a4c188dbff86da51 /tests | |
parent | bb0465258d20badae7f9aa62849c02a94244570c (diff) | |
parent | 2ec7f08421f484339818c731594f12ddb22d38c0 (diff) | |
download | Qt-6ddff0d80fb360a7b3296e039150c97729fb8d10.zip Qt-6ddff0d80fb360a7b3296e039150c97729fb8d10.tar.gz Qt-6ddff0d80fb360a7b3296e039150c97729fb8d10.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qfxwebview/data/basic.html | 12 | ||||
-rw-r--r-- | tests/auto/declarative/qfxwebview/data/basic.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qfxwebview/qfxwebview.pro | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp | 100 | ||||
-rw-r--r-- | tests/auto/declarative/sql/tst_sql.cpp | 27 |
5 files changed, 143 insertions, 7 deletions
diff --git a/tests/auto/declarative/qfxwebview/data/basic.html b/tests/auto/declarative/qfxwebview/data/basic.html new file mode 100644 index 0000000..254317c --- /dev/null +++ b/tests/auto/declarative/qfxwebview/data/basic.html @@ -0,0 +1,12 @@ +<html> +<head><title>Basic</title> +<link rel="shortcut icon" type="image/x-icon" href="basic.ico"> +</head> +<body leftmargin="0" marginwidth="0"> +<table width="123"> +<tbody> +<tr><td>This is a basic test.</td></tr> +</tbody> +</table> +</body> +</html> diff --git a/tests/auto/declarative/qfxwebview/data/basic.qml b/tests/auto/declarative/qfxwebview/data/basic.qml new file mode 100644 index 0000000..5394837 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/data/basic.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +WebView { + url: "basic.html" +} diff --git a/tests/auto/declarative/qfxwebview/qfxwebview.pro b/tests/auto/declarative/qfxwebview/qfxwebview.pro new file mode 100644 index 0000000..ee78950 --- /dev/null +++ b/tests/auto/declarative/qfxwebview/qfxwebview.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qfxwebview.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp new file mode 100644 index 0000000..834c07f --- /dev/null +++ b/tests/auto/declarative/qfxwebview/tst_qfxwebview.cpp @@ -0,0 +1,100 @@ +#include <qtest.h> +#include "../../../shared/util.h" +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qfxwebview.h> +#include <QtWebKit/qwebpage.h> +#include <QtWebKit/qwebframe.h> +#include <QtCore/qdir.h> +#include <QtCore/qfile.h> + +class tst_qfxwebview : public QObject +{ + Q_OBJECT +public: + tst_qfxwebview() {} + +private slots: + void testBasicProperties(); + void cleanupTestCase(); + + +private: + void checkNoErrors(const QmlComponent& component); + QmlEngine engine; + QString tmpDir() const + { + static QString tmpd = QDir::tempPath()+"/tst_qfxwebview-" + + QDateTime::currentDateTime().toString(QLatin1String("yyyyMMddhhmmss")); + return tmpd; + } +}; + +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_qfxwebview::cleanupTestCase() +{ + removeRecursive(tmpDir()); +} + +void tst_qfxwebview::checkNoErrors(const QmlComponent& component) +{ + if (component.isError()) { + QList<QmlError> errors = component.errors(); + for (int ii = 0; ii < errors.count(); ++ii) { + const QmlError &error = errors.at(ii); + QByteArray errorStr = QByteArray::number(error.line()) + ":" + + QByteArray::number(error.column()) + ":" + + error.description().toUtf8(); + qWarning() << errorStr; + } + } + QVERIFY(!component.isError()); +} + +void tst_qfxwebview::testBasicProperties() +{ + QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/basic.qml")); + checkNoErrors(component); + QWebSettings::enablePersistentStorage(tmpDir()); + + QFxWebView *wv = qobject_cast<QFxWebView*>(component.create()); + QVERIFY(wv != 0); + QTRY_COMPARE(wv->progress(), 1.0); + QCOMPARE(wv->title(),QString("Basic")); + wv->icon().save("test.png"); + //QCOMPARE(wv->icon(),QPixmap(SRCDIR "/data/basic.ico")); + QCOMPARE(wv->statusText(),QString("")); + QFile htmlfile(SRCDIR "/data/basic.html"); + QVERIFY(htmlfile.open(QIODevice::ReadOnly)); + QString actualhtml____ = wv->html(); // "____" is to make errors line up for easier reading + QString expectedhtml = htmlfile.readAll(); + actualhtml____.replace(QRegExp("\\s+"),""); + expectedhtml.replace(QRegExp("\\s+"),""); + QCOMPARE(actualhtml____,expectedhtml); // same, ignoring whitespace + QCOMPARE(wv->width(), 123.0); + QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html")); + QCOMPARE(wv->status(), QFxWebView::Ready); + QVERIFY(wv->reloadAction()); + QVERIFY(wv->reloadAction()->isEnabled()); + QVERIFY(wv->backAction()); + QVERIFY(!wv->backAction()->isEnabled()); + QVERIFY(wv->forwardAction()); + QVERIFY(!wv->forwardAction()->isEnabled()); + QVERIFY(wv->stopAction()); + QVERIFY(!wv->stopAction()->isEnabled()); +} + +QTEST_MAIN(tst_qfxwebview) + +#include "tst_qfxwebview.moc" diff --git a/tests/auto/declarative/sql/tst_sql.cpp b/tests/auto/declarative/sql/tst_sql.cpp index 10ce6d8..22e9ba4 100644 --- a/tests/auto/declarative/sql/tst_sql.cpp +++ b/tests/auto/declarative/sql/tst_sql.cpp @@ -14,7 +14,18 @@ class tst_sql : public QObject { Q_OBJECT public: - tst_sql() {} + tst_sql() + { + qApp->setApplicationName("tst_sql"); + qApp->setOrganizationName("Nokia"); + qApp->setOrganizationDomain("nokia.com"); + engine = new QmlEngine; + } + + ~tst_sql() + { + delete engine; + } private slots: void initTestCase(); @@ -31,7 +42,7 @@ private slots: private: QString dbDir() const; - QmlEngine engine; + QmlEngine *engine; }; class QWebPageWithJavaScriptConsoleMessages : public QWebPage { @@ -67,14 +78,16 @@ void tst_sql::cleanupTestCase() QString tst_sql::dbDir() const { - return QString(SRCDIR)+"/output"; + 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("Nokia")); - QVERIFY(engine.offlineStoragePath().contains("OfflineStorage")); + QVERIFY(engine->offlineStoragePath().contains("Nokia")); + QVERIFY(engine->offlineStoragePath().contains("OfflineStorage")); } void tst_sql::testQml_data() @@ -142,8 +155,8 @@ void tst_sql::testQml() "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 + 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); |