mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-12 04:26:43 +00:00
Added initial draft of unit test for DynamicQObject
This commit is contained in:
parent
b570e2cd98
commit
133e6d31b4
@ -1,2 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(test)
|
||||
|
@ -34,4 +34,4 @@ set(SRC_LIST
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SRC_LIST} ${HEADERS_LIST})
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Qml Qt5::Quick)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Qml Qt5::Quick)
|
||||
|
14
test/CMakeLists.txt
Normal file
14
test/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
project(TestDynamicQObject)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
if (UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-long-long -pedantic")
|
||||
endif()
|
||||
|
||||
find_package(Qt5Test REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_dynamicqobject.cpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Test)
|
52
test/test_dynamicqobject.cpp
Normal file
52
test/test_dynamicqobject.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include "../src/DynamicQObject.h"
|
||||
|
||||
class TestDynamicQObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void memoryLeakTest() {
|
||||
DynamicQObject<QObject> dynamicQObject;
|
||||
}
|
||||
|
||||
void testRegisterSignal() {
|
||||
DynamicQObject<QObject> dynamicQObject;
|
||||
int index;
|
||||
dynamicQObject.registerSignal("fooSignal", {}, index);
|
||||
QCOMPARE(index != -1, true);
|
||||
|
||||
QSignalSpy signalSpy(&dynamicQObject, SIGNAL(fooSignal()));
|
||||
dynamicQObject.emitSignal("fooSignal", {});
|
||||
QCOMPARE(signalSpy.count(), 1);
|
||||
}
|
||||
|
||||
void testRegisterSlot() {
|
||||
DynamicQObject<QObject> dynamicQObject;
|
||||
int index;
|
||||
dynamicQObject.registerSlot("fooSlot", QMetaType::Void, {}, index);
|
||||
QCOMPARE(index != -1, true);
|
||||
}
|
||||
|
||||
void testRegisterProperty() {
|
||||
DynamicQObject<QObject> dynamicQObject;
|
||||
int index = -1;
|
||||
bool result = false;
|
||||
result = dynamicQObject.registerSlot("foo", QMetaType::Int, {}, index);
|
||||
QCOMPARE(index != -1, true);
|
||||
QCOMPARE(result, true);
|
||||
result = dynamicQObject.registerSlot("setFoo", QMetaType::Void, {QMetaType::Int}, index);
|
||||
QCOMPARE(index != -1, true);
|
||||
QCOMPARE(result, true);
|
||||
result = dynamicQObject.registerSignal("fooChanged", {QMetaType::Int}, index);
|
||||
QCOMPARE(index != -1, true);
|
||||
QCOMPARE(result, true);
|
||||
result = dynamicQObject.registerProperty("foo", QMetaType::Int, "foo", "setFoo", "fooChanged");
|
||||
QCOMPARE(result, true);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestDynamicQObject)
|
||||
|
||||
#include "test_dynamicqobject.moc"
|
Loading…
x
Reference in New Issue
Block a user