24 #include "../DotGrammar.h"
25 #include "../DotFileFormatPlugin.h"
34 static const std::string
simple =
"digraph simple {a_2 -> b; c; d -> e /* error -> comment*/}";
36 static const std::string
subgraph =
"digraph trees {"
38 " 0 -> \"1\" [label = \"A\"];"
39 " 0 -> \"2\" [label = \"B\"];"
42 " Animal -> Cat [label = \"feline\"];"
43 " Animal -> Dot [label = \"canine\"];"
55 foreach(
const DataPtr &node, dataList) {
57 int index = nodeNames.
indexOf(name);
59 kDebug() <<
"Node "<< name <<
" was created unnecessarily.";
67 void DotFileFormatTest::init()
71 QFAIL(
"No plugin of DS, no way to continue!");
74 QVERIFY2(pl,
"Could create data structure of type Graph");
77 void DotFileFormatTest::simpleGraphParsing()
82 QVERIFY(doc.dataStructures().count() == 1);
83 if (doc.dataStructures().count() == 0) {
88 QVERIFY(graph->dataList(0).count() == 5);
89 QVERIFY(graph->pointers(0).count() == 2);
93 void DotFileFormatTest::parseSubgraphs()
100 void DotFileFormatTest::parseFileER()
104 importer.setFile(KUrl::fromLocalFile(
"undirected/ER.gv"));
106 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
107 Document *doc = importer.graphDocument();
112 nodeNames <<
"course" <<
"institute" <<
"student" <<
"name0" <<
"name1" <<
"name2" <<
"code" <<
"grade" <<
"number" <<
"C-I" <<
"S-C" <<
"S-I";
113 checkNodes(dataStructure, nodeNames);
116 QVERIFY(dataStructure->pointers(0).count() == 12);
122 foreach(
const DataPtr &node, dataList) {
124 if (name ==
"student") {
130 if (name ==
"name0" || name ==
"name1" || name ==
"name2") {
131 QVERIFY(node->property(
"label").toString() ==
"name");
134 PointerPtr betweenPtr = start->pointerList(end).at(0);
135 QVERIFY(betweenPtr->property(
"label") ==
"m");
139 void DotFileFormatTest::parseFileHeawood()
143 importer.setFile(KUrl::fromLocalFile(
"undirected/Heawood.gv"));
145 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
149 void DotFileFormatTest::parseFileNgk104()
153 importer.setFile(KUrl::fromLocalFile(
"undirected/ngk10_4.gv"));
155 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
159 void DotFileFormatTest::parseFilePetersen()
163 importer.setFile(KUrl::fromLocalFile(
"undirected/Petersen.gv"));
165 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
169 void DotFileFormatTest::parseFileProcess()
173 importer.setFile(KUrl::fromLocalFile(
"undirected/process.gv"));
175 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
176 Document* doc = importer.graphDocument();
180 nodeNames <<
"run" <<
"intr" <<
"runbl" <<
"kernel" <<
"zombie" <<
"sleep" <<
"swap" <<
"runmem" <<
"runswap" <<
"new";
181 checkNodes(dataStructure, nodeNames);
183 QVERIFY(dataStructure->pointers(0).count() == 13);
187 void DotFileFormatTest::parseFileAbstract()
191 importer.setFile(KUrl::fromLocalFile(
"directed/abstract.gv"));
193 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
197 void DotFileFormatTest::parseFileAlf()
201 importer.setFile(KUrl::fromLocalFile(
"directed/alf.gv"));
203 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
207 void DotFileFormatTest::parseFileArrows()
211 importer.setFile(KUrl::fromLocalFile(
"directed/arrows.gv"));
213 QEXPECT_FAIL(
"",
"File contains invalid identifiers with underbar at beginning.", Continue);
214 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
218 void DotFileFormatTest::parseFileAwilliams()
222 importer.setFile(KUrl::fromLocalFile(
"directed/awilliams.gv"));
224 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
228 void DotFileFormatTest::parseFileClust()
232 importer.setFile(KUrl::fromLocalFile(
"directed/clust.gv"));
234 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
238 void DotFileFormatTest::parseFileClust1()
242 importer.setFile(KUrl::fromLocalFile(
"directed/clust1.gv"));
244 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
248 void DotFileFormatTest::parseFileClust2()
252 importer.setFile(KUrl::fromLocalFile(
"directed/clust2.gv"));
254 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
258 void DotFileFormatTest::parseFileClust3()
262 importer.setFile(KUrl::fromLocalFile(
"directed/clust3.gv"));
264 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
268 void DotFileFormatTest::parseFileClust4()
272 importer.setFile(KUrl::fromLocalFile(
"directed/clust4.gv"));
274 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
278 void DotFileFormatTest::parseFileClust5()
282 importer.setFile(KUrl::fromLocalFile(
"directed/clust5.gv"));
284 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
288 void DotFileFormatTest::parseFileCrazy()
292 importer.setFile(KUrl::fromLocalFile(
"directed/crazy.gv"));
294 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
298 void DotFileFormatTest::parseFileCtext()
302 importer.setFile(KUrl::fromLocalFile(
"directed/ctext.gv"));
304 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
308 void DotFileFormatTest::parseFileDfa()
312 importer.setFile(KUrl::fromLocalFile(
"directed/dfa.gv"));
314 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
318 void DotFileFormatTest::parseFileFig6()
322 importer.setFile(KUrl::fromLocalFile(
"directed/fig6.gv"));
324 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
328 void DotFileFormatTest::parseFileFsm()
332 importer.setFile(KUrl::fromLocalFile(
"directed/fsm.gv"));
334 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
335 Document *doc = importer.graphDocument();
340 nodeNames <<
"LR_0" <<
"LR_1" <<
"LR_2" <<
"LR_3" <<
"LR_4" <<
"LR_5" <<
"LR_6" <<
"LR_7" <<
"LR_8";
341 checkNodes(dataStructure, nodeNames);
344 QVERIFY(dataStructure->pointers(0).count() == 14);
348 QVERIFY(dataList.length() == 9);
351 foreach(
const DataPtr &node, dataList) {
352 QString name = node->property(
"name").toString();
353 if (name ==
"LR_0") {
355 QVERIFY(node->property(
"shape").toString() ==
"doublecircle");
357 if (name ==
"LR_2") {
359 QVERIFY(node->property(
"shape").toString() ==
"circle");
363 QVERIFY(betweenPtr->property(
"label") ==
"SS(B)");
367 void DotFileFormatTest::parseFileKW91()
371 importer.setFile(KUrl::fromLocalFile(
"directed/KW91.gv"));
373 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
377 void DotFileFormatTest::parseFileLatin1()
381 importer.setFile(KUrl::fromLocalFile(
"directed/Latin1.gv"));
383 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
387 void DotFileFormatTest::parseFileNaN()
391 importer.setFile(KUrl::fromLocalFile(
"directed/NaN.gv"));
393 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
397 void DotFileFormatTest::parseFileGrammar()
401 importer.setFile(KUrl::fromLocalFile(
"directed/grammar.gv"));
403 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
407 void DotFileFormatTest::parseFileHashtable()
411 importer.setFile(KUrl::fromLocalFile(
"directed/hashtable.gv"));
413 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
417 void DotFileFormatTest::parseFileHondaTokoro()
421 importer.setFile(KUrl::fromLocalFile(
"directed/honda-tokoro.gv"));
423 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
427 void DotFileFormatTest::parseFileJapanese()
431 importer.setFile(KUrl::fromLocalFile(
"directed/japanese.gv"));
433 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
437 void DotFileFormatTest::parseFileJcctree()
441 importer.setFile(KUrl::fromLocalFile(
"directed/jcctree.gv"));
443 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
447 void DotFileFormatTest::parseFileJsort()
451 importer.setFile(KUrl::fromLocalFile(
"directed/jsort.gv"));
453 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
457 void DotFileFormatTest::parseFileLdbxtried()
461 importer.setFile(KUrl::fromLocalFile(
"directed/ldbxtried.gv"));
463 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
467 void DotFileFormatTest::parseFileLongflat()
471 importer.setFile(KUrl::fromLocalFile(
"directed/longflat.gv"));
473 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
477 void DotFileFormatTest::parseFileMike()
481 importer.setFile(KUrl::fromLocalFile(
"directed/mike.gv"));
483 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
487 void DotFileFormatTest::parseFileNhg()
491 importer.setFile(KUrl::fromLocalFile(
"directed/nhg.gv"));
493 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
497 void DotFileFormatTest::parseFileOldarrows()
501 importer.setFile(KUrl::fromLocalFile(
"directed/oldarrows.gv"));
503 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
507 void DotFileFormatTest::parseFilePgram()
511 importer.setFile(KUrl::fromLocalFile(
"directed/pgram.gv"));
513 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
517 void DotFileFormatTest::parseFilePm2way()
521 importer.setFile(KUrl::fromLocalFile(
"directed/pm2way.gv"));
523 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
527 void DotFileFormatTest::parseFilePmpipe()
531 importer.setFile(KUrl::fromLocalFile(
"directed/pmpipe.gv"));
533 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
537 void DotFileFormatTest::parseFilePolypoly()
541 importer.setFile(KUrl::fromLocalFile(
"directed/polypoly.gv"));
543 QEXPECT_FAIL(
"",
"Not parsing with unknown reason: need to investigate further.", Continue);
544 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
548 void DotFileFormatTest::parseFileProc3d()
552 importer.setFile(KUrl::fromLocalFile(
"directed/proc3d.gv"));
554 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
558 void DotFileFormatTest::parseFilePsfonttest()
562 importer.setFile(KUrl::fromLocalFile(
"directed/psfonttest.gv"));
564 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
568 void DotFileFormatTest::parseFileRecord2()
572 importer.setFile(KUrl::fromLocalFile(
"directed/record2.gv"));
574 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
578 void DotFileFormatTest::parseFileRecords()
582 importer.setFile(KUrl::fromLocalFile(
"directed/records.gv"));
584 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
588 void DotFileFormatTest::parseFileRowe()
592 importer.setFile(KUrl::fromLocalFile(
"directed/rowe.gv"));
594 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
598 void DotFileFormatTest::parseFileRussian()
602 importer.setFile(KUrl::fromLocalFile(
"directed/russian.gv"));
605 QEXPECT_FAIL(
"",
"Parsing of cyrillic characters for identifiers not yet supported.", Continue);
606 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
610 void DotFileFormatTest::parseFileSdh()
614 importer.setFile(KUrl::fromLocalFile(
"directed/sdh.gv"));
616 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
620 void DotFileFormatTest::parseFileShells()
624 importer.setFile(KUrl::fromLocalFile(
"directed/shells.gv"));
626 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
630 void DotFileFormatTest::parseFileStates()
634 importer.setFile(KUrl::fromLocalFile(
"directed/states.gv"));
636 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
640 void DotFileFormatTest::parseFileStructs()
644 importer.setFile(KUrl::fromLocalFile(
"directed/structs.gv"));
646 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
650 void DotFileFormatTest::parseFileSwitch()
654 importer.setFile(KUrl::fromLocalFile(
"directed/switch.gv"));
656 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
660 void DotFileFormatTest::parseFileTable()
664 importer.setFile(KUrl::fromLocalFile(
"directed/table.gv"));
667 QEXPECT_FAIL(
"",
"Parsing of interleaved XML tags not implemented", Continue);
668 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
672 void DotFileFormatTest::parseFileTrain11()
676 importer.setFile(KUrl::fromLocalFile(
"directed/train11.gv"));
678 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
682 void DotFileFormatTest::parseFileTrapeziumlr()
686 importer.setFile(KUrl::fromLocalFile(
"directed/trapeziumlr.gv"));
688 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
692 void DotFileFormatTest::parseFileTree()
696 importer.setFile(KUrl::fromLocalFile(
"directed/tree.gv"));
698 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
702 void DotFileFormatTest::parseFileTriedds()
706 importer.setFile(KUrl::fromLocalFile(
"directed/triedds.gv"));
708 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
712 void DotFileFormatTest::parseFileTry()
716 importer.setFile(KUrl::fromLocalFile(
"directed/try.gv"));
718 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
722 void DotFileFormatTest::parseFileUnix()
726 importer.setFile(KUrl::fromLocalFile(
"directed/unix.gv"));
728 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
729 Document *doc = importer.graphDocument();
734 nodeNames <<
"5th Edition" <<
"6th Edition" <<
"PWB 1.0" <<
"LSX" <<
"1 BSD" <<
"Mini Unix"
735 <<
"Wollongong" <<
"Interdata" <<
"Unix/TS 3.0" <<
"PWB 2.0" <<
"7th Edition"
736 <<
"8th Edition" <<
"32V" <<
"V7M" <<
"Ultrix-11" <<
"Xenix" <<
"UniPlus+" <<
"9th Edition"
737 <<
"2 BSD" <<
"2.8 BSD" <<
"2.9 BSD" <<
"3 BSD" <<
"4 BSD" <<
"4.1 BSD" <<
"4.2 BSD"
738 <<
"4.3 BSD" <<
"Ultrix-32" <<
"PWB 1.2" <<
"USG 1.0" <<
"CB Unix 1" <<
"USG 2.0" <<
739 "CB Unix 2" <<
"CB Unix 3" <<
"Unix/TS++" <<
"PDP-11 Sys V" <<
"USG 3.0" <<
"Unix/TS 1.0"
740 <<
"TS 4.0" <<
"System V.0" <<
"System V.2" <<
"System V.3";
741 checkNodes(dataStructure, nodeNames);
744 QVERIFY(dataStructure->pointers(0).count() == 49);
748 void DotFileFormatTest::parseFileUnix2()
752 importer.setFile(KUrl::fromLocalFile(
"directed/unix2.gv"));
754 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
758 void DotFileFormatTest::parseFileViewfile()
762 importer.setFile(KUrl::fromLocalFile(
"directed/viewfile.gv"));
764 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
768 void DotFileFormatTest::parseFileWorld()
772 importer.setFile(KUrl::fromLocalFile(
"directed/world.gv"));
774 QVERIFY2(importer.hasError() ==
false, importer.errorString().toStdString().c_str());
778 void DotFileFormatTest::writeAndParseTest()
785 document->
dataType(0)->addProperty(
"testproperty",
"default");
786 document->
pointerType(0)->addProperty(
"testproperty",
"default");
788 ds->setProperty(
"name",
"Graph1");
789 dataList.
insert(
"a", ds->createData(
"a", 0));
790 dataList.
insert(
"b", ds->createData(
"b", 0));
791 ds->createPointer(dataList[
"a"], dataList[
"b"], 0);
797 dotFormat.setFile(KUrl::fromLocalFile(testFile.
fileName()));
798 dotFormat.writeFile(*document);
802 dotFormat.readFile();
803 QVERIFY(!dotFormat.hasError());
804 document = dotFormat.graphDocument();
806 QCOMPARE(ds->dataList(0).count(), 2);
807 QCOMPARE(ds->pointers(0).count(), 1);
static DocumentManager & self()
boost::shared_ptr< DataStructure > DataStructurePtr
Document * activeDocument() const
Returns the currently active document, or 0 if there document list is empty.
static DataStructureBackendManager & self()
Returns self reference to backend manager.
int indexOf(const T &value, int from) const
const char * name() const
boost::shared_ptr< Pointer > PointerPtr
DataStructurePtr activeDataStructure() const
PointerTypePtr pointerType(int pointerType) const
boost::shared_ptr< Data > DataPtr
const QChar at(int position) const
DataTypePtr dataType(int dataType) const
iterator insert(const Key &key, const T &value)
bool parse(const std::string &str, Document *graphDoc)
Parse the given string str that represents the textual respresentation of a graph in DOT/Graphviz for...
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.
DataStructureBackendInterface * backend(const QString &internalName) const
Returns data structure backend identified by its identifier internalName.