Skip to content

Add QML tests for the reshape geometry editor tool#7584

Open
kaustuvpokharel wants to merge 9 commits into
masterfrom
reshapeGeometryTests
Open

Add QML tests for the reshape geometry editor tool#7584
kaustuvpokharel wants to merge 9 commits into
masterfrom
reshapeGeometryTests

Conversation

@kaustuvpokharel

Copy link
Copy Markdown
Collaborator

This adds a QML test file for the reshape tool (Reshape.qml), and a small fix to the QML test harness that was needed to get there.

The harness fix first: mounting any component that contains a DigitizingToolbar currently crashes the QML test run with a segfault. The Cogo work added a CogoOperationsModel that dereferences CogoRegistry::instance() at construction, but that singleton is only set by QgisMobileapp, which the test harness never instantiates. So it comes back null and crashes. test_qml.cpp now sets a CogoRegistry instance in qmlEngineAvailable, the same way it already sets AppInterface. This unblocks testing any digitizing-based tool, not just reshape.

The tests themselves cover the tool wiring around the reshape maths (which is already covered in test_geometryutils.cpp): init sets up the feature model and forces polygon mode, blocking mirrors the rubberband digitizing state, the confirm handler's failure path toasts an error and rolls back leaving the feature untouched, and cancel resets the rubberband.

The successful reshape geometry is left to the C++ tests. Driving a valid reshape through confirm() here would mean reproducing the live digitizing rubberband state (the trailing current vertex, the cursor coordinate confirm() appends), which is awkward to do headless and adds little over the C++ coverage that already validates reshapeFromRubberband directly.
All tests pass locally.

@kaustuvpokharel kaustuvpokharel self-assigned this Jun 17, 2026
@qfield-fairy

qfield-fairy commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

🍎 MacOS DMG universal builds

Download a MacOS DMG universal build of this PR for testing.
(Built from commit daa306e)

📱 Android builds

Download an Android arm64 build of this PR for testing.
(Built from commit daa306e)

Other Android architectures

🪟 Windows builds

Download a Windows build of this PR for testing and for arm64.

(Built from commit daa306e)

🐧 Linux AppImage builds

Download a Linux AppImage build of this PR for testing.
(Built from commit daa306e)

@nirvn nirvn closed this Jun 19, 2026
@nirvn nirvn reopened this Jun 19, 2026
Comment thread test/qml/tst_geometryeditor_reshape.qml
Comment on lines +86 to +102
function test_reshapeWithValidLineProducesExpectedGeometry() {
const model = initReshapeOnFields();
// a reshape line that crosses the polygon boundary twice, cutting a new edge
rubberband.addVertexFromPoint(GeometryUtils.point(1030845.75, 5911397.39));
rubberband.addVertexFromPoint(GeometryUtils.point(1030771.49, 5911511.09));
rubberband.addVertexFromPoint(GeometryUtils.point(1030857.23, 5911624.79));

// drive the operation directly and roll back instead of committing, so the
// shared layer data is untouched
if (!fieldsLayer.editBuffer())
fieldsLayer.startEditing();
const result = GeometryUtils.reshapeFromRubberband(fieldsLayer, model.feature.id, rubberband);
// the reshape succeeds and produces this exact polygon
compare(Number(result), Number(GeometryUtils.Success));
const expected = "Polygon ((1031040.99 5911336.9, 1030978.97 5911394.33, 1030845.75 5911397.39, 1030845.75 5911397.4, 1030857.23 5911624.79, 1031057.07 5911646.23, 1031082.33 5911535.21, 1031119.08 5911493.1, 1031093.82 5911453.28, 1031072.67 5911421.57, 1031063.19 5911407.34, 1031044.82 5911362.94, 1031041.44 5911340.01, 1031040.99 5911336.9))";
compare(fieldsLayer.getFeature(model.feature.id).geometry.asWkt(2), expected);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use the tool itself to insure it it sound (i.e. simulating a confirm click on the digitizing toolbar so the tool itself runs the onConfirmed function.

This test isn't necessarily bad (you are comparing a WKT, nice), but it's not testing what we want here: the tool itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants