MCPcopy Create free account
hub / github.com/KDAB/GammaRay / testModelRemovalInside

Method testModelRemovalInside

tests/bindinginspectortest.cpp:864–915  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

862}
863
864void BindingInspectorTest::testModelRemovalInside()
865{
866 MockObject obj1 { 53, true, 'x', 5.3, "Hello World" };
867
868 provider->data = { {
869 { &obj1, "a", &obj1, "b" },
870 { &obj1, "a", &obj1, "c" },
871 { &obj1, "a", &obj1, "d" },
872 { &obj1, "b", &obj1, "e" },
873 } };
874
875 bindingExtension->setQObject(&obj1);
876 QCOMPARE(bindingModel->rowCount(QModelIndex()), 2);
877 auto topLevelIndices = getSortedChildren(QModelIndex(), bindingModel);
878 QModelIndex obj1aIndex = topLevelIndices[0];
879 QVERIFY(obj1aIndex.isValid());
880 QCOMPARE(obj1aIndex.data().toString(), QStringLiteral("a"));
881 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 53);
882 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("2"));
883 QCOMPARE(bindingModel->rowCount(obj1aIndex), 3);
884
885 QSignalSpy rowRemovedSpy(bindingModel, &QAbstractItemModel::rowsRemoved);
886 QSignalSpy dataChangedSpy(bindingModel, &QAbstractItemModel::dataChanged);
887 QVERIFY(rowRemovedSpy.isValid());
888 QVERIFY(dataChangedSpy.isValid());
889
890 provider->data.erase(provider->data.begin(), provider->data.begin() + 2);
891 obj1.setA(12);
892
893 rowRemovedSpy.wait(500);
894 QCOMPARE(rowRemovedSpy.size(), 1);
895 QCOMPARE(rowRemovedSpy.front().front().toModelIndex(), obj1aIndex);
896 QCOMPARE(rowRemovedSpy.front().at(1).toInt(), 0);
897 QCOMPARE(rowRemovedSpy.front().at(2).toInt(), 1);
898
899 QCOMPARE(bindingModel->rowCount(obj1aIndex), 1);
900 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("1"));
901 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 12);
902
903 QModelIndex obj1dIndex = bindingModel->index(0, 0, obj1aIndex);
904 QVERIFY(obj1dIndex.isValid());
905 QCOMPARE(obj1dIndex.data().toString(), QStringLiteral("d"));
906 QCOMPARE(obj1dIndex.sibling(obj1dIndex.row(), BindingModel::ValueColumn).data().toDouble(), 5.3);
907 QCOMPARE(obj1dIndex.sibling(obj1dIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("0"));
908 QCOMPARE(bindingModel->rowCount(obj1dIndex), 0);
909
910 QCOMPARE(dataChangedSpy.size(), 2);
911 QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn)); // Fair enough, we did change the value.
912 QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn));
913 QCOMPARE(dataChangedSpy.at(1).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn)); // depth changed
914 QCOMPARE(dataChangedSpy.at(1).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn));
915}
916
917void BindingInspectorTest::testIntegration()
918{

Callers

nothing calls this directly

Calls 11

getSortedChildrenFunction · 0.85
rowMethod · 0.80
setAMethod · 0.80
QModelIndexClass · 0.50
setQObjectMethod · 0.45
rowCountMethod · 0.45
isValidMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected