From 7eeee52fb49a989cbfa05e84a866a7d46078866b Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Thu, 9 Jan 2020 21:07:36 +0100 Subject: [PATCH 01/14] Startingh UnitTesting --- src/UnitTest.pro | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/mainUnitTest.cpp | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/UnitTest.pro create mode 100644 src/mainUnitTest.cpp diff --git a/src/UnitTest.pro b/src/UnitTest.pro new file mode 100644 index 0000000..c61749e --- /dev/null +++ b/src/UnitTest.pro @@ -0,0 +1,57 @@ +QT += testlib +QT += gui +CONFIG += qt warn_on depend_includepath testcase + +TEMPLATE = app + +SOURCES += \ + GUI/IntelliPhotoGui.cpp \ + Image/IntelliImage.cpp \ + Image/IntelliRasterImage.cpp \ + Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliColorPicker.cpp \ + IntelliHelper/IntelliRenderSettings.cpp \ + IntelliHelper/IntelliToolsettings.cpp \ + IntelliHelper/IntelliTriangulation.cpp \ + Layer/PaintingArea.cpp \ + Tool/IntelliColorPicker.cpp \ + Tool/IntelliTool.cpp \ + Tool/IntelliToolCircle.cpp \ + Tool/IntelliToolFloodFill.cpp \ + Tool/IntelliToolLine.cpp \ + Tool/IntelliToolPen.cpp \ + Tool/IntelliToolPlain.cpp \ + Tool/IntelliToolPolygon.cpp \ + Tool/IntelliToolRectangle.cpp \ + mainUnitTest.cpp + +DISTFILES += \ + icons/Wechselpfeile.png \ + icons/circle-tool.svg \ + icons/eraser-tool.svg \ + icons/flood-fill-tool.svg \ + icons/icon.png \ + icons/line-tool.svg \ + icons/pen-tool.svg \ + icons/plain-tool.svg \ + icons/polygon-tool.svg \ + icons/rectangle-tool.svg + +HEADERS += \ + GUI/IntelliPhotoGui.h \ + Image/IntelliImage.h \ + Image/IntelliRasterImage.h \ + Image/IntelliShapedImage.h \ + IntelliHelper/IntelliColorPicker.h \ + IntelliHelper/IntelliRenderSettings.h \ + IntelliHelper/IntelliToolsettings.h \ + IntelliHelper/IntelliTriangulation.h \ + Layer/PaintingArea.h \ + Tool/IntelliTool.h \ + Tool/IntelliToolCircle.h \ + Tool/IntelliToolFloodFill.h \ + Tool/IntelliToolLine.h \ + Tool/IntelliToolPen.h \ + Tool/IntelliToolPlain.h \ + Tool/IntelliToolPolygon.h \ + Tool/IntelliToolRectangle.h diff --git a/src/mainUnitTest.cpp b/src/mainUnitTest.cpp new file mode 100644 index 0000000..75fb0d6 --- /dev/null +++ b/src/mainUnitTest.cpp @@ -0,0 +1,49 @@ +#include + +// add necessary includes here + +class UnitTest : public QObject +{ + Q_OBJECT + +public: + UnitTest(); + ~UnitTest(); + +private slots: + void initTestCase(); + void cleanupTestCase(); + void test_case1(); + +}; + +UnitTest::UnitTest() +{ + +} + +UnitTest::~UnitTest() +{ + +} + +void UnitTest::initTestCase() +{ + +} + +void UnitTest::cleanupTestCase() +{ + +} + +void UnitTest::test_case1() +{ + QBENCHMARK { + QVERIFY(1 == 1); + } +} + +QTEST_APPLESS_MAIN(UnitTest) + +#include "tst_unittest.moc" From 4d4a21667b21b7f73a7233801975666969c7587f Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Thu, 9 Jan 2020 22:20:11 +0100 Subject: [PATCH 02/14] start of test writing --- src/IntelliHelper/IntelliToolsettings.h | 4 ++++ src/mainUnitTest.cpp | 28 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/IntelliHelper/IntelliToolsettings.h b/src/IntelliHelper/IntelliToolsettings.h index 1a63bbc..ae11dc0 100644 --- a/src/IntelliHelper/IntelliToolsettings.h +++ b/src/IntelliHelper/IntelliToolsettings.h @@ -10,14 +10,18 @@ enum class LineStyle { SOLID_LINE, DOTTED_LINE }; + IntelliToolsettings(); virtual ~IntelliToolsettings(); + int getLineWidth(); void setLineWidth(); void setLineWidth(int LineWidth); + int getInnerAlpha(); void setInnerAlpha(); void setInnerAlpha(int innerAlpha); + LineStyle getLinestyle(); private: diff --git a/src/mainUnitTest.cpp b/src/mainUnitTest.cpp index 75fb0d6..0d27b36 100644 --- a/src/mainUnitTest.cpp +++ b/src/mainUnitTest.cpp @@ -1,10 +1,32 @@ -#include - +#include // add necessary includes here + +#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; public: UnitTest(); @@ -15,6 +37,8 @@ private slots: void cleanupTestCase(); void test_case1(); + + }; UnitTest::UnitTest() From 5a05aa4a197550c2e8527d519e1cd4d3a24f618d Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Sun, 12 Jan 2020 20:23:39 +0100 Subject: [PATCH 03/14] start of unit test --- src/GUI/IntelliPhotoGui.h | 56 ++++++------ src/Image/IntelliImage.h | 4 + src/Image/IntelliRasterImage.h | 4 + src/Image/IntelliShapedImage.h | 4 + src/IntelliHelper/IntelliColorPicker.h | 4 + src/IntelliHelper/IntelliRenderSettings.h | 4 + src/IntelliHelper/IntelliToolsettings.h | 4 + src/IntelliHelper/IntelliTriangulation.h | 3 + src/Layer/PaintingArea.cpp | 14 --- src/Layer/PaintingArea.h | 4 + src/Tool/IntelliColorPicker.cpp | 36 -------- src/Tool/IntelliTool.h | 4 + src/Tool/IntelliToolCircle.h | 5 ++ src/Tool/IntelliToolFloodFill.h | 5 ++ src/Tool/IntelliToolLine.h | 4 + src/Tool/IntelliToolPen.h | 4 + src/Tool/IntelliToolPlain.h | 5 ++ src/Tool/IntelliToolPolygon.h | 5 ++ src/Tool/IntelliToolRectangle.h | 5 ++ src/UnitTest.pro | 3 +- src/mainUnitTest.cpp | 100 +++++++++++++++++----- 21 files changed, 180 insertions(+), 97 deletions(-) delete mode 100644 src/Tool/IntelliColorPicker.cpp 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() From e1571c4bc806d41b6b60555a11bd9b569d94e84b Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Sun, 12 Jan 2020 22:14:29 +0100 Subject: [PATCH 04/14] working setup for unit tests --- src/{UnitTest.pro => IntelliUnitTest.pro} | 12 +- src/mainUnitTest.cpp | 83 +++++++++- src/tst_unittest.cpp | 191 ++++++++++++++++++++++ 3 files changed, 274 insertions(+), 12 deletions(-) rename src/{UnitTest.pro => IntelliUnitTest.pro} (90%) create mode 100644 src/tst_unittest.cpp diff --git a/src/UnitTest.pro b/src/IntelliUnitTest.pro similarity index 90% rename from src/UnitTest.pro rename to src/IntelliUnitTest.pro index 0ac2ecf..6e41ba3 100644 --- a/src/UnitTest.pro +++ b/src/IntelliUnitTest.pro @@ -1,12 +1,15 @@ QT += testlib -QT += gui -CONFIG += qt warn_on depend_includepath testcase +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + TEMPLATE = app -SOURCES += \ +SOURCES += tst_unittest.cpp \ GUI/IntelliPhotoGui.cpp \ Image/IntelliImage.cpp \ Image/IntelliRasterImage.cpp \ @@ -23,8 +26,7 @@ SOURCES += \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ Tool/IntelliToolPolygon.cpp \ - Tool/IntelliToolRectangle.cpp \ - mainUnitTest.cpp + Tool/IntelliToolRectangle.cpp DISTFILES += \ icons/Wechselpfeile.png \ diff --git a/src/mainUnitTest.cpp b/src/mainUnitTest.cpp index ce7d13f..4302e27 100644 --- a/src/mainUnitTest.cpp +++ b/src/mainUnitTest.cpp @@ -20,7 +20,7 @@ public: private slots: void initTestCase(); void cleanupTestCase(); - void test_case1(); + //void test_case1(); //test painting area void test_addLayer(); @@ -121,12 +121,81 @@ void UnitTest::cleanupTestCase() delete app; } -void UnitTest::test_case1() -{ - QBENCHMARK { - QVERIFY(1 == 1); - } -} +//void UnitTest::test_case1() +//{ +// QBENCHMARK { +// QVERIFY(1 == 1); +// } +//} + +//test painting area +void UnitTest::test_addLayer(){} +void UnitTest::test_deleteLayer(){} +void UnitTest::test_setActive(){} +void UnitTest::test_setAlpha(){} +void UnitTest::test_floodFill(){} +void UnitTest::test_moveActive(){} +void UnitTest::test_setPolygon(){} +void UnitTest::test_setLayerUp(){} +void UnitTest::test_setLayerDown(){} + +void UnitTest::test_createTools(){} + +//test Raster-Image operations +void UnitTest::test_RasterImage_drawPixel(){} +void UnitTest::test_RasterImage_drawLine(){} +void UnitTest::test_RasterImage_drawPoint(){} +void UnitTest::test_RasterImage_getDisplayable(){} +void UnitTest::test_RasterImage_setPolygon(){} +void UnitTest::test_RasterImage_loadImage(){} +void UnitTest::test_RasterImage_getPixelColor(){} +void UnitTest::test_RasterImage_getImageData(){} +void UnitTest::test_RasterImage_setImageData(){} + +//test Shaped-Image operations +void UnitTest::test_ShapedImage_drawPixel(){} +void UnitTest::test_ShapedImage_drawLine(){} +void UnitTest::test_ShapedImage_drawPoint(){} +void UnitTest::test_ShapedImage_getDisplayable(){} +void UnitTest::test_ShapedImage_setPolygon(){} +void UnitTest::test_ShapedImage_loadImage(){} +void UnitTest::test_ShapedImage_getPixelColor(){} +void UnitTest::test_ShapedImage_getImageData(){} +void UnitTest::test_ShapedImage_setImageData(){} + +//test painting-area tools +void UnitTest::test_createTool_Circle(){} +void UnitTest::test_createTool_FloodFill(){} +void UnitTest::test_createTool_Line(){} +void UnitTest::test_createTool_Pen(){} +void UnitTest::test_createTool_Plain(){} +void UnitTest::test_createTool_Polygon(){} +void UnitTest::test_createTool_Rectangle(){} + +//test tools +void UnitTest::test_Circle_fullDraw(){} +void UnitTest::test_Circle_interruptedDraw(){} + +void UnitTest::test_FloodFill_fullDraw(){} +void UnitTest::test_FloodFill_interruptedDraw(){} + +void UnitTest::test_Line_fullDraw(){} +void UnitTest::test_Line_interruptedDraw(){} + +void UnitTest::test_Pen_fullDraw(){} +void UnitTest::test_Pen_interruptedDraw(){} + +void UnitTest::test_Plain_fullDraw(){} +void UnitTest::test_Plain_interruptedDraw(){} + +void UnitTest::test_Polygon_fullDraw(){} +void UnitTest::test_Polygon_interruptedDraw(){} + +void UnitTest::test_Rectangle_fullDraw(){} +void UnitTest::test_Rectangle_interruptedDraw(){} + +//test Triangulation +void UnitTest::test_Triangulation_Coverage(){} QTEST_APPLESS_MAIN(UnitTest) diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp new file mode 100644 index 0000000..e320994 --- /dev/null +++ b/src/tst_unittest.cpp @@ -0,0 +1,191 @@ +#include +#include +// add necessary includes here +#include "GUI/IntelliPhotoGui.h" + +class UnitTest : public QObject +{ + Q_OBJECT +private: + IntelliPhotoGui* gui; + PaintingArea* area; + +public: + UnitTest(); + ~UnitTest(); + +private slots: + void initTestCase(); + 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() +{ + gui = new IntelliPhotoGui(); + area = gui->paintingArea; +} + +UnitTest::~UnitTest() +{ + +} + +void UnitTest::initTestCase() +{ + +} + +void UnitTest::cleanupTestCase() +{ + delete gui; +} + +//void UnitTest::test_case1() +//{ +// QBENCHMARK { +// QVERIFY(1 == 1); +// } +//} + +//test painting area +void UnitTest::test_addLayer(){} +void UnitTest::test_deleteLayer(){} +void UnitTest::test_setActive(){} +void UnitTest::test_setAlpha(){} +void UnitTest::test_floodFill(){} +void UnitTest::test_moveActive(){} +void UnitTest::test_setPolygon(){} +void UnitTest::test_setLayerUp(){} +void UnitTest::test_setLayerDown(){} + +void UnitTest::test_createTools(){} + +//test Raster-Image operations +void UnitTest::test_RasterImage_drawPixel(){} +void UnitTest::test_RasterImage_drawLine(){} +void UnitTest::test_RasterImage_drawPoint(){} +void UnitTest::test_RasterImage_getDisplayable(){} +void UnitTest::test_RasterImage_setPolygon(){} +void UnitTest::test_RasterImage_loadImage(){} +void UnitTest::test_RasterImage_getPixelColor(){} +void UnitTest::test_RasterImage_getImageData(){} +void UnitTest::test_RasterImage_setImageData(){} + +//test Shaped-Image operations +void UnitTest::test_ShapedImage_drawPixel(){} +void UnitTest::test_ShapedImage_drawLine(){} +void UnitTest::test_ShapedImage_drawPoint(){} +void UnitTest::test_ShapedImage_getDisplayable(){} +void UnitTest::test_ShapedImage_setPolygon(){} +void UnitTest::test_ShapedImage_loadImage(){} +void UnitTest::test_ShapedImage_getPixelColor(){} +void UnitTest::test_ShapedImage_getImageData(){} +void UnitTest::test_ShapedImage_setImageData(){} + +//test painting-area tools +void UnitTest::test_createTool_Circle(){} +void UnitTest::test_createTool_FloodFill(){} +void UnitTest::test_createTool_Line(){} +void UnitTest::test_createTool_Pen(){} +void UnitTest::test_createTool_Plain(){} +void UnitTest::test_createTool_Polygon(){} +void UnitTest::test_createTool_Rectangle(){} + +//test tools +void UnitTest::test_Circle_fullDraw(){} +void UnitTest::test_Circle_interruptedDraw(){} + +void UnitTest::test_FloodFill_fullDraw(){} +void UnitTest::test_FloodFill_interruptedDraw(){} + +void UnitTest::test_Line_fullDraw(){} +void UnitTest::test_Line_interruptedDraw(){} + +void UnitTest::test_Pen_fullDraw(){} +void UnitTest::test_Pen_interruptedDraw(){} + +void UnitTest::test_Plain_fullDraw(){} +void UnitTest::test_Plain_interruptedDraw(){} + +void UnitTest::test_Polygon_fullDraw(){} +void UnitTest::test_Polygon_interruptedDraw(){} + +void UnitTest::test_Rectangle_fullDraw(){} +void UnitTest::test_Rectangle_interruptedDraw(){} + +//test Triangulation +void UnitTest::test_Triangulation_Coverage(){} + +QTEST_MAIN(UnitTest) + +#include "tst_unittest.moc" From 371869308383b41bac5db5de9b129b4d613dd155 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Tue, 14 Jan 2020 21:49:14 +0100 Subject: [PATCH 05/14] nearly all tests but without benchmark --- src/Image/IntelliImage.cpp | 27 +- src/Layer/PaintingArea.cpp | 12 +- src/Layer/PaintingArea.h | 2 +- src/Tool/IntelliToolFloodFill.cpp | 17 +- src/tst_unittest.cpp | 979 +++++++++++++++++++++++++++--- 5 files changed, 947 insertions(+), 90 deletions(-) diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 0fa97b2..042e01f 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -59,13 +59,16 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); } // Used to draw on the widget - QPainter painter(&imageData); + QPainter* painter = new QPainter(&imageData); // Set the current settings for the pen - painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter->setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); // Draw a line from the last registered point to the current - painter.drawPoint(p1); + painter->drawPoint(p1); + delete painter; + painter = nullptr; + if(fastRenderering){ this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); } @@ -76,12 +79,15 @@ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& p this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); } // Used to draw on the widget - QPainter painter(&imageData); + QPainter* painter = new QPainter(&imageData); // Set the current settings for the pen - painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter->setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); // Draw a line from the last registered point to the current - painter.drawPoint(p1); + painter->drawPoint(p1); + delete painter; + + painter = nullptr; if(fastRenderering){ this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); } @@ -92,13 +98,16 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); } // Used to draw on the widget - QPainter painter(&imageData); + QPainter* painter = new QPainter(&imageData); // Set the current settings for the pen - painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter->setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); // Draw a line from the last registered point to the current - painter.drawLine(p1, p2); + painter->drawLine(p1, p2); + delete painter; + painter = nullptr; + if(fastRenderering){ this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); } diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index e2df40d..224cf80 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -67,7 +67,7 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff void PaintingArea::deleteLayer(int idx){ - if(idx(layerBundle.size())) { + if(idx < static_cast(layerBundle.size())&&idx>=0) { this->layerBundle.erase(layerBundle.begin()+idx); if(activeLayer>=idx) { activeLayer--; @@ -93,7 +93,9 @@ void PaintingArea::setLayerActive(int idx){ void PaintingArea::setLayerAlpha(int idx, int alpha){ if(idx>=0&&idx(layerBundle.size())) { - layerBundle[static_cast(idx)].alpha=alpha; + if(alpha>=0 && alpha<=255) { + layerBundle[static_cast(idx)].alpha=alpha; + } } } @@ -138,6 +140,12 @@ void PaintingArea::floodFill(int r, int g, int b, int a){ if(this->activeLayer==-1) { return; } + if(r >255 || g>255|| b>255 || a>255){ + return; + } + if(r < 0 || g < 0|| b < 0 || a < 0){ + return; + } IntelliImage* active = layerBundle[static_cast(activeLayer)].image; active->drawPlain(QColor(r, g, b, a)); update(); diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 666a6a7..72c6b59 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -135,7 +135,7 @@ public: void movePositionActive(int x, int y); /*! * \brief The moveActiveLayer moves the active layer to a specific position in the layer stack - * \param idx - The index of the new position the layer should be in + * \param idx - The direction the layer should move */ void moveActiveLayer(int idx); diff --git a/src/Tool/IntelliToolFloodFill.cpp b/src/Tool/IntelliToolFloodFill.cpp index cb135f8..b4d49c2 100644 --- a/src/Tool/IntelliToolFloodFill.cpp +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -25,7 +25,7 @@ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ if(!(x>=0 && xgetWidthOfActive() && y>=0 && ygetHeightOfActive())) { return; - } + } IntelliTool::onMouseLeftPressed(x,y); QPoint start(x,y); @@ -33,7 +33,10 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ Q.push(start); QColor oldColor = this->activeLayer->image->getPixelColor(start); - QColor newColor = this->colorPicker->getFirstColor(); + QColor newColor = this->colorPicker->getFirstColor(); + if(newColor == oldColor){ + return; + } Canvas->image->drawPixel(start,newColor); QPoint left, right, top, down; @@ -45,20 +48,20 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ right = QPoint(Current.x()+1,Current.y() ); top = QPoint(Current.x(),Current.y()-1); down = QPoint(Current.x(),Current.y()+1); - if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) { + if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) { Canvas->image->drawPixel(right,newColor); Q.push(right); } - if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) { + if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) { Canvas->image->drawPixel(left,newColor); Q.push(left); } - if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) { + if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) { Canvas->image->drawPixel(top,newColor); Q.push(top); } - if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) { - Canvas->image->drawPixel(down,newColor); + if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) { + Canvas->image->drawPixel(down,newColor); Q.push(down); } } diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index e320994..dd3bc01 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -2,6 +2,22 @@ #include // add necessary includes here #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 { @@ -37,8 +53,6 @@ private slots: 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(); @@ -48,21 +62,10 @@ private slots: 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(); @@ -110,81 +113,915 @@ void UnitTest::cleanupTestCase() delete gui; } -//void UnitTest::test_case1() -//{ -// QBENCHMARK { -// QVERIFY(1 == 1); -// } -//} - //test painting area -void UnitTest::test_addLayer(){} -void UnitTest::test_deleteLayer(){} -void UnitTest::test_setActive(){} -void UnitTest::test_setAlpha(){} -void UnitTest::test_floodFill(){} -void UnitTest::test_moveActive(){} -void UnitTest::test_setPolygon(){} -void UnitTest::test_setLayerUp(){} -void UnitTest::test_setLayerDown(){} +void UnitTest::test_addLayer(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); -void UnitTest::test_createTools(){} + QCOMPARE(area->layerBundle.size(), 1); + QCOMPARE(area->activeLayer, 0); + + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].width, 200); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].widthOffset, 10); + + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].height, 400); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].heightOffset, 20); + + area->deleteLayer(0); +} + +void UnitTest::test_deleteLayer(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->deleteLayer(3); + QCOMPARE(area->layerBundle.size(), 2); + QCOMPARE(area->activeLayer, 1); + + area->deleteLayer(-1); + QCOMPARE(area->layerBundle.size(), 2); + QCOMPARE(area->activeLayer, 1); + + area->deleteLayer(1); + QCOMPARE(area->layerBundle.size(), 1); + QCOMPARE(area->activeLayer, 0); + + area->deleteLayer(0); + QCOMPARE(area->layerBundle.size(), 0); + QCOMPARE(area->activeLayer, -1); + +} + +void UnitTest::test_setActive(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->setLayerActive(0); + QCOMPARE(area->activeLayer, 0); + area->setLayerActive(1); + QCOMPARE(area->activeLayer, 1); + area->setLayerActive(-1); + QCOMPARE(area->activeLayer, 1); + area->setLayerActive(3); + QCOMPARE(area->activeLayer, 1); + + area->deleteLayer(0); + area->deleteLayer(0); +} + +void UnitTest::test_setAlpha(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->setLayerAlpha(0,0); + QCOMPARE(area->layerBundle[0].alpha, 0); + + area->setLayerAlpha(0,255); + QCOMPARE(area->layerBundle[0].alpha, 255); + + area->setLayerAlpha(1,123); + QCOMPARE(area->layerBundle[1].alpha, 123); + + area->setLayerAlpha(1,-12); + QCOMPARE(area->layerBundle[1].alpha, 123); + + area->setLayerAlpha(1,300); + QCOMPARE(area->layerBundle[1].alpha, 123); + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::test_floodFill(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->floodFill(255,255,255,255); + QPoint point; + for(size_t i = 0; i<200; i++){ + point.setX(static_cast(i)); + for(size_t j = 0; i<400; i++){ + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(255,255,255,255)); + } + } + + area->floodFill(0,0,0,0); + for(size_t i = 0; i<200; i++){ + point.setX(static_cast(i)); + for(size_t j = 0; i<400; i++){ + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } + + area->floodFill(-1,-1,-1,-1); + for(size_t i = 0; i<200; i++){ + point.setX(static_cast(i)); + for(size_t j = 0; i<400; i++){ + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } + + area->floodFill(256,256,256,256); + for(size_t i = 0; i<200; i++){ + point.setX(static_cast(i)); + for(size_t j = 0; i<400; i++){ + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } + + area->deleteLayer(0); +} + +void UnitTest::test_moveActive(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->floodFill(0,0,0,255); + QPoint point(0,0); + + area->moveActiveLayer(-1); + QCOMPARE(area->activeLayer, 0); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->moveActiveLayer(-1); + QCOMPARE(area->activeLayer, 0); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->moveActiveLayer(1); + QCOMPARE(area->activeLayer, 1); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->moveActiveLayer(1); + QCOMPARE(area->activeLayer, 1); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::test_setPolygon(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; + + area->layerBundle[1].image->setPolygon(polygon); + IntelliShapedImage* image = dynamic_cast(area->layerBundle[1].image); + QCOMPARE(image->polygonData[0], polygon[0]); + QCOMPARE(image->polygonData[1], polygon[1]); + QCOMPARE(image->polygonData[2], polygon[2]); + QCOMPARE(image->polygonData[3], polygon[3]); + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::test_setLayerUp(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->selectLayerUp(); + QCOMPARE(area->activeLayer, 1); + + area->setLayerActive(0); + QCOMPARE(area->activeLayer, 0); + + area->selectLayerUp(); + QCOMPARE(area->activeLayer, 1); + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::test_setLayerDown(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + area->selectLayerDown(); + QCOMPARE(area->activeLayer, 0); + + area->selectLayerDown(); + QCOMPARE(area->activeLayer, 0); + + area->deleteLayer(1); + area->deleteLayer(0); + +} + +void UnitTest::test_createTools(){ + QVERIFY(area->Tool == nullptr); + + area->createPenTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createLineTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createPlainTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createCircleTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createPolygonTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createFloodFillTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); + + area->createRectangleTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); +} //test Raster-Image operations -void UnitTest::test_RasterImage_drawPixel(){} -void UnitTest::test_RasterImage_drawLine(){} -void UnitTest::test_RasterImage_drawPoint(){} -void UnitTest::test_RasterImage_getDisplayable(){} -void UnitTest::test_RasterImage_setPolygon(){} -void UnitTest::test_RasterImage_loadImage(){} -void UnitTest::test_RasterImage_getPixelColor(){} -void UnitTest::test_RasterImage_getImageData(){} -void UnitTest::test_RasterImage_setImageData(){} +void UnitTest::test_RasterImage_drawPixel(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + + QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_drawLine(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(0,0); + QPoint point2(10,10); + QPoint point3(5,5); + QPoint point4(6,5); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_drawPoint(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(5,5); + QPoint point2(5,6); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); + + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_getDisplayable(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + area->floodFill(255,255,255,255); + QImage img = area->layerBundle[0].image->getDisplayable(QSize(200,400),255); + QPoint point; + for(size_t i=0; i<200; i++){ + point.setX(static_cast(i)); + for(size_t j=0; j<400; j++){ + point.setY(static_cast(j)); + QVERIFY(img.pixelColor(point) == QColor(255,255,255,255)); + } + } + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_getPixelColor(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + area->floodFill(0,0,0,255); + QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_getImageData(){ + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); + + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + QImage cpy = area->layerBundle[0].image->getImageData(); + + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); + QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); + QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); + QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_setImageData(){ + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); + + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); + + area->deleteLayer(0); +} //test Shaped-Image operations -void UnitTest::test_ShapedImage_drawPixel(){} -void UnitTest::test_ShapedImage_drawLine(){} -void UnitTest::test_ShapedImage_drawPoint(){} -void UnitTest::test_ShapedImage_getDisplayable(){} -void UnitTest::test_ShapedImage_setPolygon(){} -void UnitTest::test_ShapedImage_loadImage(){} -void UnitTest::test_ShapedImage_getPixelColor(){} -void UnitTest::test_ShapedImage_getImageData(){} -void UnitTest::test_ShapedImage_setImageData(){} +void UnitTest::test_ShapedImage_drawPixel(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); -//test painting-area tools -void UnitTest::test_createTool_Circle(){} -void UnitTest::test_createTool_FloodFill(){} -void UnitTest::test_createTool_Line(){} -void UnitTest::test_createTool_Pen(){} -void UnitTest::test_createTool_Plain(){} -void UnitTest::test_createTool_Polygon(){} -void UnitTest::test_createTool_Rectangle(){} + QPoint point(0,0); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + + QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_drawLine(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(0,0); + QPoint point2(10,10); + QPoint point3(5,5); + QPoint point4(6,5); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_drawPoint(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(5,5); + QPoint point2(5,6); + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); + + + area->floodFill(255,255,255,255); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_getDisplayable(){ + area->addLayer(21,21,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + area->floodFill(255,255,255,255); + area->layerBundle[0].image->setPolygon(points); + QSize size(21,21); + QImage img = area->layerBundle[0].image->getDisplayable(size,255); + + QCOMPARE(img.pixelColor(points[0]).alpha(), 255); + QCOMPARE(img.pixelColor(points[1]).alpha(), 255); + QCOMPARE(img.pixelColor(points[2]).alpha(), 255); + QCOMPARE(img.pixelColor(points[3]).alpha(), 255); + + QCOMPARE(img.pixelColor(test[4]).alpha(), 255); + QCOMPARE(img.pixelColor(test[0]).alpha(), 0); + QCOMPARE(img.pixelColor(test[1]).alpha(), 0); + QCOMPARE(img.pixelColor(test[2]).alpha(), 0); + QCOMPARE(img.pixelColor(test[3]).alpha(), 0); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_getPixelColor(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + area->floodFill(0,0,0,255); + QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_getImageData(){ + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); + + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + QImage cpy = area->layerBundle[0].image->getImageData(); + + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); + QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); + QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); + QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_setImageData(){ + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); + + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); + + area->deleteLayer(0); +} //test tools -void UnitTest::test_Circle_fullDraw(){} -void UnitTest::test_Circle_interruptedDraw(){} +void UnitTest::test_Circle_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->floodFill(255,0,0,255); -void UnitTest::test_FloodFill_fullDraw(){} -void UnitTest::test_FloodFill_interruptedDraw(){} + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); -void UnitTest::test_Line_fullDraw(){} -void UnitTest::test_Line_interruptedDraw(){} -void UnitTest::test_Pen_fullDraw(){} -void UnitTest::test_Pen_interruptedDraw(){} + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); -void UnitTest::test_Plain_fullDraw(){} -void UnitTest::test_Plain_interruptedDraw(){} + area->deleteLayer(0); +} -void UnitTest::test_Polygon_fullDraw(){} -void UnitTest::test_Polygon_interruptedDraw(){} +void UnitTest::test_Circle_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->floodFill(255,0,0,255); -void UnitTest::test_Rectangle_fullDraw(){} -void UnitTest::test_Rectangle_interruptedDraw(){} + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + + area->deleteLayer(0); + +} + +void UnitTest::test_FloodFill_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + + area->deleteLayer(0); +} + +void UnitTest::test_FloodFill_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Line_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + + area->deleteLayer(0); +} + +void UnitTest::test_Line_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Pen_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + + area->deleteLayer(0); +} + +void UnitTest::test_Pen_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Plain_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + + area->deleteLayer(0); +} + +void UnitTest::test_Plain_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Polygon_fullDraw(){ + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); + area->Tool->onMouseMoved(points[1].x(), points[1].x()); + + area->Tool->onMouseLeftPressed(points[1].x(), points[1].x()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].x()); + area->Tool->onMouseMoved(points[2].x(), points[2].x()); + + area->Tool->onMouseLeftPressed(points[2].x(), points[2].x()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].x()); + area->Tool->onMouseMoved(points[3].x(), points[3].x()); + + area->Tool->onMouseLeftPressed(points[3].x(), points[3].x()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].x()); + area->Tool->onMouseMoved(points[0].x(), points[0].x()); + + area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); + + QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==area->colorPicker.getFirstColor()); + + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==area->colorPicker.getSecondColor()); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Polygon_interruptedDraw(){ + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); + area->Tool->onMouseMoved(points[1].x(), points[1].x()); + + area->Tool->onMouseLeftPressed(points[1].x(), points[1].x()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].x()); + area->Tool->onMouseMoved(points[2].x(), points[2].x()); + + area->Tool->onMouseLeftPressed(points[2].x(), points[2].x()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].x()); + area->Tool->onMouseMoved(points[3].x(), points[3].x()); + + area->Tool->onMouseLeftPressed(points[3].x(), points[3].x()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].x()); + area->Tool->onMouseMoved(points[0].x(), points[0].x()); + + area->Tool->onMouseRightPressed(points[0].x(), points[0].x()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].x()); + + //QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==QColor(255,0,0,255)); + + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + //QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + + area->deleteLayer(0); +} + +void UnitTest::test_Rectangle_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,150); + QPoint point3(125,125); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==area->colorPicker.getSecondColor()); + + area->deleteLayer(0); +} + +void UnitTest::test_Rectangle_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,150); + QPoint point3(125,125); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(255,0,0,255)); + + area->deleteLayer(0); +} //test Triangulation -void UnitTest::test_Triangulation_Coverage(){} +void UnitTest::test_Triangulation_Coverage(){ + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + std::vector tria = IntelliTriangulation::calculateTriangles(points); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[0]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[1]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[2]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[3]), true); + + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[4]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[0]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[1]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[2]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[3]), false); +} QTEST_MAIN(UnitTest) From 84f6bc84da3d50c485b3ac55c61d6a25ab727e95 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Tue, 14 Jan 2020 22:32:17 +0100 Subject: [PATCH 06/14] all unitTest but withouzt benchmarking --- src/Tool/IntelliToolPolygon.cpp | 5 +- src/tst_unittest.cpp | 111 ++++++++++++++++---------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 452c2bc..4cc5fa7 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -19,12 +19,12 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); isInside = IntelliTriangulation::isInPolygon(Triangles,Point); } - else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; } @@ -62,7 +62,6 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ isInside = false; - isDrawing = false; isPointNearStart = false; QPointList.clear(); IntelliTool::onMouseRightPressed(x,y); diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index dd3bc01..7432d16 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -859,93 +859,94 @@ void UnitTest::test_Polygon_fullDraw(){ area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); + area->createPolygonTool(); area->floodFill(255,0,0,255); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); - area->Tool->onMouseMoved(points[1].x(), points[1].x()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].x()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].x()); - area->Tool->onMouseMoved(points[2].x(), points[2].x()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].x()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].x()); - area->Tool->onMouseMoved(points[3].x(), points[3].x()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].x()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].x()); - area->Tool->onMouseMoved(points[0].x(), points[0].x()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==area->colorPicker.getFirstColor()); QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==area->colorPicker.getFirstColor()); QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==area->colorPicker.getFirstColor()); QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==area->colorPicker.getFirstColor()); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==area->colorPicker.getSecondColor()); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + + QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); area->deleteLayer(0); } void UnitTest::test_Polygon_interruptedDraw(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) + QPoint(100,000), + QPoint(000,100), + QPoint(100,200), + QPoint(200,100) }; std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) + QPoint(000,000), + QPoint(000,200), + QPoint(200,000), + QPoint(200,200), + QPoint(100,100) }; area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); + area->createPolygonTool(); area->floodFill(255,0,0,255); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].x()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].x()); - area->Tool->onMouseMoved(points[1].x(), points[1].x()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].x()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].x()); - area->Tool->onMouseMoved(points[2].x(), points[2].x()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].x()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].x()); - area->Tool->onMouseMoved(points[3].x(), points[3].x()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].x()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].x()); - area->Tool->onMouseMoved(points[0].x(), points[0].x()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseRightPressed(points[0].x(), points[0].x()); - area->Tool->onMouseRightReleased(points[0].x(), points[0].x()); + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); - //QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); - //QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==QColor(255,0,0,255)); + + QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); area->deleteLayer(0); } @@ -976,7 +977,7 @@ void UnitTest::test_Rectangle_interruptedDraw(){ area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPenTool(); + area->createRectangleTool(); area->floodFill(255,0,0,255); QPoint point1(100,100); From d17bf4850cc01b1a566b71df232c65eddd41ce93 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Wed, 15 Jan 2020 18:09:23 +0100 Subject: [PATCH 07/14] all benchmark just polygon interrupt missing --- src/Image/IntelliRasterImage.cpp | 1 - src/Tool/IntelliTool.cpp | 2 +- src/Tool/IntelliToolPolygon.cpp | 23 +- src/Tool/IntelliToolPolygon.h | 4 +- src/tst_unittest.cpp | 719 +++++++++++++++++++++++++++++++ 5 files changed, 734 insertions(+), 15 deletions(-) diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 8872cff..6ebf497 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -47,6 +47,5 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ } void IntelliRasterImage::setPolygon(const std::vector& polygonData){ - qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n"; return; } diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 2dd2272..7f5b54f 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -5,9 +5,9 @@ IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, In this->Area=Area; this->colorPicker=colorPicker; this->Toolsettings=Toolsettings; + this->isDrawing = false; } - IntelliTool::~IntelliTool(){ } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 4cc5fa7..57eb7c1 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -7,38 +7,38 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ isPointNearStart = false; - isDrawing = false; + drawingOfPolygon = false; isInside = false; this->ActiveType = Tooltype::POLYGON; } IntelliToolPolygon::~IntelliToolPolygon(){ - if(isDrawing) { + if(drawingOfPolygon) { IntelliTool::onMouseRightPressed(0,0); } } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); isInside = IntelliTriangulation::isInPolygon(Triangles,Point); } - else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; } - if(isInside && !isDrawing) { + if(isInside && !drawingOfPolygon) { IntelliTool::onMouseLeftPressed(x,y); QPoint drawingPoint = QPoint(x,y); - isDrawing = true; + drawingOfPolygon = true; QPointList.push_back(drawingPoint); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } - else if(isDrawing && isNearStart(x,y,QPointList.front())) { + else if(drawingOfPolygon && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); @@ -46,13 +46,14 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ } else{ isInside = false; - isDrawing = false; + drawingOfPolygon = false; QPointList.clear(); IntelliTool::onMouseRightPressed(x,y); + IntelliTool::onMouseRightReleased(x,y); } } - else if(isDrawing) { + else if(drawingOfPolygon) { QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); @@ -71,7 +72,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { isInside = false; isPointNearStart = false; - isDrawing = false; + drawingOfPolygon = false; std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; QColor colorTwo(colorPicker->getSecondColor()); @@ -99,7 +100,7 @@ void IntelliToolPolygon::onMouseRightReleased(int x, int y){ void IntelliToolPolygon::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - if(!isDrawing) { + if(!drawingOfPolygon) { Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value); } } diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index cb6365a..fa0cea9 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -25,9 +25,9 @@ class IntelliToolPolygon : public IntelliTool bool isNearStart(int x, int y, QPoint Startpoint); /*! - * \brief IsDrawing true while drawing, else false. + * \brief drawingOfPolygon true while drawing, else false. */ -bool isDrawing; +bool drawingOfPolygon; /*! * \brief isInside Checks if Point is inside Image diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index 7432d16..f5692c2 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -35,6 +35,8 @@ private slots: void cleanupTestCase(); //void test_case1(); + ///Test here + //test painting area void test_addLayer(); void test_deleteLayer(); @@ -90,6 +92,65 @@ private slots: //test Triangulation void test_Triangulation_Coverage(); + + + ///Benchmark here + + //bench painting area + void bench_addLayer(); + void bench_deleteLayer(); + void bench_setActive(); + void bench_setAlpha(); + void bench_floodFill(); + void bench_moveActive(); + void bench_setPolygon(); + void bench_setLayerUp(); + void bench_setLayerDown(); + + void bench_createTools(); + + //bench Raster-Image operations + void bench_RasterImage_drawPixel(); + void bench_RasterImage_drawLine(); + void bench_RasterImage_drawPoint(); + void bench_RasterImage_getDisplayable(); + void bench_RasterImage_getPixelColor(); + void bench_RasterImage_getImageData(); + void bench_RasterImage_setImageData(); + + //bench Shaped-Image operations + void bench_ShapedImage_drawPixel(); + void bench_ShapedImage_drawLine(); + void bench_ShapedImage_drawPoint(); + void bench_ShapedImage_getDisplayable(); + void bench_ShapedImage_getPixelColor(); + void bench_ShapedImage_getImageData(); + void bench_ShapedImage_setImageData(); + + //bench tools + void bench_Circle_fullDraw(); + void bench_Circle_interruptedDraw(); + + void bench_FloodFill_fullDraw(); + void bench_FloodFill_interruptedDraw(); + + void bench_Line_fullDraw(); + void bench_Line_interruptedDraw(); + + void bench_Pen_fullDraw(); + void bench_Pen_interruptedDraw(); + + void bench_Plain_fullDraw(); + void bench_Plain_interruptedDraw(); + + void bench_Polygon_fullDraw(); + //void bench_Polygon_interruptedDraw(); + + void bench_Rectangle_fullDraw(); + void bench_Rectangle_interruptedDraw(); + + //bench Triangulation + void bench_Triangulation_Coverage(); }; UnitTest::UnitTest() @@ -672,6 +733,7 @@ void UnitTest::test_Circle_interruptedDraw(){ } + void UnitTest::test_FloodFill_fullDraw(){ area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); @@ -714,6 +776,7 @@ void UnitTest::test_FloodFill_interruptedDraw(){ area->deleteLayer(0); } + void UnitTest::test_Line_fullDraw(){ area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); @@ -896,6 +959,7 @@ void UnitTest::test_Polygon_fullDraw(){ area->deleteLayer(0); } + void UnitTest::test_Polygon_interruptedDraw(){ area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); std::vector points{ @@ -951,6 +1015,7 @@ void UnitTest::test_Polygon_interruptedDraw(){ area->deleteLayer(0); } + void UnitTest::test_Rectangle_fullDraw(){ area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); @@ -996,6 +1061,7 @@ void UnitTest::test_Rectangle_interruptedDraw(){ area->deleteLayer(0); } + //test Triangulation void UnitTest::test_Triangulation_Coverage(){ std::vector points{ @@ -1024,6 +1090,659 @@ void UnitTest::test_Triangulation_Coverage(){ QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[3]), false); } + + +///Benchmarks here + +void UnitTest::bench_addLayer(){ + QBENCHMARK{ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + } + area->deleteLayer(0); +} + +void UnitTest::bench_deleteLayer(){ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + QBENCHMARK{ + area->deleteLayer(0); + } +} + +void UnitTest::bench_setActive(){ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->setLayerActive(0); + } + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::bench_setAlpha(){ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->setLayerAlpha(0,0); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_floodFill(){ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->floodFill(255,255,255,255); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_moveActive(){ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + + area->setLayerActive(0); + QBENCHMARK{ + area->moveActiveLayer(1); + } + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::bench_setPolygon(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; + + QBENCHMARK{ + area->layerBundle[1].image->setPolygon(polygon); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_setLayerUp(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + area->setLayerActive(0); + QBENCHMARK{ + area->selectLayerUp(); + } + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::bench_setLayerDown(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->selectLayerDown(); + } + + area->deleteLayer(1); + area->deleteLayer(0); +} + +void UnitTest::bench_createTools(){ + QBENCHMARK{ + area->createPenTool(); + } + + QBENCHMARK{ + area->createLineTool(); + } + + QBENCHMARK{ + area->createPlainTool(); + } + + QBENCHMARK{ + area->createCircleTool(); + } + + QBENCHMARK{ + area->createPolygonTool(); + } + + QBENCHMARK{ + area->createFloodFillTool(); + } + + QBENCHMARK{ + area->createRectangleTool(); + } +} + +void UnitTest::bench_RasterImage_drawPixel(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + + QBENCHMARK{ + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_drawLine(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(000,000); + QPoint point2(200,200); + + QBENCHMARK{ + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_drawPoint(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(000,000); + + QBENCHMARK{ + area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_getDisplayable(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getDisplayable(QSize(200,200),255); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_getPixelColor(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(000,000); + + QBENCHMARK{ + area->layerBundle[0].image->getPixelColor(point); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_getImageData(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_setImageData(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QImage img = area->layerBundle[0].image->getImageData(); + QBENCHMARK{ + area->layerBundle[0].image->setImageData(img); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_drawPixel(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QPoint point(0,0); + + QBENCHMARK{ + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_drawLine(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QPoint point1(000,000); + QPoint point2(200,200); + + QBENCHMARK{ + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_drawPoint(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QPoint point(000,000); + + QBENCHMARK{ + area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_getDisplayable(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getDisplayable(QSize(200,200),255); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_getPixelColor(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QPoint point(000,000); + + QBENCHMARK{ + area->layerBundle[0].image->getPixelColor(point); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_getImageData(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_setImageData(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QImage img = area->layerBundle[0].image->getImageData(); + QBENCHMARK{ + area->layerBundle[0].image->setImageData(img); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Circle_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Circle_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + + +void UnitTest::bench_FloodFill_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_FloodFill_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + + +void UnitTest::bench_Line_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Line_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Pen_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Pen_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Plain_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Plain_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Polygon_fullDraw(){ + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->floodFill(255,0,0,255); + + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); + + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); + + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); + + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); + + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + } + + area->deleteLayer(0); +} + +/* +void UnitTest::bench_Polygon_interruptedDraw(){ + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(100,000), + QPoint(000,100), + QPoint(100,200), + QPoint(200,100) + }; + + std::vector test{ + QPoint(000,000), + QPoint(000,200), + QPoint(200,000), + QPoint(200,200), + QPoint(100,100) + }; + + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->floodFill(255,0,0,255); + + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); + + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); + + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); + + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); + } + + area->deleteLayer(0); +} +*/ + +void UnitTest::bench_Rectangle_fullDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,150); + + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_Rectangle_interruptedDraw(){ + area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->floodFill(255,0,0,255); + + QPoint point1(100,100); + QPoint point2(150,150); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } + + area->deleteLayer(0); +} + + +void UnitTest::bench_Triangulation_Coverage(){ + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + + QBENCHMARK{ + std::vector tria = IntelliTriangulation::calculateTriangles(points); + QPoint point; + for(int i=0; i<200; i++){ + point.setX(i); + for(int j=0; j<200; j++){ + point.setY(j); + IntelliTriangulation::isInPolygon(tria, point); + } + } + } +} + + + + + QTEST_MAIN(UnitTest) #include "tst_unittest.moc" From 33c5708ce5b4b237e1cc7e4b092bf98af4b7c324 Mon Sep 17 00:00:00 2001 From: Jonas Mucke Date: Wed, 15 Jan 2020 19:39:15 +0100 Subject: [PATCH 08/14] all tests unified, benchmark and unit test complete --- src/tst_unittest.cpp | 188 ++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 109 deletions(-) diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index f5692c2..1bb3390 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -144,7 +144,7 @@ private slots: void bench_Plain_interruptedDraw(); void bench_Polygon_fullDraw(); - //void bench_Polygon_interruptedDraw(); + void bench_Polygon_interruptedDraw(); void bench_Rectangle_fullDraw(); void bench_Rectangle_interruptedDraw(); @@ -176,7 +176,7 @@ void UnitTest::cleanupTestCase() //test painting area void UnitTest::test_addLayer(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QCOMPARE(area->layerBundle.size(), 1); QCOMPARE(area->activeLayer, 0); @@ -184,15 +184,15 @@ void UnitTest::test_addLayer(){ QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].width, 200); QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].widthOffset, 10); - QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].height, 400); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].height, 200); QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].heightOffset, 20); area->deleteLayer(0); } void UnitTest::test_deleteLayer(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->deleteLayer(3); QCOMPARE(area->layerBundle.size(), 2); @@ -213,8 +213,8 @@ void UnitTest::test_deleteLayer(){ } void UnitTest::test_setActive(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->setLayerActive(0); QCOMPARE(area->activeLayer, 0); @@ -230,8 +230,8 @@ void UnitTest::test_setActive(){ } void UnitTest::test_setAlpha(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->setLayerAlpha(0,0); QCOMPARE(area->layerBundle[0].alpha, 0); @@ -253,13 +253,13 @@ void UnitTest::test_setAlpha(){ } void UnitTest::test_floodFill(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->floodFill(255,255,255,255); QPoint point; for(size_t i = 0; i<200; i++){ point.setX(static_cast(i)); - for(size_t j = 0; i<400; i++){ + for(size_t j = 0; i<200; i++){ point.setY(static_cast(j)); QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(255,255,255,255)); } @@ -268,7 +268,7 @@ void UnitTest::test_floodFill(){ area->floodFill(0,0,0,0); for(size_t i = 0; i<200; i++){ point.setX(static_cast(i)); - for(size_t j = 0; i<400; i++){ + for(size_t j = 0; i<200; i++){ point.setY(static_cast(j)); QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); } @@ -277,7 +277,7 @@ void UnitTest::test_floodFill(){ area->floodFill(-1,-1,-1,-1); for(size_t i = 0; i<200; i++){ point.setX(static_cast(i)); - for(size_t j = 0; i<400; i++){ + for(size_t j = 0; i<200; i++){ point.setY(static_cast(j)); QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); } @@ -286,7 +286,7 @@ void UnitTest::test_floodFill(){ area->floodFill(256,256,256,256); for(size_t i = 0; i<200; i++){ point.setX(static_cast(i)); - for(size_t j = 0; i<400; i++){ + for(size_t j = 0; i<200; i++){ point.setY(static_cast(j)); QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); } @@ -296,8 +296,8 @@ void UnitTest::test_floodFill(){ } void UnitTest::test_moveActive(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->floodFill(0,0,0,255); QPoint point(0,0); @@ -323,8 +323,8 @@ void UnitTest::test_moveActive(){ } void UnitTest::test_setPolygon(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); std::vector polygon{ QPoint(10,00), @@ -345,8 +345,8 @@ void UnitTest::test_setPolygon(){ } void UnitTest::test_setLayerUp(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->selectLayerUp(); QCOMPARE(area->activeLayer, 1); @@ -362,8 +362,8 @@ void UnitTest::test_setLayerUp(){ } void UnitTest::test_setLayerDown(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->selectLayerDown(); QCOMPARE(area->activeLayer, 0); @@ -403,7 +403,7 @@ void UnitTest::test_createTools(){ //test Raster-Image operations void UnitTest::test_RasterImage_drawPixel(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(0,0); @@ -416,7 +416,7 @@ void UnitTest::test_RasterImage_drawPixel(){ } void UnitTest::test_RasterImage_drawLine(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point1(0,0); QPoint point2(10,10); @@ -441,7 +441,7 @@ void UnitTest::test_RasterImage_drawLine(){ } void UnitTest::test_RasterImage_drawPoint(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point1(5,5); QPoint point2(5,6); @@ -461,14 +461,14 @@ void UnitTest::test_RasterImage_drawPoint(){ } void UnitTest::test_RasterImage_getDisplayable(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->floodFill(255,255,255,255); - QImage img = area->layerBundle[0].image->getDisplayable(QSize(200,400),255); + QImage img = area->layerBundle[0].image->getDisplayable(QSize(200,200),255); QPoint point; for(size_t i=0; i<200; i++){ point.setX(static_cast(i)); - for(size_t j=0; j<400; j++){ + for(size_t j=0; j<200; j++){ point.setY(static_cast(j)); QVERIFY(img.pixelColor(point) == QColor(255,255,255,255)); } @@ -478,7 +478,7 @@ void UnitTest::test_RasterImage_getDisplayable(){ } void UnitTest::test_RasterImage_getPixelColor(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(0,0); area->floodFill(0,0,0,255); @@ -538,7 +538,7 @@ void UnitTest::test_RasterImage_setImageData(){ //test Shaped-Image operations void UnitTest::test_ShapedImage_drawPixel(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(0,0); @@ -551,7 +551,7 @@ void UnitTest::test_ShapedImage_drawPixel(){ } void UnitTest::test_ShapedImage_drawLine(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point1(0,0); QPoint point2(10,10); @@ -576,7 +576,7 @@ void UnitTest::test_ShapedImage_drawLine(){ } void UnitTest::test_ShapedImage_drawPoint(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point1(5,5); QPoint point2(5,6); @@ -631,7 +631,7 @@ void UnitTest::test_ShapedImage_getDisplayable(){ } void UnitTest::test_ShapedImage_getPixelColor(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(0,0); area->floodFill(0,0,0,255); @@ -691,7 +691,7 @@ void UnitTest::test_ShapedImage_setImageData(){ //test tools void UnitTest::test_Circle_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createCircleTool(); @@ -711,7 +711,7 @@ void UnitTest::test_Circle_fullDraw(){ } void UnitTest::test_Circle_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createCircleTool(); @@ -735,7 +735,7 @@ void UnitTest::test_Circle_interruptedDraw(){ void UnitTest::test_FloodFill_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createFloodFillTool(); @@ -755,7 +755,7 @@ void UnitTest::test_FloodFill_fullDraw(){ } void UnitTest::test_FloodFill_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createFloodFillTool(); @@ -778,7 +778,7 @@ void UnitTest::test_FloodFill_interruptedDraw(){ void UnitTest::test_Line_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createLineTool(); @@ -798,7 +798,7 @@ void UnitTest::test_Line_fullDraw(){ } void UnitTest::test_Line_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createLineTool(); @@ -820,7 +820,7 @@ void UnitTest::test_Line_interruptedDraw(){ } void UnitTest::test_Pen_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPenTool(); @@ -840,7 +840,7 @@ void UnitTest::test_Pen_fullDraw(){ } void UnitTest::test_Pen_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPenTool(); @@ -862,7 +862,7 @@ void UnitTest::test_Pen_interruptedDraw(){ } void UnitTest::test_Plain_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPlainTool(); @@ -882,7 +882,7 @@ void UnitTest::test_Plain_fullDraw(){ } void UnitTest::test_Plain_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPlainTool(); @@ -1017,7 +1017,7 @@ void UnitTest::test_Polygon_interruptedDraw(){ void UnitTest::test_Rectangle_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createRectangleTool(); @@ -1039,7 +1039,7 @@ void UnitTest::test_Rectangle_fullDraw(){ } void UnitTest::test_Rectangle_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createRectangleTool(); @@ -1154,7 +1154,7 @@ void UnitTest::bench_moveActive(){ } void UnitTest::bench_setPolygon(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); std::vector polygon{ QPoint(10,00), @@ -1171,8 +1171,8 @@ void UnitTest::bench_setPolygon(){ } void UnitTest::bench_setLayerUp(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->setLayerActive(0); QBENCHMARK{ @@ -1184,8 +1184,8 @@ void UnitTest::bench_setLayerUp(){ } void UnitTest::bench_setLayerDown(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QBENCHMARK{ area->selectLayerDown(); @@ -1226,7 +1226,7 @@ void UnitTest::bench_createTools(){ } void UnitTest::bench_RasterImage_drawPixel(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(0,0); @@ -1238,7 +1238,7 @@ void UnitTest::bench_RasterImage_drawPixel(){ } void UnitTest::bench_RasterImage_drawLine(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point1(000,000); QPoint point2(200,200); @@ -1251,7 +1251,7 @@ void UnitTest::bench_RasterImage_drawLine(){ } void UnitTest::bench_RasterImage_drawPoint(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(000,000); @@ -1263,7 +1263,7 @@ void UnitTest::bench_RasterImage_drawPoint(){ } void UnitTest::bench_RasterImage_getDisplayable(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QBENCHMARK{ area->layerBundle[0].image->getDisplayable(QSize(200,200),255); @@ -1273,7 +1273,7 @@ void UnitTest::bench_RasterImage_getDisplayable(){ } void UnitTest::bench_RasterImage_getPixelColor(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QPoint point(000,000); @@ -1285,7 +1285,7 @@ void UnitTest::bench_RasterImage_getPixelColor(){ } void UnitTest::bench_RasterImage_getImageData(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QBENCHMARK{ area->layerBundle[0].image->getImageData(); @@ -1295,7 +1295,7 @@ void UnitTest::bench_RasterImage_getImageData(){ } void UnitTest::bench_RasterImage_setImageData(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); QImage img = area->layerBundle[0].image->getImageData(); QBENCHMARK{ @@ -1306,7 +1306,7 @@ void UnitTest::bench_RasterImage_setImageData(){ } void UnitTest::bench_ShapedImage_drawPixel(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QPoint point(0,0); @@ -1318,7 +1318,7 @@ void UnitTest::bench_ShapedImage_drawPixel(){ } void UnitTest::bench_ShapedImage_drawLine(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QPoint point1(000,000); QPoint point2(200,200); @@ -1331,7 +1331,7 @@ void UnitTest::bench_ShapedImage_drawLine(){ } void UnitTest::bench_ShapedImage_drawPoint(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QPoint point(000,000); @@ -1343,7 +1343,7 @@ void UnitTest::bench_ShapedImage_drawPoint(){ } void UnitTest::bench_ShapedImage_getDisplayable(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QBENCHMARK{ area->layerBundle[0].image->getDisplayable(QSize(200,200),255); @@ -1353,7 +1353,7 @@ void UnitTest::bench_ShapedImage_getDisplayable(){ } void UnitTest::bench_ShapedImage_getPixelColor(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QPoint point(000,000); @@ -1365,7 +1365,7 @@ void UnitTest::bench_ShapedImage_getPixelColor(){ } void UnitTest::bench_ShapedImage_getImageData(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QBENCHMARK{ area->layerBundle[0].image->getImageData(); @@ -1375,7 +1375,7 @@ void UnitTest::bench_ShapedImage_getImageData(){ } void UnitTest::bench_ShapedImage_setImageData(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); QImage img = area->layerBundle[0].image->getImageData(); QBENCHMARK{ @@ -1386,7 +1386,7 @@ void UnitTest::bench_ShapedImage_setImageData(){ } void UnitTest::bench_Circle_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createCircleTool(); @@ -1404,7 +1404,7 @@ void UnitTest::bench_Circle_fullDraw(){ } void UnitTest::bench_Circle_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createCircleTool(); @@ -1425,7 +1425,7 @@ void UnitTest::bench_Circle_interruptedDraw(){ void UnitTest::bench_FloodFill_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createFloodFillTool(); @@ -1443,7 +1443,7 @@ void UnitTest::bench_FloodFill_fullDraw(){ } void UnitTest::bench_FloodFill_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createFloodFillTool(); @@ -1464,7 +1464,7 @@ void UnitTest::bench_FloodFill_interruptedDraw(){ void UnitTest::bench_Line_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createLineTool(); @@ -1482,7 +1482,7 @@ void UnitTest::bench_Line_fullDraw(){ } void UnitTest::bench_Line_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createLineTool(); @@ -1503,7 +1503,7 @@ void UnitTest::bench_Line_interruptedDraw(){ } void UnitTest::bench_Pen_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPenTool(); @@ -1521,7 +1521,7 @@ void UnitTest::bench_Pen_fullDraw(){ } void UnitTest::bench_Pen_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPenTool(); @@ -1541,7 +1541,7 @@ void UnitTest::bench_Pen_interruptedDraw(){ } void UnitTest::bench_Plain_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPlainTool(); @@ -1559,7 +1559,7 @@ void UnitTest::bench_Plain_fullDraw(){ } void UnitTest::bench_Plain_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPlainTool(); @@ -1587,14 +1587,6 @@ void UnitTest::bench_Polygon_fullDraw(){ QPoint(20,10) }; - std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) - }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createPolygonTool(); @@ -1624,23 +1616,13 @@ void UnitTest::bench_Polygon_fullDraw(){ area->deleteLayer(0); } -/* + void UnitTest::bench_Polygon_interruptedDraw(){ area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); std::vector points{ - QPoint(100,000), - QPoint(000,100), - QPoint(100,200), - QPoint(200,100) + QPoint(100,000) }; - std::vector test{ - QPoint(000,000), - QPoint(000,200), - QPoint(200,000), - QPoint(200,200), - QPoint(100,100) - }; area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); @@ -1650,18 +1632,6 @@ void UnitTest::bench_Polygon_interruptedDraw(){ QBENCHMARK{ area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); - - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); - - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); - - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); @@ -1669,10 +1639,10 @@ void UnitTest::bench_Polygon_interruptedDraw(){ area->deleteLayer(0); } -*/ + void UnitTest::bench_Rectangle_fullDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createRectangleTool(); @@ -1691,7 +1661,7 @@ void UnitTest::bench_Rectangle_fullDraw(){ } void UnitTest::bench_Rectangle_interruptedDraw(){ - area->addLayer(200,400,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); area->colorPicker.setFirstColor(QColor(255,255,255,255)); area->colorPicker.setSecondColor(QColor(0,0,0,255)); area->createRectangleTool(); From cb4e48865a9be17d17f815ed28c73c67df881811 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 16 Jan 2020 10:30:34 +0100 Subject: [PATCH 09/14] Update .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 6c15b5a..76774be 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,10 @@ CMakeLists.txt.user* app_version.h phony.c +# Testing Files +*.o +*.qmake.stash + # Ignore User Files except for the pro file IntelliPhoto.* !IntelliPhoto.pro From d47e0056f99802e20cf5655fe60747fc8bf8ee64 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 16 Jan 2020 11:05:51 +0100 Subject: [PATCH 10/14] Added fix draft --- src/tst_unittest.cpp | 2240 +++++++++++++++++++++--------------------- 1 file changed, 1118 insertions(+), 1122 deletions(-) diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index 1bb3390..d011b21 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -21,142 +21,142 @@ class UnitTest : public QObject { - Q_OBJECT +Q_OBJECT private: - IntelliPhotoGui* gui; - PaintingArea* area; +IntelliPhotoGui* gui; +PaintingArea* area; public: - UnitTest(); - ~UnitTest(); +UnitTest(); +~UnitTest(); private slots: - void initTestCase(); - void cleanupTestCase(); - //void test_case1(); +void initTestCase(); +void cleanupTestCase(); +//void test_case1(); - ///Test here +///Test here - //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(); +//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(); +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_getPixelColor(); - void test_RasterImage_getImageData(); - void test_RasterImage_setImageData(); +//test Raster-Image operations +void test_RasterImage_drawPixel(); +void test_RasterImage_drawLine(); +void test_RasterImage_drawPoint(); +void test_RasterImage_getDisplayable(); +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_getPixelColor(); - void test_ShapedImage_getImageData(); - void test_ShapedImage_setImageData(); +//test Shaped-Image operations +void test_ShapedImage_drawPixel(); +void test_ShapedImage_drawLine(); +void test_ShapedImage_drawPoint(); +void test_ShapedImage_getDisplayable(); +void test_ShapedImage_getPixelColor(); +void test_ShapedImage_getImageData(); +void test_ShapedImage_setImageData(); - //test tools - void test_Circle_fullDraw(); - void test_Circle_interruptedDraw(); +//test tools +void test_Circle_fullDraw(); +void test_Circle_interruptedDraw(); - void test_FloodFill_fullDraw(); - void test_FloodFill_interruptedDraw(); +void test_FloodFill_fullDraw(); +void test_FloodFill_interruptedDraw(); - void test_Line_fullDraw(); - void test_Line_interruptedDraw(); +void test_Line_fullDraw(); +void test_Line_interruptedDraw(); - void test_Pen_fullDraw(); - void test_Pen_interruptedDraw(); +void test_Pen_fullDraw(); +void test_Pen_interruptedDraw(); - void test_Plain_fullDraw(); - void test_Plain_interruptedDraw(); +void test_Plain_fullDraw(); +void test_Plain_interruptedDraw(); - void test_Polygon_fullDraw(); - void test_Polygon_interruptedDraw(); +void test_Polygon_fullDraw(); +void test_Polygon_interruptedDraw(); - void test_Rectangle_fullDraw(); - void test_Rectangle_interruptedDraw(); +void test_Rectangle_fullDraw(); +void test_Rectangle_interruptedDraw(); - //test Triangulation - void test_Triangulation_Coverage(); +//test Triangulation +void test_Triangulation_Coverage(); - ///Benchmark here +///Benchmark here - //bench painting area - void bench_addLayer(); - void bench_deleteLayer(); - void bench_setActive(); - void bench_setAlpha(); - void bench_floodFill(); - void bench_moveActive(); - void bench_setPolygon(); - void bench_setLayerUp(); - void bench_setLayerDown(); +//bench painting area +void bench_addLayer(); +void bench_deleteLayer(); +void bench_setActive(); +void bench_setAlpha(); +void bench_floodFill(); +void bench_moveActive(); +void bench_setPolygon(); +void bench_setLayerUp(); +void bench_setLayerDown(); - void bench_createTools(); +void bench_createTools(); - //bench Raster-Image operations - void bench_RasterImage_drawPixel(); - void bench_RasterImage_drawLine(); - void bench_RasterImage_drawPoint(); - void bench_RasterImage_getDisplayable(); - void bench_RasterImage_getPixelColor(); - void bench_RasterImage_getImageData(); - void bench_RasterImage_setImageData(); +//bench Raster-Image operations +void bench_RasterImage_drawPixel(); +void bench_RasterImage_drawLine(); +void bench_RasterImage_drawPoint(); +void bench_RasterImage_getDisplayable(); +void bench_RasterImage_getPixelColor(); +void bench_RasterImage_getImageData(); +void bench_RasterImage_setImageData(); - //bench Shaped-Image operations - void bench_ShapedImage_drawPixel(); - void bench_ShapedImage_drawLine(); - void bench_ShapedImage_drawPoint(); - void bench_ShapedImage_getDisplayable(); - void bench_ShapedImage_getPixelColor(); - void bench_ShapedImage_getImageData(); - void bench_ShapedImage_setImageData(); +//bench Shaped-Image operations +void bench_ShapedImage_drawPixel(); +void bench_ShapedImage_drawLine(); +void bench_ShapedImage_drawPoint(); +void bench_ShapedImage_getDisplayable(); +void bench_ShapedImage_getPixelColor(); +void bench_ShapedImage_getImageData(); +void bench_ShapedImage_setImageData(); - //bench tools - void bench_Circle_fullDraw(); - void bench_Circle_interruptedDraw(); +//bench tools +void bench_Circle_fullDraw(); +void bench_Circle_interruptedDraw(); - void bench_FloodFill_fullDraw(); - void bench_FloodFill_interruptedDraw(); +void bench_FloodFill_fullDraw(); +void bench_FloodFill_interruptedDraw(); - void bench_Line_fullDraw(); - void bench_Line_interruptedDraw(); +void bench_Line_fullDraw(); +void bench_Line_interruptedDraw(); - void bench_Pen_fullDraw(); - void bench_Pen_interruptedDraw(); +void bench_Pen_fullDraw(); +void bench_Pen_interruptedDraw(); - void bench_Plain_fullDraw(); - void bench_Plain_interruptedDraw(); +void bench_Plain_fullDraw(); +void bench_Plain_interruptedDraw(); - void bench_Polygon_fullDraw(); - void bench_Polygon_interruptedDraw(); +void bench_Polygon_fullDraw(); +void bench_Polygon_interruptedDraw(); - void bench_Rectangle_fullDraw(); - void bench_Rectangle_interruptedDraw(); +void bench_Rectangle_fullDraw(); +void bench_Rectangle_interruptedDraw(); - //bench Triangulation - void bench_Triangulation_Coverage(); +//bench Triangulation +void bench_Triangulation_Coverage(); }; UnitTest::UnitTest() { - gui = new IntelliPhotoGui(); - area = gui->paintingArea; + gui = new IntelliPhotoGui(); + area = gui->paintingArea; } UnitTest::~UnitTest() @@ -171,1548 +171,1544 @@ void UnitTest::initTestCase() void UnitTest::cleanupTestCase() { - delete gui; + delete gui; } //test painting area void UnitTest::test_addLayer(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QCOMPARE(area->layerBundle.size(), 1); - QCOMPARE(area->activeLayer, 0); + QCOMPARE(area->layerBundle.size(), 1); + QCOMPARE(area->activeLayer, 0); - QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].width, 200); - QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].widthOffset, 10); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].width, 200); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].widthOffset, 10); - QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].height, 200); - QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].heightOffset, 20); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].height, 200); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].heightOffset, 20); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_deleteLayer(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->deleteLayer(3); - QCOMPARE(area->layerBundle.size(), 2); - QCOMPARE(area->activeLayer, 1); + area->deleteLayer(3); + QCOMPARE(area->layerBundle.size(), 2); + QCOMPARE(area->activeLayer, 1); - area->deleteLayer(-1); - QCOMPARE(area->layerBundle.size(), 2); - QCOMPARE(area->activeLayer, 1); + area->deleteLayer(-1); + QCOMPARE(area->layerBundle.size(), 2); + QCOMPARE(area->activeLayer, 1); - area->deleteLayer(1); - QCOMPARE(area->layerBundle.size(), 1); - QCOMPARE(area->activeLayer, 0); + area->deleteLayer(1); + QCOMPARE(area->layerBundle.size(), 1); + QCOMPARE(area->activeLayer, 0); - area->deleteLayer(0); - QCOMPARE(area->layerBundle.size(), 0); - QCOMPARE(area->activeLayer, -1); + area->deleteLayer(0); + QCOMPARE(area->layerBundle.size(), 0); + QCOMPARE(area->activeLayer, -1); } void UnitTest::test_setActive(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->setLayerActive(0); - QCOMPARE(area->activeLayer, 0); - area->setLayerActive(1); - QCOMPARE(area->activeLayer, 1); - area->setLayerActive(-1); - QCOMPARE(area->activeLayer, 1); - area->setLayerActive(3); - QCOMPARE(area->activeLayer, 1); + area->setLayerActive(0); + QCOMPARE(area->activeLayer, 0); + area->setLayerActive(1); + QCOMPARE(area->activeLayer, 1); + area->setLayerActive(-1); + QCOMPARE(area->activeLayer, 1); + area->setLayerActive(3); + QCOMPARE(area->activeLayer, 1); - area->deleteLayer(0); - area->deleteLayer(0); + area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_setAlpha(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->setLayerAlpha(0,0); - QCOMPARE(area->layerBundle[0].alpha, 0); + area->setLayerAlpha(0,0); + QCOMPARE(area->layerBundle[0].alpha, 0); - area->setLayerAlpha(0,255); - QCOMPARE(area->layerBundle[0].alpha, 255); + area->setLayerAlpha(0,255); + QCOMPARE(area->layerBundle[0].alpha, 255); - area->setLayerAlpha(1,123); - QCOMPARE(area->layerBundle[1].alpha, 123); + area->setLayerAlpha(1,123); + QCOMPARE(area->layerBundle[1].alpha, 123); - area->setLayerAlpha(1,-12); - QCOMPARE(area->layerBundle[1].alpha, 123); + area->setLayerAlpha(1,-12); + QCOMPARE(area->layerBundle[1].alpha, 123); - area->setLayerAlpha(1,300); - QCOMPARE(area->layerBundle[1].alpha, 123); + area->setLayerAlpha(1,300); + QCOMPARE(area->layerBundle[1].alpha, 123); - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::test_floodFill(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->floodFill(255,255,255,255); - QPoint point; - for(size_t i = 0; i<200; i++){ - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++){ - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(255,255,255,255)); - } - } + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + QPoint point; + for(size_t i = 0; i<200; i++) { + point.setX(static_cast(i)); + for(size_t j = 0; i<200; i++) { + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(255,255,255,255)); + } + } - area->floodFill(0,0,0,0); - for(size_t i = 0; i<200; i++){ - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++){ - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } + area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 0)); + for(size_t i = 0; i<200; i++) { + point.setX(static_cast(i)); + for(size_t j = 0; i<200; i++) { + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } - area->floodFill(-1,-1,-1,-1); - for(size_t i = 0; i<200; i++){ - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++){ - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } + area->layerBundle[0].image->drawPlain(QColor(-1, -1, -1, -1)); + for(size_t i = 0; i<200; i++) { + point.setX(static_cast(i)); + for(size_t j = 0; i<200; i++) { + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } - area->floodFill(256,256,256,256); - for(size_t i = 0; i<200; i++){ - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++){ - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } + area->layerBundle[0].image->drawPlain(QColor(256, 256, 256, 256)); + for(size_t i = 0; i<200; i++) { + point.setX(static_cast(i)); + for(size_t j = 0; i<200; i++) { + point.setY(static_cast(j)); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); + } + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_moveActive(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->floodFill(0,0,0,255); - QPoint point(0,0); + area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 255)); + QPoint point(0,0); - area->moveActiveLayer(-1); - QCOMPARE(area->activeLayer, 0); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + area->moveActiveLayer(-1); + QCOMPARE(area->activeLayer, 0); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); - area->moveActiveLayer(-1); - QCOMPARE(area->activeLayer, 0); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + area->moveActiveLayer(-1); + QCOMPARE(area->activeLayer, 0); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); - area->moveActiveLayer(1); - QCOMPARE(area->activeLayer, 1); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + area->moveActiveLayer(1); + QCOMPARE(area->activeLayer, 1); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); - area->moveActiveLayer(1); - QCOMPARE(area->activeLayer, 1); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); + area->moveActiveLayer(1); + QCOMPARE(area->activeLayer, 1); + QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,255)); - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::test_setPolygon(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - std::vector polygon{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,10), - QPoint(00,10) - }; + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; - area->layerBundle[1].image->setPolygon(polygon); - IntelliShapedImage* image = dynamic_cast(area->layerBundle[1].image); - QCOMPARE(image->polygonData[0], polygon[0]); - QCOMPARE(image->polygonData[1], polygon[1]); - QCOMPARE(image->polygonData[2], polygon[2]); - QCOMPARE(image->polygonData[3], polygon[3]); + area->layerBundle[1].image->setPolygon(polygon); + IntelliShapedImage* image = dynamic_cast(area->layerBundle[1].image); + QCOMPARE(image->polygonData[0], polygon[0]); + QCOMPARE(image->polygonData[1], polygon[1]); + QCOMPARE(image->polygonData[2], polygon[2]); + QCOMPARE(image->polygonData[3], polygon[3]); - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::test_setLayerUp(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->selectLayerUp(); - QCOMPARE(area->activeLayer, 1); + area->selectLayerUp(); + QCOMPARE(area->activeLayer, 1); - area->setLayerActive(0); - QCOMPARE(area->activeLayer, 0); + area->setLayerActive(0); + QCOMPARE(area->activeLayer, 0); - area->selectLayerUp(); - QCOMPARE(area->activeLayer, 1); + area->selectLayerUp(); + QCOMPARE(area->activeLayer, 1); - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::test_setLayerDown(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->selectLayerDown(); - QCOMPARE(area->activeLayer, 0); + area->selectLayerDown(); + QCOMPARE(area->activeLayer, 0); - area->selectLayerDown(); - QCOMPARE(area->activeLayer, 0); + area->selectLayerDown(); + QCOMPARE(area->activeLayer, 0); - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::test_createTools(){ - QVERIFY(area->Tool == nullptr); + QVERIFY(area->Tool == nullptr); - area->createPenTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createPenTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createLineTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createLineTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createPlainTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createPlainTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createCircleTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createCircleTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createPolygonTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createPolygonTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createFloodFillTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createFloodFillTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); - area->createRectangleTool(); - QVERIFY(dynamic_cast(area->Tool) != nullptr); + area->createRectangleTool(); + QVERIFY(dynamic_cast(area->Tool) != nullptr); } //test Raster-Image operations void UnitTest::test_RasterImage_drawPixel(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(0,0); + QPoint point(0,0); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_drawLine(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point1(0,0); - QPoint point2(10,10); - QPoint point3(5,5); - QPoint point4(6,5); + QPoint point1(0,0); + QPoint point2(10,10); + QPoint point3(5,5); + QPoint point4(6,5); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_drawPoint(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point1(5,5); - QPoint point2(5,6); + QPoint point1(5,5); + QPoint point2(5,6); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_getDisplayable(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->floodFill(255,255,255,255); - QImage img = area->layerBundle[0].image->getDisplayable(QSize(200,200),255); - QPoint point; - for(size_t i=0; i<200; i++){ - point.setX(static_cast(i)); - for(size_t j=0; j<200; j++){ - point.setY(static_cast(j)); - QVERIFY(img.pixelColor(point) == QColor(255,255,255,255)); - } - } + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + QImage img = area->layerBundle[0].image->getDisplayable(QSize(200,200),255); + QPoint point; + for(size_t i=0; i<200; i++) { + point.setX(static_cast(i)); + for(size_t j=0; j<200; j++) { + point.setY(static_cast(j)); + QVERIFY(img.pixelColor(point) == QColor(255,255,255,255)); + } + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_getPixelColor(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(0,0); - area->floodFill(0,0,0,255); - QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); + QPoint point(0,0); + area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_getImageData(){ - area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); - QImage img(2,2, QImage::Format_ARGB32); - img.setPixelColor(0,0, Qt::red); - img.setPixelColor(0,1, Qt::yellow); - img.setPixelColor(1,0, Qt::blue); - img.setPixelColor(1,1, Qt::green); + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); - area->layerBundle[0].image->setImageData(img); - img = img.convertToFormat(QImage::Format_Indexed8); - QImage cpy = area->layerBundle[0].image->getImageData(); + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + QImage cpy = area->layerBundle[0].image->getImageData(); - QPoint point1(0,0); - QPoint point2(0,1); - QPoint point3(1,0); - QPoint point4(1,1); - QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); - QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); - QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); - QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); + QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); + QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); + QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_RasterImage_setImageData(){ - area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); - QImage img(2,2, QImage::Format_ARGB32); - img.setPixelColor(0,0, Qt::red); - img.setPixelColor(0,1, Qt::yellow); - img.setPixelColor(1,0, Qt::blue); - img.setPixelColor(1,1, Qt::green); + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); - area->layerBundle[0].image->setImageData(img); - img = img.convertToFormat(QImage::Format_Indexed8); + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); - QPoint point1(0,0); - QPoint point2(0,1); - QPoint point3(1,0); - QPoint point4(1,1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); - area->deleteLayer(0); + area->deleteLayer(0); } //test Shaped-Image operations void UnitTest::test_ShapedImage_drawPixel(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(0,0); + QPoint point(0,0); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point) == QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_drawLine(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point1(0,0); - QPoint point2(10,10); - QPoint point3(5,5); - QPoint point4(6,5); + QPoint point1(0,0); + QPoint point2(10,10); + QPoint point3(5,5); + QPoint point4(6,5); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(255,255,255,255)); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255),3); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4)==QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_drawPoint(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point1(5,5); - QPoint point2(5,6); + QPoint point1(5,5); + QPoint point2(5,6); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(255,255,255,255)); - area->floodFill(255,255,255,255); - area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->drawPoint(point1, QColor(0,0,0,255),5); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == QColor(0,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_getDisplayable(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; + area->addLayer(21,21,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; - std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) - }; - area->floodFill(255,255,255,255); - area->layerBundle[0].image->setPolygon(points); - QSize size(21,21); - QImage img = area->layerBundle[0].image->getDisplayable(size,255); + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + area->layerBundle[0].image->setPolygon(points); + QSize size(21,21); + QImage img = area->layerBundle[0].image->getDisplayable(size,255); - QCOMPARE(img.pixelColor(points[0]).alpha(), 255); - QCOMPARE(img.pixelColor(points[1]).alpha(), 255); - QCOMPARE(img.pixelColor(points[2]).alpha(), 255); - QCOMPARE(img.pixelColor(points[3]).alpha(), 255); + QCOMPARE(img.pixelColor(points[0]).alpha(), 255); + QCOMPARE(img.pixelColor(points[1]).alpha(), 255); + QCOMPARE(img.pixelColor(points[2]).alpha(), 255); + QCOMPARE(img.pixelColor(points[3]).alpha(), 255); - QCOMPARE(img.pixelColor(test[4]).alpha(), 255); - QCOMPARE(img.pixelColor(test[0]).alpha(), 0); - QCOMPARE(img.pixelColor(test[1]).alpha(), 0); - QCOMPARE(img.pixelColor(test[2]).alpha(), 0); - QCOMPARE(img.pixelColor(test[3]).alpha(), 0); + QCOMPARE(img.pixelColor(test[4]).alpha(), 255); + QCOMPARE(img.pixelColor(test[0]).alpha(), 0); + QCOMPARE(img.pixelColor(test[1]).alpha(), 0); + QCOMPARE(img.pixelColor(test[2]).alpha(), 0); + QCOMPARE(img.pixelColor(test[3]).alpha(), 0); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_getPixelColor(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(0,0); - area->floodFill(0,0,0,255); - QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); + QPoint point(0,0); + area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point)==QColor(0,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_getImageData(){ - area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); - QImage img(2,2, QImage::Format_ARGB32); - img.setPixelColor(0,0, Qt::red); - img.setPixelColor(0,1, Qt::yellow); - img.setPixelColor(1,0, Qt::blue); - img.setPixelColor(1,1, Qt::green); + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); - area->layerBundle[0].image->setImageData(img); - img = img.convertToFormat(QImage::Format_Indexed8); - QImage cpy = area->layerBundle[0].image->getImageData(); + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); + QImage cpy = area->layerBundle[0].image->getImageData(); - QPoint point1(0,0); - QPoint point2(0,1); - QPoint point3(1,0); - QPoint point4(1,1); - QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); - QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); - QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); - QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(cpy.pixelColor(point1) == img.pixelColor(point1)); + QVERIFY(cpy.pixelColor(point2) == img.pixelColor(point2)); + QVERIFY(cpy.pixelColor(point3) == img.pixelColor(point3)); + QVERIFY(cpy.pixelColor(point4) == img.pixelColor(point4)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_ShapedImage_setImageData(){ - area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(2,2,10,20,IntelliImage::ImageType::RASTERIMAGE); - QImage img(2,2, QImage::Format_ARGB32); - img.setPixelColor(0,0, Qt::red); - img.setPixelColor(0,1, Qt::yellow); - img.setPixelColor(1,0, Qt::blue); - img.setPixelColor(1,1, Qt::green); + QImage img(2,2, QImage::Format_ARGB32); + img.setPixelColor(0,0, Qt::red); + img.setPixelColor(0,1, Qt::yellow); + img.setPixelColor(1,0, Qt::blue); + img.setPixelColor(1,1, Qt::green); - area->layerBundle[0].image->setImageData(img); - img = img.convertToFormat(QImage::Format_Indexed8); + area->layerBundle[0].image->setImageData(img); + img = img.convertToFormat(QImage::Format_Indexed8); - QPoint point1(0,0); - QPoint point2(0,1); - QPoint point3(1,0); - QPoint point4(1,1); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); + QPoint point1(0,0); + QPoint point2(0,1); + QPoint point3(1,0); + QPoint point4(1,1); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1) == img.pixelColor(point1)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2) == img.pixelColor(point2)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3) == img.pixelColor(point3)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point4) == img.pixelColor(point4)); - area->deleteLayer(0); + area->deleteLayer(0); } //test tools void UnitTest::test_Circle_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createCircleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getSecondColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Circle_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createCircleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_FloodFill_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createFloodFillTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_FloodFill_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createFloodFillTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Line_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createLineTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Line_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createLineTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Pen_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPenTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Pen_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPenTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Plain_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Plain_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,100); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Polygon_fullDraw(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; - std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) - }; + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->floodFill(255,0,0,255); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseMoved(points[0].x(), points[0].y()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==area->colorPicker.getSecondColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Polygon_interruptedDraw(){ - area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(100,000), - QPoint(000,100), - QPoint(100,200), - QPoint(200,100) - }; + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(100,000), + QPoint(000,100), + QPoint(100,200), + QPoint(200,100) + }; - std::vector test{ - QPoint(000,000), - QPoint(000,200), - QPoint(200,000), - QPoint(200,200), - QPoint(100,100) - }; + std::vector test{ + QPoint(000,000), + QPoint(000,200), + QPoint(200,000), + QPoint(200,200), + QPoint(100,100) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->floodFill(255,0,0,255); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); - area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(points[3])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[4])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[0])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[1])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[2])==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(test[3])==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Rectangle_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createRectangleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,150); - QPoint point3(125,125); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,150); + QPoint point3(125,125); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==area->colorPicker.getSecondColor()); - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::test_Rectangle_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createRectangleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,150); - QPoint point3(125,125); - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + QPoint point1(100,100); + QPoint point2(150,150); + QPoint point3(125,125); + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); - QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==QColor(255,0,0,255)); + QVERIFY(area->layerBundle[0].image->getPixelColor(point3)==QColor(255,0,0,255)); - area->deleteLayer(0); + area->deleteLayer(0); } //test Triangulation void UnitTest::test_Triangulation_Coverage(){ - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; - std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) - }; - std::vector tria = IntelliTriangulation::calculateTriangles(points); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[0]), true); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[1]), true); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[2]), true); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[3]), true); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; + std::vector tria = IntelliTriangulation::calculateTriangles(points); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[0]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[1]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[2]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, points[3]), true); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[4]), true); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[0]), false); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[1]), false); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[2]), false); - QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[3]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[4]), true); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[0]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[1]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[2]), false); + QCOMPARE(IntelliTriangulation::isInPolygon(tria, test[3]), false); } - ///Benchmarks here void UnitTest::bench_addLayer(){ - QBENCHMARK{ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - } - area->deleteLayer(0); + QBENCHMARK{ + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + } + area->deleteLayer(0); } void UnitTest::bench_deleteLayer(){ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->deleteLayer(0); - } + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + QBENCHMARK{ + area->deleteLayer(0); + } } void UnitTest::bench_setActive(){ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->setLayerActive(0); - } + QBENCHMARK{ + area->setLayerActive(0); + } - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::bench_setAlpha(){ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->setLayerAlpha(0,0); - } + QBENCHMARK{ + area->setLayerAlpha(0,0); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_floodFill(){ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->floodFill(255,255,255,255); - } + QBENCHMARK{ + area->layerBundle[0].image->drawPlain(QColor(255, 255, 255, 255)); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_moveActive(){ - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,0,0,IntelliImage::ImageType::RASTERIMAGE); - area->setLayerActive(0); - QBENCHMARK{ - area->moveActiveLayer(1); - } + area->setLayerActive(0); + QBENCHMARK{ + area->moveActiveLayer(1); + } - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::bench_setPolygon(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - std::vector polygon{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,10), - QPoint(00,10) - }; + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; - QBENCHMARK{ - area->layerBundle[1].image->setPolygon(polygon); - } + QBENCHMARK{ + area->layerBundle[1].image->setPolygon(polygon); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_setLayerUp(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->setLayerActive(0); - QBENCHMARK{ - area->selectLayerUp(); - } + area->setLayerActive(0); + QBENCHMARK{ + area->selectLayerUp(); + } - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::bench_setLayerDown(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->selectLayerDown(); - } + QBENCHMARK{ + area->selectLayerDown(); + } - area->deleteLayer(1); - area->deleteLayer(0); + area->deleteLayer(1); + area->deleteLayer(0); } void UnitTest::bench_createTools(){ - QBENCHMARK{ - area->createPenTool(); - } + QBENCHMARK{ + area->createPenTool(); + } - QBENCHMARK{ - area->createLineTool(); - } + QBENCHMARK{ + area->createLineTool(); + } - QBENCHMARK{ - area->createPlainTool(); - } + QBENCHMARK{ + area->createPlainTool(); + } - QBENCHMARK{ - area->createCircleTool(); - } + QBENCHMARK{ + area->createCircleTool(); + } - QBENCHMARK{ - area->createPolygonTool(); - } + QBENCHMARK{ + area->createPolygonTool(); + } - QBENCHMARK{ - area->createFloodFillTool(); - } + QBENCHMARK{ + area->createFloodFillTool(); + } - QBENCHMARK{ - area->createRectangleTool(); - } + QBENCHMARK{ + area->createRectangleTool(); + } } void UnitTest::bench_RasterImage_drawPixel(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(0,0); + QPoint point(0,0); - QBENCHMARK{ - area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); - } + QBENCHMARK{ + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_drawLine(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point1(000,000); - QPoint point2(200,200); + QPoint point1(000,000); + QPoint point2(200,200); - QBENCHMARK{ - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); - } + QBENCHMARK{ + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_drawPoint(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(000,000); + QPoint point(000,000); - QBENCHMARK{ - area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); - } + QBENCHMARK{ + area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_getDisplayable(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->layerBundle[0].image->getDisplayable(QSize(200,200),255); - } + QBENCHMARK{ + area->layerBundle[0].image->getDisplayable(QSize(200,200),255); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_getPixelColor(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QPoint point(000,000); + QPoint point(000,000); - QBENCHMARK{ - area->layerBundle[0].image->getPixelColor(point); - } + QBENCHMARK{ + area->layerBundle[0].image->getPixelColor(point); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_getImageData(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QBENCHMARK{ - area->layerBundle[0].image->getImageData(); - } + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_RasterImage_setImageData(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - QImage img = area->layerBundle[0].image->getImageData(); - QBENCHMARK{ - area->layerBundle[0].image->setImageData(img); - } + QImage img = area->layerBundle[0].image->getImageData(); + QBENCHMARK{ + area->layerBundle[0].image->setImageData(img); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_drawPixel(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QPoint point(0,0); + QPoint point(0,0); - QBENCHMARK{ - area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); - } + QBENCHMARK{ + area->layerBundle[0].image->drawPixel(point, QColor(0,0,0,255)); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_drawLine(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QPoint point1(000,000); - QPoint point2(200,200); + QPoint point1(000,000); + QPoint point2(200,200); - QBENCHMARK{ - area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); - } + QBENCHMARK{ + area->layerBundle[0].image->drawLine(point1, point2, QColor(0,0,0,255), 1); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_drawPoint(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QPoint point(000,000); + QPoint point(000,000); - QBENCHMARK{ - area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); - } + QBENCHMARK{ + area->layerBundle[0].image->drawPoint(point, QColor(0,0,0,255), 1); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_getDisplayable(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QBENCHMARK{ - area->layerBundle[0].image->getDisplayable(QSize(200,200),255); - } + QBENCHMARK{ + area->layerBundle[0].image->getDisplayable(QSize(200,200),255); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_getPixelColor(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QPoint point(000,000); + QPoint point(000,000); - QBENCHMARK{ - area->layerBundle[0].image->getPixelColor(point); - } + QBENCHMARK{ + area->layerBundle[0].image->getPixelColor(point); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_getImageData(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QBENCHMARK{ - area->layerBundle[0].image->getImageData(); - } + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_ShapedImage_setImageData(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - QImage img = area->layerBundle[0].image->getImageData(); - QBENCHMARK{ - area->layerBundle[0].image->setImageData(img); - } + QImage img = area->layerBundle[0].image->getImageData(); + QBENCHMARK{ + area->layerBundle[0].image->setImageData(img); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Circle_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createCircleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Circle_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createCircleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createCircleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_FloodFill_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createFloodFillTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_FloodFill_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createFloodFillTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createFloodFillTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Line_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createLineTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Line_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createLineTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createLineTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); + QPoint point1(100,100); + QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Pen_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPenTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Pen_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPenTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPenTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Plain_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Plain_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPlainTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPlainTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,100); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,100); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Polygon_fullDraw(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->floodFill(255,0,0,255); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseMoved(points[0].x(), points[0].y()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Polygon_interruptedDraw(){ - area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(100,000) - }; + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(100,000) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->floodFill(255,0,0,255); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); - area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Rectangle_fullDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createRectangleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,150); + QPoint point1(100,100); + QPoint point2(150,150); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Rectangle_interruptedDraw(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createRectangleTool(); - area->floodFill(255,0,0,255); + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createRectangleTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QPoint point1(100,100); - QPoint point2(150,150); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(point1.x(), point1.y()); - area->Tool->onMouseMoved(point2.x(), point2.y()); - area->Tool->onMouseRightPressed(point2.x(), point2.y()); - area->Tool->onMouseRightReleased(point2.x(),point2.y()); - area->Tool->onMouseLeftReleased(point2.x(), point2.y()); - } + QPoint point1(100,100); + QPoint point2(150,150); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(point1.x(), point1.y()); + area->Tool->onMouseMoved(point2.x(), point2.y()); + area->Tool->onMouseRightPressed(point2.x(), point2.y()); + area->Tool->onMouseRightReleased(point2.x(),point2.y()); + area->Tool->onMouseLeftReleased(point2.x(), point2.y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Triangulation_Coverage(){ - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; - std::vector test{ - QPoint(00,00), - QPoint(00,20), - QPoint(20,00), - QPoint(20,20), - QPoint(10,10) - }; + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; + std::vector test{ + QPoint(00,00), + QPoint(00,20), + QPoint(20,00), + QPoint(20,20), + QPoint(10,10) + }; - QBENCHMARK{ - std::vector tria = IntelliTriangulation::calculateTriangles(points); - QPoint point; - for(int i=0; i<200; i++){ - point.setX(i); - for(int j=0; j<200; j++){ - point.setY(j); - IntelliTriangulation::isInPolygon(tria, point); - } - } - } + QBENCHMARK{ + std::vector tria = IntelliTriangulation::calculateTriangles(points); + QPoint point; + for(int i=0; i<200; i++) { + point.setX(i); + for(int j=0; j<200; j++) { + point.setY(j); + IntelliTriangulation::isInPolygon(tria, point); + } + } + } } - - - QTEST_MAIN(UnitTest) #include "tst_unittest.moc" From 226ab269574764e6a718921f3f07f83fe89b2c12 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 16 Jan 2020 12:26:56 +0100 Subject: [PATCH 11/14] Added Unit Testing Files to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 76774be..22c1e68 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,10 @@ phony.c # Testing Files *.o *.qmake.stash +src/Makefile +src/moc_* +src/target_wrapper.sh +src/tst_unittest.moc # Ignore User Files except for the pro file IntelliPhoto.* From c3ff1dbc0af72350acc364d3c6e3e3cdcda7a0d5 Mon Sep 17 00:00:00 2001 From: Mienek Date: Thu, 16 Jan 2020 12:36:19 +0100 Subject: [PATCH 12/14] =?UTF-8?q?kein=20bock=20mehr=20mach=20dein=20schei?= =?UTF-8?q?=C3=9F=20richtig=20das=20n=C3=A4chste=20mal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IntelliUnitTest.pro | 2 + src/Tool/IntelliToolPolygon.cpp | 15 +--- src/tst_unittest.cpp | 128 ++++++++++++++------------------ 3 files changed, 61 insertions(+), 84 deletions(-) diff --git a/src/IntelliUnitTest.pro b/src/IntelliUnitTest.pro index 6e41ba3..a285e28 100644 --- a/src/IntelliUnitTest.pro +++ b/src/IntelliUnitTest.pro @@ -10,6 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TEMPLATE = app SOURCES += tst_unittest.cpp \ + GUI/IntelliInputDialog.cpp \ GUI/IntelliPhotoGui.cpp \ Image/IntelliImage.cpp \ Image/IntelliRasterImage.cpp \ @@ -41,6 +42,7 @@ DISTFILES += \ icons/rectangle-tool.svg HEADERS += \ + GUI/IntelliInputDialog.h \ GUI/IntelliPhotoGui.h \ Image/IntelliImage.h \ Image/IntelliRasterImage.h \ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index d80c471..e860120 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -52,7 +52,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ this->Canvas->image->calculateVisiblity(); } } - else if(drawingOfPolygon && isNearStart(x,y,QPointList.front())) { + else if(drawingOfPolygon && QPointList.size() > 0 && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); @@ -90,7 +90,6 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { isInside = false; isPointNearStart = false; - isDrawing = false; if(!isSettingPolygon) { std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; @@ -139,17 +138,11 @@ void IntelliToolPolygon::onMouseMoved(int x, int y){ } bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ - bool isNear = false; int StartX = Startpoint.x(); int StartY = Startpoint.y(); int valueToNear = 5; - for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) { - for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) { - if((i == x) && (j == y)) { - isNear = true; - } - } - } - return isNear; + float euklid = sqrt(pow(static_cast(StartX-x),2.f)+pow(static_cast(StartY-y),2.f)); + + return static_cast(euklid)layerBundle[0].image->drawPlain(QColor(-1, -1, -1, -1)); - for(size_t i = 0; i<200; i++) { - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++) { - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } - - area->layerBundle[0].image->drawPlain(QColor(256, 256, 256, 256)); - for(size_t i = 0; i<200; i++) { - point.setX(static_cast(i)); - for(size_t j = 0; i<200; i++) { - point.setY(static_cast(j)); - QVERIFY(area->layerBundle[static_cast(area->activeLayer)].image->getPixelColor(point)==QColor(0,0,0,0)); - } - } - area->deleteLayer(0); } @@ -299,7 +281,7 @@ void UnitTest::test_moveActive(){ area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - area->layerBundle[0].image->drawPlain(QColor(0, 0, 0, 255)); + area->layerBundle[1].image->drawPlain(QColor(0, 0, 0, 255)); QPoint point(0,0); area->moveActiveLayer(-1); @@ -1153,20 +1135,20 @@ void UnitTest::bench_moveActive(){ } void UnitTest::bench_setPolygon(){ - area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); - std::vector polygon{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,10), - QPoint(00,10) - }; + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; - QBENCHMARK{ - area->layerBundle[1].image->setPolygon(polygon); - } + QBENCHMARK{ + area->layerBundle[0].image->setPolygon(polygon); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_setLayerUp(){ @@ -1578,65 +1560,65 @@ void UnitTest::bench_Plain_interruptedDraw(){ } void UnitTest::bench_Polygon_fullDraw(){ - area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(10,00), - QPoint(00,10), - QPoint(10,20), - QPoint(20,10) - }; + area->addLayer(21,21,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,20), + QPoint(20,10) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseMoved(points[1].x(), points[1].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + area->Tool->onMouseMoved(points[1].x(), points[1].y()); - area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); - area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); - area->Tool->onMouseMoved(points[2].x(), points[2].y()); + area->Tool->onMouseLeftPressed(points[1].x(), points[1].y()); + area->Tool->onMouseLeftReleased(points[1].x(), points[1].y()); + area->Tool->onMouseMoved(points[2].x(), points[2].y()); - area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); - area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); - area->Tool->onMouseMoved(points[3].x(), points[3].y()); + area->Tool->onMouseLeftPressed(points[2].x(), points[2].y()); + area->Tool->onMouseLeftReleased(points[2].x(), points[2].y()); + area->Tool->onMouseMoved(points[3].x(), points[3].y()); - area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); - area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); - area->Tool->onMouseMoved(points[0].x(), points[0].y()); + area->Tool->onMouseLeftPressed(points[3].x(), points[3].y()); + area->Tool->onMouseLeftReleased(points[3].x(), points[3].y()); + area->Tool->onMouseMoved(points[0].x(), points[0].y()); - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } void UnitTest::bench_Polygon_interruptedDraw(){ - area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); - std::vector points{ - QPoint(100,000) - }; + area->addLayer(201,201,10,20,IntelliImage::ImageType::RASTERIMAGE); + std::vector points{ + QPoint(100,000) + }; - area->colorPicker.setFirstColor(QColor(255,255,255,255)); - area->colorPicker.setSecondColor(QColor(0,0,0,255)); - area->createPolygonTool(); - area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); + area->colorPicker.setFirstColor(QColor(255,255,255,255)); + area->colorPicker.setSecondColor(QColor(0,0,0,255)); + area->createPolygonTool(); + area->layerBundle[0].image->drawPlain(QColor(255, 0, 0, 255)); - QBENCHMARK{ - area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); - area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); + QBENCHMARK{ + area->Tool->onMouseLeftPressed(points[0].x(), points[0].y()); + area->Tool->onMouseLeftReleased(points[0].x(), points[0].y()); - area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); - area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); - } + area->Tool->onMouseRightPressed(points[0].x(), points[0].y()); + area->Tool->onMouseRightReleased(points[0].x(), points[0].y()); + } - area->deleteLayer(0); + area->deleteLayer(0); } From 764aaa927f9ccb50a451c880277a42d7382506ec Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 16 Jan 2020 12:43:33 +0100 Subject: [PATCH 13/14] Added execution rights for .pro files --- src/IntelliPhoto.pro | 0 src/IntelliUnitTest.pro | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/IntelliPhoto.pro mode change 100644 => 100755 src/IntelliUnitTest.pro diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro old mode 100644 new mode 100755 diff --git a/src/IntelliUnitTest.pro b/src/IntelliUnitTest.pro old mode 100644 new mode 100755 From 805199619314723da6c8b4b23254e6cf4bf88e3c Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Thu, 16 Jan 2020 12:10:23 +0100 Subject: [PATCH 14/14] fixed unit test --- src/Tool/IntelliToolPolygon.cpp | 4 +++- src/tst_unittest.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index e860120..d457395 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -23,7 +23,7 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { if(Area->getPolygonDataOfRealLayer().size()>2) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); @@ -80,6 +80,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ } void IntelliToolPolygon::onMouseRightPressed(int x, int y){ + drawingOfPolygon = false; isInside = false; isPointNearStart = false; QPointList.clear(); @@ -90,6 +91,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { isInside = false; isPointNearStart = false; + drawingOfPolygon = false; if(!isSettingPolygon) { std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp index 11b1850..dc21b8a 100644 --- a/src/tst_unittest.cpp +++ b/src/tst_unittest.cpp @@ -37,6 +37,7 @@ void cleanupTestCase(); ///Test here + //test painting area void test_addLayer(); void test_deleteLayer(); @@ -171,7 +172,7 @@ void UnitTest::initTestCase() void UnitTest::cleanupTestCase() { - delete gui; + } //test painting area