From 57c6a4c544c254a6003ced3122e5a6de8428f258 Mon Sep 17 00:00:00 2001 From: joncruz Date: Fri, 1 Aug 2008 07:52:55 +0000 Subject: [PATCH] Added to tests for SVG units, and fixed warning of missing case --- src/svg/svg-length-test.h | 44 +++++++++++++++++++++++++++++++++++++++ src/svg/svg-length.cpp | 1 + src/svg/svg-length.h | 35 ++++++++++++++++--------------- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h index 829612b26..0f1ca5c95 100644 --- a/src/svg/svg-length-test.h +++ b/src/svg/svg-length-test.h @@ -4,6 +4,9 @@ #include #include +// function internal to svg-length.cpp: +gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit); + class SvgLengthTest : public CxxTest::TestSuite { private: @@ -90,6 +93,47 @@ public: } } + void testEnumMappedToString() + { + for ( int i = (static_cast(SVGLength::NONE) + 1); i <= static_cast(SVGLength::LAST_UNIT); i++ ) { + SVGLength::Unit target = static_cast(i); + // PX is a special case where we don't have a unit string + if ( (target != SVGLength::PX) && (target != SVGLength::FOOT) ) { + gchar const* val = sp_svg_length_get_css_units(target); + TSM_ASSERT_DIFFERS(i, val, ""); + } + } + } + + // Ensure that all unit suffix strings used are allowed by SVG + void testStringsAreValidSVG() + { + gchar const* valid[] = {"", "em", "ex", "px", "pt", "pc", "cm", "mm", "in", "%"}; + std::set validStrings(valid, valid + G_N_ELEMENTS(valid)); + for ( int i = (static_cast(SVGLength::NONE) + 1); i <= static_cast(SVGLength::LAST_UNIT); i++ ) { + SVGLength::Unit target = static_cast(i); + gchar const* val = sp_svg_length_get_css_units(target); + TSM_ASSERT(i, validStrings.find(std::string(val)) != validStrings.end()); + } + } + + // Ensure that all unit suffix strings allowed by SVG are covered by enum + void testValidSVGStringsSupported() + { + // Note that "px" is ommitted from the list, as it will be assumed to be so if not explicitly set. + gchar const* valid[] = {"em", "ex", "pt", "pc", "cm", "mm", "in", "%"}; + std::set validStrings(valid, valid + G_N_ELEMENTS(valid)); + for ( int i = (static_cast(SVGLength::NONE) + 1); i <= static_cast(SVGLength::LAST_UNIT); i++ ) { + SVGLength::Unit target = static_cast(i); + gchar const* val = sp_svg_length_get_css_units(target); + std::set::iterator iter = validStrings.find(std::string(val)); + if (iter != validStrings.end()) { + validStrings.erase(iter); + } + } + TSM_ASSERT_EQUALS(validStrings, validStrings.size(), 0); + } + // TODO: More tests }; diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index 8c2a8caf3..505ca4ad9 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -508,6 +508,7 @@ gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit) case SVGLength::MM: return "mm"; case SVGLength::CM: return "cm"; case SVGLength::INCH: return "in"; + case SVGLength::FOOT: return ""; // Does not have a "foot" unit string in the SVG spec case SVGLength::EM: return "em"; case SVGLength::EX: return "ex"; case SVGLength::PERCENT: return "%"; diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h index 9623d20f3..1f4be8123 100644 --- a/src/svg/svg-length.h +++ b/src/svg/svg-length.h @@ -1,5 +1,5 @@ -#ifndef __SP_SVG_LENGTH_H__ -#define __SP_SVG_LENGTH_H__ +#ifndef SEEN_SP_SVG_LENGTH_H +#define SEEN_SP_SVG_LENGTH_H /** * \file src/svg/svg-length.h @@ -21,19 +21,20 @@ class SVGLength { public: - + enum Unit { NONE, - PX, - PT, - PC, - MM, - CM, - INCH, - FOOT, - EM, - EX, - PERCENT + PX, + PT, + PC, + MM, + CM, + INCH, + FOOT, + EM, + EX, + PERCENT, + LAST_UNIT = PERCENT }; bool _set; @@ -43,9 +44,9 @@ public: float operator=(float v) { _set = true; - unit = NONE; - value = computed = v; - return v; + unit = NONE; + value = computed = v; + return v; } bool read(gchar const *str); @@ -56,7 +57,7 @@ public: void update(double em, double ex, double scale); }; -#endif +#endif // SEEN_SP_SVG_LENGTH_H /* Local Variables: -- 2.30.2