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

Method testModelInsertions

tests/bindinginspectortest.cpp:719–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

717}
718
719void BindingInspectorTest::testModelInsertions()
720{
721 MockObject obj1 { 53, true, 'x', 5.3, "Hello World" };
722 MockObject obj2 { 35, false, 'y', 3.5, "Bye, World" };
723
724 provider->data = { { { &obj1, "a", &obj1, "e" } } };
725
726 bindingExtension->setQObject(&obj1);
727 QCOMPARE(bindingModel->rowCount(QModelIndex()), 1);
728 QModelIndex obj1aIndex = bindingModel->index(0, 0, QModelIndex());
729 QVERIFY(obj1aIndex.isValid());
730 QCOMPARE(obj1aIndex.data().toString(), QStringLiteral("a"));
731 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 53);
732 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("1"));
733 QCOMPARE(bindingModel->rowCount(obj1aIndex), 1);
734
735 QModelIndex obj1eIndex = bindingModel->index(0, 0, obj1aIndex);
736 QVERIFY(obj1eIndex.isValid());
737 QCOMPARE(obj1eIndex.data().toString(), QStringLiteral("e"));
738 QCOMPARE(obj1eIndex.sibling(obj1eIndex.row(), BindingModel::ValueColumn).data().toString(), QStringLiteral("Hello World"));
739 QCOMPARE(obj1eIndex.sibling(obj1eIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("0"));
740 QCOMPARE(bindingModel->rowCount(obj1eIndex), 0);
741
742 QSignalSpy rowAddedSpy(bindingModel, &QAbstractItemModel::rowsInserted);
743 QSignalSpy dataChangedSpy(bindingModel, &QAbstractItemModel::dataChanged);
744 QVERIFY(rowAddedSpy.isValid());
745 QVERIFY(dataChangedSpy.isValid());
746
747 provider->data.emplace(provider->data.end(), &obj1, "a", &obj1, "b");
748 provider->data.emplace(provider->data.end(), &obj1, "a", &obj1, "c");
749 provider->data.emplace(provider->data.end(), &obj1, "c", &obj2, "a");
750 provider->data.emplace(provider->data.end(), &obj1, "e", &obj2, "a");
751 obj1.setA(12);
752
753 rowAddedSpy.wait(500);
754 QCOMPARE(rowAddedSpy.size(), 2);
755 QCOMPARE(rowAddedSpy.front().at(0).toModelIndex(), obj1aIndex);
756 QCOMPARE(rowAddedSpy.front().at(1).toInt(), 0);
757 QCOMPARE(rowAddedSpy.front().at(2).toInt(), 1);
758
759 QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("2"));
760 QCOMPARE(bindingModel->rowCount(obj1aIndex), 3);
761
762 auto obj1aChildren = getSortedChildren(obj1aIndex);
763 obj1eIndex = obj1aChildren[2];
764 QVERIFY(obj1eIndex.isValid());
765 QCOMPARE(obj1eIndex.data().toString(), QStringLiteral("e"));
766 QCOMPARE(obj1eIndex.sibling(obj1eIndex.row(), BindingModel::ValueColumn).data().toString(), QStringLiteral("Hello World"));
767 QCOMPARE(obj1eIndex.sibling(obj1eIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("1"));
768 QCOMPARE(bindingModel->rowCount(obj1eIndex), 1);
769
770 QModelIndex obj1bIndex = obj1aChildren[0];
771 QVERIFY(obj1bIndex.isValid());
772 QCOMPARE(obj1bIndex.data().toString(), QStringLiteral("b"));
773 QCOMPARE(obj1bIndex.sibling(obj1bIndex.row(), BindingModel::ValueColumn).data().toBool(), true);
774 QCOMPARE(obj1bIndex.sibling(obj1bIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("0"));
775 QCOMPARE(bindingModel->rowCount(obj1bIndex), 0);
776

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected