diff options
Diffstat (limited to 'dviware/dvisvgm/tests')
-rw-r--r-- | dviware/dvisvgm/tests/GraphicsPathParserTest.cpp | 27 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/JFMReaderTest.cpp | 7 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/Makefile.am | 6 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/Makefile.in | 65 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/OFMReaderTest.cpp | 128 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/TFMReaderTest.cpp | 7 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/UtilityTest.cpp | 35 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/data/Makefile.am | 4 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/data/Makefile.in | 4 | ||||
-rw-r--r-- | dviware/dvisvgm/tests/data/omarab.ofm | bin | 0 -> 12576 bytes | |||
-rw-r--r-- | dviware/dvisvgm/tests/data/upjf-g.ofm | bin | 0 -> 292 bytes |
11 files changed, 260 insertions, 23 deletions
diff --git a/dviware/dvisvgm/tests/GraphicsPathParserTest.cpp b/dviware/dvisvgm/tests/GraphicsPathParserTest.cpp index 7de23c9374..93615ca536 100644 --- a/dviware/dvisvgm/tests/GraphicsPathParserTest.cpp +++ b/dviware/dvisvgm/tests/GraphicsPathParserTest.cpp @@ -150,7 +150,20 @@ TEST(GraphicsPathParserTest, combined) { } -TEST(GraphicsPathParserTest, error) { +TEST(GraphicsPathParserTest, floats) { + GraphicsPathParser<double> parser; + auto path = parser.parse("M10 10.1L20.2 50.3Q 100 100 -10.1 -10.2 Z C 10e-1 2e2 30 40 50 60Z"); + ostringstream oss; + path.writeSVG(oss, false); + EXPECT_EQ(oss.str(), "M10 10.1L20.2 50.3Q100 100-10.1-10.2ZC1 200 30 40 50 60Z"); + oss.str(""); + path = parser.parse("m10 10.1l20.2 50.3q 100 100 -10.1 -10.2 z c 10 20 30 40 50 60 z"); + path.writeSVG(oss, false); + EXPECT_EQ(oss.str(), "M10 10.1L30.2 60.4Q130.2 160.4 20.1 50.2ZC20 30.1 40 50.1 60 70.1Z"); +} + + +TEST(GraphicsPathParserTest, error1) { GraphicsPathParser<int> parser; EXPECT_THROW(parser.parse("10 20"), GraphicsPathParserException); // missing command EXPECT_THROW(parser.parse("M10 "), GraphicsPathParserException); // missing y-coordinate @@ -161,3 +174,15 @@ TEST(GraphicsPathParserTest, error) { EXPECT_THROW(parser.parse("A 10 20 45 2 0 100 100"), GraphicsPathParserException); // invalid large-arc-flag EXPECT_THROW(parser.parse("A 10 20 45 0 5 100 100"), GraphicsPathParserException); // invalid sweep-flag } + + +TEST(GraphicsPathParserTest, error2) { + GraphicsPathParser<double> parser; + EXPECT_THROW(parser.parse("10 20"), GraphicsPathParserException); // missing command + EXPECT_THROW(parser.parse("M"), GraphicsPathParserException); // missing coordinates + EXPECT_THROW(parser.parse("M10.1 "), GraphicsPathParserException); // missing y-coordinate + EXPECT_THROW(parser.parse("M 10 20..5"), GraphicsPathParserException); // invalid double dots + EXPECT_THROW(parser.parse("M 10 20.5."), GraphicsPathParserException); // invalid trailing dot + EXPECT_THROW(parser.parse("M 10-20.1+"), GraphicsPathParserException); // invalid trailing plus + EXPECT_THROW(parser.parse("M.+10.20"), GraphicsPathParserException); // invalid plus after dot +} diff --git a/dviware/dvisvgm/tests/JFMReaderTest.cpp b/dviware/dvisvgm/tests/JFMReaderTest.cpp index 6ca10c7a83..b641f677d9 100644 --- a/dviware/dvisvgm/tests/JFMReaderTest.cpp +++ b/dviware/dvisvgm/tests/JFMReaderTest.cpp @@ -40,7 +40,8 @@ class JFMReaderTest : public ::testing::Test { string fname = string(SRCDIR)+"/data/cidjmgr0-h.tfm"; ifstream ifs(fname, ios::binary); ASSERT_TRUE(ifs.is_open()) << "failed opening " << fname; - jfm = util::make_unique<JFM>(ifs); + jfm = util::make_unique<JFM>(); + jfm->read(ifs); } protected: @@ -51,8 +52,8 @@ class JFMReaderTest : public ::testing::Test { TEST_F(JFMReaderTest, properties) { EXPECT_EQ(jfm->getChecksum(), 0u); EXPECT_FALSE(jfm->verticalLayout()); - EXPECT_EQ(jfm->firstChar(), 0); - EXPECT_EQ(jfm->lastChar(), 1); + EXPECT_EQ(jfm->firstChar(), 0u); + EXPECT_EQ(jfm->lastChar(), 1u); EXPECT_EQ(jfm->minChar(), 13143u); EXPECT_EQ(jfm->maxChar(), 14696u); EXPECT_DOUBLE_EQ(jfm->getDesignSize(), 10.0*72.0/72.27); diff --git a/dviware/dvisvgm/tests/Makefile.am b/dviware/dvisvgm/tests/Makefile.am index 3ce3d363be..2667de0a52 100644 --- a/dviware/dvisvgm/tests/Makefile.am +++ b/dviware/dvisvgm/tests/Makefile.am @@ -246,6 +246,12 @@ MessageExceptionTest_SOURCES = MessageExceptionTest.cpp testutil.hpp MessageExceptionTest_CPPFLAGS = -I$(dvisvgm_srcdir)/tests/gtest/include $(LIBS_CFLAGS) MessageExceptionTest_LDADD = $(TESTLIBS) +TESTS += OFMReaderTest +check_PROGRAMS += OFMReaderTest +OFMReaderTest_SOURCES = OFMReaderTest.cpp testutil.hpp +OFMReaderTest_CPPFLAGS = -I$(dvisvgm_srcdir)/tests/gtest/include $(LIBS_CFLAGS) +OFMReaderTest_LDADD = $(TESTLIBS) + TESTS += PageRagesTest check_PROGRAMS += PageRagesTest PageRagesTest_SOURCES = PageRagesTest.cpp testutil.hpp diff --git a/dviware/dvisvgm/tests/Makefile.in b/dviware/dvisvgm/tests/Makefile.in index c0a3270987..2222a330a5 100644 --- a/dviware/dvisvgm/tests/Makefile.in +++ b/dviware/dvisvgm/tests/Makefile.in @@ -107,8 +107,8 @@ TESTS = hashcheck$(EXEEXT) BezierTest$(EXEEXT) BitmapTest$(EXEEXT) \ GraphicsPathParserTest$(EXEEXT) GraphicsPathTest$(EXEEXT) \ HashFunctionTest$(EXEEXT) JFMReaderTest$(EXEEXT) \ LengthTest$(EXEEXT) MapLineTest$(EXEEXT) MatrixTest$(EXEEXT) \ - MessageExceptionTest$(EXEEXT) PageRagesTest$(EXEEXT) \ - PageSizeTest$(EXEEXT) PairTest$(EXEEXT) \ + MessageExceptionTest$(EXEEXT) OFMReaderTest$(EXEEXT) \ + PageRagesTest$(EXEEXT) PageSizeTest$(EXEEXT) PairTest$(EXEEXT) \ PapersizeSpecialTest$(EXEEXT) PDFParserTest$(EXEEXT) \ PSInterpreterTest$(EXEEXT) RangeMapTest$(EXEEXT) \ ShadingPatchTest$(EXEEXT) SpecialManagerTest$(EXEEXT) \ @@ -138,8 +138,8 @@ check_PROGRAMS = hashcheck$(EXEEXT) BezierTest$(EXEEXT) \ GraphicsPathParserTest$(EXEEXT) GraphicsPathTest$(EXEEXT) \ HashFunctionTest$(EXEEXT) JFMReaderTest$(EXEEXT) \ LengthTest$(EXEEXT) MapLineTest$(EXEEXT) MatrixTest$(EXEEXT) \ - MessageExceptionTest$(EXEEXT) PageRagesTest$(EXEEXT) \ - PageSizeTest$(EXEEXT) PairTest$(EXEEXT) \ + MessageExceptionTest$(EXEEXT) OFMReaderTest$(EXEEXT) \ + PageRagesTest$(EXEEXT) PageSizeTest$(EXEEXT) PairTest$(EXEEXT) \ PapersizeSpecialTest$(EXEEXT) PDFParserTest$(EXEEXT) \ PSInterpreterTest$(EXEEXT) RangeMapTest$(EXEEXT) \ ShadingPatchTest$(EXEEXT) SpecialManagerTest$(EXEEXT) \ @@ -307,6 +307,9 @@ am_MessageExceptionTest_OBJECTS = \ MessageExceptionTest-MessageExceptionTest.$(OBJEXT) MessageExceptionTest_OBJECTS = $(am_MessageExceptionTest_OBJECTS) MessageExceptionTest_DEPENDENCIES = $(am__DEPENDENCIES_5) +am_OFMReaderTest_OBJECTS = OFMReaderTest-OFMReaderTest.$(OBJEXT) +OFMReaderTest_OBJECTS = $(am_OFMReaderTest_OBJECTS) +OFMReaderTest_DEPENDENCIES = $(am__DEPENDENCIES_5) am_PDFParserTest_OBJECTS = PDFParserTest-PDFParserTest.$(OBJEXT) PDFParserTest_OBJECTS = $(am_PDFParserTest_OBJECTS) PDFParserTest_DEPENDENCIES = $(am__DEPENDENCIES_5) @@ -454,6 +457,7 @@ am__depfiles_remade = ./$(DEPDIR)/BezierTest-BezierTest.Po \ ./$(DEPDIR)/MapLineTest-MapLineTest.Po \ ./$(DEPDIR)/MatrixTest-MatrixTest.Po \ ./$(DEPDIR)/MessageExceptionTest-MessageExceptionTest.Po \ + ./$(DEPDIR)/OFMReaderTest-OFMReaderTest.Po \ ./$(DEPDIR)/PDFParserTest-PDFParserTest.Po \ ./$(DEPDIR)/PSInterpreterTest-PSInterpreterTest.Po \ ./$(DEPDIR)/PageRagesTest-PageRagesTest.Po \ @@ -538,11 +542,12 @@ SOURCES = $(libgtest_la_SOURCES) $(BezierTest_SOURCES) \ $(HashFunctionTest_SOURCES) $(JFMReaderTest_SOURCES) \ $(LengthTest_SOURCES) $(MapLineTest_SOURCES) \ $(MatrixTest_SOURCES) $(MessageExceptionTest_SOURCES) \ - $(PDFParserTest_SOURCES) $(PSInterpreterTest_SOURCES) \ - $(PageRagesTest_SOURCES) $(PageSizeTest_SOURCES) \ - $(PairTest_SOURCES) $(PapersizeSpecialTest_SOURCES) \ - $(RangeMapTest_SOURCES) $(SVGOutputTest_SOURCES) \ - $(ShadingPatchTest_SOURCES) $(SpecialManagerTest_SOURCES) \ + $(OFMReaderTest_SOURCES) $(PDFParserTest_SOURCES) \ + $(PSInterpreterTest_SOURCES) $(PageRagesTest_SOURCES) \ + $(PageSizeTest_SOURCES) $(PairTest_SOURCES) \ + $(PapersizeSpecialTest_SOURCES) $(RangeMapTest_SOURCES) \ + $(SVGOutputTest_SOURCES) $(ShadingPatchTest_SOURCES) \ + $(SpecialManagerTest_SOURCES) \ $(SplittedCharInputBufferTest_SOURCES) \ $(StreamInputBufferTest_SOURCES) $(StreamReaderTest_SOURCES) \ $(StreamWriterTest_SOURCES) $(StringMatcherTest_SOURCES) \ @@ -570,11 +575,12 @@ DIST_SOURCES = $(libgtest_la_SOURCES) $(BezierTest_SOURCES) \ $(HashFunctionTest_SOURCES) $(JFMReaderTest_SOURCES) \ $(LengthTest_SOURCES) $(MapLineTest_SOURCES) \ $(MatrixTest_SOURCES) $(MessageExceptionTest_SOURCES) \ - $(PDFParserTest_SOURCES) $(PSInterpreterTest_SOURCES) \ - $(PageRagesTest_SOURCES) $(PageSizeTest_SOURCES) \ - $(PairTest_SOURCES) $(PapersizeSpecialTest_SOURCES) \ - $(RangeMapTest_SOURCES) $(SVGOutputTest_SOURCES) \ - $(ShadingPatchTest_SOURCES) $(SpecialManagerTest_SOURCES) \ + $(OFMReaderTest_SOURCES) $(PDFParserTest_SOURCES) \ + $(PSInterpreterTest_SOURCES) $(PageRagesTest_SOURCES) \ + $(PageSizeTest_SOURCES) $(PairTest_SOURCES) \ + $(PapersizeSpecialTest_SOURCES) $(RangeMapTest_SOURCES) \ + $(SVGOutputTest_SOURCES) $(ShadingPatchTest_SOURCES) \ + $(SpecialManagerTest_SOURCES) \ $(SplittedCharInputBufferTest_SOURCES) \ $(StreamInputBufferTest_SOURCES) $(StreamReaderTest_SOURCES) \ $(StreamWriterTest_SOURCES) $(StringMatcherTest_SOURCES) \ @@ -1141,6 +1147,9 @@ MatrixTest_LDADD = $(TESTLIBS) MessageExceptionTest_SOURCES = MessageExceptionTest.cpp testutil.hpp MessageExceptionTest_CPPFLAGS = -I$(dvisvgm_srcdir)/tests/gtest/include $(LIBS_CFLAGS) MessageExceptionTest_LDADD = $(TESTLIBS) +OFMReaderTest_SOURCES = OFMReaderTest.cpp testutil.hpp +OFMReaderTest_CPPFLAGS = -I$(dvisvgm_srcdir)/tests/gtest/include $(LIBS_CFLAGS) +OFMReaderTest_LDADD = $(TESTLIBS) PageRagesTest_SOURCES = PageRagesTest.cpp testutil.hpp PageRagesTest_CPPFLAGS = -I$(dvisvgm_srcdir)/tests/gtest/include $(LIBS_CFLAGS) PageRagesTest_LDADD = $(TESTLIBS) @@ -1421,6 +1430,10 @@ MessageExceptionTest$(EXEEXT): $(MessageExceptionTest_OBJECTS) $(MessageExceptio @rm -f MessageExceptionTest$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(MessageExceptionTest_OBJECTS) $(MessageExceptionTest_LDADD) $(LIBS) +OFMReaderTest$(EXEEXT): $(OFMReaderTest_OBJECTS) $(OFMReaderTest_DEPENDENCIES) $(EXTRA_OFMReaderTest_DEPENDENCIES) + @rm -f OFMReaderTest$(EXEEXT) + $(AM_V_CXXLD)$(CXXLINK) $(OFMReaderTest_OBJECTS) $(OFMReaderTest_LDADD) $(LIBS) + PDFParserTest$(EXEEXT): $(PDFParserTest_OBJECTS) $(PDFParserTest_DEPENDENCIES) $(EXTRA_PDFParserTest_DEPENDENCIES) @rm -f PDFParserTest$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(PDFParserTest_OBJECTS) $(PDFParserTest_LDADD) $(LIBS) @@ -1574,6 +1587,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MapLineTest-MapLineTest.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MatrixTest-MatrixTest.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MessageExceptionTest-MessageExceptionTest.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/OFMReaderTest-OFMReaderTest.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PDFParserTest-PDFParserTest.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PSInterpreterTest-PSInterpreterTest.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PageRagesTest-PageRagesTest.Po@am__quote@ # am--include-marker @@ -2111,6 +2125,20 @@ MessageExceptionTest-MessageExceptionTest.obj: MessageExceptionTest.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(MessageExceptionTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o MessageExceptionTest-MessageExceptionTest.obj `if test -f 'MessageExceptionTest.cpp'; then $(CYGPATH_W) 'MessageExceptionTest.cpp'; else $(CYGPATH_W) '$(srcdir)/MessageExceptionTest.cpp'; fi` +OFMReaderTest-OFMReaderTest.o: OFMReaderTest.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OFMReaderTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT OFMReaderTest-OFMReaderTest.o -MD -MP -MF $(DEPDIR)/OFMReaderTest-OFMReaderTest.Tpo -c -o OFMReaderTest-OFMReaderTest.o `test -f 'OFMReaderTest.cpp' || echo '$(srcdir)/'`OFMReaderTest.cpp +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/OFMReaderTest-OFMReaderTest.Tpo $(DEPDIR)/OFMReaderTest-OFMReaderTest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='OFMReaderTest.cpp' object='OFMReaderTest-OFMReaderTest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OFMReaderTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o OFMReaderTest-OFMReaderTest.o `test -f 'OFMReaderTest.cpp' || echo '$(srcdir)/'`OFMReaderTest.cpp + +OFMReaderTest-OFMReaderTest.obj: OFMReaderTest.cpp +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OFMReaderTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT OFMReaderTest-OFMReaderTest.obj -MD -MP -MF $(DEPDIR)/OFMReaderTest-OFMReaderTest.Tpo -c -o OFMReaderTest-OFMReaderTest.obj `if test -f 'OFMReaderTest.cpp'; then $(CYGPATH_W) 'OFMReaderTest.cpp'; else $(CYGPATH_W) '$(srcdir)/OFMReaderTest.cpp'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/OFMReaderTest-OFMReaderTest.Tpo $(DEPDIR)/OFMReaderTest-OFMReaderTest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='OFMReaderTest.cpp' object='OFMReaderTest-OFMReaderTest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OFMReaderTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o OFMReaderTest-OFMReaderTest.obj `if test -f 'OFMReaderTest.cpp'; then $(CYGPATH_W) 'OFMReaderTest.cpp'; else $(CYGPATH_W) '$(srcdir)/OFMReaderTest.cpp'; fi` + PDFParserTest-PDFParserTest.o: PDFParserTest.cpp @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(PDFParserTest_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT PDFParserTest-PDFParserTest.o -MD -MP -MF $(DEPDIR)/PDFParserTest-PDFParserTest.Tpo -c -o PDFParserTest-PDFParserTest.o `test -f 'PDFParserTest.cpp' || echo '$(srcdir)/'`PDFParserTest.cpp @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/PDFParserTest-PDFParserTest.Tpo $(DEPDIR)/PDFParserTest-PDFParserTest.Po @@ -3012,6 +3040,13 @@ MessageExceptionTest.log: MessageExceptionTest$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +OFMReaderTest.log: OFMReaderTest$(EXEEXT) + @p='OFMReaderTest$(EXEEXT)'; \ + b='OFMReaderTest'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) PageRagesTest.log: PageRagesTest$(EXEEXT) @p='PageRagesTest$(EXEEXT)'; \ b='PageRagesTest'; \ @@ -3362,6 +3397,7 @@ distclean: distclean-recursive -rm -f ./$(DEPDIR)/MapLineTest-MapLineTest.Po -rm -f ./$(DEPDIR)/MatrixTest-MatrixTest.Po -rm -f ./$(DEPDIR)/MessageExceptionTest-MessageExceptionTest.Po + -rm -f ./$(DEPDIR)/OFMReaderTest-OFMReaderTest.Po -rm -f ./$(DEPDIR)/PDFParserTest-PDFParserTest.Po -rm -f ./$(DEPDIR)/PSInterpreterTest-PSInterpreterTest.Po -rm -f ./$(DEPDIR)/PageRagesTest-PageRagesTest.Po @@ -3470,6 +3506,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f ./$(DEPDIR)/MapLineTest-MapLineTest.Po -rm -f ./$(DEPDIR)/MatrixTest-MatrixTest.Po -rm -f ./$(DEPDIR)/MessageExceptionTest-MessageExceptionTest.Po + -rm -f ./$(DEPDIR)/OFMReaderTest-OFMReaderTest.Po -rm -f ./$(DEPDIR)/PDFParserTest-PDFParserTest.Po -rm -f ./$(DEPDIR)/PSInterpreterTest-PSInterpreterTest.Po -rm -f ./$(DEPDIR)/PageRagesTest-PageRagesTest.Po diff --git a/dviware/dvisvgm/tests/OFMReaderTest.cpp b/dviware/dvisvgm/tests/OFMReaderTest.cpp new file mode 100644 index 0000000000..efc6f05464 --- /dev/null +++ b/dviware/dvisvgm/tests/OFMReaderTest.cpp @@ -0,0 +1,128 @@ +/************************************************************************* +** OFMReaderTest.cpp ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** Copyright (C) 2005-2023 Martin Gieseking <martin.gieseking@uos.de> ** +** ** +** This program is free software; you can redistribute it and/or ** +** modify it under the terms of the GNU General Public License as ** +** published by the Free Software Foundation; either version 3 of ** +** the License, or (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, but ** +** WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program; if not, see <http://www.gnu.org/licenses/>. ** +*************************************************************************/ + +#include <gtest/gtest.h> +#include <fstream> +#include <string> +#include <vector> +#include "Length.hpp" +#include "OFM.hpp" + +#ifndef SRCDIR +#define SRCDIR "." +#endif + +using namespace std; + + +class OFMReaderTest : public ::testing::Test { + public: + void SetUp () override { + string fname = string(SRCDIR)+"/data/omarab.ofm"; + ifstream ifs(fname, ios::binary); + ASSERT_TRUE(ifs.is_open()) << "failed to open " << fname; + ofm0.read(ifs); + scale0 = ofm0.getDesignSize(); + ifs.close(); + + fname = string(SRCDIR)+"/data/upjf-g.ofm"; + ifs.open(fname, ios::binary); + ASSERT_TRUE(ifs.is_open()) << "failed to open " << fname; + ofm1.read(ifs); + scale1 = ofm1.getDesignSize(); + } + + protected: + OFM0 ofm0; + OFM1 ofm1; + double scale0=0, scale1=0; +}; + + +TEST_F(OFMReaderTest, properties) { + EXPECT_EQ(ofm0.getChecksum(), 0x9DCC4880u); + EXPECT_FALSE(ofm0.verticalLayout()); + EXPECT_EQ(ofm0.firstChar(), 0x21u); + EXPECT_EQ(ofm0.lastChar(), 0x059Fu); + EXPECT_NEAR(ofm0.getDesignSize(), 10.0*Length::pt2bp, 0.000001); + + EXPECT_EQ(ofm1.getChecksum(), 0u); + EXPECT_FALSE(ofm1.verticalLayout()); + EXPECT_EQ(ofm1.firstChar(), 0x2600u); + EXPECT_EQ(ofm1.lastChar(), 0xFFFFu); + EXPECT_NEAR(ofm1.getDesignSize(), 10.0*Length::pt2bp, 0.000001); +} + + +TEST_F(OFMReaderTest, charWidth) { + EXPECT_NEAR(ofm0.getCharWidth(0x029D), 0.853*scale0, 0.0001); + EXPECT_NEAR(ofm0.getCharWidth(0x02A0), 0.444*scale0, 0.0001); + EXPECT_NEAR(ofm0.getCharWidth(0x1000), 0, 0.0001); + + EXPECT_NEAR(ofm1.getCharWidth(0x2600), 1.0*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharWidth(0xFF00), 0.5*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharWidth(0xFF01), 0.5*scale1, 0.0001); +} + + +TEST_F(OFMReaderTest, charHeight) { + EXPECT_NEAR(ofm0.getCharHeight(0x029D), 0.298*scale0, 0.0001); + EXPECT_NEAR(ofm0.getCharHeight(0x02A0), 0.685*scale0, 0.0001); + EXPECT_DOUBLE_EQ(ofm0.getCharHeight(0x1000), 0); + + EXPECT_NEAR(ofm1.getCharHeight(0x2600), 0.9*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharHeight(0xFF00), 0.9*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharHeight(0xFF01), 0.9*scale1, 0.0001); +} + + +TEST_F(OFMReaderTest, charDepth) { + EXPECT_NEAR(ofm0.getCharDepth(0x029D), 0.3*scale0, 0.0001); + EXPECT_NEAR(ofm0.getCharDepth(0x02A0), 0, 0.0001); + EXPECT_NEAR(ofm0.getCharDepth(0x1000), 0, 0.0001); + + EXPECT_NEAR(ofm1.getCharDepth(0x2600), 0.1*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharDepth(0xFF00), 0.1*scale1, 0.0001); + EXPECT_NEAR(ofm1.getCharDepth(0xFF01), 0.1*scale1, 0.0001); +} + + +TEST_F(OFMReaderTest, italicCorr) { + EXPECT_DOUBLE_EQ(ofm0.getItalicCorr(0x029D), 0); + EXPECT_DOUBLE_EQ(ofm0.getItalicCorr(0x02A0), 0); + EXPECT_DOUBLE_EQ(ofm0.getItalicCorr(0x1000), 0); + + EXPECT_DOUBLE_EQ(ofm1.getItalicCorr(0x2600), 0); + EXPECT_DOUBLE_EQ(ofm1.getItalicCorr(0xFF00), 0); + EXPECT_DOUBLE_EQ(ofm1.getItalicCorr(0xFF01), 0); +} + + +TEST_F(OFMReaderTest, params) { + EXPECT_NEAR(ofm0.getSpace(), 0.5*scale0, 0.0001); + EXPECT_NEAR(ofm0.getSpaceShrink(), 0.1*scale0, 0.0001); + EXPECT_NEAR(ofm0.getSpaceStretch(), 0.3*scale0, 0.0001); + EXPECT_NEAR(ofm0.getQuad(), 1.0*scale0, 0.0001); + + EXPECT_NEAR(ofm1.getSpace(), 0, 0.0001); + EXPECT_NEAR(ofm1.getSpaceShrink(), 0, 0.0001); + EXPECT_NEAR(ofm1.getSpaceStretch(), 0.1*scale1, 0.0001); + EXPECT_NEAR(ofm1.getQuad(), 1.0*scale1, 0.0001); +} diff --git a/dviware/dvisvgm/tests/TFMReaderTest.cpp b/dviware/dvisvgm/tests/TFMReaderTest.cpp index 40d40e2967..6e2b660fa6 100644 --- a/dviware/dvisvgm/tests/TFMReaderTest.cpp +++ b/dviware/dvisvgm/tests/TFMReaderTest.cpp @@ -40,7 +40,8 @@ class TFMReaderTest : public ::testing::Test { string fname = string(SRCDIR)+"/data/cmr10.tfm"; ifstream ifs(fname, ios::binary); ASSERT_TRUE(ifs.is_open()) << "failed opening " << fname; - tfm = util::make_unique<TFM>(ifs); + tfm = util::make_unique<TFM>(); + tfm->read(ifs); } protected: @@ -52,8 +53,8 @@ TEST_F(TFMReaderTest, properties) { ASSERT_NE(tfm, nullptr); EXPECT_EQ(tfm->getChecksum(), 0x4BF16079u); EXPECT_FALSE(tfm->verticalLayout()); - EXPECT_EQ(tfm->firstChar(), 0); - EXPECT_EQ(tfm->lastChar(), 127); + EXPECT_EQ(tfm->firstChar(), 0u); + EXPECT_EQ(tfm->lastChar(), 127u); EXPECT_DOUBLE_EQ(tfm->getDesignSize(), 10.0*72.0/72.27); } diff --git a/dviware/dvisvgm/tests/UtilityTest.cpp b/dviware/dvisvgm/tests/UtilityTest.cpp index 4c920e417c..f5fda4a35b 100644 --- a/dviware/dvisvgm/tests/UtilityTest.cpp +++ b/dviware/dvisvgm/tests/UtilityTest.cpp @@ -188,3 +188,38 @@ TEST(UtilityTest, ilog2) { EXPECT_EQ(ilog2(uint32_t(0xffffffff >> i)), 31-i); } } + + +TEST(UtilityTest, read_double) { + istringstream iss("123 -456 .123 -.456 0.123 -0.456 +123.456 -123.456 10e-3 -1e-3 4.5e2 1.23e-3 2.30.4"); + double value=0; + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 123.0, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, -456.0, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, .123, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, -.456, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, .123, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, -.456, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 123.456, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, -123.456, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 10e-3, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, -1e-3, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 4.5e2, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 1.23e-3, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, 2.3, 0.000001); + EXPECT_TRUE(util::read_double(iss, value)); + EXPECT_NEAR(value, .4, 0.000001); + EXPECT_FALSE(util::read_double(iss, value)); // eof, no further characters to read +}
\ No newline at end of file diff --git a/dviware/dvisvgm/tests/data/Makefile.am b/dviware/dvisvgm/tests/data/Makefile.am index 52caa64fef..237979cc24 100644 --- a/dviware/dvisvgm/tests/data/Makefile.am +++ b/dviware/dvisvgm/tests/data/Makefile.am @@ -14,11 +14,13 @@ EXTRA_DIST = \ frktest-nf-cmp.svg \ frktest-wf-cmp.svg \ lmmono12-regular.otf \ + omarab.ofm \ + ot1.cmap \ sample.dvi \ sample-nf-cmp.svg \ sample.sfd \ sample-wf-cmp.svg \ sample_v2.dvi \ sample_v3.dvi \ - ot1.cmap + upjf-g.ofm diff --git a/dviware/dvisvgm/tests/data/Makefile.in b/dviware/dvisvgm/tests/data/Makefile.in index 6027ed575c..95e477202f 100644 --- a/dviware/dvisvgm/tests/data/Makefile.in +++ b/dviware/dvisvgm/tests/data/Makefile.in @@ -299,13 +299,15 @@ EXTRA_DIST = \ frktest-nf-cmp.svg \ frktest-wf-cmp.svg \ lmmono12-regular.otf \ + omarab.ofm \ + ot1.cmap \ sample.dvi \ sample-nf-cmp.svg \ sample.sfd \ sample-wf-cmp.svg \ sample_v2.dvi \ sample_v3.dvi \ - ot1.cmap + upjf-g.ofm all: all-am diff --git a/dviware/dvisvgm/tests/data/omarab.ofm b/dviware/dvisvgm/tests/data/omarab.ofm Binary files differnew file mode 100644 index 0000000000..a231c1d6e0 --- /dev/null +++ b/dviware/dvisvgm/tests/data/omarab.ofm diff --git a/dviware/dvisvgm/tests/data/upjf-g.ofm b/dviware/dvisvgm/tests/data/upjf-g.ofm Binary files differnew file mode 100644 index 0000000000..507aa833b4 --- /dev/null +++ b/dviware/dvisvgm/tests/data/upjf-g.ofm |