• 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.12
  • kdeedu
  • rocs
  • RocsCore
  • LoadSave
  • Plugins
  • tgfFileFormat
  • Tests
TestTgfFileFormatPlugin.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 "TestTgfFileFormatPlugin.h"
20 #include "DataStructure.h"
21 #include "Data.h"
22 #include "Pointer.h"
23 #include "DocumentManager.h"
24 #include <qtest_kde.h>
25 #include "../TgfFileFormatPlugin.h"
26 
27 
28 TestTgfFileFormatPlugin::TestTgfFileFormatPlugin()
29 {
30 }
31 
32 void TestTgfFileFormatPlugin::serializeUnserializeTest()
33 {
34  DocumentManager::self().addDocument(new Document("testSerialization"));
35  Document* document = DocumentManager::self().activeDocument();
36  QMap<QString, DataPtr> dataList;
37 
38  // Creates a simple Graph with 5 data elements and connect them with pointers.
39  DataStructurePtr ds = document->activeDataStructure();
40  ds->setProperty("name", "Graph1");
41  dataList.insert("a", ds->createData("first node", 0));
42  dataList.insert("b", ds->createData("b", 0));
43  dataList.insert("c", ds->createData("c", 0));
44  dataList.insert("d", ds->createData("d", 0));
45  dataList.insert("e", ds->createData("e", 0));
46 
47  ds->createPointer(dataList["a"], dataList["b"], 0)->setProperty("value", "test value");
48  ds->createPointer(dataList["b"], dataList["c"], 0);
49  ds->createPointer(dataList["c"], dataList["d"], 0);
50  ds->createPointer(dataList["d"], dataList["e"], 0);
51  ds->createPointer(dataList["e"], dataList["a"], 0);
52 
53  // create exporter plugin
54  TgfFileFormatPlugin serializer(this, QList<QVariant>());
55  serializer.setFile(KUrl::fromLocalFile("test.tgf"));
56  serializer.writeFile(*document);
57  QVERIFY(serializer.hasError() == false);
58 
59  // create importer
60  TgfFileFormatPlugin importer(this, QList<QVariant>());
61  importer.setFile(KUrl::fromLocalFile("test.tgf"));
62  importer.readFile();
63  QVERIFY(importer.hasError() == false);
64  QVERIFY(importer.isGraphDocument());
65  Document* testDoc = importer.graphDocument();
66  ds = testDoc->dataStructures().at(0);
67 
68  // test imported values
69  QVERIFY(ds);
70  QVERIFY2(ds->dataList(0).size() == 5, "ERROR: Number of data is not 5 ");
71  QVERIFY2(ds->pointers(0).size() == 5, "ERROR: Number of pointers is not 5 ");
72  foreach(DataPtr n, ds->dataList(0)) {
73  QVERIFY2(n->outPointerList().size() == 1, "ERROR: Number of out pointers is not 1");
74  QVERIFY2(n->inPointerList().size() == 1, "ERROR: Number of in pointers is not 1");
75  QVERIFY2(n->adjacentDataList().size() == 2, "ERROR: Number of Adjacent Nodes is not 2");
76  QVERIFY2(n->pointerList().size() == 2, "ERROR: Number of adjacent pointers is not 2");
77  }
78  QVERIFY(ds->dataList(0).at(0)->property("name").toString() == "first node");
79  QVERIFY(ds->pointers(0).at(0)->property("value").toString() == "test value");
80 }
81 
82 QTEST_MAIN(TestTgfFileFormatPlugin);
TgfFileFormatPlugin
class TgfFileFormatPlugin: Import and Export Plugin for TGF
Definition: TgfFileFormatPlugin.h:41
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
TestTgfFileFormatPlugin
Definition: TestTgfFileFormatPlugin.h:29
Data.h
DataStructure.h
QTEST_MAIN
QTEST_MAIN(TestTgfFileFormatPlugin)
Document::activeDataStructure
DataStructurePtr activeDataStructure() const
Definition: Document.cpp:431
TestTgfFileFormatPlugin.h
Document
Definition: Document.h:41
Document::dataStructures
QList< DataStructurePtr > & dataStructures() const
Definition: Document.cpp:227
TestTgfFileFormatPlugin::TestTgfFileFormatPlugin
TestTgfFileFormatPlugin()
Definition: TestTgfFileFormatPlugin.cpp:28
Pointer.h
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
DocumentManager::addDocument
void addDocument(Document *document)
Add document to document list and set this document as active document.
Definition: DocumentManager.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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