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

Class PropertyModelTest

tests/propertymodeltest.cpp:31–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29using namespace TestHelpers;
30
31class PropertyModelTest : public BaseProbeTest
32{
33 Q_OBJECT
34private slots:
35 void initTestCase()
36 {
37 createProbe();
38 }
39
40 static void testPropertyModel()
41 {
42 PropertyTestObject obj;
43 obj.setProperty("dynamicProperty", 5);
44
45 AggregatedPropertyModel model;
46 QAbstractItemModelTester modelTest(&model);
47 model.setObject(&obj);
48
49 QVERIFY(model.rowCount() > 9);
50 auto dynRow = searchFixedIndex(&model, "dynamicProperty");
51 QVERIFY(dynRow.isValid());
52 QCOMPARE(dynRow.data(Qt::DisplayRole).toString(), QStringLiteral("dynamicProperty"));
53 QVERIFY(dynRow.sibling(dynRow.row(), 1).flags() & Qt::ItemIsEditable);
54 QCOMPARE(dynRow.sibling(dynRow.row(), 1).data(Qt::DisplayRole).toString(),
55 QStringLiteral("5"));
56 QCOMPARE(dynRow.sibling(dynRow.row(), 1).data(Qt::EditRole), QVariant(5));
57
58 auto qmoRow = searchFixedIndex(&model, "intProp");
59 QVERIFY(qmoRow.isValid());
60 QCOMPARE(qmoRow.data(Qt::DisplayRole).toString(), QStringLiteral("intProp"));
61 auto qmoRow2 = qmoRow.sibling(qmoRow.row(), 1);
62 QVERIFY(qmoRow2.flags() & Qt::ItemIsEditable);
63 QCOMPARE(qmoRow2.data(Qt::DisplayRole).toString(), QStringLiteral("0"));
64 QCOMPARE(qmoRow2.data(Qt::EditRole), QVariant(0));
65 model.setData(qmoRow2, 12);
66 QCOMPARE(obj.intProp(), 12);
67
68 auto moRow = searchFixedIndex(&model, "thread");
69 QVERIFY(moRow.isValid());
70 QCOMPARE(moRow.data(Qt::DisplayRole).toString(), QStringLiteral("thread"));
71 QVERIFY((moRow.sibling(moRow.row(), 1).flags() & Qt::ItemIsEditable) == 0);
72 QVERIFY(!moRow.sibling(moRow.row(), 1).data(Qt::DisplayRole).toString().isEmpty());
73 }
74
75 static void testMetaObject()
76 {
77 AggregatedPropertyModel model;
78 model.setObject(ObjectInstance(nullptr, &Gadget::staticMetaObject));
79 QAbstractItemModelTester modelTest(&model);
80
81 QCOMPARE(model.rowCount(), 1);
82 auto qmoRow = searchFixedIndex(&model, "prop1");
83 QVERIFY(qmoRow.isValid());
84 }
85
86 static void testChangeNotification()
87 {
88 ChangingPropertyObject obj;

Callers

nothing calls this directly

Calls 1

initTestCaseFunction · 0.70

Tested by

no test coverage detected