diff --git a/.gitignore b/.gitignore index 6c15b5a..22c1e68 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,14 @@ CMakeLists.txt.user* app_version.h 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.* !IntelliPhoto.pro diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index f3d2900..464adec 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -10,9 +10,10 @@ #include #include #include - #include "IntelliInputDialog.h" +//for unit testing +class UnitTest; // PaintingArea used to paint the image class PaintingArea; @@ -25,6 +26,10 @@ class IntelliColorPicker; * \brief The IntelliPhotoGui base class handles the graphical user interface and events 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 Q_OBJECT public: /*! @@ -139,30 +144,30 @@ 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* actionCreateNewRasterLayer; diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index aa12450..0017877 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/Image/IntelliImage.h b/src/Image/IntelliImage.h index 0d2fe42..c56ceaa 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.cpp b/src/Image/IntelliRasterImage.cpp index a63a767..3106e36 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/Image/IntelliRasterImage.h b/src/Image/IntelliRasterImage.h index 79338c4..eecc67c 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 d2cc4c6..001ce02 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 8a8416a..e703eb6 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 2ad627d..1fef570 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 f7c0891..1b0f90c 100644 --- a/src/IntelliHelper/IntelliToolsettings.h +++ b/src/IntelliHelper/IntelliToolsettings.h @@ -1,12 +1,18 @@ #ifndef INTELLITOOLSETTINGS_H #define INTELLITOOLSETTINGS_H +//for unit testing +class UnitTest; + class IntelliToolsettings { +friend UnitTest; public: IntelliToolsettings(); virtual ~IntelliToolsettings(); + int getLineWidth(); void setLineWidth(int LineWidth); + int getInnerAlpha(); void setInnerAlpha(int innerAlpha); diff --git a/src/IntelliHelper/IntelliTriangulation.h b/src/IntelliHelper/IntelliTriangulation.h index 3678953..716915c 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/IntelliPhoto.pro b/src/IntelliPhoto.pro old mode 100644 new mode 100755 diff --git a/src/IntelliUnitTest.pro b/src/IntelliUnitTest.pro new file mode 100755 index 0000000..a285e28 --- /dev/null +++ b/src/IntelliUnitTest.pro @@ -0,0 +1,62 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +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 \ + Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliColorPicker.cpp \ + IntelliHelper/IntelliRenderSettings.cpp \ + IntelliHelper/IntelliToolsettings.cpp \ + IntelliHelper/IntelliTriangulation.cpp \ + Layer/PaintingArea.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 + +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/IntelliInputDialog.h \ + 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/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 0333f23..f39aa75 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -82,7 +82,7 @@ void PaintingArea::deleteLayer(int idx, bool isTool){ if(!isTool) { updateTools(); } - if(idx(layerBundle.size())) { + if(idx(layerBundle.size())&&idx>=0) { this->layerBundle.erase(layerBundle.begin() + idx); if(activeLayer>=idx) { activeLayer--; @@ -109,7 +109,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; + } } } void PaintingArea::setPolygon(int idx){ diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index c282c39..0587a71 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,10 @@ 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 Q_OBJECT friend IntelliTool; friend IntelliPhotoGui; 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.cpp b/src/Tool/IntelliTool.cpp index 9b9ffc1..bfb7553 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/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 46a4340..e33ac45 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.cpp b/src/Tool/IntelliToolFloodFill.cpp index 5301eee..aa536b6 100644 --- a/src/Tool/IntelliToolFloodFill.cpp +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -34,6 +34,9 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ QColor oldColor = this->activeLayer->image->getPixelColor(start); QColor newColor = this->colorPicker->getFirstColor(); + if(newColor == oldColor) { + return; + } Canvas->image->drawPixel(start,newColor); QPoint left, right, top, down; diff --git a/src/Tool/IntelliToolFloodFill.h b/src/Tool/IntelliToolFloodFill.h index 21b7c94..b1d29f6 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 f5e7e34..1a4c8aa 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 cee28ed..851ec74 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 8baca3c..0c97c15 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.cpp b/src/Tool/IntelliToolPolygon.cpp index 9b21fe9..d457395 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -7,7 +7,7 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon) : IntelliTool(Area, colorPicker, Toolsettings){ isPointNearStart = false; - isDrawing = false; + drawingOfPolygon = false; isInside = false; this->isSettingPolygon = isSettingPolygon; if(isSettingPolygon) { @@ -17,13 +17,13 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c } 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()) { if(Area->getPolygonDataOfRealLayer().size()>2) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); @@ -36,15 +36,15 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ isInside = true; } } - 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()); @@ -52,7 +52,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ this->Canvas->image->calculateVisiblity(); } } - else if(isDrawing && 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()); @@ -62,13 +62,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()); @@ -79,8 +80,8 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ } void IntelliToolPolygon::onMouseRightPressed(int x, int y){ + drawingOfPolygon = false; isInside = false; - isDrawing = false; isPointNearStart = false; QPointList.clear(); IntelliTool::onMouseRightPressed(x,y); @@ -90,7 +91,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(isPointNearStart) { isInside = false; isPointNearStart = false; - isDrawing = false; + drawingOfPolygon = false; if(!isSettingPolygon) { std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; @@ -139,17 +140,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) #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. @@ -20,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/Tool/IntelliToolRectangle.h b/src/Tool/IntelliToolRectangle.h index 2ead165..d39bef2 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/mainUnitTest.cpp b/src/mainUnitTest.cpp new file mode 100644 index 0000000..4302e27 --- /dev/null +++ b/src/mainUnitTest.cpp @@ -0,0 +1,202 @@ +#include +// add necessary includes here +#include + +#include "GUI/IntelliPhotoGui.h" + + +class UnitTest : public QObject +{ + Q_OBJECT +private: + IntelliPhotoGui* gui; + PaintingArea* area; + QApplication* app; + +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() +{ + 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() +{ + +} + +void UnitTest::initTestCase() +{ + +} + +void UnitTest::cleanupTestCase() +{ + delete gui; + delete app; +} + +//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) + +#include "tst_unittest.moc" diff --git a/src/tst_unittest.cpp b/src/tst_unittest.cpp new file mode 100644 index 0000000..dc21b8a --- /dev/null +++ b/src/tst_unittest.cpp @@ -0,0 +1,1697 @@ +#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: +IntelliPhotoGui* gui; +PaintingArea* area; + +public: +UnitTest(); +~UnitTest(); + +private slots: +void initTestCase(); +void cleanupTestCase(); +//void test_case1(); + +///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(); + +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 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(); + +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(); + + +///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() +{ + gui = new IntelliPhotoGui(); + area = gui->paintingArea; +} + +UnitTest::~UnitTest() +{ + +} + +void UnitTest::initTestCase() +{ + +} + +void UnitTest::cleanupTestCase() +{ + +} + +//test painting area +void UnitTest::test_addLayer(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + 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, 200); + QCOMPARE(area->layerBundle[static_cast(area->activeLayer)].heightOffset, 20); + + 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->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,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->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->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,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + 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->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->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->layerBundle[1].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, 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,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) + }; + + 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,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + area->addLayer(200,200,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,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->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(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + + 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)); + + area->deleteLayer(0); +} + +void UnitTest::test_RasterImage_drawLine(){ + 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); + + 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->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); +} + +void UnitTest::test_RasterImage_drawPoint(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(5,5); + QPoint point2(5,6); + + 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->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); +} + +void UnitTest::test_RasterImage_getDisplayable(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + 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); +} + +void UnitTest::test_RasterImage_getPixelColor(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + 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); +} + +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(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point(0,0); + + 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)); + + area->deleteLayer(0); +} + +void UnitTest::test_ShapedImage_drawLine(){ + 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); + + 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->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); +} + +void UnitTest::test_ShapedImage_drawPoint(){ + area->addLayer(200,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QPoint point1(5,5); + QPoint point2(5,6); + + 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->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); +} + +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->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(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,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + 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); +} + +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(){ + 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()); + + + QVERIFY(area->layerBundle[0].image->getPixelColor(point1)==area->colorPicker.getSecondColor()); + QVERIFY(area->layerBundle[0].image->getPixelColor(point2)==area->colorPicker.getFirstColor()); + + 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->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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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,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()); + + + 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->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[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()); + + 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(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->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[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()); + + + 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,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()); + + + 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,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()); + + 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(){ + 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); +} + + +///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->layerBundle[0].image->drawPlain(QColor(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,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + std::vector polygon{ + QPoint(10,00), + QPoint(00,10), + QPoint(10,10), + QPoint(00,10) + }; + + QBENCHMARK{ + area->layerBundle[0].image->setPolygon(polygon); + } + + 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->setLayerActive(0); + QBENCHMARK{ + area->selectLayerUp(); + } + + 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); + + 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,200,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,200,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,200,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,200,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,200,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,200,10,20,IntelliImage::ImageType::RASTERIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_RasterImage_setImageData(){ + area->addLayer(200,200,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,200,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,200,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,200,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,200,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,200,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,200,10,20,IntelliImage::ImageType::SHAPEDIMAGE); + + QBENCHMARK{ + area->layerBundle[0].image->getImageData(); + } + + area->deleteLayer(0); +} + +void UnitTest::bench_ShapedImage_setImageData(){ + area->addLayer(200,200,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,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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + } + + 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->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()); + + 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) + }; + + + 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->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,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->onMouseLeftReleased(point2.x(), point2.y()); + } + + 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->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()); + } + + 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"