• 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
TestLoadSave.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "TestLoadSave.h"
20 #include "DataStructure.h"
21 #include "Data.h"
22 #include "Pointer.h"
23 #include <qtest_kde.h>
24 #include <ktemporaryfile.h>
25 
26 #include <Document.h>
27 #include <DocumentManager.h>
28 #include <Project.h>
29 
30 TestLoadSave::TestLoadSave()
31 {
32  DocumentManager::self().addDocument(new Document("test"));;
33 }
34 
35 
36 void TestLoadSave::serializeUnserializeTest()
37 {
38  DocumentManager::self().addDocument(new Document("testSerialization"));
39  Document *document = DocumentManager::self().activeDocument();
40  QMap<QString, DataPtr> dataList;
41 
42  // register additional properties
43  document->dataType(0)->addProperty("testproperty", "default");
44  document->pointerType(0)->addProperty("testproperty", "default");
45 
46  // Creates a simple Graph with 5 data elements and connect them with pointers.
47  DataStructurePtr ds = document->activeDataStructure();
48  ds->setProperty("name", "Graph1");
49  dataList.insert("a", ds->createData("a", 0));
50  dataList.insert("b", ds->createData("b", 0));
51  dataList.insert("c", ds->createData("c", 0));
52  dataList.insert("d", ds->createData("d", 0));
53  dataList.insert("e", ds->createData("e", 0));
54 
55  ds->createPointer(dataList["a"], dataList["b"], 0);
56  ds->createPointer(dataList["b"], dataList["c"], 0);
57  ds->createPointer(dataList["c"], dataList["d"], 0);
58  ds->createPointer(dataList["d"], dataList["e"], 0);
59  ds->createPointer(dataList["e"], dataList["a"], 0);
60 
61  // serialize into file "serializetest.graph"
62  DocumentManager::self().activeDocument()->saveAs("serializetest");
63  DocumentManager::self().removeDocument(DocumentManager::self().activeDocument());
64  Document* testDoc = new Document("testDoc");
65 
66  // unserialize and test properties
67  DocumentManager::self().addDocument(testDoc);
68  DocumentManager::self().changeDocument(testDoc);
69  DocumentManager::self().openDocument(KUrl::fromLocalFile("serializetest.graph"));
70 
71  // default data structure also present
72  QVERIFY2(DocumentManager::self().activeDocument()->dataStructures().count() == 1, "ERROR: DataStructure not loaded");
73 
74  document = DocumentManager::self().activeDocument();
75  QVERIFY(document->dataType(0)->propertyDefaultValue("testproperty").toString() == "default");
76  QVERIFY(document->pointerType(0)->propertyDefaultValue("testproperty").toString() == "default");
77 
78  ds = document->dataStructures().at(0);
79  QVERIFY2(ds->dataList(0).size() == 5, "ERROR: Number of data is not 5 ");
80  QVERIFY2(ds->pointers(0).size() == 5, "ERROR: Number of pointers is not 5 ");
81 
82  foreach(DataPtr n, ds->dataList(0)) {
83  QVERIFY2(n->outPointerList().size() == 1, "ERROR: Number of out pointers is not 1");
84  QVERIFY2(n->inPointerList().size() == 1, "ERROR: Number of in pointers is not 1");
85  QVERIFY2(n->adjacentDataList().size() == 2, "ERROR: Number of Adjacent Nodes is not 2");
86  QVERIFY2(n->pointerList().size() == 2, "ERROR: Number of adjacent pointers is not 2");
87  }
88 }
89 
90 
91 void TestLoadSave::serializeUnserializeTypesTest()
92 {
93  QMap<QString, DataPtr> dataList;
94 
95  // start with new document!
96  DocumentManager::self().addDocument(new Document("testTypes"));
97  Document *document = DocumentManager::self().activeDocument();
98  DataStructurePtr ds = DocumentManager::self().activeDocument()->activeDataStructure();
99 
100  // register 2nd data and pointer type
101  int dataTypeID = document->registerDataType("testDatatype");
102  int pointerTypeID = document->registerPointerType("testPointertype");
103 
104  // add test data
105  ds->setProperty("name", "Graph1");
106  dataList.insert("a", ds->createData("a", dataTypeID));
107  dataList.insert("b", ds->createData("b", dataTypeID));
108  ds->createPointer(dataList["a"], dataList["b"], pointerTypeID);
109 
110  // serialize into file "serializetest.graph"
111  DocumentManager::self().activeDocument()->saveAs("serializetest");
112  DocumentManager::self().removeDocument(DocumentManager::self().activeDocument());
113  Document* testDoc = new Document("testDoc");
114 
115  // unserialize and test properties
116  DocumentManager::self().addDocument(testDoc);
117  DocumentManager::self().changeDocument(testDoc);
118  DocumentManager::self().openDocument(KUrl::fromLocalFile("serializetest.graph"));
119  document = DocumentManager::self().activeDocument();
120  ds = document->dataStructures().at(0);
121 
122  // default data structure also present
123  QVERIFY2(document->dataType(dataTypeID), "ERROR: Data type not present");
124  QVERIFY2(document->pointerType(pointerTypeID), "ERROR: Pointer type not present");
125  QVERIFY2(ds->dataList(dataTypeID).size() > 0, "ERROR: type of data element changed");
126  QVERIFY2(ds->pointers(pointerTypeID).size() > 0, "ERROR: type of pointer changed");
127 }
128 
129 void TestLoadSave::projectLoadSaveTest()
130 {
131  KTemporaryFile temp;
132  temp.setPrefix("rocsproject");
133  temp.setSuffix(".tmp");
134  temp.setAutoRemove(false);
135  temp.open();
136 
137  // prepare project and save
138  Project* testProject = new Project(KUrl::fromLocalFile(temp.fileName()));
139  testProject->setName("new test name");
140  testProject->addCodeFile(KUrl::fromLocalFile("/path/to/code.js"));
141  testProject->addGraphFile(KUrl::fromLocalFile("/path/to/graph.graph"));
142  testProject->writeProjectFile();
143 
144  // load project
145  Project* testProject2 = new Project(KUrl::fromLocalFile(temp.fileName()));
146  QVERIFY2(testProject2->name().compare("new test name") == 0, "ERROR: project name changed");
147  QVERIFY(testProject2->codeFiles().count() == 1);
148  QVERIFY2(
149  testProject2->codeFiles().at(0).equals(KUrl::fromLocalFile("/path/to/code.js")),
150  "ERROR: path of code file changed"
151  );
152  QVERIFY2(
153  testProject2->graphFiles().at(0).equals(KUrl::fromLocalFile("/path/to/graph.graph")),
154  "ERROR: path of graph file changed"
155  );
156 
157  delete testProject;
158  delete testProject2;
159 }
160 
161 void TestLoadSave::loadMultipleLayerGraphTest()
162 {
163  DocumentManager::self().openDocument(KUrl::fromLocalFile("TestGraphFiles/multipleLayerGraph.graph"));
164  Document *document = DocumentManager::self().activeDocument();
165 
166  QVERIFY2(document->pointerTypeList().length() == 2, "two pointer types expected");
167  QVERIFY2(!document->activeDataStructure()->dataList(0).first()->property("name").toString().isEmpty(), "property must be present");
168  QVERIFY2(!document->activeDataStructure()->dataList(0).first()->property("target").toString().isEmpty(), "property must be present");
169 }
170 
171 QTEST_KDEMAIN_CORE(TestLoadSave)
Project::addCodeFile
int addCodeFile(const KUrl &file)
Add code file to project.
Definition: Project.cpp:161
Document::registerDataType
int registerDataType(const QString &name, int identifier=0)
Register new type for data elements.
Definition: Document.cpp:124
TestLoadSave
Definition: TestLoadSave.h:29
Project::name
QString name() const
Returns name of the project.
Definition: Project.cpp:136
TestLoadSave.h
DocumentManager.h
DocumentManager::self
static DocumentManager & self()
Definition: DocumentManager.cpp:57
DataStructurePtr
boost::shared_ptr< DataStructure > DataStructurePtr
Definition: CoreTypes.h:38
GmlParser::document
Document * document
Definition: GmlGrammar.cpp:40
DocumentManager::activeDocument
Document * activeDocument() const
Returns the currently active document, or 0 if there document list is empty.
Definition: DocumentManager.cpp:96
QList::at
const T & at(int i) const
QMap< QString, DataPtr >
Project.h
Project::addGraphFile
int addGraphFile(const KUrl &file)
Add graph file to project.
Definition: Project.cpp:221
Data.h
Document.h
Project
A "Project" object represents the compilation of file pointers that form a Rocs project.
Definition: Project.h:47
DataStructure.h
TestLoadSave::TestLoadSave
TestLoadSave()
Definition: TestLoadSave.cpp:30
Document::registerPointerType
int registerPointerType(const QString &name, int identifier=0)
Register new type for pointers.
Definition: Document.cpp:142
Document::activeDataStructure
DataStructurePtr activeDataStructure() const
Definition: Document.cpp:431
Project::writeProjectFile
bool writeProjectFile(const QString &fileUrl=QString())
Save the project to its current file if empty or no filename is given.
Definition: Project.cpp:315
DocumentManager::changeDocument
void changeDocument(Document *document)
Change active document to be document.
Definition: DocumentManager.cpp:143
Project::setName
void setName(const QString &name)
Set project name.
Definition: Project.cpp:129
Document
Definition: Document.h:41
Document::pointerType
PointerTypePtr pointerType(int pointerType) const
Definition: Document.cpp:207
Document::dataStructures
QList< DataStructurePtr > & dataStructures() const
Definition: Document.cpp:227
Project::graphFiles
QList< KUrl > graphFiles() const
Get list of all graph files of the project that have a path.
Definition: Project.cpp:244
Pointer.h
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
Document::pointerTypeList
QList< int > pointerTypeList() const
Getter for all registered pointer types.
Definition: Document.cpp:165
Document::dataType
DataTypePtr dataType(int dataType) const
Definition: Document.cpp:197
Project::codeFiles
QList< KUrl > codeFiles() const
Get list of all code files of the project that have a path.
Definition: Project.cpp:184
QMap::insert
iterator insert(const Key &key, const T &value)
QString::compare
int compare(const QString &other) const
DocumentManager::addDocument
void addDocument(Document *document)
Add document to document list and set this document as active document.
Definition: DocumentManager.cpp:106
Document::saveAs
void saveAs(const QString &fileUrl)
Save graph document under the given fileUrl.
Definition: Document.cpp:381
DocumentManager::openDocument
Document * openDocument(const KUrl &documentUrl)
Loads graph document specified by documentUrl and adds document to document list. ...
Definition: DocumentManager.cpp:245
DocumentManager::removeDocument
void removeDocument(Document *document)
Remove document from document list.
Definition: DocumentManager.cpp:173
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