start of unit test

This commit is contained in:
Jonas Mucke
2020-01-12 20:23:39 +01:00
parent 573cabf448
commit 5a05aa4a19
21 changed files with 180 additions and 97 deletions

View File

@@ -11,6 +11,9 @@
#include <QLabel>
#include <QLineEdit>
//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;

View File

@@ -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:

View File

@@ -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:
/*!

View File

@@ -4,10 +4,14 @@
#include "Image/IntelliRasterImage.h"
#include <vector>
//for unit testing
class UnitTest;
/*!
* \brief The IntelliShapedImage manages a Shapedimage.
*/
class IntelliShapedImage : public IntelliRasterImage {
friend UnitTest;
friend IntelliTool;
private:
/*!

View File

@@ -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.

View File

@@ -1,9 +1,13 @@
#ifndef INTELLIRENDERSETTINGS_H
#define INTELLIRENDERSETTINGS_H
//for unit testing
class UnitTest;
class IntelliRenderSettings
{
friend UnitTest;
public:
IntelliRenderSettings();

View File

@@ -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.

View File

@@ -1,6 +1,9 @@
#ifndef INTELLITRIANGULATION_H
#define INTELLITRIANGULATION_H
//for unit testing
class UnitTest;
#include <QPoint>
#include <vector>

View File

@@ -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<QPoint> 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(){

View File

@@ -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

View File

@@ -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;
}

View File

@@ -5,6 +5,9 @@
#include "IntelliHelper/IntelliToolsettings.h"
#include <vector>
//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,

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.
*/

View File

@@ -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.
*/

View File

@@ -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.

View File

@@ -5,11 +5,16 @@
#include "IntelliHelper/IntelliTriangulation.h"
#include <vector>
#include <QPoint>
//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.

View File

@@ -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.

View File

@@ -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 \

View File

@@ -1,32 +1,17 @@
#include <QtTest>
// add necessary includes here
#include<string>
#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()