Added initial draft of unit test for DynamicQObject

This commit is contained in:
cuke 2015-09-19 19:13:08 +02:00
parent b570e2cd98
commit 133e6d31b4
4 changed files with 80 additions and 13 deletions

View File

@ -1,2 +1,3 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(test)

View File

@ -34,4 +34,4 @@ set(SRC_LIST
) )
add_library(${PROJECT_NAME} SHARED ${SRC_LIST} ${HEADERS_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
View 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)

View 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"