diff options
author | Norbert Preining <preining@logic.at> | 2019-11-22 02:37:37 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2019-11-22 02:37:37 +0000 |
commit | ed122ac9332b07846c8f32309a90ee20351b89c3 (patch) | |
tree | 1278ed5b65e4815140098fa574e662cd405e25ab /Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp | |
parent | 4d251c1585708a66ebdec74139a6bf13049aa49c (diff) |
dvisvgm update to 2.8.1 (from Martin Gieseking)
git-svn-id: svn://tug.org/texlive/trunk@52883 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp | 190 |
1 files changed, 151 insertions, 39 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp index 572ba6142be..4b4cdb6d424 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/tests/DvisvgmSpecialTest.cpp @@ -41,33 +41,37 @@ class DvisvgmSpecialTest : public ::testing::Test { protected: class ActionsRecorder : public EmptySpecialActions { public: - ActionsRecorder () : defs(""), page("") {} - void appendToDefs(unique_ptr<XMLNode> &&node) override {defs.append(std::move(node));} - void appendToPage(unique_ptr<XMLNode> &&node) override {page.append(std::move(node));} - void embed (const BoundingBox &bb) override {bbox.embed(bb);} - double getX () const override {return 0;} - double getY () const override {return 0;} - void clear () {defs.clear(); page.clear(); bbox=BoundingBox(0, 0, 0, 0);} - bool defsEquals (const string &str) const {return defs.getText() == str;} - bool pageEquals (const string &str) const {return page.getText() == str;} - bool bboxEquals (const string &str) const {return bbox.toSVGViewBox() == str;} - const Matrix& getMatrix () const override {static Matrix m(1); return m;} - string bboxString () const {return bbox.toSVGViewBox();} - string pageString () const {return page.getText();} - - void write (ostream &os) const { - os << "defs: " << defs.getText() << '\n' - << "page: " << page.getText() << '\n' - << "bbox: " << bbox.toSVGViewBox() << '\n'; + void embed (const BoundingBox &bb) override {bbox.embed(bb);} + double getX () const override {return 0;} + double getY () const override {return 0;} + bool defsEquals (const string &str) const {return defsString() == str;} + bool pageEquals (const string &str) const {return pageString() == str;} + bool bboxEquals (const string &str) const {return bbox.toSVGViewBox() == str;} + string bboxString () const {return bbox.toSVGViewBox();} + string defsString () const {return toString(svgTree().defsNode());} + string pageString () const {return toString(svgTree().pageNode());} + + void clear () { + SpecialActions::svgTree().reset(); + SpecialActions::svgTree().newPage(1); + bbox = BoundingBox(0, 0, 0, 0); + } + + protected: + string toString (const XMLNode *node) const { + ostringstream oss; + if (node) + node->write(oss); + return oss.str(); } private: - XMLTextNode defs, page; BoundingBox bbox; }; void SetUp () override { recorder.clear(); + XMLElement::WRITE_NEWLINES = false; } protected: @@ -81,29 +85,137 @@ TEST_F(DvisvgmSpecialTest, basic) { } -TEST_F(DvisvgmSpecialTest, raw) { +TEST_F(DvisvgmSpecialTest, rawText) { istringstream iss("raw first{?nl}"); handler.process("", iss, recorder); EXPECT_TRUE(recorder.defsEquals("")); - EXPECT_TRUE(recorder.pageEquals("first\n")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'>first\n</g>")) << recorder.pageString(); iss.clear(); iss.str("raw \t second {?bbox dummy} \t"); handler.process("", iss, recorder); EXPECT_TRUE(recorder.defsEquals("")); - EXPECT_TRUE(recorder.pageEquals("first\nsecond 0 0 0 0")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'>first\nsecond 0 0 0 0</g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawPage1) { + istringstream iss("raw <elem attr1='1' attr2='20'>text1<inner><text2</inner>text3</elem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><elem attr1='1' attr2='20'>text1<inner><text2</inner>text3</elem></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawPage2) { + istringstream iss("raw <elem attr1='1' attr2='20'>text1"); + handler.process("", iss, recorder); + iss.clear(); iss.str("raw text2<inner>text3</inner><my:empty-elem/>text4"); + handler.process("", iss, recorder); + iss.clear(); iss.str("raw </elem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><elem attr1='1' attr2='20'>text1text2<inner>text3</inner><my:empty-elem/>text4</elem></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawPage3) { + istringstream iss("raw <elem attr1='1' attr2="); + handler.process("", iss, recorder); + iss.clear(); iss.str("raw '20'>text2<inner>text3</inner>text4</e"); + handler.process("", iss, recorder); + iss.clear(); iss.str("raw lem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><elem attr1='1' attr2='20'>text2<inner>text3</inner>text4</elem></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawDefs1) { + istringstream iss("rawdef <elem attr1='1' attr2='20'>text1<inner><text2</inner>text3</elem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("<defs><elem attr1='1' attr2='20'>text1<inner><text2</inner>text3</elem></defs>")) << recorder.defsString(); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); +} + + +TEST_F(DvisvgmSpecialTest, rawDefs2) { + istringstream iss("rawdef <elem attr1='1' attr2='20'>text1"); + handler.process("", iss, recorder); + iss.clear(); iss.str("rawdef text2<inner>text3</inner>text4"); + handler.process("", iss, recorder); + iss.clear(); iss.str("rawdef </elem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("<defs><elem attr1='1' attr2='20'>text1text2<inner>text3</inner>text4</elem></defs>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); +} + + +TEST_F(DvisvgmSpecialTest, rawDefs3) { + istringstream iss("rawdef <elem attr1='1' a"); + handler.process("", iss, recorder); + iss.clear(); iss.str("rawdef ttr2='20'>text2<inner>text3</in"); + handler.process("", iss, recorder); + iss.clear(); iss.str("rawdef ner>text4</elem>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("<defs><elem attr1='1' attr2='20'>text2<inner>text3</inner>text4</elem></defs>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); +} + + +TEST_F(DvisvgmSpecialTest, rawCDATA) { + istringstream iss("raw <outer>text1<![CDATA[1 < 2 <!--test-->]]>text2</outer>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><outer>text1<![CDATA[1 < 2 <!--test-->]]>text2</outer></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawComments) { + istringstream iss("raw <first/><second><!-- 1 < 2 ->--->text</second>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><first/><second><!-- 1 < 2 ->--->text</second></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawPI) { + istringstream iss("raw <first/><?pi1 whatever?><second><?pi2 whatever?></second>"); + handler.process("", iss, recorder); + EXPECT_TRUE(recorder.defsEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><first/><?pi1 whatever?><second><?pi2 whatever?></second></g>")) << recorder.pageString(); +} + + +TEST_F(DvisvgmSpecialTest, rawPageFail) { + istringstream iss("raw <elem attr1='1' attr2='20'"); + EXPECT_THROW({handler.process("", iss, recorder); handler.finishPage();}, SpecialException); // incomplete opening tag + iss.clear(); iss.str("raw </elem>"); + EXPECT_THROW(handler.process("", iss, recorder), SpecialException); // spurious closing tag + iss.clear(); iss.str("raw <open>text</close>"); + EXPECT_THROW(handler.process("", iss, recorder), SpecialException); // mismatching tags +} + + +TEST_F(DvisvgmSpecialTest, rawDefsFail) { + istringstream iss("rawdef <elem attr1='1' attr2='20'"); + EXPECT_THROW({handler.process("", iss, recorder); handler.finishPage();}, SpecialException); // incomplete opening tag + iss.clear(); iss.str("rawdef </elem>"); + EXPECT_THROW(handler.process("", iss, recorder), SpecialException); // spurious closing tag + iss.clear(); iss.str("rawdef <open>text</close>"); + EXPECT_THROW(handler.process("", iss, recorder), SpecialException); // mismatching tags } TEST_F(DvisvgmSpecialTest, rawdef) { std::istringstream iss("rawdef first"); handler.process("", iss, recorder); - EXPECT_TRUE(recorder.defsEquals("first")); - EXPECT_TRUE(recorder.pageEquals("")); + EXPECT_TRUE(recorder.defsEquals("<defs>first</defs>")) << recorder.defsString(); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); - iss.clear(); iss.str("rawdef \t second \t"); + iss.clear(); iss.str("rawdef \t <second></second> \t"); handler.process("", iss, recorder); - EXPECT_TRUE(recorder.defsEquals("firstsecond")); - EXPECT_TRUE(recorder.pageEquals("")); + EXPECT_TRUE(recorder.defsEquals("<defs>first<second/></defs>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); } @@ -111,7 +223,7 @@ TEST_F(DvisvgmSpecialTest, pattern1) { const auto cmds = { "rawset pat1", "raw text1", - "raw text2", + "raw <elem>text2</elem>", "endrawset", "raw first", "rawput pat1", @@ -128,7 +240,7 @@ TEST_F(DvisvgmSpecialTest, pattern1) { } handler.finishPage(); EXPECT_TRUE(recorder.defsEquals("")); - EXPECT_TRUE(recorder.pageEquals("firsttext1text2text1text2")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'>firsttext1<elem>text2</elem>text1<elem>text2</elem></g>")) << recorder.pageString(); } @@ -136,7 +248,7 @@ TEST_F(DvisvgmSpecialTest, pattern2) { const auto cmds = { "rawset pat2", "rawdef text1", - "rawdef text2", + "rawdef <elem>text2</elem>", "endrawset", "rawdef first", "rawput pat2", @@ -152,16 +264,16 @@ TEST_F(DvisvgmSpecialTest, pattern2) { handler.process("", iss, recorder); } handler.finishPage(); - EXPECT_TRUE(recorder.defsEquals("firsttext1text2")); - EXPECT_TRUE(recorder.pageEquals("")); + EXPECT_TRUE(recorder.defsEquals("<defs>firsttext1<elem>text2</elem></defs>")) << recorder.defsString(); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); } TEST_F(DvisvgmSpecialTest, pattern3) { const auto cmds = { "rawset pat3", - "raw text1", - "rawdef text2", + "raw <elem first='a' second='x\"y\"'>text<empty/></elem>", + "rawdef <a/>text2", "endrawset", "rawdef first", "raw second", @@ -177,8 +289,8 @@ TEST_F(DvisvgmSpecialTest, pattern3) { std::istringstream iss(cmd); handler.process("", iss, recorder); } - EXPECT_TRUE(recorder.defsEquals("firsttext2")); - EXPECT_TRUE(recorder.pageEquals("secondtext1text1")); + EXPECT_TRUE(recorder.defsEquals("<defs>first<a/>text2</defs>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'>second<elem first='a' second='x\"y\"'>text<empty/></elem><elem first='a' second='x\"y\"'>text<empty/></elem></g>")) << recorder.pageString(); handler.finishPage(); } @@ -201,13 +313,13 @@ TEST_F(DvisvgmSpecialTest, processImg) { std::istringstream iss("img 72.27 72.27 test.png"); handler.process("", iss, recorder); EXPECT_TRUE(recorder.defsEquals("")); - EXPECT_TRUE(recorder.pageEquals("<image x='0' y='0' width='72' height='72' xlink:href='test.png'/>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><image x='0' y='0' width='72' height='72' xlink:href='test.png'/></g>")) << recorder.pageString(); recorder.clear(); iss.clear(); iss.str("img 10bp 20bp test2.png"); handler.process("", iss, recorder); - EXPECT_TRUE(recorder.pageEquals("<image x='0' y='0' width='10' height='20' xlink:href='test2.png'/>")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'><image x='0' y='0' width='10' height='20' xlink:href='test2.png'/></g>")) << recorder.pageString(); } @@ -221,7 +333,7 @@ TEST_F(DvisvgmSpecialTest, processBBox) { std::istringstream iss("bbox abs 0 0 72.27 72.27"); handler.process("", iss, recorder); EXPECT_TRUE(recorder.defsEquals("")); - EXPECT_TRUE(recorder.pageEquals("")); + EXPECT_TRUE(recorder.pageEquals("<g id='page1'/>")); EXPECT_TRUE(recorder.bboxEquals("0 0 72 72")); recorder.clear(); |