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

Class PropertyBinderTest

tests/propertybindertest.cpp:65–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63using namespace GammaRay;
64
65class PropertyBinderTest : public QObject
66{
67 Q_OBJECT
68private slots:
69 void testBinding()
70 {
71 auto *obj1 = new MyObject(this);
72 auto *obj2 = new MyObject(this);
73 new PropertyBinder(obj1, "intProp", obj2, "intProp");
74
75 obj1->setIntProp(5);
76 QCOMPARE(obj2->intProp(), 5);
77
78 obj2->setIntProp(9);
79 QCOMPARE(obj1->intProp(), 9);
80
81 delete obj2;
82 obj1->setIntProp(42); // don't crash
83 }
84
85 void testInitialBinding()
86 {
87 std::unique_ptr<MyObject> obj1(new MyObject(this));
88 obj1->setIntProp(18);
89 std::unique_ptr<MyObject> obj2(new MyObject(this));
90 QVERIFY(obj1->intProp() != obj2->intProp());
91 new PropertyBinder(obj1.get(), "intProp", obj2.get(), "intProp");
92 QCOMPARE(obj2->intProp(), 18);
93 }
94
95 void testMultiBinding()
96 {
97 std::unique_ptr<MyObject> obj1(new MyObject(this));
98 obj1->setIntProp(18);
99 obj1->setIntProp2(133);
100 std::unique_ptr<MyObject> obj2(new MyObject(this));
101
102 auto binder = new PropertyBinder(obj1.get(), obj2.get());
103 binder->add("intProp", "intProp");
104 binder->add("intProp2", "intProp2");
105
106 QVERIFY(obj1->intProp() != obj2->intProp());
107 QVERIFY(obj1->intProp2() != obj2->intProp2());
108
109 binder->syncSourceToDestination();
110
111 QCOMPARE(obj2->intProp(), 18);
112 QCOMPARE(obj2->intProp2(), 133);
113
114 obj2->setIntProp(23);
115 QCOMPARE(obj1->intProp(), 23);
116 }
117};
118
119QTEST_MAIN(PropertyBinderTest)
120

Callers

nothing calls this directly

Calls 2

setIntPropMethod · 0.45
intPropMethod · 0.45

Tested by

no test coverage detected