From 01cb691e8a619fcb4c6e1e67980ae10fe04b364e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 7 Dec 2011 13:26:48 +1000 Subject: 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 --- tests/auto/qtquick2/examples/tst_examples.cpp | 69 +++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 9 deletions(-) (limited to 'tests/auto/qtquick2/examples') 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 #include +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("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 object(component.beginCreate(engine.rootContext())); + QQuickItem *root = qobject_cast(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("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) -- cgit v1.2.3