From bdec1c2cc5876bab2278bfc16858844bb70901af Mon Sep 17 00:00:00 2001 From: Jasper van de Gronde Date: Wed, 6 Aug 2008 14:31:46 +0000 Subject: 2Geom version of the path tests + some additional small changes. (bzr r6578) --- src/svg/Makefile_insert | 3 +- src/svg/svg-length-test.h | 2 +- src/svg/svg-path-geom-test.h | 563 +++++++++++++++++++++++++++++++++++++++++++ src/svg/svg-path-nr-test.h | 493 +++++++++++++++++++++++++++++++++++++ src/svg/svg-path-test.h | 493 ------------------------------------- 5 files changed, 1059 insertions(+), 495 deletions(-) create mode 100644 src/svg/svg-path-geom-test.h create mode 100644 src/svg/svg-path-nr-test.h delete mode 100644 src/svg/svg-path-test.h (limited to 'src') diff --git a/src/svg/Makefile_insert b/src/svg/Makefile_insert index e8f31b3c8..f7d2fcc5e 100644 --- a/src/svg/Makefile_insert +++ b/src/svg/Makefile_insert @@ -50,7 +50,8 @@ svg_test_svg_includes = \ $(srcdir)/svg/svg-affine-test.h \ $(srcdir)/svg/svg-color-test.h \ $(srcdir)/svg/svg-length-test.h \ - $(srcdir)/svg/svg-path-test.h + $(srcdir)/svg/svg-path-geom-test.h \ + $(srcdir)/svg/svg-path-nr-test.h svg_libtest_svg_a_SOURCES = \ svg/test-svg.cpp \ diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h index 0f1ca5c95..ce709b51d 100644 --- a/src/svg/svg-length-test.h +++ b/src/svg/svg-length-test.h @@ -131,7 +131,7 @@ public: validStrings.erase(iter); } } - TSM_ASSERT_EQUALS(validStrings, validStrings.size(), 0); + TSM_ASSERT_EQUALS(validStrings, validStrings.size(), 0u); } // TODO: More tests diff --git a/src/svg/svg-path-geom-test.h b/src/svg/svg-path-geom-test.h new file mode 100644 index 000000000..1bcc5fb17 --- /dev/null +++ b/src/svg/svg-path-geom-test.h @@ -0,0 +1,563 @@ +#include +#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-nr-test.h b/src/svg/svg-path-nr-test.h new file mode 100644 index 000000000..df9c46051 --- /dev/null +++ b/src/svg/svg-path-nr-test.h @@ -0,0 +1,493 @@ +#include +#include "libnr/n-art-bpath.h" +#include "svg/svg.h" +#include "2geom/coord.h" +#include "prefs-utils.h" +#include "streq.h" +#include +#include +#include + +class SvgPathNRTest : public CxxTest::TestSuite +{ +private: + std::vector rectanglesAbsoluteClosed; + std::vector rectanglesRelativeClosed; + std::vector rectanglesAbsoluteOpen; + std::vector rectanglesRelativeOpen; + NArtBpath rectangleBpath[5+1]; +public: + 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"); + 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"); + rectangleBpath[0].code = NR_MOVETO; + rectangleBpath[0].x3 = 1; + rectangleBpath[0].y3 = 2; + rectangleBpath[1].code = NR_LINETO; + rectangleBpath[1].x3 = 4; + rectangleBpath[1].y3 = 2; + rectangleBpath[2].code = NR_LINETO; + rectangleBpath[2].x3 = 4; + rectangleBpath[2].y3 = 8; + rectangleBpath[3].code = NR_LINETO; + rectangleBpath[3].x3 = 1; + rectangleBpath[3].y3 = 8; + rectangleBpath[4].code = NR_LINETO; + rectangleBpath[4].x3 = 1; + rectangleBpath[4].y3 = 2; + rectangleBpath[5].code = NR_END; + // 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 SvgPathNRTest *createSuite() { return new SvgPathNRTest(); } + static void destroySuite( SvgPathNRTest *suite ) { delete suite; } + + void testReadRectanglesAbsoluteClosed() + { + rectangleBpath[0].code = NR_MOVETO; + for(size_t i=0; icode != NR_END && b->code == a->code) { + switch(a->code) { + case NR_MOVETO: + case NR_MOVETO_OPEN: + case NR_LINETO: + if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; + break; + case NR_CURVETO: + if (!Geom::are_near(a->x1,b->x1, eps) || !Geom::are_near(a->y1,b->y1, eps)) return false; + if (!Geom::are_near(a->x2,b->x2, eps) || !Geom::are_near(a->y2,b->y2, eps)) return false; + if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; + break; + default: + TS_FAIL("Unknown path code!"); + } + a++; + b++; + } + return a->code == b->code; + } +}; + + +/* + 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-test.h deleted file mode 100644 index 28173cbd1..000000000 --- a/src/svg/svg-path-test.h +++ /dev/null @@ -1,493 +0,0 @@ -#include -#include "libnr/n-art-bpath.h" -#include "svg/svg.h" -#include "2geom/coord.h" -#include "prefs-utils.h" -#include "streq.h" -#include -#include -#include - -class SvgPathTest : public CxxTest::TestSuite -{ -private: - std::vector rectanglesAbsoluteClosed; - std::vector rectanglesRelativeClosed; - std::vector rectanglesAbsoluteOpen; - std::vector rectanglesRelativeOpen; - NArtBpath rectangleBpath[5+1]; -public: - SvgPathTest() { - // 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"); - rectangleBpath[0].code = NR_MOVETO; - rectangleBpath[0].x3 = 1; - rectangleBpath[0].y3 = 2; - rectangleBpath[1].code = NR_LINETO; - rectangleBpath[1].x3 = 4; - rectangleBpath[1].y3 = 2; - rectangleBpath[2].code = NR_LINETO; - rectangleBpath[2].x3 = 4; - rectangleBpath[2].y3 = 8; - rectangleBpath[3].code = NR_LINETO; - rectangleBpath[3].x3 = 1; - rectangleBpath[3].y3 = 8; - rectangleBpath[4].code = NR_LINETO; - rectangleBpath[4].x3 = 1; - rectangleBpath[4].y3 = 2; - rectangleBpath[5].code = NR_END; - // 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 SvgPathTest *createSuite() { return new SvgPathTest(); } - static void destroySuite( SvgPathTest *suite ) { delete suite; } - - void testReadRectanglesAbsoluteClosed() - { - rectangleBpath[0].code = NR_MOVETO; - for(size_t i=0; icode != NR_END && b->code == a->code) { - switch(a->code) { - case NR_MOVETO: - case NR_MOVETO_OPEN: - case NR_LINETO: - if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; - break; - case NR_CURVETO: - if (!Geom::are_near(a->x1,b->x1, eps) || !Geom::are_near(a->y1,b->y1, eps)) return false; - if (!Geom::are_near(a->x2,b->x2, eps) || !Geom::are_near(a->y2,b->y2, eps)) return false; - if (!Geom::are_near(a->x3,b->x3, eps) || !Geom::are_near(a->y3,b->y3, eps)) return false; - break; - default: - TS_FAIL("Unknown path code!"); - } - a++; - b++; - } - return a->code == b->code; - } -}; - - -/* - 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 : -- cgit v1.2.3