Skip to content

Commit

Permalink
Add drawing test (#78)
Browse files Browse the repository at this point in the history
Some paths on symbols were not being drawn before #76. This adds a test
for that case.
  • Loading branch information
jeffwheeler authored Jun 15, 2024
1 parent bb6cc3b commit 771a46d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/brd_gui/brdview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ BrdView::BrdView(MainWindow *parent)

// drawFile();

((MainWindow *)parent)->updatePosition(QPointF(0, 0));
if (parent != nullptr) {
((MainWindow *)parent)->updatePosition(QPointF(0, 0));
}
};

void BrdView::loadFile(File<kAMax> *fs) {
Expand All @@ -38,6 +40,10 @@ void BrdView::zoomOut() { scale(1 / 1.2, 1 / 1.2); }

void BrdView::zoomFit() { fitInView(scene->sceneRect(), Qt::KeepAspectRatio); }

bool BrdView::drewKey(const uint32_t ptr) {
return already_drawn.count(ptr) > 0;
}

void BrdView::keyPressEvent(QKeyEvent *event) {
qint32 k = event->key();

Expand Down
2 changes: 2 additions & 0 deletions src/brd_gui/brdview.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class BrdView : public QGraphicsView {

void selectLayer(std::set<std::pair<uint16_t, uint16_t>> layers);

bool drewKey(const uint32_t ptr);

enum layer_choice { ALL = -1, FAB = -2 };

protected:
Expand Down
10 changes: 7 additions & 3 deletions src/brd_gui/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
find_package(Qt6 COMPONENTS Widgets Gui Test REQUIRED)

qt_add_executable(gui_test gui_test.cpp)
add_test(NAME TestGui COMMAND gui_test)
qt_add_executable(mainwindow_test mainwindow_test.cpp)
add_test(NAME TestMainWindow COMMAND mainwindow_test)

target_link_libraries(gui_test PRIVATE BrdGui Qt::Widgets Qt::Test)
qt_add_executable(brdview_test brdview_test.cpp)
add_test(NAME TestBrdView COMMAND brdview_test)

target_link_libraries(mainwindow_test PRIVATE BrdGui Qt::Widgets Qt::Test)
target_link_libraries(brdview_test PRIVATE BrdGui Qt::Widgets Qt::Test)
22 changes: 22 additions & 0 deletions src/brd_gui/test/brdview_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "brdview_test.h"

#include "brd_gui/brdview.h"

void TestBrdView::drawAllSymbolPaths() {
BrdView brdview;

auto parsed_file = parse_file("../../test/data/fmc_tlu/fmc_tlu_v1f_38.brd");
if (parsed_file) {
brdview.loadFile(&parsed_file.value());
}

// Show the appropriate layer
const std::set<std::pair<uint16_t, uint16_t>> layers = {{0x09, 0xFD}};
brdview.selectLayer(layers);

// If we don't iterate over all symbol paths, we miss this one.
QVERIFY2(brdview.drewKey(0x000055F6),
"Path unexpectedly missing after selecting its layer");
}

QTEST_MAIN(TestBrdView)
7 changes: 7 additions & 0 deletions src/brd_gui/test/brdview_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <QTest>

class TestBrdView : public QObject {
Q_OBJECT
private slots:
void drawAllSymbolPaths();
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "gui_test.h"
#include "mainwindow_test.h"

#include "brd_gui/mainwindow.h"

Expand Down
File renamed without changes.

0 comments on commit 771a46d

Please sign in to comment.