26 #include <qtest_kde.h>
28 #include <kross/core/action.h>
29 #include <kross/core/manager.h>
40 void TestDataStructure::init()
45 void TestDataStructure::cleanup()
50 void TestDataStructure::dataAddDeleteTest()
57 for (
int i = 0; i < 10; i++) {
60 QVERIFY2(ds->dataList(0).size() == 10,
"ERROR: Number of data elements is not 10");
63 foreach(
DataPtr data, dataList) {
67 QVERIFY2(ds->dataList(0).size() == 0,
"ERROR: Not all data elements were deleted");
72 void TestDataStructure::pointerAddDeleteTest()
81 for (
int i = 0; i < 10; i++) {
84 QVERIFY2(ds->dataList(0).size() == 10,
"ERROR: Number of data elements is not 10");
88 for (
int i = 0; i < dataList.
size() - 1; i++) {
89 ds->createPointer(dataList[i], dataList[i + 1], 0);
91 QVERIFY2(ds->pointers(0).size() == 9,
"ERROR: Number of data elements is not 9");
92 QVERIFY2(dataList[0]->pointerList().size() == 1,
"ERROR: data gives wrong number of pointers");
93 QVERIFY2(dataList[1]->pointerList().size() == 2,
"ERROR: data gives wrong number of pointers");
97 ds->pointers(0).first()->remove();
98 QVERIFY2(ds->pointers(0).size() == 8,
"ERROR: pointer was not removed");
99 QVERIFY2(dataList[0]->pointerList().size() == 0,
"ERROR: data gives wrong number of pointers");
100 QVERIFY2(dataList[1]->pointerList().size() == 1,
"ERROR: data gives wrong number of pointers");
105 QVERIFY2(ds->pointers(0).size() == 7,
"ERROR: data deletion did not remove its pointers");
110 QVERIFY2(ds->pointers(0).size() == 5,
"ERROR: data deletion did not remove its both pointers");
114 void TestDataStructure::createSimpleGraph()
121 ds->setProperty(
"name",
"Graph1");
122 dataList.
insert(
"a", ds->createData(
"a", 0));
123 dataList.
insert(
"b", ds->createData(
"b", 0));
124 dataList.
insert(
"c", ds->createData(
"c", 0));
125 dataList.
insert(
"d", ds->createData(
"d", 0));
126 dataList.
insert(
"e", ds->createData(
"e", 0));
128 ds->createPointer(dataList[
"a"], dataList[
"b"], 0);
129 ds->createPointer(dataList[
"b"], dataList[
"c"], 0);
130 ds->createPointer(dataList[
"c"], dataList[
"d"], 0);
131 ds->createPointer(dataList[
"d"], dataList[
"e"], 0);
132 ds->createPointer(dataList[
"e"], dataList[
"a"], 0);
134 QVERIFY2(ds->dataList(0).size() == 5,
"ERROR: Number of data is not 5 ");
135 QVERIFY2(ds->pointers(0).size() == 5,
"ERROR: Number of pointers is not 5 ");
137 foreach(
DataPtr n, ds->dataList(0)) {
138 QVERIFY2(n->outPointerList().size() == 1,
"ERROR: Number of out pointers is not 1");
139 QVERIFY2(n->inPointerList().size() == 1,
"ERROR: Number of in pointers is not 1");
140 QVERIFY2(n->adjacentDataList().size() == 2,
"ERROR: Number of Adjacent Nodes is not 2");
141 QVERIFY2(n->pointerList().size() == 2,
"ERROR: Number of adjacent pointers is not 2");
147 void TestDataStructure::dataTypesTest()
151 DataList dataListDefault, dataList1, dataList2;
152 QVERIFY2(ds->document()->dataTypeList().size() == 1,
"ERROR: no default data type created");
155 int type1 = ds->document()->registerDataType(
"type1");
156 int type2 = ds->document()->registerDataType(
"type2");
157 QVERIFY2(ds->document()->dataTypeList().size() == 3,
"ERROR: data types were not created");
160 for (
int i = 0; i < 3; i++) {
165 QVERIFY2(ds->dataList(0).size() == 3,
166 "list contains " + ds->dataList(0).size()
168 QVERIFY2(ds->dataList(type1).size() == 3,
169 "list contains " + ds->dataList(0).size()
171 QVERIFY2(ds->dataList(type2).size() == 3,
172 "list contains " + ds->dataList(0).size()
174 QVERIFY2(dataListDefault.
at(0)->dataType() == 0,
"ERROR: not correct autoset of type");
175 QVERIFY2(dataList1.
at(0)->dataType() == type1,
"ERROR: not correct autoset of type");
176 QVERIFY2(dataList2.
at(0)->dataType() == type2,
"ERROR: not correct autoset of type");
179 ds->createPointer(dataListDefault[0], dataList1[0], 0);
180 ds->createPointer(dataList1[0], dataList2[0], 0);
181 ds->createPointer(dataList2[0], dataListDefault[0], 0);
182 QVERIFY2(ds->pointers(0).size() == 3,
"ERROR: pointers were not correctly created");
185 ds->document()->removeDataType(type2);
186 QVERIFY2(!ds->document()->dataTypeList().contains(type2),
"ERROR: data type was not unregistered");
187 QVERIFY2(ds->pointers(0).size() == 1,
"ERROR: pointers were not correctly deleted");
191 void TestDataStructure::pointerTypesTest()
197 QVERIFY2(ds->document()->pointerTypeList().size() == 1,
"ERROR: no default pointer type created");
200 for (
int i = 0; i < 10; i++) {
205 int type1 = ds->document()->registerPointerType(
"type1");
206 QVERIFY2(ds->document()->pointerTypeList().size() == 2,
"ERROR: pointer types were not created");
209 for (
int i = 0; i < 4; i++) {
210 ds->createPointer(dataList[i], dataList[i + 1], 0);
212 for (
int i = 0; i < 9; i++) {
213 ds->createPointer(dataList[i], dataList[i + 1], type1);
215 QVERIFY2(ds->pointers(0).size() == 4,
"ERROR: wrong number of pointers");
216 QVERIFY2(ds->pointers(type1).size() == 9,
"ERROR: wrong number of pointers");
217 QVERIFY(dataList[0]->adjacentDataList().size() == 1);
218 QVERIFY(dataList[1]->adjacentDataList().size() == 2);
219 QVERIFY(dataList[5]->adjacentDataList().size() == 2);
223 QVERIFY2(ds->pointers(0).size() == 3,
"ERROR: wrong number of pointers");
224 QVERIFY2(ds->pointers(type1).size() == 8,
"ERROR: wrong number of pointers");
226 ds->document()->removePointerType(type1);
227 QVERIFY(dataList[2]->adjacentDataList().size() == 2);
228 QVERIFY(dataList[6]->adjacentDataList().size() == 0);
231 void TestDataStructure::pointerDirectionChange()
239 dataList.
insert(0, ds->createData(
"0", 0));
240 dataList.
insert(1, ds->createData(
"1", 0));
243 dataList[0]->createPointer(dataList[1]);
244 QVERIFY(dataList[0]->outPointerList().length() == 1);
245 QVERIFY(dataList[0]->inPointerList().length() == 0);
246 QVERIFY(dataList[0]->adjacentDataList().length() == 1);
247 QVERIFY(dataList[1]->outPointerList().length() == 0);
248 QVERIFY(dataList[1]->inPointerList().length() == 1);
249 QVERIFY(dataList[1]->adjacentDataList().length() == 1);
252 QVERIFY(dataList[0]->outPointerList().length() == 1);
253 QVERIFY(dataList[0]->inPointerList().length() == 1);
254 QVERIFY(dataList[0]->adjacentDataList().length() == 1);
255 QVERIFY(dataList[1]->outPointerList().length() == 1);
256 QVERIFY(dataList[1]->inPointerList().length() == 1);
257 QVERIFY(dataList[1]->adjacentDataList().length() == 1);
260 QVERIFY(dataList[0]->outPointerList().length() == 1);
261 QVERIFY(dataList[0]->inPointerList().length() == 0);
262 QVERIFY(dataList[0]->adjacentDataList().length() == 1);
263 QVERIFY(dataList[1]->outPointerList().length() == 0);
264 QVERIFY(dataList[1]->inPointerList().length() == 1);
265 QVERIFY(dataList[1]->adjacentDataList().length() == 1);
iterator remove(iterator pos)
static DocumentManager & self()
boost::shared_ptr< DataStructure > DataStructurePtr
Document * activeDocument() const
Returns the currently active document, or 0 if there document list is empty.
const T & at(int i) const
static DataStructurePtr create(Document *parent=0)
QList< boost::shared_ptr< Data > > DataList
QString number(int n, int base)
Document * newDocument()
Creates and loads a new graph document.
void append(const T &value)
DataStructurePtr addDataStructure(const QString &name=QString())
Add data structure to graph document with name name.
void setActiveDataStructure(int index)
Sets the active data structure of graph document with index index in the data structure list...
boost::shared_ptr< Data > DataPtr
iterator insert(const Key &key, const T &value)
void addDocument(Document *document)
Add document to document list and set this document as active document.
void removeDocument(Document *document)
Remove document from document list.