From bd6c301c136ca7dd8f0bc89a90ad85e0f01be01b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 22 Jan 2017 17:05:37 +0100 Subject: tikz output --- tikzit/src/test/testmain.cpp | 5 ++- tikzit/src/test/testparser.cpp | 71 ++++++++++++++++++++++++++++++++++---- tikzit/src/test/testparser.h | 4 +-- tikzit/src/test/testtikzoutput.cpp | 40 +++++++++++++++++++++ tikzit/src/test/testtikzoutput.h | 14 ++++++++ 5 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 tikzit/src/test/testtikzoutput.cpp create mode 100644 tikzit/src/test/testtikzoutput.h (limited to 'tikzit/src/test') diff --git a/tikzit/src/test/testmain.cpp b/tikzit/src/test/testmain.cpp index 613be7a..56491ed 100644 --- a/tikzit/src/test/testmain.cpp +++ b/tikzit/src/test/testmain.cpp @@ -1,5 +1,6 @@ #include "testtest.h" #include "testparser.h" +#include "testtikzoutput.h" #include #include @@ -9,8 +10,10 @@ 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(&parser, argc, argv) | + QTest::qExec(&tikzOutput, argc, argv); if (r == 0) std::cout << "***************** All tests passed! *****************\n"; else std::cout << "***************** Some tests failed. *****************\n"; diff --git a/tikzit/src/test/testparser.cpp b/tikzit/src/test/testparser.cpp index e978892..bbc90cf 100644 --- a/tikzit/src/test/testparser.cpp +++ b/tikzit/src/test/testparser.cpp @@ -54,19 +54,78 @@ void TestParser::parseEdgeGraph() bool res = ga.parse( "\\begin{tikzpicture}\n" " \\begin{pgfonlayer}{nodelayer}\n" - " \\node [style=none] (0) at (-1, -1) {};\n" - " \\node [style=none] (1) at (0, 1) {};\n" - " \\node [style=none] (2) at (1, -1) {};\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=diredge] (1.center) to (2.center);\n" - " \\draw [style=diredge] (2.center) to (0.center);\n" - " \\draw [style=diredge] (0.center) to (1.center);\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::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(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/tikzit/src/test/testparser.h b/tikzit/src/test/testparser.h index 8e2e589..69dc965 100644 --- a/tikzit/src/test/testparser.h +++ b/tikzit/src/test/testparser.h @@ -7,11 +7,11 @@ class TestParser : public QObject { Q_OBJECT private slots: - //void initTestCase(); void parseEmptyGraph(); void parseNodeGraph(); void parseEdgeGraph(); - //void cleanupTestCase(); + void parseEdgeNode(); + void parseBbox(); }; #endif // TESTPARSER_H diff --git a/tikzit/src/test/testtikzoutput.cpp b/tikzit/src/test/testtikzoutput.cpp new file mode 100644 index 0000000..8b14bd3 --- /dev/null +++ b/tikzit/src/test/testtikzoutput.cpp @@ -0,0 +1,40 @@ +#include "testtikzoutput.h" +#include "graphelementproperty.h" +#include "graphelementdata.h" + +#include + +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() == ""); +} diff --git a/tikzit/src/test/testtikzoutput.h b/tikzit/src/test/testtikzoutput.h new file mode 100644 index 0000000..24c594e --- /dev/null +++ b/tikzit/src/test/testtikzoutput.h @@ -0,0 +1,14 @@ +#ifndef TESTTIKZOUTPUT_H +#define TESTTIKZOUTPUT_H + +#include + +class TestTikzOutput : public QObject +{ + Q_OBJECT +private slots: + void escape(); + void data(); +}; + +#endif // TESTTIKZOUTPUT_H -- cgit v1.2.3