From 771a46d89dcac4352d02959a9035692a428df424 Mon Sep 17 00:00:00 2001 From: Jeff Wheeler Date: Fri, 14 Jun 2024 21:45:27 -0700 Subject: [PATCH] Add drawing test (#78) Some paths on symbols were not being drawn before #76. This adds a test for that case. --- src/brd_gui/brdview.cpp | 8 ++++++- src/brd_gui/brdview.h | 2 ++ src/brd_gui/test/CMakeLists.txt | 10 ++++++--- src/brd_gui/test/brdview_test.cpp | 22 +++++++++++++++++++ src/brd_gui/test/brdview_test.h | 7 ++++++ .../{gui_test.cpp => mainwindow_test.cpp} | 2 +- .../test/{gui_test.h => mainwindow_test.h} | 0 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/brd_gui/test/brdview_test.cpp create mode 100644 src/brd_gui/test/brdview_test.h rename src/brd_gui/test/{gui_test.cpp => mainwindow_test.cpp} (85%) rename src/brd_gui/test/{gui_test.h => mainwindow_test.h} (100%) diff --git a/src/brd_gui/brdview.cpp b/src/brd_gui/brdview.cpp index 81cdb0c..fb97938 100644 --- a/src/brd_gui/brdview.cpp +++ b/src/brd_gui/brdview.cpp @@ -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 *fs) { @@ -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(); diff --git a/src/brd_gui/brdview.h b/src/brd_gui/brdview.h index 5831002..26392fc 100644 --- a/src/brd_gui/brdview.h +++ b/src/brd_gui/brdview.h @@ -43,6 +43,8 @@ class BrdView : public QGraphicsView { void selectLayer(std::set> layers); + bool drewKey(const uint32_t ptr); + enum layer_choice { ALL = -1, FAB = -2 }; protected: diff --git a/src/brd_gui/test/CMakeLists.txt b/src/brd_gui/test/CMakeLists.txt index 56a106c..5243875 100644 --- a/src/brd_gui/test/CMakeLists.txt +++ b/src/brd_gui/test/CMakeLists.txt @@ -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) diff --git a/src/brd_gui/test/brdview_test.cpp b/src/brd_gui/test/brdview_test.cpp new file mode 100644 index 0000000..c386e9a --- /dev/null +++ b/src/brd_gui/test/brdview_test.cpp @@ -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> 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) diff --git a/src/brd_gui/test/brdview_test.h b/src/brd_gui/test/brdview_test.h new file mode 100644 index 0000000..61e1b24 --- /dev/null +++ b/src/brd_gui/test/brdview_test.h @@ -0,0 +1,7 @@ +#include + +class TestBrdView : public QObject { + Q_OBJECT + private slots: + void drawAllSymbolPaths(); +}; diff --git a/src/brd_gui/test/gui_test.cpp b/src/brd_gui/test/mainwindow_test.cpp similarity index 85% rename from src/brd_gui/test/gui_test.cpp rename to src/brd_gui/test/mainwindow_test.cpp index b9dda97..6f90953 100644 --- a/src/brd_gui/test/gui_test.cpp +++ b/src/brd_gui/test/mainwindow_test.cpp @@ -1,4 +1,4 @@ -#include "gui_test.h" +#include "mainwindow_test.h" #include "brd_gui/mainwindow.h" diff --git a/src/brd_gui/test/gui_test.h b/src/brd_gui/test/mainwindow_test.h similarity index 100% rename from src/brd_gui/test/gui_test.h rename to src/brd_gui/test/mainwindow_test.h