mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-28 02:55:05 +00:00
diffUpdate inserted an element at its target index without removing it from its previous index, so a pure permutation like [d,a,b,c] -> [a,b,c,d] left every misplaced element in the model twice and the removal pass never reclaimed them because their pointer is still in newValues. Any caller that re-sorts an existing list (dbusmenu re-layout, desktopentry re-scan) can hit this. Found via a downstream niri workspace backend where a monitor hot-plug re-sorts the model.
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "objectmodel.hpp"
|
|
|
|
#include <qlist.h>
|
|
#include <qobject.h>
|
|
#include <qtest.h>
|
|
#include <qtestcase.h>
|
|
|
|
#include "../model.hpp"
|
|
|
|
void TestObjectModel::diffUpdateInsertRemove() {
|
|
QObject a;
|
|
QObject b;
|
|
QObject c;
|
|
QObject d;
|
|
|
|
auto model = ObjectModel<QObject>(nullptr);
|
|
model.insertObject(&a);
|
|
model.insertObject(&b);
|
|
model.insertObject(&c);
|
|
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &b, &c}));
|
|
|
|
// drop b, append d — relative order of survivors unchanged
|
|
model.diffUpdate({&a, &c, &d});
|
|
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &c, &d}));
|
|
}
|
|
|
|
void TestObjectModel::diffUpdateReorder() {
|
|
QObject a;
|
|
QObject b;
|
|
QObject c;
|
|
QObject d;
|
|
|
|
auto model = ObjectModel<QObject>(nullptr);
|
|
model.insertObject(&d);
|
|
model.insertObject(&a);
|
|
model.insertObject(&b);
|
|
model.insertObject(&c);
|
|
QCOMPARE(model.valueList(), (QList<QObject*> {&d, &a, &b, &c}));
|
|
|
|
// pure permutation: same elements, different order. Previously turned
|
|
// [d,a,b,c] into [a,b,c,d,a,b,c] because the old row was never removed
|
|
// before inserting at the new index.
|
|
model.diffUpdate({&a, &b, &c, &d});
|
|
QCOMPARE(model.valueList(), (QList<QObject*> {&a, &b, &c, &d}));
|
|
}
|
|
|
|
QTEST_MAIN(TestObjectModel);
|