summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2009-10-09 00:29:51 +0000
committerjoncruz <joncruz@users.sourceforge.net>2009-10-09 00:29:51 +0000
commit0d815ac5672dc97bc5e6af2283ef632b42eb1967 (patch)
treecfc182360af40357e6b03f43a878c383e40f04db /src
parentAdded simplistic test cases (diff)
downloadinkscape-0d815ac5672dc97bc5e6af2283ef632b42eb1967.tar.gz
inkscape-0d815ac5672dc97bc5e6af2283ef632b42eb1967.zip
Refactored multiple methods to single data-driven one.
(bzr r8750)
Diffstat (limited to 'src')
-rw-r--r--src/svg/svg-length-test.h45
1 files changed, 18 insertions, 27 deletions
diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h
index 2c2fe34f0..833b4a08b 100644
--- a/src/svg/svg-length-test.h
+++ b/src/svg/svg-length-test.h
@@ -13,9 +13,13 @@ private:
struct test_t {
char const* str; SVGLength::Unit unit; float value; float computed;
};
+ struct testd_t {
+ char const* str; double val; int prec; int minexp;
+ };
static test_t const absolute_tests[12];
static test_t const relative_tests[3];
static char const * fail_tests[8];
+
public:
SvgLengthTest() {
}
@@ -134,34 +138,21 @@ public:
TSM_ASSERT_EQUALS(validStrings, validStrings.size(), 0u);
}
-
-
- void testFourPlaces()
- {
- double val = 761.92918978947023;
- int precision = 4;
- int minexp = -8;
- char buf[256] = {0};
-
- memset(buf, 0xCC, sizeof(buf)); // Make it easy to detect an overrun.
- unsigned int retval = sp_svg_number_write_de( buf, sizeof(buf), val, precision, minexp );
- TSM_ASSERT_EQUALS("Number of chars written", retval, 5u);
- TSM_ASSERT_EQUALS("Numeric string written", std::string(buf), std::string("761.9"));
- TSM_ASSERT_EQUALS(std::string("Buffer overrun ") + buf, '\xCC', buf[retval + 1]);
- }
-
- void testTwoPlaces()
+ void testPlaces()
{
- double val = 761.92918978947023;
- int precision = 2;
- int minexp = -8;
- char buf[256] = {0};
-
- memset(buf, 0xCC, sizeof(buf)); // Make it easy to detect an overrun.
- unsigned int retval = sp_svg_number_write_de( buf, sizeof(buf), val, precision, minexp );
- TSM_ASSERT_EQUALS("Number of chars written", retval, 3u);
- TSM_ASSERT_EQUALS("Numeric string written", std::string(buf), std::string("760"));
- TSM_ASSERT_EQUALS(std::string("Buffer overrun ") + buf, '\xCC', buf[retval + 1]);
+ testd_t const precTests[] = {
+ {"760", 761.92918978947023, 2, -8},
+ {"761.9", 761.92918978947023, 4, -8},
+ };
+
+ for ( size_t i = 0; i < G_N_ELEMENTS(precTests); i++ ) {
+ char buf[256] = {0};
+ memset(buf, 0xCC, sizeof(buf)); // Make it easy to detect an overrun.
+ unsigned int retval = sp_svg_number_write_de( buf, sizeof(buf), precTests[i].val, precTests[i].prec, precTests[i].minexp );
+ TSM_ASSERT_EQUALS("Number of chars written", retval, strlen(precTests[i].str));
+ TSM_ASSERT_EQUALS("Numeric string written", std::string(buf), std::string(precTests[i].str));
+ TSM_ASSERT_EQUALS(std::string("Buffer overrun ") + precTests[i].str, '\xCC', buf[retval + 1]);
+ }
}
// TODO: More tests