• 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
  • LoadSave
  • Plugins
  • dotFileFormat
  • Tests
DotFileFormatTest.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
4  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "DotFileFormatTest.h"
21 #include <QTest>
22 #include <string>
23 #include <Document.h>
24 #include "../DotGrammar.h"
25 #include "../DotFileFormatPlugin.h"
26 #include "Data.h"
27 #include "Pointer.h"
28 #include <DocumentManager.h>
29 #include <DataStructure.h>
30 #include <DataStructureBackendManager.h>
31 #include <KDebug>
32 #include <KUrl>
33 
34 static const std::string simple = "digraph simple {a_2 -> b; c; d -> e /* error -> comment*/}";
35 
36 static const std::string subgraph = "digraph trees {"
37  " subgraph t {"
38  " 0 -> \"1\" [label = \"A\"];"
39  " 0 -> \"2\" [label = \"B\"];"
40  " }"
41  " subgraph u {"
42  " Animal -> Cat [label = \"feline\"];"
43  " Animal -> Dot [label = \"canine\"];"
44  " }"
45  "}";
46 
47 void DotFileFormatTest::checkNodes(DataStructurePtr dataStructure, QList<QString> nodeNames)
48 {
49  QList<DataPtr> dataList = dataStructure->dataList(0);
50 
51 // foreach(const DataPtr &node, dataList) {
52 // kDebug() << node->property("name").toString();
53 // }
54 
55  foreach(const DataPtr &node, dataList) {
56  QString name = node->property("name").toString();
57  int index = nodeNames.indexOf(name);
58  if (index == -1) {
59  kDebug() << "Node "<< name << " was created unnecessarily.";
60  }
61  QVERIFY(index != -1);
62  nodeNames.removeAt(index);
63  }
64  QVERIFY(nodeNames.isEmpty());
65 }
66 
67 void DotFileFormatTest::init()
68 {
69  // test for graph data structure plugin
70  if (DataStructureBackendManager::self().backends().count() == 0) {
71  QFAIL("No plugin of DS, no way to continue!");
72  }
73  DataStructureBackendInterface *pl = DataStructureBackendManager::self().backend("Graph");
74  QVERIFY2(pl,"Could create data structure of type Graph");
75 }
76 
77 void DotFileFormatTest::simpleGraphParsing()
78 {
79  Document doc("testSimple");
80  QVERIFY(DotParser::parse(simple, &doc));
81 
82  QVERIFY(doc.dataStructures().count() == 1);
83  if (doc.dataStructures().count() == 0) {
84  return;
85  }
86 
87  DataStructurePtr graph = doc.dataStructures().at(0);
88  QVERIFY(graph->dataList(0).count() == 5);
89  QVERIFY(graph->pointers(0).count() == 2);
90 }
91 
92 
93 void DotFileFormatTest::parseSubgraphs()
94 {
95  Document doc("testSubgraphs");
96  QVERIFY(DotParser::parse(subgraph, &doc));
97 }
98 
99 
100 void DotFileFormatTest::parseFileER()
101 {
102  // create importer plugin
103  DotFileFormatPlugin importer(this, QList<QVariant>());
104  importer.setFile(KUrl::fromLocalFile("undirected/ER.gv"));
105  importer.readFile();
106  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
107  Document *doc = importer.graphDocument();
108  DataStructurePtr dataStructure = doc->activeDataStructure();
109 
110  // Check that all of the node names were imported, and that there are no extras.
111  QList<QString> nodeNames;
112  nodeNames << "course" << "institute" << "student" << "name0" << "name1" << "name2" << "code" << "grade" << "number" << "C-I" << "S-C" << "S-I";
113  checkNodes(dataStructure, nodeNames);
114 
115  // Check the numbers of pointers
116  QVERIFY(dataStructure->pointers(0).count() == 12);
117 
118  // Check that a pointer has the correct label & that the node labels work.
119  QList<DataPtr> dataList = dataStructure->dataList(0);
120  DataPtr start;
121  DataPtr end;
122  foreach(const DataPtr &node, dataList) {
123  QString name = node->property("name").toString();
124  if (name == "student") {
125  start = node;
126  }
127  if (name == "S-C") {
128  end = node;
129  }
130  if (name == "name0" || name == "name1" || name == "name2") {
131  QVERIFY(node->property("label").toString() == "name");
132  }
133  }
134  PointerPtr betweenPtr = start->pointerList(end).at(0);
135  QVERIFY(betweenPtr->property("label") == "m");
136 }
137 
138 
139 void DotFileFormatTest::parseFileHeawood()
140 {
141  // create importer plugin
142  DotFileFormatPlugin importer(this, QList<QVariant>());
143  importer.setFile(KUrl::fromLocalFile("undirected/Heawood.gv"));
144  importer.readFile();
145  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
146 }
147 
148 
149 void DotFileFormatTest::parseFileNgk104()
150 {
151  // create importer plugin
152  DotFileFormatPlugin importer(this, QList<QVariant>());
153  importer.setFile(KUrl::fromLocalFile("undirected/ngk10_4.gv"));
154  importer.readFile();
155  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
156 }
157 
158 
159 void DotFileFormatTest::parseFilePetersen()
160 {
161  // create importer plugin
162  DotFileFormatPlugin importer(this, QList<QVariant>());
163  importer.setFile(KUrl::fromLocalFile("undirected/Petersen.gv"));
164  importer.readFile();
165  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
166 }
167 
168 
169 void DotFileFormatTest::parseFileProcess()
170 {
171  // create importer plugin
172  DotFileFormatPlugin importer(this, QList<QVariant>());
173  importer.setFile(KUrl::fromLocalFile("undirected/process.gv"));
174  importer.readFile();
175  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
176  Document* doc = importer.graphDocument();
177  DataStructurePtr dataStructure = doc->activeDataStructure();
178  // Check that all of the node names were imported, and that there are no extras.
179  QList<QString> nodeNames;
180  nodeNames << "run" << "intr" << "runbl" << "kernel" << "zombie" << "sleep" << "swap" << "runmem" << "runswap" << "new";
181  checkNodes(dataStructure, nodeNames);
182  // Check the numbers of pointers
183  QVERIFY(dataStructure->pointers(0).count() == 13);
184 }
185 
186 
187 void DotFileFormatTest::parseFileAbstract()
188 {
189  // create importer plugin
190  DotFileFormatPlugin importer(this, QList<QVariant>());
191  importer.setFile(KUrl::fromLocalFile("directed/abstract.gv"));
192  importer.readFile();
193  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
194 }
195 
196 
197 void DotFileFormatTest::parseFileAlf()
198 {
199  // create importer plugin
200  DotFileFormatPlugin importer(this, QList<QVariant>());
201  importer.setFile(KUrl::fromLocalFile("directed/alf.gv"));
202  importer.readFile();
203  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
204 }
205 
206 
207 void DotFileFormatTest::parseFileArrows()
208 {
209  // create importer plugin
210  DotFileFormatPlugin importer(this, QList<QVariant>());
211  importer.setFile(KUrl::fromLocalFile("directed/arrows.gv"));
212  importer.readFile();
213  QEXPECT_FAIL("", "File contains invalid identifiers with underbar at beginning.", Continue);
214  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
215 }
216 
217 
218 void DotFileFormatTest::parseFileAwilliams()
219 {
220  // create importer plugin
221  DotFileFormatPlugin importer(this, QList<QVariant>());
222  importer.setFile(KUrl::fromLocalFile("directed/awilliams.gv"));
223  importer.readFile();
224  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
225 }
226 
227 
228 void DotFileFormatTest::parseFileClust()
229 {
230  // create importer plugin
231  DotFileFormatPlugin importer(this, QList<QVariant>());
232  importer.setFile(KUrl::fromLocalFile("directed/clust.gv"));
233  importer.readFile();
234  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
235 }
236 
237 
238 void DotFileFormatTest::parseFileClust1()
239 {
240  // create importer plugin
241  DotFileFormatPlugin importer(this, QList<QVariant>());
242  importer.setFile(KUrl::fromLocalFile("directed/clust1.gv"));
243  importer.readFile();
244  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
245 }
246 
247 
248 void DotFileFormatTest::parseFileClust2()
249 {
250  // create importer plugin
251  DotFileFormatPlugin importer(this, QList<QVariant>());
252  importer.setFile(KUrl::fromLocalFile("directed/clust2.gv"));
253  importer.readFile();
254  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
255 }
256 
257 
258 void DotFileFormatTest::parseFileClust3()
259 {
260  // create importer plugin
261  DotFileFormatPlugin importer(this, QList<QVariant>());
262  importer.setFile(KUrl::fromLocalFile("directed/clust3.gv"));
263  importer.readFile();
264  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
265 }
266 
267 
268 void DotFileFormatTest::parseFileClust4()
269 {
270  // create importer plugin
271  DotFileFormatPlugin importer(this, QList<QVariant>());
272  importer.setFile(KUrl::fromLocalFile("directed/clust4.gv"));
273  importer.readFile();
274  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
275 }
276 
277 
278 void DotFileFormatTest::parseFileClust5()
279 {
280  // create importer plugin
281  DotFileFormatPlugin importer(this, QList<QVariant>());
282  importer.setFile(KUrl::fromLocalFile("directed/clust5.gv"));
283  importer.readFile();
284  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
285 }
286 
287 
288 void DotFileFormatTest::parseFileCrazy()
289 {
290  // create importer plugin
291  DotFileFormatPlugin importer(this, QList<QVariant>());
292  importer.setFile(KUrl::fromLocalFile("directed/crazy.gv"));
293  importer.readFile();
294  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
295 }
296 
297 
298 void DotFileFormatTest::parseFileCtext()
299 {
300  // create importer plugin
301  DotFileFormatPlugin importer(this, QList<QVariant>());
302  importer.setFile(KUrl::fromLocalFile("directed/ctext.gv"));
303  importer.readFile();
304  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
305 }
306 
307 
308 void DotFileFormatTest::parseFileDfa()
309 {
310  // create importer plugin
311  DotFileFormatPlugin importer(this, QList<QVariant>());
312  importer.setFile(KUrl::fromLocalFile("directed/dfa.gv"));
313  importer.readFile();
314  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
315 }
316 
317 
318 void DotFileFormatTest::parseFileFig6()
319 {
320  // create importer plugin
321  DotFileFormatPlugin importer(this, QList<QVariant>());
322  importer.setFile(KUrl::fromLocalFile("directed/fig6.gv"));
323  importer.readFile();
324  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
325 }
326 
327 
328 void DotFileFormatTest::parseFileFsm()
329 {
330  // create importer plugin
331  DotFileFormatPlugin importer(this, QList<QVariant>());
332  importer.setFile(KUrl::fromLocalFile("directed/fsm.gv"));
333  importer.readFile();
334  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
335  Document *doc = importer.graphDocument();
336  DataStructurePtr dataStructure = doc->activeDataStructure();
337 
338  // Check that all of the node names were imported, and that there are no extras.
339  QList<QString> nodeNames;
340  nodeNames << "LR_0" << "LR_1" << "LR_2" << "LR_3" << "LR_4" << "LR_5" << "LR_6" << "LR_7" << "LR_8";
341  checkNodes(dataStructure, nodeNames);
342 
343  // Check the numbers of pointers
344  QVERIFY(dataStructure->pointers(0).count() == 14);
345 
346  // Check that a pointer has the correct label and that the shapes are correct.
347  QList<DataPtr> dataList = dataStructure->dataList(0);
348  QVERIFY(dataList.length() == 9); // Make the test quit because the parser has too many LR nodes.
349  DataPtr start;
350  DataPtr end;
351  foreach(const DataPtr &node, dataList) {
352  QString name = node->property("name").toString();
353  if (name == "LR_0") {
354  start = node;
355  QVERIFY(node->property("shape").toString() == "doublecircle");
356  }
357  if (name == "LR_2") {
358  end = node;
359  QVERIFY(node->property("shape").toString() == "circle");
360  }
361  }
362  PointerPtr betweenPtr = start->pointerList(end).at(0);
363  QVERIFY(betweenPtr->property("label") == "SS(B)");
364 }
365 
366 
367 void DotFileFormatTest::parseFileKW91()
368 {
369  // create importer plugin
370  DotFileFormatPlugin importer(this, QList<QVariant>());
371  importer.setFile(KUrl::fromLocalFile("directed/KW91.gv"));
372  importer.readFile();
373  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
374 }
375 
376 
377 void DotFileFormatTest::parseFileLatin1()
378 {
379  // create importer plugin
380  DotFileFormatPlugin importer(this, QList<QVariant>());
381  importer.setFile(KUrl::fromLocalFile("directed/Latin1.gv"));
382  importer.readFile();
383  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
384 }
385 
386 
387 void DotFileFormatTest::parseFileNaN()
388 {
389  // create importer plugin
390  DotFileFormatPlugin importer(this, QList<QVariant>());
391  importer.setFile(KUrl::fromLocalFile("directed/NaN.gv"));
392  importer.readFile();
393  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
394 }
395 
396 
397 void DotFileFormatTest::parseFileGrammar()
398 {
399  // create importer plugin
400  DotFileFormatPlugin importer(this, QList<QVariant>());
401  importer.setFile(KUrl::fromLocalFile("directed/grammar.gv"));
402  importer.readFile();
403  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
404 }
405 
406 
407 void DotFileFormatTest::parseFileHashtable()
408 {
409  // create importer plugin
410  DotFileFormatPlugin importer(this, QList<QVariant>());
411  importer.setFile(KUrl::fromLocalFile("directed/hashtable.gv"));
412  importer.readFile();
413  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
414 }
415 
416 
417 void DotFileFormatTest::parseFileHondaTokoro()
418 {
419  // create importer plugin
420  DotFileFormatPlugin importer(this, QList<QVariant>());
421  importer.setFile(KUrl::fromLocalFile("directed/honda-tokoro.gv"));
422  importer.readFile();
423  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
424 }
425 
426 
427 void DotFileFormatTest::parseFileJapanese()
428 {
429  // create importer plugin
430  DotFileFormatPlugin importer(this, QList<QVariant>());
431  importer.setFile(KUrl::fromLocalFile("directed/japanese.gv"));
432  importer.readFile();
433  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
434 }
435 
436 
437 void DotFileFormatTest::parseFileJcctree()
438 {
439  // create importer plugin
440  DotFileFormatPlugin importer(this, QList<QVariant>());
441  importer.setFile(KUrl::fromLocalFile("directed/jcctree.gv"));
442  importer.readFile();
443  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
444 }
445 
446 
447 void DotFileFormatTest::parseFileJsort()
448 {
449  // create importer plugin
450  DotFileFormatPlugin importer(this, QList<QVariant>());
451  importer.setFile(KUrl::fromLocalFile("directed/jsort.gv"));
452  importer.readFile();
453  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
454 }
455 
456 
457 void DotFileFormatTest::parseFileLdbxtried()
458 {
459  // create importer plugin
460  DotFileFormatPlugin importer(this, QList<QVariant>());
461  importer.setFile(KUrl::fromLocalFile("directed/ldbxtried.gv"));
462  importer.readFile();
463  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
464 }
465 
466 
467 void DotFileFormatTest::parseFileLongflat()
468 {
469  // create importer plugin
470  DotFileFormatPlugin importer(this, QList<QVariant>());
471  importer.setFile(KUrl::fromLocalFile("directed/longflat.gv"));
472  importer.readFile();
473  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
474 }
475 
476 
477 void DotFileFormatTest::parseFileMike()
478 {
479  // create importer plugin
480  DotFileFormatPlugin importer(this, QList<QVariant>());
481  importer.setFile(KUrl::fromLocalFile("directed/mike.gv"));
482  importer.readFile();
483  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
484 }
485 
486 
487 void DotFileFormatTest::parseFileNhg()
488 {
489  // create importer plugin
490  DotFileFormatPlugin importer(this, QList<QVariant>());
491  importer.setFile(KUrl::fromLocalFile("directed/nhg.gv"));
492  importer.readFile();
493  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
494 }
495 
496 
497 void DotFileFormatTest::parseFileOldarrows()
498 {
499  // create importer plugin
500  DotFileFormatPlugin importer(this, QList<QVariant>());
501  importer.setFile(KUrl::fromLocalFile("directed/oldarrows.gv"));
502  importer.readFile();
503  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
504 }
505 
506 
507 void DotFileFormatTest::parseFilePgram()
508 {
509  // create importer plugin
510  DotFileFormatPlugin importer(this, QList<QVariant>());
511  importer.setFile(KUrl::fromLocalFile("directed/pgram.gv"));
512  importer.readFile();
513  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
514 }
515 
516 
517 void DotFileFormatTest::parseFilePm2way()
518 {
519  // create importer plugin
520  DotFileFormatPlugin importer(this, QList<QVariant>());
521  importer.setFile(KUrl::fromLocalFile("directed/pm2way.gv"));
522  importer.readFile();
523  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
524 }
525 
526 
527 void DotFileFormatTest::parseFilePmpipe()
528 {
529  // create importer plugin
530  DotFileFormatPlugin importer(this, QList<QVariant>());
531  importer.setFile(KUrl::fromLocalFile("directed/pmpipe.gv"));
532  importer.readFile();
533  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
534 }
535 
536 
537 void DotFileFormatTest::parseFilePolypoly()
538 {
539  // create importer plugin
540  DotFileFormatPlugin importer(this, QList<QVariant>());
541  importer.setFile(KUrl::fromLocalFile("directed/polypoly.gv"));
542  importer.readFile();
543  QEXPECT_FAIL("", "Not parsing with unknown reason: need to investigate further.", Continue);
544  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
545 }
546 
547 
548 void DotFileFormatTest::parseFileProc3d()
549 {
550  // create importer plugin
551  DotFileFormatPlugin importer(this, QList<QVariant>());
552  importer.setFile(KUrl::fromLocalFile("directed/proc3d.gv"));
553  importer.readFile();
554  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
555 }
556 
557 
558 void DotFileFormatTest::parseFilePsfonttest()
559 {
560  // create importer plugin
561  DotFileFormatPlugin importer(this, QList<QVariant>());
562  importer.setFile(KUrl::fromLocalFile("directed/psfonttest.gv"));
563  importer.readFile();
564  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
565 }
566 
567 
568 void DotFileFormatTest::parseFileRecord2()
569 {
570  // create importer plugin
571  DotFileFormatPlugin importer(this, QList<QVariant>());
572  importer.setFile(KUrl::fromLocalFile("directed/record2.gv"));
573  importer.readFile();
574  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
575 }
576 
577 
578 void DotFileFormatTest::parseFileRecords()
579 {
580  // create importer plugin
581  DotFileFormatPlugin importer(this, QList<QVariant>());
582  importer.setFile(KUrl::fromLocalFile("directed/records.gv"));
583  importer.readFile();
584  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
585 }
586 
587 
588 void DotFileFormatTest::parseFileRowe()
589 {
590  // create importer plugin
591  DotFileFormatPlugin importer(this, QList<QVariant>());
592  importer.setFile(KUrl::fromLocalFile("directed/rowe.gv"));
593  importer.readFile();
594  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
595 }
596 
597 
598 void DotFileFormatTest::parseFileRussian()
599 {
600  // create importer plugin
601  DotFileFormatPlugin importer(this, QList<QVariant>());
602  importer.setFile(KUrl::fromLocalFile("directed/russian.gv"));
603  importer.readFile();
604 
605  QEXPECT_FAIL("", "Parsing of cyrillic characters for identifiers not yet supported.", Continue);
606  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
607 }
608 
609 
610 void DotFileFormatTest::parseFileSdh()
611 {
612  // create importer plugin
613  DotFileFormatPlugin importer(this, QList<QVariant>());
614  importer.setFile(KUrl::fromLocalFile("directed/sdh.gv"));
615  importer.readFile();
616  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
617 }
618 
619 
620 void DotFileFormatTest::parseFileShells()
621 {
622  // create importer plugin
623  DotFileFormatPlugin importer(this, QList<QVariant>());
624  importer.setFile(KUrl::fromLocalFile("directed/shells.gv"));
625  importer.readFile();
626  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
627 }
628 
629 
630 void DotFileFormatTest::parseFileStates()
631 {
632  // create importer plugin
633  DotFileFormatPlugin importer(this, QList<QVariant>());
634  importer.setFile(KUrl::fromLocalFile("directed/states.gv"));
635  importer.readFile();
636  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
637 }
638 
639 
640 void DotFileFormatTest::parseFileStructs()
641 {
642  // create importer plugin
643  DotFileFormatPlugin importer(this, QList<QVariant>());
644  importer.setFile(KUrl::fromLocalFile("directed/structs.gv"));
645  importer.readFile();
646  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
647 }
648 
649 
650 void DotFileFormatTest::parseFileSwitch()
651 {
652  // create importer plugin
653  DotFileFormatPlugin importer(this, QList<QVariant>());
654  importer.setFile(KUrl::fromLocalFile("directed/switch.gv"));
655  importer.readFile();
656  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
657 }
658 
659 
660 void DotFileFormatTest::parseFileTable()
661 {
662  // create importer plugin
663  DotFileFormatPlugin importer(this, QList<QVariant>());
664  importer.setFile(KUrl::fromLocalFile("directed/table.gv"));
665  importer.readFile();
666 
667  QEXPECT_FAIL("", "Parsing of interleaved XML tags not implemented", Continue);
668  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
669 }
670 
671 
672 void DotFileFormatTest::parseFileTrain11()
673 {
674  // create importer plugin
675  DotFileFormatPlugin importer(this, QList<QVariant>());
676  importer.setFile(KUrl::fromLocalFile("directed/train11.gv"));
677  importer.readFile();
678  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
679 }
680 
681 
682 void DotFileFormatTest::parseFileTrapeziumlr()
683 {
684  // create importer plugin
685  DotFileFormatPlugin importer(this, QList<QVariant>());
686  importer.setFile(KUrl::fromLocalFile("directed/trapeziumlr.gv"));
687  importer.readFile();
688  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
689 }
690 
691 
692 void DotFileFormatTest::parseFileTree()
693 {
694  // create importer plugin
695  DotFileFormatPlugin importer(this, QList<QVariant>());
696  importer.setFile(KUrl::fromLocalFile("directed/tree.gv"));
697  importer.readFile();
698  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
699 }
700 
701 
702 void DotFileFormatTest::parseFileTriedds()
703 {
704  // create importer plugin
705  DotFileFormatPlugin importer(this, QList<QVariant>());
706  importer.setFile(KUrl::fromLocalFile("directed/triedds.gv"));
707  importer.readFile();
708  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
709 }
710 
711 
712 void DotFileFormatTest::parseFileTry()
713 {
714  // create importer plugin
715  DotFileFormatPlugin importer(this, QList<QVariant>());
716  importer.setFile(KUrl::fromLocalFile("directed/try.gv"));
717  importer.readFile();
718  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
719 }
720 
721 
722 void DotFileFormatTest::parseFileUnix()
723 {
724  // create importer plugin
725  DotFileFormatPlugin importer(this, QList<QVariant>());
726  importer.setFile(KUrl::fromLocalFile("directed/unix.gv"));
727  importer.readFile();
728  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
729  Document *doc = importer.graphDocument();
730  DataStructurePtr dataStructure = doc->activeDataStructure();
731 
732  // check that all of the node names were imported, and that there are no extra nodes
733  QList<QString> nodeNames;
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);
742 
743  // check number of pointers
744  QVERIFY(dataStructure->pointers(0).count() == 49);
745 }
746 
747 
748 void DotFileFormatTest::parseFileUnix2()
749 {
750  // create importer plugin
751  DotFileFormatPlugin importer(this, QList<QVariant>());
752  importer.setFile(KUrl::fromLocalFile("directed/unix2.gv"));
753  importer.readFile();
754  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
755 }
756 
757 
758 void DotFileFormatTest::parseFileViewfile()
759 {
760  // create importer plugin
761  DotFileFormatPlugin importer(this, QList<QVariant>());
762  importer.setFile(KUrl::fromLocalFile("directed/viewfile.gv"));
763  importer.readFile();
764  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
765 }
766 
767 
768 void DotFileFormatTest::parseFileWorld()
769 {
770  // create importer plugin
771  DotFileFormatPlugin importer(this, QList<QVariant>());
772  importer.setFile(KUrl::fromLocalFile("directed/world.gv"));
773  importer.readFile();
774  QVERIFY2(importer.hasError() == false, importer.errorString().toStdString().c_str());
775 }
776 
777 
778 void DotFileFormatTest::writeAndParseTest()
779 {
780  DocumentManager::self().addDocument(new Document("testSerialization"));
781  Document *document = DocumentManager::self().activeDocument();
782  QMap<QString, DataPtr> dataList;
783 
784  // create simple graph with two nodes and one edge
785  document->dataType(0)->addProperty("testproperty", "default");
786  document->pointerType(0)->addProperty("testproperty", "default");
787  DataStructurePtr ds = document->activeDataStructure();
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);
792 
793  // create testfile
794  DotFileFormatPlugin dotFormat(this, QList<QVariant>());
795  QTemporaryFile testFile;
796  testFile.open();
797  dotFormat.setFile(KUrl::fromLocalFile(testFile.fileName()));
798  dotFormat.writeFile(*document);
799  DocumentManager::self().removeDocument(DocumentManager::self().activeDocument());
800 
801  // load document and test
802  dotFormat.readFile();
803  QVERIFY(!dotFormat.hasError());
804  document = dotFormat.graphDocument();
805  ds = document->activeDataStructure();
806  QCOMPARE(ds->dataList(0).count(), 2);
807  QCOMPARE(ds->pointers(0).count(), 1);
808 }
809 
810 
811 QTEST_MAIN(DotFileFormatTest)
DotFileFormatTest.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
QMap< QString, DataPtr >
QList::removeAt
void removeAt(int i)
Data.h
DotFileFormatTest
Definition: DotFileFormatTest.h:27
DataStructureBackendManager::self
static DataStructureBackendManager & self()
Returns self reference to backend manager.
Definition: DataStructureBackendManager.cpp:233
Document.h
QList::indexOf
int indexOf(const T &value, int from) const
QObject::name
const char * name() const
PointerPtr
boost::shared_ptr< Pointer > PointerPtr
Definition: CoreTypes.h:35
DataStructure.h
QList::isEmpty
bool isEmpty() const
QTEST_MAIN
QTEST_MAIN(TestTgfFileFormatPlugin)
Document::activeDataStructure
DataStructurePtr activeDataStructure() const
Definition: Document.cpp:431
QString
QList< QString >
Document
Definition: Document.h:41
QTemporaryFile::fileName
QString fileName() const
subgraph
static const std::string subgraph
Definition: DotFileFormatTest.cpp:36
Document::pointerType
PointerTypePtr pointerType(int pointerType) const
Definition: Document.cpp:207
Pointer.h
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
QString::at
const QChar at(int position) const
Document::dataType
DataTypePtr dataType(int dataType) const
Definition: Document.cpp:197
DataStructureBackendInterface
Definition: DataStructureBackendInterface.h:42
QMap::insert
iterator insert(const Key &key, const T &value)
DotParser::parse
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...
Definition: DotGrammar.cpp:474
QTemporaryFile
DotFileFormatPlugin
Definition: DotFileFormatPlugin.h:28
QTemporaryFile::open
bool open()
DocumentManager::addDocument
void addDocument(Document *document)
Add document to document list and set this document as active document.
Definition: DocumentManager.cpp:106
DataStructureBackendManager.h
simple
static const std::string simple
Definition: DotFileFormatTest.cpp:34
DocumentManager::removeDocument
void removeDocument(Document *document)
Remove document from document list.
Definition: DocumentManager.cpp:173
DataStructureBackendManager::backend
DataStructureBackendInterface * backend(const QString &internalName) const
Returns data structure backend identified by its identifier internalName.
Definition: DataStructureBackendManager.cpp:280
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