mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-12 12:46:24 +00:00
Improved QQmlContext and QQmlApplicationEngine tests
This commit is contained in:
parent
d993980cd4
commit
9a88ffd48e
@ -4,5 +4,6 @@ import QtQuick.Controls 1.4
|
|||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
width: 100
|
width: 100
|
||||||
height: 100
|
height: 100
|
||||||
|
objectName: "testWindow"
|
||||||
Component.onCompleted: visible = true
|
Component.onCompleted: visible = true
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
// DOtherSide
|
// DOtherSide
|
||||||
#include "DOtherSide/DOtherSide.h"
|
#include "DOtherSide/DOtherSide.h"
|
||||||
@ -91,7 +93,7 @@ private slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void testCreateAndDelete() {
|
void testCreateAndDelete() {
|
||||||
|
// Implicit by invoking init and cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLoadUrl() {
|
void testLoadUrl() {
|
||||||
@ -99,9 +101,19 @@ private slots:
|
|||||||
dos_qurl_create(&url, "qrc:///main.qml", QUrl::TolerantMode);
|
dos_qurl_create(&url, "qrc:///main.qml", QUrl::TolerantMode);
|
||||||
QVERIFY(url != nullptr);
|
QVERIFY(url != nullptr);
|
||||||
dos_qqmlapplicationengine_load_url(m_engine, url);
|
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);
|
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 testRootObjects() {
|
||||||
void** rootObjects = nullptr;
|
void** rootObjects = nullptr;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
@ -117,6 +129,8 @@ private slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
|
||||||
|
|
||||||
void* m_engine;
|
void* m_engine;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -151,7 +165,24 @@ private slots:
|
|||||||
m_engine = nullptr;
|
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:
|
private:
|
||||||
|
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
|
||||||
|
QQmlContext* context() { return static_cast<QQmlContext*>(m_context); }
|
||||||
|
|
||||||
void* m_engine;
|
void* m_engine;
|
||||||
void* m_context;
|
void* m_context;
|
||||||
};
|
};
|
||||||
@ -197,6 +228,7 @@ int main(int argc, char* argv[])
|
|||||||
success &= ExecuteTest<TestQGuiApplication>(argc, argv);
|
success &= ExecuteTest<TestQGuiApplication>(argc, argv);
|
||||||
success &= ExecuteTest<TestQApplication>(argc, argv);
|
success &= ExecuteTest<TestQApplication>(argc, argv);
|
||||||
success &= ExecuteGuiTest<TestQQmlApplicationEngine>(argc, argv);
|
success &= ExecuteGuiTest<TestQQmlApplicationEngine>(argc, argv);
|
||||||
|
success &= ExecuteGuiTest<TestQQmlContext>(argc, argv);
|
||||||
success &= ExecuteTest<TestDynamicQObject>(argc, argv);
|
success &= ExecuteTest<TestDynamicQObject>(argc, argv);
|
||||||
return success ? 0 : 1;
|
return success ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user