2015-11-23 20:33:17 +00:00
|
|
|
// std
|
2015-09-20 09:39:25 +00:00
|
|
|
#include <tuple>
|
|
|
|
#include <iostream>
|
2015-11-23 20:33:17 +00:00
|
|
|
// Qt
|
2015-09-20 09:39:25 +00:00
|
|
|
#include <QDebug>
|
2015-11-23 20:33:17 +00:00
|
|
|
#include <QTest>
|
|
|
|
#include <QSignalSpy>
|
2015-12-28 12:21:02 +00:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QQuickWindow>
|
2015-12-29 11:12:45 +00:00
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQuickItem>
|
2015-12-28 12:21:02 +00:00
|
|
|
|
2015-11-23 20:33:17 +00:00
|
|
|
// DOtherSide
|
2015-12-28 12:21:02 +00:00
|
|
|
#include "DOtherSide/DOtherSide.h"
|
2015-11-23 20:33:17 +00:00
|
|
|
#include "DOtherSide/DynamicQObject.h"
|
2015-12-27 14:40:33 +00:00
|
|
|
#include "DOtherSide/DynamicQObjectFactory.h"
|
2015-09-19 17:13:08 +00:00
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
template<typename Test>
|
|
|
|
bool ExecuteTest(int argc, char* argv[]) {
|
|
|
|
Test test;
|
|
|
|
return QTest::qExec(&test, argc, argv) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Test>
|
|
|
|
bool ExecuteGuiTest(int argc, char* argv[]) {
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
Test test;
|
|
|
|
return QTest::qExec(&test, argc, argv) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test QGuiApplication
|
|
|
|
*/
|
|
|
|
class TestQGuiApplication : public QObject
|
2015-09-20 09:39:25 +00:00
|
|
|
{
|
2015-12-28 12:21:02 +00:00
|
|
|
Q_OBJECT
|
2015-12-28 12:46:32 +00:00
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
private slots:
|
|
|
|
void testExecution() {
|
|
|
|
bool quit = false;
|
|
|
|
dos_qguiapplication_create();
|
|
|
|
QTimer::singleShot(100, [&quit](){ quit = true; dos_qguiapplication_quit(); });
|
|
|
|
dos_qguiapplication_exec();
|
|
|
|
QVERIFY(quit);
|
|
|
|
dos_qguiapplication_delete();
|
|
|
|
}
|
2015-09-20 09:39:25 +00:00
|
|
|
};
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
/*
|
|
|
|
* Test QApplication
|
|
|
|
*/
|
|
|
|
class TestQApplication : public QObject
|
2015-09-19 17:13:08 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-12-28 12:46:32 +00:00
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
private slots:
|
|
|
|
void testExecution() {
|
|
|
|
bool quit = false;
|
|
|
|
dos_qapplication_create();
|
|
|
|
QTimer::singleShot(100, [&quit](){ quit = true; dos_qapplication_quit(); });
|
|
|
|
dos_qapplication_exec();
|
|
|
|
QVERIFY(quit);
|
|
|
|
dos_qapplication_delete();
|
|
|
|
}
|
|
|
|
};
|
2015-09-19 17:13:08 +00:00
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
/*
|
|
|
|
* Test QQmlApplicationEngine
|
|
|
|
*/
|
|
|
|
class TestQQmlApplicationEngine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-12-28 12:46:32 +00:00
|
|
|
|
2015-09-19 17:13:08 +00:00
|
|
|
private slots:
|
2015-12-28 12:21:02 +00:00
|
|
|
void initTestCase() {
|
|
|
|
m_engine = nullptr;
|
2015-09-19 17:13:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
void cleanupTestCase() {
|
|
|
|
QVERIFY(m_engine == nullptr);
|
|
|
|
}
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void init() {
|
|
|
|
QVERIFY(m_engine == nullptr);
|
|
|
|
dos_qqmlapplicationengine_create(&m_engine);
|
|
|
|
QVERIFY(m_engine != nullptr);
|
|
|
|
}
|
2015-09-19 17:13:08 +00:00
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void cleanup() {
|
|
|
|
dos_qqmlapplicationengine_delete(m_engine);
|
|
|
|
m_engine = nullptr;
|
2015-09-19 17:13:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void testCreateAndDelete() {
|
2015-12-29 11:12:45 +00:00
|
|
|
// Implicit by invoking init and cleanup
|
2015-09-19 17:13:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void testLoadUrl() {
|
|
|
|
void* url = nullptr;
|
|
|
|
dos_qurl_create(&url, "qrc:///main.qml", QUrl::TolerantMode);
|
|
|
|
QVERIFY(url != nullptr);
|
|
|
|
dos_qqmlapplicationengine_load_url(m_engine, url);
|
2015-12-29 11:12:45 +00:00
|
|
|
QCOMPARE(engine()->rootObjects().size(), 1);
|
|
|
|
QCOMPARE(engine()->rootObjects().front()->objectName(), QString::fromLocal8Bit("testWindow"));
|
|
|
|
QVERIFY(engine()->rootObjects().front()->isWindowType());
|
2015-12-28 12:21:02 +00:00
|
|
|
dos_qurl_delete(url);
|
2015-09-19 17:13:08 +00:00
|
|
|
}
|
2015-09-20 09:39:25 +00:00
|
|
|
|
2015-12-29 11:12:45 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void testRootObjects() {
|
|
|
|
void** rootObjects = nullptr;
|
|
|
|
int length = 0;
|
|
|
|
void* url = nullptr;
|
|
|
|
dos_qurl_create(&url, "qrc:///main.qml", QUrl::TolerantMode);
|
|
|
|
dos_qqmlapplicationengine_load_url(m_engine, url);
|
|
|
|
dos_qurl_delete(url);
|
|
|
|
dos_qqmlapplicationengine_rootObjects(m_engine, &rootObjects, &length);
|
|
|
|
QCOMPARE(length, 1);
|
|
|
|
QObject* window = reinterpret_cast<QObject*>(rootObjects[0]);
|
|
|
|
QVERIFY(window->isWindowType());
|
|
|
|
dos_qobjectptr_array_delete(rootObjects);
|
2015-12-27 14:40:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
private:
|
2015-12-29 11:12:45 +00:00
|
|
|
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
|
|
|
|
|
2015-12-28 12:21:02 +00:00
|
|
|
void* m_engine;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test QQmlContext
|
|
|
|
*/
|
2015-12-28 12:46:32 +00:00
|
|
|
class TestQQmlContext : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-12-28 12:21:02 +00:00
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
private slots:
|
|
|
|
void initTestCase() {
|
|
|
|
m_engine = nullptr;
|
|
|
|
m_context = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanupTestCase() {
|
|
|
|
QVERIFY(m_engine == nullptr);
|
|
|
|
QVERIFY(m_context == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
dos_qqmlapplicationengine_create(&m_engine);
|
|
|
|
dos_qqmlapplicationengine_context(m_engine, &m_context);
|
|
|
|
QVERIFY(m_engine != nullptr);
|
|
|
|
QVERIFY(m_context != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup() {
|
|
|
|
m_context = nullptr;
|
|
|
|
dos_qqmlapplicationengine_delete(m_engine);
|
|
|
|
m_engine = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-12-29 11:12:45 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
private:
|
2015-12-29 11:12:45 +00:00
|
|
|
QQmlApplicationEngine* engine() { return static_cast<QQmlApplicationEngine*>(m_engine); }
|
|
|
|
QQmlContext* context() { return static_cast<QQmlContext*>(m_context); }
|
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
void* m_engine;
|
|
|
|
void* m_context;
|
2015-12-28 12:21:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
Q_INIT_RESOURCE(Resources);
|
|
|
|
bool success = true;
|
|
|
|
success &= ExecuteTest<TestQGuiApplication>(argc, argv);
|
|
|
|
success &= ExecuteTest<TestQApplication>(argc, argv);
|
|
|
|
success &= ExecuteGuiTest<TestQQmlApplicationEngine>(argc, argv);
|
2015-12-29 11:12:45 +00:00
|
|
|
success &= ExecuteGuiTest<TestQQmlContext>(argc, argv);
|
2015-12-28 12:21:02 +00:00
|
|
|
return success ? 0 : 1;
|
|
|
|
}
|
2015-09-19 17:13:08 +00:00
|
|
|
|
2015-12-28 12:46:32 +00:00
|
|
|
#include "test_dotherside.moc"
|