diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 43aa03e..6dd85f2 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -11,6 +11,9 @@ #include #include +//for unit testing +class UnitTest; + // PaintingArea used to paint the image class PaintingArea; @@ -22,6 +25,7 @@ class IntelliColorPicker; * \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program */ class IntelliPhotoGui : public QMainWindow { + friend UnitTest; // Declares our class as a QObject which is the base class // for all Qt objects // QObjects handle events @@ -129,47 +133,47 @@ QLabel* ActiveLayerImageLine; QPalette Palette; // The menu widgets -QMenu*saveAsMenu; -QMenu*fileMenu; -QMenu*renderMenu; -QMenu*optionMenu; -QMenu*layerMenu; -QMenu*colorMenu; -QMenu*toolCreationMenu; -QMenu*toolSettingsMenu; -QMenu*toolMenu; -QMenu*helpMenu; +QMenu* saveAsMenu; +QMenu* fileMenu; +QMenu* renderMenu; +QMenu* optionMenu; +QMenu* layerMenu; +QMenu* colorMenu; +QMenu* toolCreationMenu; +QMenu* toolSettingsMenu; +QMenu* toolMenu; +QMenu* helpMenu; // All the actions that can occur // meta image actions (need further modularisation) -QAction*actionOpen; -QAction*actionExit; +QAction* actionOpen; +QAction* actionExit; //Rendersetting actions QAction*actionUpdateRenderSettingsOn; QAction*actionUpdateRenderSettingsOff; // color Picker actions -QAction*actionColorPickerFirstColor; -QAction*actionColorPickerSecondColor; -QAction*actionColorSwap; +QAction* actionColorPickerFirstColor; +QAction* actionColorPickerSecondColor; +QAction* actionColorSwap; // tool actions -QAction*actionCreatePenTool; -QAction*actionCreatePlainTool; -QAction*actionCreateLineTool; -QAction*actionCreateRectangleTool; -QAction*actionCreateCircleTool; -QAction*actionCreatePolygonTool; -QAction*actionCreateFloodFillTool; +QAction* actionCreatePenTool; +QAction* actionCreatePlainTool; +QAction* actionCreateLineTool; +QAction* actionCreateRectangleTool; +QAction* actionCreateCircleTool; +QAction* actionCreatePolygonTool; +QAction* actionCreateFloodFillTool; // dialog actions -QAction*actionAboutDialog; -QAction*actionAboutQtDialog; +QAction* actionAboutDialog; +QAction* actionAboutQtDialog; // layer change actions -QAction*actionCreateNewLayer; -QAction*actionDeleteLayer; +QAction* actionCreateNewLayer; +QAction* actionDeleteLayer; QAction* actionSetActiveLayer; QAction* actionSetActiveAlpha; QAction* actionMovePositionUp; diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 185063d..5ba0337 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -11,12 +11,16 @@ #include "IntelliHelper/IntelliTriangulation.h" #include "IntelliHelper/IntelliRenderSettings.h" +//for unit testing +class UnitTest; + class IntelliTool; /*! * \brief An abstract class which manages the basic IntelliImage operations. */ class IntelliImage { + friend UnitTest; friend IntelliTool; public: diff --git a/src/Image/IntelliRasterImage.h b/src/Image/IntelliRasterImage.h index f589843..f05be17 100644 --- a/src/Image/IntelliRasterImage.h +++ b/src/Image/IntelliRasterImage.h @@ -3,10 +3,14 @@ #include "Image/IntelliImage.h" +//for unit testing +class UnitTest; + /*! * \brief The IntelliRasterImage manages a RASTERIMAGE. */ class IntelliRasterImage : public IntelliImage { + friend UnitTest; friend IntelliTool; protected: /*! diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 220ad75..e3ce35d 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -4,10 +4,14 @@ #include "Image/IntelliRasterImage.h" #include +//for unit testing +class UnitTest; + /*! * \brief The IntelliShapedImage manages a Shapedimage. */ class IntelliShapedImage : public IntelliRasterImage { + friend UnitTest; friend IntelliTool; private: /*! diff --git a/src/IntelliHelper/IntelliColorPicker.h b/src/IntelliHelper/IntelliColorPicker.h index 4ea686b..948b2e1 100644 --- a/src/IntelliHelper/IntelliColorPicker.h +++ b/src/IntelliHelper/IntelliColorPicker.h @@ -5,10 +5,14 @@ #include "QPoint" #include "QColorDialog" +//for unit testing +class UnitTest; + /*! * \brief The IntelliColorPicker manages the selected colors for one whole project. */ class IntelliColorPicker { + friend UnitTest; public: /*! * \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production. diff --git a/src/IntelliHelper/IntelliRenderSettings.h b/src/IntelliHelper/IntelliRenderSettings.h index a0be040..21c7bc9 100644 --- a/src/IntelliHelper/IntelliRenderSettings.h +++ b/src/IntelliHelper/IntelliRenderSettings.h @@ -1,9 +1,13 @@ #ifndef INTELLIRENDERSETTINGS_H #define INTELLIRENDERSETTINGS_H +//for unit testing +class UnitTest; + class IntelliRenderSettings { + friend UnitTest; public: IntelliRenderSettings(); diff --git a/src/IntelliHelper/IntelliToolsettings.h b/src/IntelliHelper/IntelliToolsettings.h index ae11dc0..8a3e837 100644 --- a/src/IntelliHelper/IntelliToolsettings.h +++ b/src/IntelliHelper/IntelliToolsettings.h @@ -1,7 +1,11 @@ #ifndef INTELLITOOLSETTINGS_H #define INTELLITOOLSETTINGS_H +//for unit testing +class UnitTest; + class IntelliToolsettings { + friend UnitTest; public: /*! * \brief The LineStyle enum classifing all ways of drawing a line. diff --git a/src/IntelliHelper/IntelliTriangulation.h b/src/IntelliHelper/IntelliTriangulation.h index 21ebfa3..02ac065 100644 --- a/src/IntelliHelper/IntelliTriangulation.h +++ b/src/IntelliHelper/IntelliTriangulation.h @@ -1,6 +1,9 @@ #ifndef INTELLITRIANGULATION_H #define INTELLITRIANGULATION_H +//for unit testing +class UnitTest; + #include #include diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 779c2bb..e2df40d 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -22,20 +22,6 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); - this->addLayer(200,200,0,0,IntelliImage::ImageType::SHAPEDIMAGE); - layerBundle[0].image->drawPlain(QColor(0,0,255,255)); - std::vector polygon; - polygon.push_back(QPoint(100,000)); - polygon.push_back(QPoint(200,100)); - polygon.push_back(QPoint(100,200)); - polygon.push_back(QPoint(000,100)); - layerBundle[0].image->setPolygon(polygon); - - this->addLayer(200,200,150,150,IntelliImage::ImageType::RASTERIMAGE); - layerBundle[1].image->drawPlain(QColor(0,255,0,255)); - layerBundle[1].alpha=200; - - activeLayer=0; } PaintingArea::~PaintingArea(){ diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index fad58dd..666a6a7 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -14,6 +14,9 @@ #include "Tool/IntelliTool.h" #include "IntelliHelper/IntelliColorPicker.h" +//for unit testing +class UnitTest; + /*! * \brief The LayerObject struct holds all the information needed to construct a layer * \param width - Stores the width of a layer in pixels @@ -36,6 +39,7 @@ struct LayerObject { */ class PaintingArea : public QWidget { + friend UnitTest; // Declares our class as a QObject which is the base class // for all Qt objects // QObjects handle events diff --git a/src/Tool/IntelliColorPicker.cpp b/src/Tool/IntelliColorPicker.cpp deleted file mode 100644 index 67ba35c..0000000 --- a/src/Tool/IntelliColorPicker.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "IntelliColorPicker.h" -#include "QDebug" - -IntelliColorPicker::IntelliColorPicker(PaintingArea* Area) - : IntelliTool(Area){ - firstColor = {255,0,0,255}; - secondColor = {0,0,255,255}; -} - -IntelliColorPicker::~IntelliColorPicker(){ - -} - -void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){ - QString Titel; - QColor newColor; - if(firstOrSecondColor == 1) { - Titel = "Choose first Color"; - newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel); - this->firstColor = newColor; - qDebug() << "Firstcolor" << this->firstColor; - } - else{ - Titel = "Choose second Color"; - newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel); - this->secondColor = newColor; - } -} - -QColor IntelliColorPicker::getFirstColor(){ - return firstColor; -} - -QColor IntelliColorPicker::getSecondColor(){ - return secondColor; -} diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index 56404aa..213ec1f 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -5,6 +5,9 @@ #include "IntelliHelper/IntelliToolsettings.h" #include +//for unit testing +class UnitTest; + struct LayerObject; class PaintingArea; @@ -12,6 +15,7 @@ class PaintingArea; * \brief An abstract class that manages the basic events, like mouse clicks or scrolls events. */ class IntelliTool { + friend UnitTest; public: enum class Tooltype { CIRCLE, diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h index d75665d..53dfbd7 100644 --- a/src/Tool/IntelliToolCircle.h +++ b/src/Tool/IntelliToolCircle.h @@ -4,10 +4,15 @@ #include "QColor" #include "QPoint" + +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolCircle class represents a tool to draw a circle. */ class IntelliToolCircle : public IntelliTool { + friend UnitTest; /*! * \brief A function that implements a circle drawing algorithm. * \param radius - The radius of the circle. diff --git a/src/Tool/IntelliToolFloodFill.h b/src/Tool/IntelliToolFloodFill.h index 3e93699..699de0e 100644 --- a/src/Tool/IntelliToolFloodFill.h +++ b/src/Tool/IntelliToolFloodFill.h @@ -4,10 +4,15 @@ #include "QColor" +//for unit testing +class UnitTest; + + /*! * \brief The IntelliToolFloodFill class represents a tool to flood FIll a certian area. */ class IntelliToolFloodFill : public IntelliTool { + friend UnitTest; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. diff --git a/src/Tool/IntelliToolLine.h b/src/Tool/IntelliToolLine.h index 1bae946..ee7fe3b 100644 --- a/src/Tool/IntelliToolLine.h +++ b/src/Tool/IntelliToolLine.h @@ -4,10 +4,14 @@ #include "QPoint" +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolFloodFill class represents a tool to draw a line. */ class IntelliToolLine : public IntelliTool { + friend UnitTest; /*! * \brief The starting point of the line. */ diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index 39aab9e..82428ad 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -5,10 +5,14 @@ #include "QColor" #include "QPoint" +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolPen class represents a tool to draw a line. */ class IntelliToolPen : public IntelliTool { + friend UnitTest; /*! * \brief point - Represents the previous point to help drawing a line. */ diff --git a/src/Tool/IntelliToolPlain.h b/src/Tool/IntelliToolPlain.h index c4b294c..331507c 100644 --- a/src/Tool/IntelliToolPlain.h +++ b/src/Tool/IntelliToolPlain.h @@ -3,10 +3,15 @@ #include "IntelliTool.h" #include "QColor" + +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolPlainTool class represents a tool to fill the whole canvas with one color. */ class IntelliToolPlainTool : public IntelliTool { + friend UnitTest; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index 920a556..cb6365a 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -5,11 +5,16 @@ #include "IntelliHelper/IntelliTriangulation.h" #include #include + +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolPolygon managed the Drawing of Polygonforms */ class IntelliToolPolygon : public IntelliTool { + friend UnitTest; /*! * \brief Checks if the given Point lies near the starting Point. * \param x - x coordinate of a point. diff --git a/src/Tool/IntelliToolRectangle.h b/src/Tool/IntelliToolRectangle.h index 041e860..ba6694a 100644 --- a/src/Tool/IntelliToolRectangle.h +++ b/src/Tool/IntelliToolRectangle.h @@ -5,10 +5,15 @@ #include "QColor" #include "QPoint" + +//for unit testing +class UnitTest; + /*! * \brief The IntelliToolRectangle class represents a tool to draw a rectangle. */ class IntelliToolRectangle : public IntelliTool { + friend UnitTest; /*! * \brief A function that implements a rectagle drawing algorithm. * \param othercorner - The second corner point of the rectangle. diff --git a/src/UnitTest.pro b/src/UnitTest.pro index c61749e..0ac2ecf 100644 --- a/src/UnitTest.pro +++ b/src/UnitTest.pro @@ -2,6 +2,8 @@ QT += testlib QT += gui CONFIG += qt warn_on depend_includepath testcase +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + TEMPLATE = app SOURCES += \ @@ -14,7 +16,6 @@ SOURCES += \ IntelliHelper/IntelliToolsettings.cpp \ IntelliHelper/IntelliTriangulation.cpp \ Layer/PaintingArea.cpp \ - Tool/IntelliColorPicker.cpp \ Tool/IntelliTool.cpp \ Tool/IntelliToolCircle.cpp \ Tool/IntelliToolFloodFill.cpp \ diff --git a/src/mainUnitTest.cpp b/src/mainUnitTest.cpp index 0d27b36..ce7d13f 100644 --- a/src/mainUnitTest.cpp +++ b/src/mainUnitTest.cpp @@ -1,32 +1,17 @@ #include // add necessary includes here - +#include #include "GUI/IntelliPhotoGui.h" -#include "Image/IntelliImage.h" -#include "Image/IntelliRasterImage.h" -#include "Image/IntelliShapedImage.h" -#include "IntelliHelper/IntelliColorPicker.h" -#include "IntelliHelper/IntelliRenderSettings.h" -#include "IntelliHelper/IntelliToolsettings.h" -#include "IntelliHelper/IntelliTriangulation.h" -#include "Layer/PaintingArea.h" -#include "Tool/IntelliTool.h" -#include "Tool/IntelliToolCircle.h" -#include "Tool/IntelliToolFloodFill.h" -#include "Tool/IntelliToolLine.h" -#include "Tool/IntelliToolPen.h" -#include "Tool/IntelliToolPlain.h" -#include "Tool/IntelliToolPolygon.h" -#include "Tool/IntelliToolRectangle.h" + class UnitTest : public QObject { Q_OBJECT private: - PaintingArea* area; IntelliPhotoGui* gui; - QImage* image; + PaintingArea* area; + QApplication* app; public: UnitTest(); @@ -37,13 +22,87 @@ private slots: void cleanupTestCase(); void test_case1(); + //test painting area + void test_addLayer(); + void test_deleteLayer(); + void test_setActive(); + void test_setAlpha(); + void test_floodFill(); + void test_moveActive(); + void test_setPolygon(); + void test_setLayerUp(); + void test_setLayerDown(); + void test_createTools(); + //test Raster-Image operations + void test_RasterImage_drawPixel(); + void test_RasterImage_drawLine(); + void test_RasterImage_drawPoint(); + void test_RasterImage_getDisplayable(); + void test_RasterImage_setPolygon(); + void test_RasterImage_loadImage(); + void test_RasterImage_getPixelColor(); + void test_RasterImage_getImageData(); + void test_RasterImage_setImageData(); + + //test Shaped-Image operations + void test_ShapedImage_drawPixel(); + void test_ShapedImage_drawLine(); + void test_ShapedImage_drawPoint(); + void test_ShapedImage_getDisplayable(); + void test_ShapedImage_setPolygon(); + void test_ShapedImage_loadImage(); + void test_ShapedImage_getPixelColor(); + void test_ShapedImage_getImageData(); + void test_ShapedImage_setImageData(); + + //test painting-area tools + void test_createTool_Circle(); + void test_createTool_FloodFill(); + void test_createTool_Line(); + void test_createTool_Pen(); + void test_createTool_Plain(); + void test_createTool_Polygon(); + void test_createTool_Rectangle(); + + //test tools + void test_Circle_fullDraw(); + void test_Circle_interruptedDraw(); + + void test_FloodFill_fullDraw(); + void test_FloodFill_interruptedDraw(); + + void test_Line_fullDraw(); + void test_Line_interruptedDraw(); + + void test_Pen_fullDraw(); + void test_Pen_interruptedDraw(); + + void test_Plain_fullDraw(); + void test_Plain_interruptedDraw(); + + void test_Polygon_fullDraw(); + void test_Polygon_interruptedDraw(); + + void test_Rectangle_fullDraw(); + void test_Rectangle_interruptedDraw(); + + //test Triangulation + void test_Triangulation_Coverage(); }; UnitTest::UnitTest() { + char arg0[] = "programName"; + char arg1[] = "arg1"; + char arg2[] = "arg2"; + char *argv[] = {arg0, arg1, arg2, nullptr}; + int argc = sizeof(argv) / sizeof(char*) - 1; + app = new QApplication(argc,argv); + gui = new IntelliPhotoGui(); + area = gui->paintingArea; } UnitTest::~UnitTest() @@ -58,7 +117,8 @@ void UnitTest::initTestCase() void UnitTest::cleanupTestCase() { - + delete gui; + delete app; } void UnitTest::test_case1()