Improved QQmlContext and QQmlApplicationEngine tests

This commit is contained in:
Filippo Cucchetto 2015-12-29 12:12:45 +01:00
parent d993980cd4
commit 9a88ffd48e
2 changed files with 34 additions and 1 deletions

View File

@ -4,5 +4,6 @@ import QtQuick.Controls 1.4
ApplicationWindow {
width: 100
height: 100
objectName: "testWindow"
Component.onCompleted: visible = true
}

View File

@ -8,6 +8,8 @@
#include <QTimer>
#include <QApplication>
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QQuickItem>
// DOtherSide
#include "DOtherSide/DOtherSide.h"
@ -91,7 +93,7 @@ private slots:
}
void testCreateAndDelete() {
// Implicit by invoking init and cleanup
}
void testLoadUrl() {
@ -99,9 +101,19 @@ private slots:
dos_qurl_create(&url, "qrc:///main.qml", QUrl::TolerantMode);
QVERIFY(url != nullptr);
dos_qqmlapplicationengine_load_url(m_engine, url);
QCOMPARE(engine()->rootObjects().size(), 1);
QCOMPARE(engine()->rootObjects().front()->objectName(), QString::fromLocal8Bit("testWindow"));
QVERIFY(engine()->rootObjects().front()->isWindowType());
dos_qurl_delete(url);
}
void testLoadData() {
dos_qqmlapplicationengine_load_data(m_engine, "import QtQuick.Controls 1.4; ApplicationWindow { objectName: \"testWindow\"}");
QCOMPARE(engine()->rootObjects().size(), 1);
QCOMPARE(engine()->rootObjects().front()->objectName(), QString::fromLocal8Bit("testWindow"));
QVERIFY(engine()->rootObjects().front()->isWindowType());
}
void testRootObjects() {
void** rootObjects = nullptr;
int length = 0;
@ -117,6 +129,8 @@ private slots:
}
private:
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
void* m_engine;
};
@ -151,7 +165,24 @@ private slots:
m_engine = nullptr;
}
void testCreateAndDelete() {
// Implicit by invoking init and cleanup
}
void testSetContextProperty() {
QVariant testData("Test Message");
dos_qqmlcontext_setcontextproperty(m_context, "testData", &testData);
engine()->loadData("import QtQuick 2.5; Text { objectName: \"label\"; text: testData } ");
QObject* label = engine()->rootObjects().first();
QVERIFY(label != nullptr);
QCOMPARE(label->objectName(), QString::fromLocal8Bit("label"));
QCOMPARE(label->property("text").toString(), testData.toString());
}
private:
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
QQmlContext* context() { return static_cast<QQmlContext*>(m_context); }
void* m_engine;
void* m_context;
};
@ -197,6 +228,7 @@ int main(int argc, char* argv[])
success &= ExecuteTest<TestQGuiApplication>(argc, argv);
success &= ExecuteTest<TestQApplication>(argc, argv);
success &= ExecuteGuiTest<TestQQmlApplicationEngine>(argc, argv);
success &= ExecuteGuiTest<TestQQmlContext>(argc, argv);
success &= ExecuteTest<TestDynamicQObject>(argc, argv);
return success ? 0 : 1;
}