[kgraphviewer-devel] [KGraphViewer/libkgraphviz] 3257ce7: Update tests
Kevin Funk
krf at electrostorm.net
Thu Dec 16 15:58:15 CET 2010
A tests/kgraphviz/examples/subgraph.dot [License: Trivialfile.]
commit 3257ce7707e0810fcc5a5e1ccc134bbe692a707b
Author: Kevin Funk <krf at electrostorm.net>
Date: Thu Dec 16 15:19:42 2010 +0100
Update tests
* Add check for subgraph importing
* Add URL referring to the origin of the dot files in the examples
directory
diff --git a/tests/kgraphviz/examples/CMakeLists.txt b/tests/kgraphviz/examples/CMakeLists.txt
index 451a48b..809d3bf 100644
--- a/tests/kgraphviz/examples/CMakeLists.txt
+++ b/tests/kgraphviz/examples/CMakeLists.txt
@@ -1,2 +1,3 @@
install( FILES directed-acyclic-graph.dot DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
+install( FILES subgraph.dot DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
install( FILES undirected-acyclic-graph.dot DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
diff --git a/tests/kgraphviz/examples/directed-acyclic-graph.dot b/tests/kgraphviz/examples/directed-acyclic-graph.dot
index c0763b3..e01882b 100644
--- a/tests/kgraphviz/examples/directed-acyclic-graph.dot
+++ b/tests/kgraphviz/examples/directed-acyclic-graph.dot
@@ -1,3 +1,5 @@
+// http://en.wikipedia.org/w/index.php?title=DOT_language&oldid=401084448#Graph_types
+
digraph graphname {
a -> b -> c;
b -> d;
diff --git a/tests/kgraphviz/examples/subgraph.dot b/tests/kgraphviz/examples/subgraph.dot
new file mode 100644
index 0000000..0b06137
--- /dev/null
+++ b/tests/kgraphviz/examples/subgraph.dot
@@ -0,0 +1,29 @@
+// from: http://www.graphviz.org/Gallery/directed/cluster.html
+
+digraph G {
+
+ subgraph cluster_0 {
+ style=filled;
+ color=lightgrey;
+ node [style=filled,color=white];
+ a0 -> a1 -> a2 -> a3;
+ label = "process #1";
+ }
+
+ subgraph cluster_1 {
+ node [style=filled];
+ b0 -> b1 -> b2 -> b3;
+ label = "process #2";
+ color=blue
+ }
+ start -> a0;
+ start -> b0;
+ a1 -> b3;
+ b2 -> a3;
+ a3 -> a0;
+ a3 -> end;
+ b3 -> end;
+
+ start [shape=Mdiamond];
+ end [shape=Msquare];
+}
diff --git a/tests/kgraphviz/examples/undirected-acyclic-graph.dot b/tests/kgraphviz/examples/undirected-acyclic-graph.dot
index a739e6d..fb63757 100644
--- a/tests/kgraphviz/examples/undirected-acyclic-graph.dot
+++ b/tests/kgraphviz/examples/undirected-acyclic-graph.dot
@@ -1,3 +1,5 @@
+// http://en.wikipedia.org/w/index.php?title=DOT_language&oldid=401084448#Graph_types
+
graph graphname {
a -- b -- c;
b -- d;
diff --git a/tests/kgraphviz/graphiotests.cpp b/tests/kgraphviz/graphiotests.cpp
index 63591de..fc8ea60 100644
--- a/tests/kgraphviz/graphiotests.cpp
+++ b/tests/kgraphviz/graphiotests.cpp
@@ -21,6 +21,7 @@
#include <kgraphviz/graphio.h>
#include <kgraphviz/dotgraph.h>
+#include <kgraphviz/graphsubgraph.h>
#include <qtest_kde.h>
@@ -33,7 +34,9 @@ class GraphIOTests : public QObject
Q_OBJECT
private Q_SLOTS:
- void testImportGraphFromFile();
+ void testImportGraph();
+ void testImportSubGraph();
+
void testImportGraphFromInvalidFile();
void testExportImportGraph();
@@ -43,7 +46,7 @@ private Q_SLOTS:
using namespace KGraphViz;
-void GraphIOTests::testImportGraphFromFile()
+void GraphIOTests::testImportGraph()
{
GraphIO io;
io.loadFromDotFile("examples/directed-acyclic-graph.dot");
@@ -55,6 +58,31 @@ void GraphIOTests::testImportGraphFromFile()
QVERIFY(graph->edges().size() == 3);
}
+void GraphIOTests::testImportSubGraph()
+{
+ GraphIO io;
+ io.loadFromDotFile("examples/subgraph.dot");
+ QVERIFY(QTest::kWaitForSignal(&io, SIGNAL(finished()), 3000) == true);
+
+ DotGraph* graph = io.readData();
+ QVERIFY(graph != 0);
+
+ // test root
+ QCOMPARE(graph->nodes().size(), 2);
+ QCOMPARE(graph->edges().size(), 13);
+ QCOMPARE(graph->subgraphs().size(), 2);
+
+ // test first subgraph
+ GraphSubgraph* subgraph1 = graph->subgraphs()["cluster_0"];
+ QVERIFY(subgraph1 != 0);
+ QCOMPARE(subgraph1->content().size(), 4);
+
+ // test second subgraph
+ GraphSubgraph* subgraph2 = graph->subgraphs()["cluster_1"];
+ QVERIFY(subgraph2 != 0);
+ QCOMPARE(subgraph2->content().size(), 4);
+}
+
void GraphIOTests::testImportGraphFromInvalidFile()
{
GraphIO io;
More information about the kgraphviewer-devel
mailing list