Permalink
Browse files

New layer dialog unit test

  • Loading branch information...
feragon committed Aug 12, 2016
1 parent d98d9aa commit cc68991419d8a0b9697d1765d3098ebbd6f8bc84
@@ -8,7 +8,6 @@ AddLayerDialog::AddLayerDialog(lc::Document_SPtr document, QWidget* parent) :
AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr document, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddLayerDialog),
_document(document),
_oldLayer(oldLayer) {
ui->setupUi(this);
@@ -26,7 +25,9 @@ AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr docum
if(oldLayer != nullptr) {
ui->name->setText(oldLayer->name().c_str());
linePatternSelect->setCurrentText(oldLayer->linePattern()->name().c_str());
if(oldLayer->linePattern() != nullptr) {
linePatternSelect->setCurrentText(oldLayer->linePattern()->name().c_str());
}
lineWidthSelect->setWidth(oldLayer->lineWidth().width());
colorSelect->setColor(oldLayer->color());
@@ -32,11 +32,12 @@ class AddLayerDialog : public QDialog {
private slots:
void accept();
private:
protected:
Ui::AddLayerDialog* ui;
lc::Document_SPtr _document;
LinePatternSelect* linePatternSelect;
LineWidthSelect* lineWidthSelect;
ColorSelect* colorSelect;
private:
lc::Layer_CSPtr _oldLayer;
};
View
@@ -60,7 +60,8 @@ if(WITH_QTUI)
ui/clicommandtest.h
ui/uitests.h
ui/widgets/layers.h
ui/dialogs/addlinepatterndialog.h)
ui/dialogs/addlinepatterndialog.h
ui/dialogs/addlayerdialog.h)
set(src
${src}
@@ -0,0 +1,33 @@
#pragma once
#include <dialogs/addlayerdialog.cpp>
class AddLayerDialogTest : public AddLayerDialog {
public:
AddLayerDialogTest(lc::Document_SPtr document, QWidget* parent = 0) :
AddLayerDialog(document, parent) {
}
AddLayerDialogTest(lc::Layer_CSPtr oldLayer, lc::Document_SPtr document, QWidget* parent = 0) :
AddLayerDialog(oldLayer, document, parent) {
}
std::string layerName() {
return ui->name->text().toStdString();
}
std::string linePatternName() {
if(linePatternSelect->linePattern() == nullptr) {
return "";
}
return linePatternSelect->linePattern()->name();
};
double lineWidthValue() {
return lineWidthSelect->lineWidth()->width();
};
lc::Color color() {
return colorSelect->color();
};
};
View
@@ -2,6 +2,9 @@
#include "uitests.h"
#include "widgets/layers.h"
#include "dialogs/addlayerdialog.h"
#include <cad/meta/metalinewidth.h>
TEST(LayersTest, Creation) {
QApplication app(argc, argv);
auto document = createDocument();
@@ -107,4 +110,30 @@ TEST(LayersTest, Remove) {
EXPECT_EQ(0, layers->nbLayers()) << "Layer was not removed";
delete layers;
}
TEST(LayersTest, EditionDialog) {
QApplication app(argc, argv);
auto document = createDocument();
auto width = 0.13;
auto color = lc::Color(1, 2, 3, 4);
auto linePattern = std::make_shared<const lc::DxfLinePattern>("LP", "Line Pattern", std::vector<double>{1, -1, 0, -1}, 3);
auto layer = std::make_shared<const lc::Layer>("Layer", lc::MetaLineWidthByValue(width), color, linePattern, false);
auto operation = std::make_shared<lc::operation::AddLinePattern>(document, linePattern);
operation->execute();
AddLayerDialogTest layerDialog(layer, document);
auto dialogColor = layerDialog.color();
EXPECT_EQ(layer->name(), layerDialog.layerName());
EXPECT_EQ(linePattern->name(), layerDialog.linePatternName());
EXPECT_EQ(width, layerDialog.lineWidthValue());
EXPECT_TRUE(
color.red() == dialogColor.red() &&
color.green() == dialogColor.green() &&
color.blue() == dialogColor.blue()
);
}

0 comments on commit cc68991

Please sign in to comment.