From 741dec82d06d12a1c8cbe2baf7a9b9437b5ddec5 Mon Sep 17 00:00:00 2001 From: jaspervdg Date: Wed, 6 Aug 2008 14:31:46 +0000 Subject: [PATCH] 2Geom version of the path tests + some additional small changes. --- build.xml | 5 +- src/svg/Makefile_insert | 3 +- src/svg/svg-length-test.h | 2 +- src/svg/svg-path-geom-test.h | 563 ++++++++++++++++++ .../{svg-path-test.h => svg-path-nr-test.h} | 8 +- 5 files changed, 573 insertions(+), 8 deletions(-) create mode 100644 src/svg/svg-path-geom-test.h rename src/svg/{svg-path-test.h => svg-path-nr-test.h} (98%) diff --git a/build.xml b/build.xml index c8a65cab3..4a8bb0933 100644 --- a/build.xml +++ b/build.xml @@ -52,7 +52,7 @@ - + @@ -250,7 +250,8 @@ - + + +#include "2geom/coord.h" +#include "2geom/curves.h" +#include "2geom/pathvector.h" +#include "svg/svg.h" +#include "prefs-utils.h" +#include "streq.h" +#include +#include +#include +#include + +class SvgPathGeomTest : public CxxTest::TestSuite +{ +private: + std::vector rectanglesAbsoluteClosed; + std::vector rectanglesRelativeClosed; + std::vector rectanglesAbsoluteOpen; + std::vector rectanglesRelativeOpen; + Geom::PathVector rectanglepv; +public: + SvgPathGeomTest() { + // Lots of ways to define the same rectangle + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2 Z"); + rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 4,2 4,8 1,8 z"); + rectanglesAbsoluteClosed.push_back("M 1,2 H 4 V 8 H 1 z"); + rectanglesRelativeClosed.push_back("m 1,2 l 3,0 l 0,6 l -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 3,0 0,6 -3,0 z"); + rectanglesRelativeClosed.push_back("m 1,2 h 3 v 6 h -3 z"); + rectanglesAbsoluteOpen.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 4,2 4,8 1,8 1,2"); + rectanglesAbsoluteOpen.push_back("M 1,2 H 4 V 8 H 1 V 2"); + rectanglesRelativeOpen.push_back("m 1,2 l 3,0 l 0,6 l -3,0 l 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 3,0 0,6 -3,0 0,-6"); + rectanglesRelativeOpen.push_back("m 1,2 h 3 v 6 h -3 v -6"); + rectanglepv.push_back(Geom::Path(Geom::Point(1,2))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(1,2),Geom::Point(4,2))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(4,2),Geom::Point(4,8))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(4,8),Geom::Point(1,8))); + rectanglepv.back().append(Geom::LineSegment(Geom::Point(1,8),Geom::Point(1,2))); + // TODO: Also test some (smooth) cubic/quadratic beziers and elliptical arcs + } + +// createSuite and destroySuite get us per-suite setup and teardown +// without us having to worry about static initialization order, etc. + static SvgPathGeomTest *createSuite() { return new SvgPathGeomTest(); } + static void destroySuite( SvgPathGeomTest *suite ) { delete suite; } + + void testReadRectanglesAbsoluteClosed() + { + rectanglepv.back().close(); + for(size_t i=0; i(ca)) + { + Geom::LineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la)[0],(*lb)[0], eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la)[0][Geom::X], (*la)[0][Geom::Y], (*lb)[0][Geom::X], (*lb)[0][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[1],(*lb)[1], eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la)[1][Geom::X], (*la)[1][Geom::Y], (*lb)[1][Geom::X], (*lb)[1][Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::HLineSegment const *la = dynamic_cast(ca)) + { + Geom::HLineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::VLineSegment const *la = dynamic_cast(ca)) + { + Geom::VLineSegment const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else if(Geom::CubicBezier const *la = dynamic_cast(ca)) + { + Geom::CubicBezier const *lb = dynamic_cast(cb); + if (!Geom::are_near((*la)[0],(*lb)[0], eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la)[0][Geom::X], (*la)[0][Geom::Y], (*lb)[0][Geom::X], (*lb)[0][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[1],(*lb)[1], eps)) { + char temp[200]; + sprintf(temp, "Different 1st control point: (%g,%g) != (%g,%g)", (*la)[1][Geom::X], (*la)[1][Geom::Y], (*lb)[1][Geom::X], (*lb)[1][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[2],(*lb)[2], eps)) { + char temp[200]; + sprintf(temp, "Different 2nd control point: (%g,%g) != (%g,%g)", (*la)[2][Geom::X], (*la)[2][Geom::Y], (*lb)[2][Geom::X], (*lb)[2][Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la)[3],(*lb)[3], eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la)[3][Geom::X], (*la)[3][Geom::Y], (*lb)[3][Geom::X], (*lb)[3][Geom::Y]); + TS_FAIL(temp); + return false; + } + } + else + { + TS_FAIL((std::string("Unknown curve type: ") + typeid(*ca).name()).c_str()); + return false; + } + } + else // not same type + { + if(Geom::LineSegment const *la = dynamic_cast(ca)) + { + if (Geom::HLineSegment const *lb = dynamic_cast(cb)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else if (Geom::VLineSegment const *lb = dynamic_cast(cb)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else { + TS_FAIL((std::string("Different curve types: ") + typeid(*ca).name() + " != " + typeid(*cb).name()).c_str()); + return false; + } + } + else if(Geom::LineSegment const *lb = dynamic_cast(cb)) + { + if (Geom::HLineSegment const *la = dynamic_cast(ca)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else if (Geom::VLineSegment const *la = dynamic_cast(ca)) { + if (!Geom::are_near((*la).initialPoint(),(*lb).initialPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different start of segment: (%g,%g) != (%g,%g)", (*la).initialPoint()[Geom::X], (*la).initialPoint()[Geom::Y], (*lb).initialPoint()[Geom::X], (*lb).initialPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + if (!Geom::are_near((*la).finalPoint(),(*lb).finalPoint(), eps)) { + char temp[200]; + sprintf(temp, "Different end of segment: (%g,%g) != (%g,%g)", (*la).finalPoint()[Geom::X], (*la).finalPoint()[Geom::Y], (*lb).finalPoint()[Geom::X], (*lb).finalPoint()[Geom::Y]); + TS_FAIL(temp); + return false; + } + } else { + TS_FAIL((std::string("Different curve types: ") + typeid(*ca).name() + " != " + typeid(*cb).name()).c_str()); + return false; + } + } + } + } + } + return true; + } +}; + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/svg/svg-path-test.h b/src/svg/svg-path-nr-test.h similarity index 98% rename from src/svg/svg-path-test.h rename to src/svg/svg-path-nr-test.h index 28173cbd1..df9c46051 100644 --- a/src/svg/svg-path-test.h +++ b/src/svg/svg-path-nr-test.h @@ -8,7 +8,7 @@ #include #include -class SvgPathTest : public CxxTest::TestSuite +class SvgPathNRTest : public CxxTest::TestSuite { private: std::vector rectanglesAbsoluteClosed; @@ -17,7 +17,7 @@ private: std::vector rectanglesRelativeOpen; NArtBpath rectangleBpath[5+1]; public: - SvgPathTest() { + SvgPathNRTest() { // Lots of ways to define the same rectangle rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 L 1,2 Z"); rectanglesAbsoluteClosed.push_back("M 1,2 L 4,2 L 4,8 L 1,8 z"); @@ -53,8 +53,8 @@ public: // createSuite and destroySuite get us per-suite setup and teardown // without us having to worry about static initialization order, etc. - static SvgPathTest *createSuite() { return new SvgPathTest(); } - static void destroySuite( SvgPathTest *suite ) { delete suite; } + static SvgPathNRTest *createSuite() { return new SvgPathNRTest(); } + static void destroySuite( SvgPathNRTest *suite ) { delete suite; } void testReadRectanglesAbsoluteClosed() { -- 2.30.2