• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • RocsCore
  • Tests
TestDynamicProperties.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "TestDynamicProperties.h"
21 
22 #include "DataStructure.h"
23 #include "Data.h"
24 #include "Pointer.h"
25 
26 #include <QTest>
27 #include <Document.h>
28 #include <DataStructureBackendManager.h>
29 
30 TestDynamicProperties::TestDynamicProperties()
31 {
32 }
33 
34 void TestDynamicProperties::initTestCase()
35 {
36  QVERIFY2(DataStructureBackendManager::self().backends().count() > 0, "DataStruture Plugins not loaded");
37  _document = new Document("untitled");
38 }
39 
40 void TestDynamicProperties::cleanup()
41 {
42 }
43 
44 void TestDynamicProperties::addNodeDynamicProperty()
45 {
46  DataStructurePtr g = _document->addDataStructure("A graph");
47 
48  DataPtr n = g->createData("Node", 0);
49  QByteArray property = "newProperty";
50  n->addDynamicProperty(property, QVariant(0));
51  QVERIFY2(n->property(property) != QVariant::Invalid, "Property not added.");
52 }
53 
54 void TestDynamicProperties::addEdgeDynamicProperty()
55 {
56  DataStructurePtr g = _document->addDataStructure("A graph");
57 
58  DataPtr n1 = g->createData("Node1", 0);
59  DataPtr n2 = g->createData("Node2", 0);
60  PointerPtr e = g->createPointer(n1, n2, 0);
61  QVERIFY2(e->getPointer().get() != 0, "Pointer not created!");
62  QByteArray property = "newProperty";
63  e->addDynamicProperty(property, QVariant(0));
64  QVERIFY2(e->property(property) != QVariant::Invalid, "Property not added.");
65 }
66 
67 void TestDynamicProperties::addGraphDynamicProperty()
68 {
69  DataStructurePtr g = _document->addDataStructure("A graph");
70 
71  QByteArray property = "newProperty";
72  g->addDynamicProperty(property);
73  QVERIFY2(g->property(property) != QVariant::Invalid, "Property not added.");
74 }
75 
76 void TestDynamicProperties::removeNodeDynamicProperty()
77 {
78  DataStructurePtr g = _document->addDataStructure("A graph");
79 
80  DataPtr n = g->createData("Node", 0);
81  QByteArray property = "newProperty";
82  int propertyNumber = n->dynamicPropertyNames().size();
83 
84  n->addDynamicProperty(property, QVariant(0));
85  QVERIFY2(n->property(property) != QVariant::Invalid, "Property not added.");
86  QVERIFY(n->dynamicPropertyNames().size() == propertyNumber+1);
87 
88  n->removeDynamicProperty(property);
89  QVERIFY2(!n->property(property).isValid(), "Property not removed.");
90 
91  QVERIFY2(n->dynamicPropertyNames().size() == propertyNumber, "Still having property.");
92 }
93 
94 void TestDynamicProperties::removeEdgeDynamicProperty()
95 {
96  DataStructurePtr g = _document->addDataStructure("A graph");
97 
98  DataPtr n1 = g->createData("Node", 0);
99  DataPtr n2 = g->createData("Node", 0);
100  PointerPtr e = g->createPointer(n1, n2, 0);
101  QByteArray property = "newProperty";
102  e->addDynamicProperty(property, QVariant(0));
103  QVERIFY2(e->property(property) != QVariant::Invalid, "Property not added.");
104  e->removeDynamicProperty(property);
105  QVERIFY2(e->property(property) == QVariant::Invalid, "Property not removed.");
106  QVERIFY2(e->dynamicPropertyNames().size() == 0, "Still having property.");
107 }
108 
109 void TestDynamicProperties::removeGraphDynamicProperty()
110 {
111  DataStructurePtr g = _document->addDataStructure("A graph");
112 
113  QByteArray property = "newProperty";
114  g->addDynamicProperty(property, QVariant(0));
115  QVERIFY2(g->property(property).isValid(), "Property not added.");
116  g->removeDynamicProperty(property);
117  QVERIFY2(!g->property(property).isValid(), "Property not removed.");
118  QVERIFY2(g->dynamicPropertyNames().size() == 0, "Still having property.");
119 }
120 
121 void TestDynamicProperties::insertInvalidNames()
122 {
123  DataStructurePtr g = _document->addDataStructure("A graph");
124 
125  DataPtr n1 = g->createData("Node 1", 0);
126  DataPtr n2 = g->createData("Node 2", 0);
127  PointerPtr e = g->createPointer(n1, n2, 0);
128 
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));
135 
136  n1->addDynamicProperty(property_number, QVariant(0));
137  e->addDynamicProperty(property_number, QVariant(0));
138  g->addDynamicProperty(property_number, QVariant(0));
139 
140  n1->addDynamicProperty(property_nonAscii, QVariant(0));
141  e->addDynamicProperty(property_nonAscii, QVariant(0));
142  g->addDynamicProperty(property_nonAscii, QVariant(0));
143 
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.");
147 
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.");
151 
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.");
155 }
156 
157 void TestDynamicProperties::renameProperties()
158 {
159  DataStructurePtr g = _document->addDataStructure("A graph");
160 
161  DataPtr n1 = g->createData("Node 1", 0);
162  DataPtr n2 = g->createData("Node 2", 0);
163  PointerPtr e = g->createPointer(n1, n2, 0);
164 
165  QByteArray property = "newProperty";
166  n1->addDynamicProperty(property, QVariant(0));
167  n2->addDynamicProperty(property, QVariant(0));
168  e->addDynamicProperty(property, QVariant(0));
169  g->addDynamicProperty(property, QVariant(0));
170 
171  n1->renameDynamicProperty(property, QByteArray("newName_Node"));
172  e->renameDynamicProperty(property, QByteArray("newName_Edge"));
173  g->renameDynamicProperty(property, QByteArray("newName_Graph"));
174 
175  QVERIFY(n1->dynamicPropertyNames().contains(QByteArray("newName_Node")));
176  QCOMPARE(e->dynamicPropertyNames()[0], QByteArray("newName_Edge"));
177  QCOMPARE(g->dynamicPropertyNames()[0], QByteArray("newName_Graph"));
178 }
179 
180 void TestDynamicProperties::renamePropertiesToInvalidNames()
181 {
182  DataStructurePtr g = _document->addDataStructure("graph");
183 
184  DataPtr n1 = g->createData("Node 1", 0);
185  DataPtr n2 = g->createData("Node 2", 0);
186  PointerPtr e = g->createPointer(n1, n2, 0);
187 
188  QByteArray property = "newProperty";
189  n1->addDynamicProperty(property, QVariant(0));
190  n2->addDynamicProperty(property, QVariant(0));
191  e->addDynamicProperty(property, QVariant(0));
192  g->addDynamicProperty(property, QVariant(0));
193 
194  QByteArray property_space = "new Property";
195  QByteArray property_number = "0Property";
196  QByteArray property_nonAscii = "Olá";
197 
198  n1->renameDynamicProperty(property, property_nonAscii);
199  e->renameDynamicProperty(property, property_number);
200  g->renameDynamicProperty(property, property_space);
201 
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.");
204 
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.");
207 
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.");
210 }
211 
212 
213 QTEST_MAIN(TestDynamicProperties)
QByteArray
DataStructurePtr
boost::shared_ptr< DataStructure > DataStructurePtr
Definition: CoreTypes.h:38
Data.h
DataStructureBackendManager::self
static DataStructureBackendManager & self()
Returns self reference to backend manager.
Definition: DataStructureBackendManager.cpp:233
Document.h
PointerPtr
boost::shared_ptr< Pointer > PointerPtr
Definition: CoreTypes.h:35
DataStructure.h
QObject::property
QVariant property(const char *name) const
QTEST_MAIN
QTEST_MAIN(TestTgfFileFormatPlugin)
Document::addDataStructure
DataStructurePtr addDataStructure(const QString &name=QString())
Add data structure to graph document with name name.
Definition: Document.cpp:333
TestDynamicProperties.h
Document
Definition: Document.h:41
Pointer.h
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
DataStructureBackendManager.h
TestDynamicProperties::TestDynamicProperties
TestDynamicProperties()
Definition: TestDynamicProperties.cpp:30
TestDynamicProperties
Definition: TestDynamicProperties.h:26
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal