diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-12-07 13:26:48 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-07 13:17:06 +0100 |
commit | 01cb691e8a619fcb4c6e1e67980ae10fe04b364e (patch) | |
tree | 5deb244badc31335e04444edf1dac482251c72a2 | |
parent | 66a3c0d7a18008920ae112abf8640b2dcef04d9f (diff) |
Move snippets to separate test in the examples testcase
This test filters out warning messages, so as to not clutter the logs.
Also altered an example so that v8 doesn't spit out a warning message.
Change-Id: I89ab9f1c12bee6cea88e06ce5bf98f2f69a13559
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
-rw-r--r-- | doc/src/snippets/declarative/codingconventions/myscript.js | 3 | ||||
-rw-r--r-- | tests/auto/qtquick2/examples/tst_examples.cpp | 69 |
2 files changed, 63 insertions, 9 deletions
diff --git a/doc/src/snippets/declarative/codingconventions/myscript.js b/doc/src/snippets/declarative/codingconventions/myscript.js index cfa646250b..e7f83c259c 100644 --- a/doc/src/snippets/declarative/codingconventions/myscript.js +++ b/doc/src/snippets/declarative/codingconventions/myscript.js @@ -1,5 +1,8 @@ function calculateWidth(parent) { + if (parent == null) + return 0 + var w = parent.width / 3 // ... // more javascript code diff --git a/tests/auto/qtquick2/examples/tst_examples.cpp b/tests/auto/qtquick2/examples/tst_examples.cpp index e56d6a352b..3d9a8ad14a 100644 --- a/tests/auto/qtquick2/examples/tst_examples.cpp +++ b/tests/auto/qtquick2/examples/tst_examples.cpp @@ -50,6 +50,13 @@ #include <QDeclarativeEngine> #include <QDeclarativeError> +static QtMsgHandler testlibMsgHandler = 0; +void msgHandlerFilter(QtMsgType type, const char *msg) +{ + if (type == QtCriticalMsg || type == QtFatalMsg) + (*testlibMsgHandler)(type, msg); +} + class tst_examples : public QObject { Q_OBJECT @@ -57,8 +64,13 @@ public: tst_examples(); private slots: + void init(); + void cleanup(); + void sgexamples_data(); void sgexamples(); + void sgsnippets_data(); + void sgsnippets(); void namingConvention(); private: @@ -105,6 +117,18 @@ tst_examples::tst_examples() #endif } +void tst_examples::init() +{ + if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets")) + testlibMsgHandler = qInstallMsgHandler(msgHandlerFilter); +} + +void tst_examples::cleanup() +{ + if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets")) + qInstallMsgHandler(testlibMsgHandler); +} + /* This tests that the examples follow the naming convention required to have them tested by the examples() test. @@ -201,23 +225,16 @@ that they start and exit cleanly. Examples are any .qml files under the examples/ directory that start with a lower case letter. */ -static void silentErrorsMsgHandler(QtMsgType, const char *) -{ -} - - void tst_examples::sgexamples_data() { QTest::addColumn<QString>("file"); QString examples = QLatin1String(SRCDIR) + "/../../../../examples/declarative/"; QString tutorials = QLatin1String(SRCDIR) + "/../../../../examples/tutorials/"; //Only declarative tutorials since modularization - QString snippets = QLatin1String(SRCDIR) + "/../../../../doc/src/snippets/declarative"; QStringList files; files << findQmlFiles(QDir(examples)); files << findQmlFiles(QDir(tutorials)); - files << findQmlFiles(QDir(snippets)); foreach (const QString &file, files) QTest::newRow(qPrintable(file)) << file; @@ -227,8 +244,42 @@ void tst_examples::sgexamples() { QFETCH(QString, file); - QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler); - qInstallMsgHandler(old); + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(file)); + if (component.status() == QDeclarativeComponent::Error) + qWarning() << component.errors(); + QCOMPARE(component.status(), QDeclarativeComponent::Ready); + + QScopedPointer<QObject> object(component.beginCreate(engine.rootContext())); + QQuickItem *root = qobject_cast<QQuickItem *>(object.data()); + if (!root) + component.completeCreate(); + QVERIFY(root); + + QQuickCanvas canvas; + root->setParentItem(canvas.rootItem()); + component.completeCreate(); + canvas.show(); + + QTest::qWaitForWindowShown(&canvas); + +} + +void tst_examples::sgsnippets_data() +{ + QTest::addColumn<QString>("file"); + + QString snippets = QLatin1String(SRCDIR) + "/../../../../doc/src/snippets/declarative"; + + QStringList files; + files << findQmlFiles(QDir(snippets)); + + foreach (const QString &file, files) + QTest::newRow(qPrintable(file)) << file; +} + +void tst_examples::sgsnippets() +{ + QFETCH(QString, file); QDeclarativeComponent component(&engine, QUrl::fromLocalFile(file)); if (component.status() == QDeclarativeComponent::Error) |