Skip to content

Commit

Permalink
Reuse a QQuickCanvas in examples auto test.
Browse files Browse the repository at this point in the history
Much faster than creating a new one for each example.

Change-Id: Ic32f244047e0dba78134ba0e3d368260be838f1e
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
  • Loading branch information
Martin Jones authored and Qt by Nokia committed Mar 14, 2012
1 parent 6b8c356 commit 34280c4
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions tests/auto/quick/examples/tst_examples.cpp
Expand Up @@ -62,6 +62,7 @@ class tst_examples : public QObject
Q_OBJECT
public:
tst_examples();
~tst_examples();

private slots:
void init();
Expand All @@ -81,9 +82,11 @@ private slots:
QStringList findQmlFiles(const QDir &);

QQmlEngine engine;

QQuickCanvas *canvas;
};

tst_examples::tst_examples()
tst_examples::tst_examples() : canvas(0)
{
// Add files to exclude here
excludedFiles << "doc/src/snippets/qml/listmodel.qml"; //Just a ListModel, no root QQuickItem
Expand Down Expand Up @@ -112,6 +115,11 @@ tst_examples::tst_examples()
#endif
}

tst_examples::~tst_examples()
{
delete canvas;
}

void tst_examples::init()
{
if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets"))
Expand Down Expand Up @@ -252,13 +260,16 @@ void tst_examples::sgexamples()
component.completeCreate();
QVERIFY(root);

QQuickCanvas canvas;
root->setParentItem(canvas.rootItem());
if (!canvas) {
canvas = new QQuickCanvas();
canvas->resize(240, 320);
canvas->show();
QTest::qWaitForWindowShown(canvas);
}
root->setParentItem(canvas->rootItem());
component.completeCreate();
canvas.show();

QTest::qWaitForWindowShown(&canvas);

qApp->processEvents();
}

void tst_examples::sgsnippets_data()
Expand Down Expand Up @@ -293,13 +304,16 @@ void tst_examples::sgsnippets()
component.completeCreate();
QVERIFY(root);

QQuickCanvas canvas;
root->setParentItem(canvas.rootItem());
if (!canvas) {
canvas = new QQuickCanvas();
canvas->resize(240, 320);
canvas->show();
QTest::qWaitForWindowShown(canvas);
}
root->setParentItem(canvas->rootItem());
component.completeCreate();
canvas.show();

QTest::qWaitForWindowShown(&canvas);

qApp->processEvents();
}

QTEST_MAIN(tst_examples)
Expand Down

0 comments on commit 34280c4

Please sign in to comment.