summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-01-04 16:00:52 +0100
committerAleks Kissinger <aleks0@gmail.com>2018-01-04 16:00:52 +0100
commit738ecbd5fad2b46836bfd6a94aeebf165ae2bbca (patch)
treedf04709807cc9ec8481a3ebc7d80ac25e5b2f457 /src/test
parent0421a96749743868554d44585050b1b3d04864d2 (diff)
relocated source code to the root
Diffstat (limited to 'src/test')
-rw-r--r--src/test/testmain.cpp22
-rw-r--r--src/test/testparser.cpp163
-rw-r--r--src/test/testparser.h18
-rw-r--r--src/test/testtest.cpp10
-rw-r--r--src/test/testtest.h17
-rw-r--r--src/test/testtikzoutput.cpp97
-rw-r--r--src/test/testtikzoutput.h17
7 files changed, 344 insertions, 0 deletions
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
new file mode 100644
index 0000000..56491ed
--- /dev/null
+++ b/src/test/testmain.cpp
@@ -0,0 +1,22 @@
+#include "testtest.h"
+#include "testparser.h"
+#include "testtikzoutput.h"
+
+#include <QTest>
+#include <QDebug>
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+ TestTest test;
+ TestParser parser;
+ TestTikzOutput tikzOutput;
+ int r = QTest::qExec(&test, argc, argv) |
+ QTest::qExec(&parser, argc, argv) |
+ QTest::qExec(&tikzOutput, argc, argv);
+
+ if (r == 0) std::cout << "***************** All tests passed! *****************\n";
+ else std::cout << "***************** Some tests failed. *****************\n";
+
+ return r;
+}
diff --git a/src/test/testparser.cpp b/src/test/testparser.cpp
new file mode 100644
index 0000000..e220e2e
--- /dev/null
+++ b/src/test/testparser.cpp
@@ -0,0 +1,163 @@
+#include "testparser.h"
+#include "graph.h"
+#include "tikzgraphassembler.h"
+
+#include <QTest>
+#include <QVector>
+
+//void TestParser::initTestCase()
+//{
+
+//}
+
+//void TestParser::cleanupTestCase()
+//{
+
+//}
+
+void TestParser::parseEmptyGraph()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse("\\begin{tikzpicture}\n\\end{tikzpicture}");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 0);
+ QVERIFY(g->edges().size() == 0);
+ delete g;
+}
+
+void TestParser::parseNodeGraph()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse(
+ "\\begin{tikzpicture}\n"
+ " \\node (node0) at (1.1, -2.2) {};\n"
+ " \\node (node1) at (3, 4) {test};\n"
+ "\\end{tikzpicture}");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 2);
+ QVERIFY(g->edges().size() == 0);
+ QVERIFY(g->nodes()[0]->name() == "node0");
+ QVERIFY(g->nodes()[0]->label() == "");
+ QVERIFY(g->nodes()[0]->point() == QPointF(1.1,-2.2));
+ QVERIFY(g->nodes()[1]->name() == "node1");
+ QVERIFY(g->nodes()[1]->label() == "test");
+ QVERIFY(g->nodes()[1]->point() == QPointF(3,4));
+ delete g;
+}
+
+void TestParser::parseEdgeGraph()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse(
+ "\\begin{tikzpicture}\n"
+ " \\begin{pgfonlayer}{nodelayer}\n"
+ " \\node [style=x, {foo++}] (0) at (-1, -1) {};\n"
+ " \\node [style=y] (1) at (0, 1) {};\n"
+ " \\node [style=z] (2) at (1, -1) {};\n"
+ " \\end{pgfonlayer}\n"
+ " \\begin{pgfonlayer}{edgelayer}\n"
+ " \\draw [style=a] (1.center) to (2);\n"
+ " \\draw [style=b, foo] (2) to (0.west);\n"
+ " \\draw [style=c] (0) to (1);\n"
+ " \\end{pgfonlayer}\n"
+ "\\end{tikzpicture}\n");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 3);
+ QVERIFY(g->edges().size() == 3);
+ QVERIFY(g->nodes()[0]->data()->atom("foo++"));
+ QVERIFY(g->edges()[0]->data()->property("style") == "a");
+ QVERIFY(!g->edges()[0]->data()->atom("foo"));
+ QVERIFY(g->edges()[1]->data()->property("style") == "b");
+ QVERIFY(g->edges()[1]->data()->atom("foo"));
+ QVERIFY(g->edges()[2]->data()->property("style") == "c");
+ Node *en = g->edges()[0]->edgeNode();
+ QVERIFY(en == 0);
+ delete g;
+}
+
+void TestParser::parseEdgeNode()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse(
+ "\\begin{tikzpicture}\n"
+ " \\begin{pgfonlayer}{nodelayer}\n"
+ " \\node [style=none] (0) at (-1, 0) {};\n"
+ " \\node [style=none] (1) at (1, 0) {};\n"
+ " \\end{pgfonlayer}\n"
+ " \\begin{pgfonlayer}{edgelayer}\n"
+ " \\draw [style=diredge] (0.center) to node[foo, bar=baz baz]{test} (1.center);\n"
+ " \\end{pgfonlayer}\n"
+ "\\end{tikzpicture}\n");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 2);
+ QVERIFY(g->edges().size() == 1);
+ Node *en = g->edges()[0]->edgeNode();
+ QVERIFY(en != 0);
+ QVERIFY(en->label() == "test");
+ QVERIFY(en->data()->atom("foo"));
+ QVERIFY(en->data()->property("bar") == "baz baz");
+ delete g;
+}
+
+void TestParser::parseEdgeBends()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse(
+ "\\begin{tikzpicture}\n"
+ " \\begin{pgfonlayer}{nodelayer}\n"
+ " \\node [style=white] (0) at (-1, 0) {};\n"
+ " \\node [style=black] (1) at (1, 0) {};\n"
+ " \\end{pgfonlayer}\n"
+ " \\begin{pgfonlayer}{edgelayer}\n"
+ " \\draw [style=diredge,bend left] (0) to (1);\n"
+ " \\draw [style=diredge,bend right] (0) to (1);\n"
+ " \\draw [style=diredge,bend left=20] (0) to (1);\n"
+ " \\draw [style=diredge,bend right=80] (0) to (1);\n"
+ " \\draw [style=diredge,in=10,out=150,looseness=2] (0) to (1);\n"
+ " \\end{pgfonlayer}\n"
+ "\\end{tikzpicture}\n");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 2);
+ QVERIFY(g->edges().size() == 5);
+ QVERIFY(g->edges()[0]->bend() == -30);
+ QVERIFY(g->edges()[1]->bend() == 30);
+ QVERIFY(g->edges()[2]->bend() == -20);
+ QVERIFY(g->edges()[3]->bend() == 80);
+ QVERIFY(g->edges()[4]->inAngle() == 10);
+ QVERIFY(g->edges()[4]->outAngle() == 150);
+ QVERIFY(g->edges()[4]->weight() == 2.0f/2.5f);
+}
+
+void TestParser::parseBbox()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+ bool res = ga.parse(
+ "\\begin{tikzpicture}\n"
+ " \\path [use as bounding box] (-1.5,-1.5) rectangle (1.5,1.5);\n"
+ " \\begin{pgfonlayer}{nodelayer}\n"
+ " \\node [style=white dot] (0) at (-1, -1) {};\n"
+ " \\node [style=white dot] (1) at (0, 1) {};\n"
+ " \\node [style=white dot] (2) at (1, -1) {};\n"
+ " \\end{pgfonlayer}\n"
+ " \\begin{pgfonlayer}{edgelayer}\n"
+ " \\draw [style=diredge] (1) to (2);\n"
+ " \\draw [style=diredge] (2) to (0);\n"
+ " \\draw [style=diredge] (0) to (1);\n"
+ " \\end{pgfonlayer}\n"
+ "\\end{tikzpicture}\n");
+ QVERIFY(res);
+ QVERIFY(g->nodes().size() == 3);
+ QVERIFY(g->edges().size() == 3);
+ QVERIFY(g->hasBbox());
+ QVERIFY(g->bbox() == QRectF(QPointF(-1.5,-1.5), QPointF(1.5,1.5)));
+
+ delete g;
+}
+
+
diff --git a/src/test/testparser.h b/src/test/testparser.h
new file mode 100644
index 0000000..a40a58f
--- /dev/null
+++ b/src/test/testparser.h
@@ -0,0 +1,18 @@
+#ifndef TESTPARSER_H
+#define TESTPARSER_H
+
+#include <QObject>
+
+class TestParser : public QObject
+{
+ Q_OBJECT
+private slots:
+ void parseEmptyGraph();
+ void parseNodeGraph();
+ void parseEdgeGraph();
+ void parseEdgeNode();
+ void parseEdgeBends();
+ void parseBbox();
+};
+
+#endif // TESTPARSER_H
diff --git a/src/test/testtest.cpp b/src/test/testtest.cpp
new file mode 100644
index 0000000..59173c0
--- /dev/null
+++ b/src/test/testtest.cpp
@@ -0,0 +1,10 @@
+#include "testtest.h"
+
+#include <QObject>
+#include <QTest>
+
+void TestTest::initTestCase() { qDebug("initialising test"); }
+void TestTest::myFirstTest() { QVERIFY(1 == 1); }
+void TestTest::mySecondTest() { QVERIFY(1 != 2); }
+void TestTest::cleanupTestCase() { qDebug("cleaning up test"); }
+
diff --git a/src/test/testtest.h b/src/test/testtest.h
new file mode 100644
index 0000000..69a0bc8
--- /dev/null
+++ b/src/test/testtest.h
@@ -0,0 +1,17 @@
+#ifndef TESTTEST_H
+#define TESTTEST_H
+
+#include <QObject>
+#include <QTest>
+
+class TestTest: public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase();
+ void myFirstTest();
+ void mySecondTest();
+ void cleanupTestCase();
+};
+
+#endif // TESTTEST_H
diff --git a/src/test/testtikzoutput.cpp b/src/test/testtikzoutput.cpp
new file mode 100644
index 0000000..f086786
--- /dev/null
+++ b/src/test/testtikzoutput.cpp
@@ -0,0 +1,97 @@
+#include "testtikzoutput.h"
+#include "graphelementproperty.h"
+#include "graphelementdata.h"
+#include "graph.h"
+#include "tikzgraphassembler.h"
+
+#include <QTest>
+#include <QRectF>
+#include <QPointF>
+
+void TestTikzOutput::escape()
+{
+ QVERIFY(GraphElementProperty::tikzEscape("foo") == "foo");
+ QVERIFY(GraphElementProperty::tikzEscape("foo'") == "foo'");
+ QVERIFY(GraphElementProperty::tikzEscape("foo bar") == "foo bar");
+ QVERIFY(GraphElementProperty::tikzEscape("foo.bar") == "foo.bar");
+ QVERIFY(GraphElementProperty::tikzEscape("foo-bar") == "foo-bar");
+ QVERIFY(GraphElementProperty::tikzEscape("foo >") == "foo >");
+ QVERIFY(GraphElementProperty::tikzEscape("foo <") == "foo <");
+ QVERIFY(GraphElementProperty::tikzEscape("foo+") == "{foo+}");
+ QVERIFY(GraphElementProperty::tikzEscape("foo{bar}") == "{foo{bar}}");
+}
+
+void TestTikzOutput::data()
+{
+ GraphElementData d;
+ QVERIFY(d.tikz() == "");
+ d.setAtom("foo");
+ QVERIFY(d.tikz() == "[foo]");
+ d.setAtom("bar");
+ QVERIFY(d.tikz() == "[foo, bar]");
+ d.setProperty("foo","bar");
+ QVERIFY(d.tikz() == "[foo, bar, foo=bar]");
+ d.setAtom("foo+");
+ QVERIFY(d.tikz() == "[foo, bar, foo=bar, {foo+}]");
+ d.unsetAtom("foo");
+ QVERIFY(d.tikz() == "[bar, foo=bar, {foo+}]");
+ d.unsetProperty("foo");
+ QVERIFY(d.tikz() == "[bar, {foo+}]");
+ d.unsetAtom("foo+");
+ QVERIFY(d.tikz() == "[bar]");
+ d.unsetAtom("bar");
+ QVERIFY(d.tikz() == "");
+}
+
+void TestTikzOutput::graphEmpty()
+{
+ Graph *g = new Graph();
+
+ QString tikz =
+ "\\begin{tikzpicture}\n"
+ "\\end{tikzpicture}\n";
+ QVERIFY(g->tikz() == tikz);
+
+ delete g;
+}
+
+void TestTikzOutput::graphFromTikz()
+{
+ Graph *g = new Graph();
+ TikzGraphAssembler ga(g);
+
+ QString tikz =
+ "\\begin{tikzpicture}\n"
+ "\t\\path [use as bounding box] (-1.5,-1.5) rectangle (1.5,1.5);\n"
+ "\t\\begin{pgfonlayer}{nodelayer}\n"
+ "\t\t\\node [style=white dot] (0) at (-1, -1) {};\n"
+ "\t\t\\node [style=white dot] (1) at (0, 1) {};\n"
+ "\t\t\\node [style=white dot] (2) at (1, -1) {};\n"
+ "\t\\end{pgfonlayer}\n"
+ "\t\\begin{pgfonlayer}{edgelayer}\n"
+ "\t\t\\draw [style=diredge] (1) to (2);\n"
+ "\t\t\\draw [style=diredge] (2.center) to (0);\n"
+ "\t\t\\draw [style=diredge] (0) to ();\n"
+ "\t\\end{pgfonlayer}\n"
+ "\\end{tikzpicture}\n";
+ bool res = ga.parse(tikz);
+ QVERIFY2(res, "parsed successfully");
+ QVERIFY2(g->tikz() == tikz, "produced matching tikz");
+
+ delete g;
+}
+
+void TestTikzOutput::graphBbox()
+{
+ Graph *g = new Graph();
+ g->setBbox(QRectF(QPointF(-0.75, -0.5), QPointF(0.25, 1)));
+
+ QString tikz =
+ "\\begin{tikzpicture}\n"
+ "\t\\path [use as bounding box] (-0.75,-0.5) rectangle (0.25,1);\n"
+ "\\end{tikzpicture}\n";
+ QVERIFY(g->tikz() == tikz);
+
+
+ delete g;
+}
diff --git a/src/test/testtikzoutput.h b/src/test/testtikzoutput.h
new file mode 100644
index 0000000..dff1db1
--- /dev/null
+++ b/src/test/testtikzoutput.h
@@ -0,0 +1,17 @@
+#ifndef TESTTIKZOUTPUT_H
+#define TESTTIKZOUTPUT_H
+
+#include <QObject>
+
+class TestTikzOutput : public QObject
+{
+ Q_OBJECT
+private slots:
+ void escape();
+ void data();
+ void graphBbox();
+ void graphEmpty();
+ void graphFromTikz();
+};
+
+#endif // TESTTIKZOUTPUT_H