summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 94ba79f)
raw | patch | inline | side by side (parent: 94ba79f)
author | joncruz <joncruz@users.sourceforge.net> | |
Fri, 1 Aug 2008 07:52:55 +0000 (07:52 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Fri, 1 Aug 2008 07:52:55 +0000 (07:52 +0000) |
src/svg/svg-length-test.h | patch | blob | history | |
src/svg/svg-length.cpp | patch | blob | history | |
src/svg/svg-length.h | patch | blob | history |
index 829612b26530871b7ab001fcded4cdadc642c5d5..0f1ca5c959908545b54bf27080347450330c8bf4 100644 (file)
#include <glib.h>
#include <utility>
+// function internal to svg-length.cpp:
+gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit);
+
class SvgLengthTest : public CxxTest::TestSuite
{
private:
}
}
+ void testEnumMappedToString()
+ {
+ for ( int i = (static_cast<int>(SVGLength::NONE) + 1); i <= static_cast<int>(SVGLength::LAST_UNIT); i++ ) {
+ SVGLength::Unit target = static_cast<SVGLength::Unit>(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<std::string> validStrings(valid, valid + G_N_ELEMENTS(valid));
+ for ( int i = (static_cast<int>(SVGLength::NONE) + 1); i <= static_cast<int>(SVGLength::LAST_UNIT); i++ ) {
+ SVGLength::Unit target = static_cast<SVGLength::Unit>(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<std::string> validStrings(valid, valid + G_N_ELEMENTS(valid));
+ for ( int i = (static_cast<int>(SVGLength::NONE) + 1); i <= static_cast<int>(SVGLength::LAST_UNIT); i++ ) {
+ SVGLength::Unit target = static_cast<SVGLength::Unit>(i);
+ gchar const* val = sp_svg_length_get_css_units(target);
+ std::set<std::string>::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 8c2a8caf3f4f6f514045c458a23ebe74cc2b6df2..505ca4ad9bbbcb3dce5cd93026148f461fda6b76 100644 (file)
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
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 9623d20f37a1815141138cfcd6e6b9200c91f4d3..1f4be8123eaebe4d21c4164e064e502464f593fc 100644 (file)
--- a/src/svg/svg-length.h
+++ b/src/svg/svg-length.h
-#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
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;
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);
void update(double em, double ex, double scale);
};
-#endif
+#endif // SEEN_SP_SVG_LENGTH_H
/*
Local Variables: