mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-21 13:54:13 +02:00
Add regression test for elements-panel project-open auto-select crash
- tst_elementspanelprojectopen drives ElementsPanel::projectWasOpened() -- the slot the application connects to a project being opened -- on a fresh panel whose first reload() has not run, reproducing the detached-item ordering deterministically offscreen. - On master without the guard the test fails: the auto-select leaves currentItem() pointing at an item whose treeWidget() is not the panel (and on some builds crashes in QTreeModel). With the guard it passes: no item is selected while the project is detached. - Registered via qet_add_app_test(), which links the application code and runs a real QETApp offscreen. Generated-by: Claude Code Signed-off-by: hairykiwi <174199+hairykiwi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include "qetapptest.h"
|
||||
|
||||
#include "elementspanel.h"
|
||||
#include "projectview.h"
|
||||
#include "qetproject.h"
|
||||
|
||||
// projectWasOpened() adds the project to the elements panel. Before the panel's
|
||||
// first reload() the project's tree item is left detached (treeWidget() ==
|
||||
// nullptr), and selecting its first child crashed in QTreeModel
|
||||
// (pre-existing since a82f6de23).
|
||||
class tst_elementspanelprojectopen : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void addProjectBeforeReloadDoesNotCrash()
|
||||
{
|
||||
// A real one-folio project from the running app; diagrams()
|
||||
// builds the lazy folio, so the project item will have a child.
|
||||
QETDiagramEditor *editor = QetAppTest::editor();
|
||||
QVERIFY(editor);
|
||||
QVERIFY(editor->newProject());
|
||||
ProjectView *pv = editor->currentProjectView();
|
||||
QVERIFY(pv);
|
||||
QETProject *project = pv->project();
|
||||
QVERIFY(project);
|
||||
QVERIFY(!project->diagrams().isEmpty());
|
||||
|
||||
// Fresh panel: reload() has not run, so the project item is inserted detached.
|
||||
ElementsPanel panel;
|
||||
|
||||
// Without the guard this selects a detached item; with it, nothing is selected.
|
||||
panel.projectWasOpened(project);
|
||||
|
||||
QTreeWidgetItem *current = panel.currentItem();
|
||||
QVERIFY2(current == nullptr || current->treeWidget() == &panel,
|
||||
"the panel selected a detached item it does not own");
|
||||
}
|
||||
};
|
||||
|
||||
QET_APP_TEST_MAIN(tst_elementspanelprojectopen)
|
||||
|
||||
#include "tst_elementspanelprojectopen.moc"
|
||||
Reference in New Issue
Block a user