From 5a3bd4733fd2c998af4d39a7b0d94e0e9d680938 Mon Sep 17 00:00:00 2001
From: guido basten <1542094@uni-wuppertal.de>
Date: Fri, 15 Feb 2019 09:58:16 +0100
Subject: [PATCH] Added the first unit tests for jpsdatamanager and the
 tests.pro

---
 jpseditor.pro               |   1 +
 tests/TestMain.cpp          |   5 +
 tests/datamanager_tests.cpp | 181 ++++++++++++++++++++++++++++++++++++
 tests/tests.pro             | 102 ++++++++++++++++++++
 4 files changed, 289 insertions(+)
 create mode 100644 tests/TestMain.cpp
 create mode 100644 tests/datamanager_tests.cpp
 create mode 100644 tests/tests.pro

diff --git a/jpseditor.pro b/jpseditor.pro
index aad960d..6696320 100644
--- a/jpseditor.pro
+++ b/jpseditor.pro
@@ -4,3 +4,4 @@ CONFIG+=ordered
 
 SUBDIRS = \
     src \
+    tests \
diff --git a/tests/TestMain.cpp b/tests/TestMain.cpp
new file mode 100644
index 0000000..4617279
--- /dev/null
+++ b/tests/TestMain.cpp
@@ -0,0 +1,5 @@
+#define CATCH_CONFIG_MAIN
+
+#include <catch2/catch.hpp>
+
+
diff --git a/tests/datamanager_tests.cpp b/tests/datamanager_tests.cpp
new file mode 100644
index 0000000..d97e8bd
--- /dev/null
+++ b/tests/datamanager_tests.cpp
@@ -0,0 +1,181 @@
+#include <catch2/catch.hpp>
+#include "../src/datamanager.h"
+#include "../src/jpsLineItem.h"
+#include "../src/jpsregion.h"
+#include "../src/jpslandmark.h"
+
+
+jpsRegion create_testregion (int &id);
+
+
+
+TEST_CASE("get functions")
+{
+    jpsDatamanager *testobject = new jpsDatamanager;
+
+    SECTION("get roomlist")
+    {
+        QList<jpsRoom *> testroomlist;
+
+        //test the length of the roomlist with get_roomlist
+        testroomlist = testobject->get_roomlist();
+        REQUIRE(testroomlist.length() == 0);
+
+        //add a room with new_room and check the length again
+        testobject->new_room();
+        testroomlist = testobject->get_roomlist();
+        REQUIRE(testroomlist.length() == 1);
+
+        testobject->new_room();
+        testroomlist = testobject->get_roomlist();
+        REQUIRE(testroomlist.length() == 2);
+
+    }
+
+    SECTION("get crossingList")            
+    {
+        //test the length of the crossingList with get_crossingList
+        REQUIRE(testobject->get_crossingList().length() == 0);
+
+
+        // add a crossingpiont (door) to the list
+        QGraphicsLineItem *testline = new  QGraphicsLineItem(qreal(0),qreal(0),qreal(2),qreal(0));
+        jpsLineItem *testLineItem_1 = new jpsLineItem(testline);
+        testLineItem_1->set_Door();
+        testobject->new_crossing(testLineItem_1);
+        REQUIRE(testobject->get_crossingList().length() == 1);
+
+
+        testline->setLine(qreal(2),qreal(2),qreal(4),qreal(2));
+        jpsLineItem *testLineItem_2 = new jpsLineItem(testline);
+        testLineItem_2->set_Door();
+        testobject->new_crossing(testLineItem_2);
+        REQUIRE(testobject->get_crossingList().length() == 2);
+
+    }
+
+    SECTION("get obstacellist")
+    {
+        //test the length of the obstaclelist with get_obstacleist
+        REQUIRE(testobject->get_obstaclelist().length() == 0);
+
+        //add a obstacle and test the length again
+        testobject->new_obstacle();
+        REQUIRE(testobject->get_obstaclelist().length() == 1);
+
+        testobject->new_obstacle();
+        REQUIRE(testobject->get_obstaclelist().length() == 2);
+    }
+
+    SECTION("get exitlist")
+    {
+        //test the length of the exitlist with get_exitlist
+        REQUIRE(testobject->get_exitList().length() == 0);
+
+        //add a exit and test the length again
+        QGraphicsLineItem *testline = new  QGraphicsLineItem(qreal(0),qreal(0),qreal(2),qreal(0));
+        jpsLineItem *testLineItem_1 = new jpsLineItem(testline);
+        testobject->new_exit(testLineItem_1);
+
+        REQUIRE(testobject->get_exitList().length() == 1);
+
+
+        testline->setLine(qreal(2),qreal(2),qreal(4),qreal(2));
+        jpsLineItem *testLineItem_2 = new jpsLineItem(testline);
+        testobject->new_exit(testLineItem_2);
+
+        REQUIRE(testobject->get_exitList().length() == 2);
+
+
+
+    }
+
+
+
+
+    SECTION("get all connections")
+    {
+        //test the length of the connection list with GetAllConnections
+        REQUIRE(testobject->GetAllConnections().length() == 0);
+
+        //add a connection and test the length again
+        jpsConnection *testconnection_1 = new jpsConnection;
+        testobject->NewConnection(testconnection_1);
+        REQUIRE(testobject->GetAllConnections().length() == 1);
+
+        jpsConnection *testconnection_2 =new jpsConnection;
+        testobject->NewConnection(testconnection_2);
+        REQUIRE(testobject->GetAllConnections().length() == 2);
+
+
+    }
+
+    SECTION("get regions and get regions counter")
+    {
+        int testid = 1;
+        REQUIRE(testobject->GetRegionCounter() == 0);
+        REQUIRE(testobject->GetRegions().length() == testobject->GetRegionCounter());
+
+        jpsRegion testregion_1 = create_testregion(testid);
+        testid ++;
+        testobject->NewRegion(&testregion_1);
+        REQUIRE(testobject->GetRegionCounter() == 1);
+        REQUIRE(testobject->GetRegions().length() == testobject->GetRegionCounter());
+
+        jpsRegion testregion_2 = create_testregion(testid);
+        testobject->NewRegion(&testregion_2);
+        REQUIRE(testobject->GetRegionCounter() == 2);
+        REQUIRE(testobject->GetRegions().length() == testobject->GetRegionCounter());
+    }
+
+    SECTION("get landmarks")
+    {
+        //test the lenght if the landmark list with get_landmarks
+        REQUIRE(testobject->get_landmarks().length() == 0);
+
+        //create and and add a landmark to the list. Then test it again
+        jpsLandmark *testlandmark_1 = new jpsLandmark;
+        testobject->new_landmark(testlandmark_1);
+        REQUIRE(testobject->get_landmarks().length() == 1);
+
+        jpsLandmark *testlandmark_2 = new jpsLandmark;
+        testobject->new_landmark(testlandmark_2);
+        REQUIRE(testobject->get_landmarks().length() == 2);
+
+//        delete testlandmark_1;
+//        delete testlandmark_2;
+
+    }
+
+
+}
+
+
+
+
+jpsRegion create_testregion (int &id)
+{
+    const QString testcaption = "testcaption";
+    const QString testtype = "Regnion";
+    const QPointF testpoint (0,0);
+    const qreal testqreal= 0;
+    jpsRegion testregion = jpsRegion(id,testcaption,testpoint,testqreal,testqreal);
+
+    return testregion;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/tests.pro b/tests/tests.pro
new file mode 100644
index 0000000..c630b29
--- /dev/null
+++ b/tests/tests.pro
@@ -0,0 +1,102 @@
+QT       += core gui
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = JPSeditorUnitTests
+TEMPLATE = app
+
+CONFIG += console
+CONFIG += c++11
+
+FORMS += \
+    ../src/forms/mainwindow.ui \
+    ../src/forms/roomwidget.ui \
+    ../src/forms/widgetlandmark.ui \
+    ../src/forms/widgetsettings.ui \
+    ../src/forms/inifilewidget.ui \
+    ../src/forms/settingdialog.ui
+
+
+
+
+SOURCES += TestMain.cpp \
+    datamanager_tests.cpp \
+    ../src/mainWindow.cpp \
+    ../src/GraphicView.cpp \
+    ../src/roomwidget.cpp \
+    ../src/rooms.cpp \
+    ../src/datamanager.cpp \
+    ../src/jpscrossing.cpp \
+    ../src/jpsLineItem.cpp \
+    ../src/jpsexit.cpp \
+    ../src/jpsobstacle.cpp \
+    ../src/jpslandmark.cpp \
+    ../src/dxflib/src/dl_writer_ascii.cpp \
+    ../src/dxflib/src/dl_dxf.cpp \
+    ../src/widgetlandmark.cpp \
+    ../src/graphicscene.cpp \
+    ../src/widgetsettings.cpp \
+    ../src/jpsconnection.cpp \
+    ../src/UndoFramework/actionstack.cpp \
+    ../src/UndoFramework/action.cpp \
+    ../src/UndoFramework/lineaction.cpp \
+    ../src/jpsregion.cpp \
+    ../src/AutomaticRoomIdentification/roomdefinition.cpp \
+    ../src/AutomaticRoomIdentification/roomidentification.cpp \
+    ../src/settingdialog.cpp \
+    ../src/tinyxml/tinystr.cpp \
+    ../src/tinyxml/tinyxml.cpp \
+    ../src/tinyxml/tinyxmlerror.cpp \
+    ../src/tinyxml/tinyxmlparser.cpp \
+    ../src/inifilewidget.cpp \
+
+	
+HEADERS += \
+    ../src/mainWindow.h \
+    ../src/GraphicView.h \
+    ../src/roomwidget.h \
+    ../src/rooms.h \
+    ../src/datamanager.h \
+    ../src/jpscrossing.h \
+    ../src/jpsLineItem.h \
+    ../src/jpsexit.h \
+    ../src/jpsobstacle.h \
+    ../src/jpslandmark.h \
+    ../src/dxflib/src/dl_writer_ascii.h \
+    ../src/dxflib/src/dl_writer.h \
+    ../src/dxflib/src/dl_global.h \
+    ../src/dxflib/src/dl_extrusion.h \
+    ../src/dxflib/src/dl_exception.h \
+    ../src/dxflib/src/dl_entities.h \
+    ../src/dxflib/src/dl_dxf.h \
+    ../src/dxflib/src/dl_creationinterface.h \
+    ../src/dxflib/src/dl_creationadapter.h \
+    ../src/dxflib/src/dl_codes.h \
+    ../src/dxflib/src/dl_attributes.h \
+    ../src/widgetlandmark.h \
+    ../src/graphicscene.h \
+    ../src/widgetsettings.h \
+    ../src/jpsconnection.h \
+    ../src/UndoFramework/actionstack.h \
+    ../src/UndoFramework/action.h \
+    ../src/UndoFramework/lineaction.h \
+    ../src/jpsregion.h \
+    ../src/AutomaticRoomIdentification/roomID.h\
+    ../src/AutomaticRoomIdentification/roomdefinition.h \
+    ../src/AutomaticRoomIdentification/roomidentification.h \
+    ../src/dtrace.h \
+    ../src/settingdialog.h \
+    ../src/tinyxml/tinystr.h \
+    ../src/tinyxml/tinyxml.h \
+    ../src/inifilewidget.h \
+
+
+INCLUDEPATH += \
+    ../build \
+    ../examples \
+    ../src \
+    ../examples/1_tutorial \
+    ../examples/2_mixedusage \
+    ../examples/3_bottleneck \
+
+
+DESTDIR = $$PWD/..
-- 
GitLab