[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [rocs/dataUseOnlyDynamicProperties] src: Fix unit tests.
From: Andreas Cord-Landwehr <cola () uni-paderborn ! de>
Date: 2012-09-22 19:50:16
Message-ID: 20120922195016.37463A6094 () git ! kde ! org
[Download RAW message or body]
Git commit e800833ac1fe0cd4fa50cec480f8117ce36cd83b by Andreas Cord-Landwehr.
Committed on 22/09/2012 at 21:49.
Pushed by cordlandwehr into branch 'dataUseOnlyDynamicProperties'.
Fix unit tests.
M +0 -31 src/Core/DataStructure.cpp
M +0 -2 src/Core/DataStructure.h
M +1 -1 src/Interface/DataPropertiesWidget.cpp
M +1 -1 src/Interface/PointerPropertiesWidget.cpp
M +9 -18 src/Models/model_GraphProperties.cpp
M +1 -1 src/Models/model_GraphProperties.h
M +12 -113 src/Tests/TestDynamicProperties.cpp
M +0 -8 src/Tests/TestDynamicProperties.h
http://commits.kde.org/rocs/e800833ac1fe0cd4fa50cec480f8117ce36cd83b
diff --git a/src/Core/DataStructure.cpp b/src/Core/DataStructure.cpp
index fd4e3d5..e151c96 100644
--- a/src/Core/DataStructure.cpp
+++ b/src/Core/DataStructure.cpp
@@ -367,9 +367,6 @@ DataPtr DataStructure::addData(QString name, int dataType)
DataPtr n = Data::create(this->getDataStructure(), generateUniqueIdentifier(), \
dataType);
- if (n->property("name") == QVariant::Invalid) {
- document()->dataType(dataType)->addProperty("name");
- }
n->setProperty("name", name);
return addData(n, dataType);
}
@@ -572,20 +569,6 @@ void DataStructure::removeDynamicProperty(const QString& \
property) }
-void DataStructure::addDataDynamicProperty(const QString& property, QVariant value)
-{
- // do not change properties concurrently, not thread safe
- foreach(const DataList& dataType, d->_dataTypeLists) {
- DataList::const_iterator data = dataType.constBegin();
- while (data != dataType.constEnd()) {
- (*data)->addDynamicProperty(property, value);
- ++data;
- }
- }
- d->m_globalPropertiesData.insert(property, value);
-}
-
-
void DataStructure::addPointersDynamicProperty(const QString& property, QVariant \
value) {
// do not change properties concurrently, not thread safe
@@ -599,20 +582,6 @@ void DataStructure::addPointersDynamicProperty(const QString& \
property, QVariant d->m_globalPropertiesData.insert(property, value);
}
-
-void DataStructure::removeDataDynamicProperty(const QString& property)
-{
- // do not change properties concurrently, not thread safe
- foreach(const DataList& dataType, d->_dataTypeLists) {
- DataList::const_iterator data = dataType.constBegin();
- while (data != dataType.constEnd()) {
- (*data)->removeDynamicProperty(property);
- ++data;
- }
- }
- d->m_globalPropertiesData.remove(property);
-}
-
void DataStructure::removePointersDynamicProperty(const QString& property)
{
// do not change properties concurrently, not thread safe
diff --git a/src/Core/DataStructure.h b/src/Core/DataStructure.h
index aa4cafc..8724220 100644
--- a/src/Core/DataStructure.h
+++ b/src/Core/DataStructure.h
@@ -204,10 +204,8 @@ public slots:
/**
* add dynamic property to all data elements of data structure
*/
- void addDataDynamicProperty(const QString& property, QVariant value = \
QVariant(0));
void addPointersDynamicProperty(const QString& property, QVariant value = \
QVariant(0));
- void removeDataDynamicProperty(const QString& property);
void removePointersDynamicProperty(const QString& property);
/**
diff --git a/src/Interface/DataPropertiesWidget.cpp \
b/src/Interface/DataPropertiesWidget.cpp index 03811c1..38e71a8 100644
--- a/src/Interface/DataPropertiesWidget.cpp
+++ b/src/Interface/DataPropertiesWidget.cpp
@@ -163,5 +163,5 @@ void DataPropertiesWidget::updateDataTypes()
void DataPropertiesWidget::addProperty()
{
GraphPropertiesModel *model = qobject_cast< \
GraphPropertiesModel*>(ui->_propertiesTable->model());
- model->addDynamicProperty(i18n("untitled %1", model->rowCount()), 0, \
_data.get(), false); + model->addDynamicProperty(i18n("untitled%1", \
model->rowCount()), 0, _data.get()); }
diff --git a/src/Interface/PointerPropertiesWidget.cpp \
b/src/Interface/PointerPropertiesWidget.cpp index 6c39b59..0cd6f73 100644
--- a/src/Interface/PointerPropertiesWidget.cpp
+++ b/src/Interface/PointerPropertiesWidget.cpp
@@ -104,7 +104,7 @@ void PointerPropertiesWidget::on__addProperty_clicked()
GraphPropertiesModel *model = qobject_cast< \
GraphPropertiesModel*>(ui->_propertiesTable->model());
model->addDynamicProperty(ui->_propertyName->text(), \
QVariant(ui->_propertyValue->text()),
- _pointer.get(), (ui->_isPropertyGlobal->checkState() \
== Qt::Checked)); + _pointer.get());
}
diff --git a/src/Models/model_GraphProperties.cpp \
b/src/Models/model_GraphProperties.cpp index c05199e..248ab8f 100644
--- a/src/Models/model_GraphProperties.cpp
+++ b/src/Models/model_GraphProperties.cpp
@@ -154,7 +154,7 @@ bool GraphPropertiesModel::setData(const QModelIndex &index, \
const QVariant &val
}
-void GraphPropertiesModel::addDynamicProperty(QString name, QVariant value, QObject \
*obj, bool isGlobal) +void GraphPropertiesModel::addDynamicProperty(QString name, \
QVariant value, QObject *obj) {
// Need check if the propertie already exists
bool insertingRow = false;
@@ -168,23 +168,14 @@ void GraphPropertiesModel::addDynamicProperty(QString name, \
QVariant value, QObj insertingRow = true;
}
- if (isGlobal) {
- if (Pointer * pointer = qobject_cast<Pointer*> (obj)) {
- pointer->dataStructure()->addPointersDynamicProperty(name, value);
- }
- if (Data * datum = qobject_cast<Data*> (obj)) {
- datum->dataStructure()->addDataDynamicProperty(name, value);
- }
- } else {
- if (Pointer * pointer = qobject_cast<Pointer*> (obj)) {
- pointer->addDynamicProperty(name, value);
- }
- if (Data * datum = qobject_cast<Data*> (obj)) {
- datum->addDynamicProperty(name, value);
- }
- if (DataStructure * dataStructure = qobject_cast<DataStructure*> (obj)) {
- dataStructure->addDynamicProperty(name, value);
- }
+ if (Pointer * pointer = qobject_cast<Pointer*> (obj)) {
+ pointer->addDynamicProperty(name, value);
+ }
+ if (Data * datum = qobject_cast<Data*> (obj)) {
+ datum->addDynamicProperty(name, value);
+ }
+ if (DataStructure * dataStructure = qobject_cast<DataStructure*> (obj)) {
+ dataStructure->addDynamicProperty(name, value);
}
if (insertingRow) { /* if inserting, need finish*/
diff --git a/src/Models/model_GraphProperties.h b/src/Models/model_GraphProperties.h
index 08d9373..e42d535 100644
--- a/src/Models/model_GraphProperties.h
+++ b/src/Models/model_GraphProperties.h
@@ -66,7 +66,7 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const;
/**Add properti to data source and insert a new row,*/
- void addDynamicProperty(QString name, QVariant value, QObject *obj, bool \
isGlobal); + void addDynamicProperty(QString name, QVariant value, QObject *obj);
private:
QObject *_dataSource;
diff --git a/src/Tests/TestDynamicProperties.cpp \
b/src/Tests/TestDynamicProperties.cpp index 72d4d28..65df209 100644
--- a/src/Tests/TestDynamicProperties.cpp
+++ b/src/Tests/TestDynamicProperties.cpp
@@ -79,52 +79,23 @@ void TestDynamicProperties::addGraphDynamicProperty()
QVERIFY2(DynamicPropertiesList::New()->type(g.get(), property) == Unique, \
"Property isn't Unique."); }
-void TestDynamicProperties::addToAllNodes()
-{
- DataStructurePtr g = _document->addDataStructure("A graph");
-
- DataPtr n = g->addData("Node1");
- DataPtr n2 = g->addData("Node2");
-
- QByteArray property = "newProperty";
- g->addDataDynamicProperty(property);
- QVERIFY2(n->property(property) != QVariant::Invalid, "Property not added to \
Node1.");
- QVERIFY2(n2->property(property) != QVariant::Invalid, "Property not added to \
Node2.");
- QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) == Global, \
"Property isn't Global. (by node 1)");
- QVERIFY2(DynamicPropertiesList::New()->type(n2.get(), property) == Global, \
"Property isn't Global. (by node 2)");
-}
-
-void TestDynamicProperties::addToAllEdges()
-{
- DataStructurePtr g = _document->addDataStructure("A graph");
-
- DataPtr n1 = g->addData("Node");
- DataPtr n2 = g->addData("Node");
- DataPtr n3 = g->addData("Node");
- PointerPtr e = g->addPointer(n1, n2);
- PointerPtr e2 = g->addPointer(n2, n3);
- PointerPtr e3 = g->addPointer(n1, n3);
-
- QByteArray property = "newProperty";
- g->addPointersDynamicProperty(property, QVariant(0));
- QVERIFY2(e->property(property) != QVariant::Invalid, "Property not added.");
- QVERIFY2(DynamicPropertiesList::New()->type(e.get(), property) == Global, \
"Property isn't Global. (by Edge 1)");
- QVERIFY2(DynamicPropertiesList::New()->type(e2.get(), property) == Global, \
"Property isn't Global. (by Edge 2)");
- QVERIFY2(DynamicPropertiesList::New()->type(e3.get(), property) == Global, \
"Property isn't Global. (by Edge 3)");
-}
-
void TestDynamicProperties::removeNodeDynamicProperty()
{
DataStructurePtr g = _document->addDataStructure("A graph");
DataPtr n = g->addData("Node");
QByteArray property = "newProperty";
+ int propertyNumber = n->dynamicPropertyNames().size();
+
n->addDynamicProperty(property, QVariant(0));
QVERIFY2(n->property(property) != QVariant::Invalid, "Property not added.");
+ QVERIFY(n->dynamicPropertyNames().size() == propertyNumber+1);
+
n->removeDynamicProperty(property);
QVERIFY2(n->property(property) == QVariant::Invalid, "Property not removed.");
QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) == None, \
"Property isn't None.");
- QVERIFY2(n->dynamicPropertyNames().size() == 0, "Still having property.");
+
+ QVERIFY2(n->dynamicPropertyNames().size() == propertyNumber, "Still having \
property."); }
void TestDynamicProperties::removeEdgeDynamicProperty()
@@ -156,79 +127,6 @@ void TestDynamicProperties::removeGraphDynamicProperty()
QVERIFY2(g->dynamicPropertyNames().size() == 0, "Still having property.");
}
-void TestDynamicProperties::removeToAllNodes()
-{
- DataStructurePtr g = _document->addDataStructure("A graph");
-
- DataPtr n = g->addData("Node 1");
- DataPtr n2 = g->addData("Node 2");
-
- QByteArray property = "newProperty";
- g->addDataDynamicProperty(property, QVariant(0));
-
- QVERIFY2(n->property(property) != QVariant::Invalid, "Property not added.");
- QVERIFY2(n2->property(property) != QVariant::Invalid, "Property not added.");
-
- g->removeDataDynamicProperty(property);
- QVERIFY2(n->property(property) == QVariant::Invalid, "Property not removed from \
node 1.");
- QVERIFY2(n2->property(property) == QVariant::Invalid, "Property not removedfrom \
node 2.");
- QVERIFY2(DynamicPropertiesList::New()->type(n.get(), property) == None, \
"Property isn't None.");
-}
-
-void TestDynamicProperties::removeToAllEdges()
-{
- DataStructurePtr g = _document->addDataStructure("A graph");
-
- DataPtr n1 = g->addData("1");
- DataPtr n2 = g->addData("2");
- DataPtr n3 = g->addData("3");
- PointerPtr e = g->addPointer(n1, n2);
- PointerPtr e2 = g->addPointer(n2, n3);
- QByteArray property = "newProperty";
- g->addPointersDynamicProperty(property, QVariant(0));
-
- QVERIFY2(e->property(property) != QVariant::Invalid, "Property not added to edge \
2.");
- QVERIFY2(e2->property(property) != QVariant::Invalid, "Property not added to \
edge 2.");
- g->removePointersDynamicProperty(property);
- QVERIFY2(e->property(property) == QVariant::Invalid, "Property not removed from \
edge 1.");
- QVERIFY2(e2->property(property) == QVariant::Invalid, "Property not removed from \
edge 2.");
- QVERIFY2(DynamicPropertiesList::New()->type(e.get(), property) == None, \
"Property isn't None.");
-}
-
-void TestDynamicProperties::MultipleProperties()
-{
- DataStructurePtr g = _document->addDataStructure("A graph");
-
- DataPtr n1 = g->addData("Node 1");
- DataPtr n2 = g->addData("Node 2");
- DataPtr n3 = g->addData("Node 3");
- PointerPtr e1 = g->addPointer(n3, n1);
- PointerPtr e2 = g->addPointer(n2, n1);
- PointerPtr e3 = g->addPointer(n3, n2);
-
- QByteArray property = "newProperty";
- g->addDataDynamicProperty(property, QVariant(0));
- g->addPointersDynamicProperty(property, QVariant(0));
-
- QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) == Global, \
"Property isn't global");
- QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) == Global, \
"Property isn't global");
-
- n1->removeDynamicProperty(property);
- e1->removeDynamicProperty(property);
- QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) == Multiple, \
"Property isn't Multiple");
- QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) == Multiple, \
"Property isn't Multiple");
-
- n2->removeDynamicProperty(property);
- e2->removeDynamicProperty(property);
- QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) == Unique, \
"Property isn't Unique");
- QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) == Unique, \
"Property isn't Unique");
-
- n3->removeDynamicProperty(property);
- e3->removeDynamicProperty(property);
- QVERIFY2(DynamicPropertiesList::New()->type(n1.get(), property) == None, \
"Property isn't None");
- QVERIFY2(DynamicPropertiesList::New()->type(e1.get(), property) == None, \
"Property isn't Unique");
-}
-
void TestDynamicProperties::changeNames()
{
DataStructurePtr g = _document->addDataStructure("A graph");
@@ -238,7 +136,8 @@ void TestDynamicProperties::changeNames()
PointerPtr e = g->addPointer(n1, n2);
QString property = "newProperty";
- g->addDataDynamicProperty(property, QVariant(0));
+ n1->addDynamicProperty(property, QVariant(0));
+ n2->addDynamicProperty(property, QVariant(0));
g->addPointersDynamicProperty(property, QVariant(0));
g->addDynamicProperty(property, QVariant(0));
@@ -246,10 +145,10 @@ void TestDynamicProperties::changeNames()
DynamicPropertiesList::New()->changePropertyName(property, \
QString("newName_Edge"), e.get());
DynamicPropertiesList::New()->changePropertyName(property, \
QString("newName_Graph"), g.get());
- QCOMPARE(n1->dynamicPropertyNames() [0], QByteArray("newName_Node"));
- QCOMPARE(n2->dynamicPropertyNames() [0], QByteArray("newName_Node"));
- QCOMPARE(e->dynamicPropertyNames() [0], QByteArray("newName_Edge"));
- QCOMPARE(g->dynamicPropertyNames() [0], QByteArray("newName_Graph"));
+ QVERIFY(n1->dynamicPropertyNames().contains(QByteArray("newName_Node")));
+ QVERIFY(n2->dynamicPropertyNames().contains(QByteArray("newName_Node")));
+ QCOMPARE(e->dynamicPropertyNames()[0], QByteArray("newName_Edge"));
+ QCOMPARE(g->dynamicPropertyNames()[0], QByteArray("newName_Graph"));
}
QTEST_MAIN(TestDynamicProperties)
diff --git a/src/Tests/TestDynamicProperties.h b/src/Tests/TestDynamicProperties.h
index 022a66e..6ecce89 100644
--- a/src/Tests/TestDynamicProperties.h
+++ b/src/Tests/TestDynamicProperties.h
@@ -37,18 +37,10 @@ private slots:
void addEdgeDynamicProperty();
void addGraphDynamicProperty();
- void addToAllNodes();
- void addToAllEdges();
-
void removeNodeDynamicProperty();
void removeEdgeDynamicProperty();
void removeGraphDynamicProperty();
- void removeToAllNodes();
- void removeToAllEdges();
-
- void MultipleProperties();
-
void changeNames();
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic