34 void TestDynamicProperties::initTestCase()
37 _document =
new Document(
"untitled");
40 void TestDynamicProperties::cleanup()
44 void TestDynamicProperties::addNodeDynamicProperty()
48 DataPtr n = g->createData(
"Node", 0);
51 QVERIFY2(n->property(
property) != QVariant::Invalid,
"Property not added.");
54 void TestDynamicProperties::addEdgeDynamicProperty()
58 DataPtr n1 = g->createData(
"Node1", 0);
59 DataPtr n2 = g->createData(
"Node2", 0);
61 QVERIFY2(e->getPointer().get() != 0,
"Pointer not created!");
64 QVERIFY2(e->property(
property) != QVariant::Invalid,
"Property not added.");
67 void TestDynamicProperties::addGraphDynamicProperty()
71 QByteArray
property =
"newProperty";
73 QVERIFY2(g->property(
property) != QVariant::Invalid,
"Property not added.");
76 void TestDynamicProperties::removeNodeDynamicProperty()
80 DataPtr n = g->createData(
"Node", 0);
81 QByteArray
property =
"newProperty";
82 int propertyNumber = n->dynamicPropertyNames().size();
85 QVERIFY2(n->property(
property) != QVariant::Invalid,
"Property not added.");
86 QVERIFY(n->dynamicPropertyNames().size() == propertyNumber+1);
89 QVERIFY2(!n->property(
property).isValid(),
"Property not removed.");
91 QVERIFY2(n->dynamicPropertyNames().size() == propertyNumber,
"Still having property.");
94 void TestDynamicProperties::removeEdgeDynamicProperty()
98 DataPtr n1 = g->createData(
"Node", 0);
99 DataPtr n2 = g->createData(
"Node", 0);
101 QByteArray
property =
"newProperty";
103 QVERIFY2(e->property(
property) != QVariant::Invalid,
"Property not added.");
105 QVERIFY2(e->property(
property) == QVariant::Invalid,
"Property not removed.");
106 QVERIFY2(e->dynamicPropertyNames().size() == 0,
"Still having property.");
109 void TestDynamicProperties::removeGraphDynamicProperty()
113 QByteArray
property =
"newProperty";
115 QVERIFY2(g->property(
property).isValid(),
"Property not added.");
117 QVERIFY2(!g->property(
property).isValid(),
"Property not removed.");
118 QVERIFY2(g->dynamicPropertyNames().size() == 0,
"Still having property.");
121 void TestDynamicProperties::insertInvalidNames()
125 DataPtr n1 = g->createData(
"Node 1", 0);
126 DataPtr n2 = g->createData(
"Node 2", 0);
129 QByteArray property_space =
"new Property";
130 QByteArray property_number =
"0Property";
131 QByteArray property_nonAscii =
"Olá";
132 n1->addDynamicProperty(property_space,
QVariant(0));
133 e->addDynamicProperty(property_space,
QVariant(0));
134 g->addDynamicProperty(property_space,
QVariant(0));
136 n1->addDynamicProperty(property_number,
QVariant(0));
137 e->addDynamicProperty(property_number,
QVariant(0));
138 g->addDynamicProperty(property_number,
QVariant(0));
140 n1->addDynamicProperty(property_nonAscii,
QVariant(0));
141 e->addDynamicProperty(property_nonAscii,
QVariant(0));
142 g->addDynamicProperty(property_nonAscii,
QVariant(0));
144 QVERIFY2(e->property(property_space) == QVariant::Invalid,
"Invalid Property (with space) added to edge.");
145 QVERIFY2(e->property(property_number) == QVariant::Invalid,
"Invalid Property (starts by number) added to edge.");
146 QVERIFY2(e->property(property_nonAscii) == QVariant::Invalid,
"Invalid Property (non ASCII) added to edge.");
148 QVERIFY2(n1->property(property_space) == QVariant::Invalid,
"Invalid Property (with space) added to node 1.");
149 QVERIFY2(n1->property(property_number) == QVariant::Invalid,
"Invalid Property (starts by number) added to node 1.");
150 QVERIFY2(n1->property(property_nonAscii) == QVariant::Invalid,
"Invalid Property (non ASCII) added to node 1.");
152 QVERIFY2(g->property(property_space) == QVariant::Invalid,
"Invalid Property (with space) added to graph.");
153 QVERIFY2(g->property(property_number) == QVariant::Invalid,
"Invalid Property (starts by number) added to graph.");
154 QVERIFY2(g->property(property_nonAscii) == QVariant::Invalid,
"Invalid Property (non ASCII) added to graph.");
157 void TestDynamicProperties::renameProperties()
161 DataPtr n1 = g->createData(
"Node 1", 0);
162 DataPtr n2 = g->createData(
"Node 2", 0);
165 QByteArray
property =
"newProperty";
171 n1->renameDynamicProperty(
property, QByteArray(
"newName_Node"));
172 e->renameDynamicProperty(
property, QByteArray(
"newName_Edge"));
173 g->renameDynamicProperty(
property, QByteArray(
"newName_Graph"));
175 QVERIFY(n1->dynamicPropertyNames().contains(QByteArray(
"newName_Node")));
176 QCOMPARE(e->dynamicPropertyNames()[0], QByteArray(
"newName_Edge"));
177 QCOMPARE(g->dynamicPropertyNames()[0], QByteArray(
"newName_Graph"));
180 void TestDynamicProperties::renamePropertiesToInvalidNames()
184 DataPtr n1 = g->createData(
"Node 1", 0);
185 DataPtr n2 = g->createData(
"Node 2", 0);
188 QByteArray
property =
"newProperty";
194 QByteArray property_space =
"new Property";
195 QByteArray property_number =
"0Property";
196 QByteArray property_nonAscii =
"Olá";
198 n1->renameDynamicProperty(
property, property_nonAscii);
199 e->renameDynamicProperty(
property, property_number);
200 g->renameDynamicProperty(
property, property_space);
202 QVERIFY2(g->property(property_space) == QVariant::Invalid,
"Invalid Property (with space) added to graph.");
203 QVERIFY2(g->property(
property) != QVariant::Invalid,
"Original property was changed.");
205 QVERIFY2(n1->property(property_nonAscii) == QVariant::Invalid,
"Invalid Property (with space) added to node.");
206 QVERIFY2(n1->property(
property) != QVariant::Invalid,
"Original property was changed.");
208 QVERIFY2(e->property(property_number) == QVariant::Invalid,
"Invalid Property (with space) added to edge.");
209 QVERIFY2(e->property(
property) != QVariant::Invalid,
"Original property was changed.");
boost::shared_ptr< DataStructure > DataStructurePtr
static DataStructureBackendManager & self()
Returns self reference to backend manager.
boost::shared_ptr< Pointer > PointerPtr
QVariant property(const char *name) const
DataStructurePtr addDataStructure(const QString &name=QString())
Add data structure to graph document with name name.
boost::shared_ptr< Data > DataPtr