diff options
| -rw-r--r-- | src/svg/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/svg/css-ostringstream-test.h | 88 | ||||
| -rw-r--r-- | src/svg/stringstream-test.h | 87 | ||||
| -rw-r--r-- | testfiles/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | testfiles/src/svg-stringstream-test.cpp | 156 |
5 files changed, 157 insertions, 177 deletions
diff --git a/src/svg/CMakeLists.txt b/src/svg/CMakeLists.txt index 8cbb5d704..e52febe78 100644 --- a/src/svg/CMakeLists.txt +++ b/src/svg/CMakeLists.txt @@ -16,10 +16,8 @@ set(svg_SRC # ------- # Headers - css-ostringstream-test.h css-ostringstream.h path-string.h - stringstream-test.h stringstream.h strip-trailing-zeros.h svg-affine-test.h diff --git a/src/svg/css-ostringstream-test.h b/src/svg/css-ostringstream-test.h deleted file mode 100644 index ed8af2d77..000000000 --- a/src/svg/css-ostringstream-test.h +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2010 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#include <cxxtest/TestSuite.h> -#include "svg/css-ostringstream.h" - -template<typename T> -static void -css_test_datum(T const x, std::string const &exp_str) -{ - Inkscape::CSSOStringStream s; - s << x; - TS_ASSERT_EQUALS(s.str(), exp_str); -} - -static void -css_test_float(float const x, std::string const &exp_str) -{ - css_test_datum(x, exp_str); - css_test_datum((double) x, exp_str); -} - -class CSSOStringStreamTest : public CxxTest::TestSuite -{ -public: - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static CSSOStringStreamTest *createSuite() { return new CSSOStringStreamTest(); } - static void destroySuite( CSSOStringStreamTest *suite ) { delete suite; } - - void testFloats() - { - css_test_float(4.5, "4.5"); - css_test_float(4.0, "4"); - css_test_float(0.0, "0"); - css_test_float(-3.75, "-3.75"); - css_test_float(-2.0625, "-2.0625"); - css_test_float(-0.0625, "-0.0625"); - css_test_float(30.0, "30"); - css_test_float(12345678.0, "12345678"); - css_test_float(3e9, "3000000000"); - css_test_float(-3.5e9, "-3500000000"); - css_test_float(3e-7, "0.0000003"); - css_test_float(3e-8, "0.00000003"); - css_test_float(3e-9, "0"); - css_test_float(32768e9, "32768000000000"); - css_test_float(-10.5, "-10.5"); - } - - void testOtherTypes() - { - css_test_datum('3', "3"); - css_test_datum('x', "x"); - css_test_datum((unsigned char) '$', "$"); - css_test_datum((signed char) 'Z', "Z"); - css_test_datum(" my string ", " my string "); - css_test_datum((signed char const *) "023", "023"); - css_test_datum((unsigned char const *) "023", "023"); - } - - void testConcat() - { - Inkscape::CSSOStringStream s; - s << "hello, "; - s << -53.5; - TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5")); - } - -}; - - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/svg/stringstream-test.h b/src/svg/stringstream-test.h deleted file mode 100644 index 868c9a029..000000000 --- a/src/svg/stringstream-test.h +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * TODO: insert short description here - *//* - * Authors: see git history - * - * Copyright (C) 2014 Authors - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ -#include <cxxtest/TestSuite.h> -#include "svg/stringstream.h" -#include <2geom/point.h> - -template<typename T> -static void -svg_test_datum(T const x, std::string const &exp_str) -{ - Inkscape::SVGOStringStream s; - s << x; - TS_ASSERT_EQUALS(s.str(), exp_str); -} - -static void -svg_test_float(float const x, std::string const &exp_str) -{ - svg_test_datum(x, exp_str); - svg_test_datum((double) x, exp_str); -} - -class StringStreamTest : public CxxTest::TestSuite -{ -public: - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static StringStreamTest *createSuite() { return new StringStreamTest(); } - static void destroySuite( StringStreamTest *suite ) { delete suite; } - - void testFloats() - { - svg_test_float(4.5, "4.5"); - svg_test_float(4.0, "4"); - svg_test_float(0.0, "0"); - svg_test_float(-3.75, "-3.75"); - svg_test_float(-2.0625, "-2.0625"); - svg_test_float(-0.0625, "-0.0625"); - svg_test_float(30.0, "30"); - svg_test_float(12345678.0, "12345678"); - svg_test_float(3e9, "3e+009"); - svg_test_float(-3.5e9, "-3.5e+009"); - svg_test_float(32768e9, "3.2768e+013"); - svg_test_float(-10.5, "-10.5"); - } - - void testOtherTypes() - { - svg_test_datum('3', "3"); - svg_test_datum('x', "x"); - svg_test_datum((unsigned char) '$', "$"); - svg_test_datum((signed char) 'Z', "Z"); - svg_test_datum(" my string ", " my string "); - svg_test_datum((signed char const *) "023", "023"); - svg_test_datum((unsigned char const *) "023", "023"); - svg_test_datum(Geom::Point(1.23, 3.45), "1.23,3.45"); - } - - void testConcat() - { - Inkscape::SVGOStringStream s; - s << "hello, "; - s << -53.5; - TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5")); - } - -}; - - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/testfiles/CMakeLists.txt b/testfiles/CMakeLists.txt index ddf3a66c4..ae3398f7b 100644 --- a/testfiles/CMakeLists.txt +++ b/testfiles/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_SOURCES object-style-test style-elem-test style-test + svg-stringstream-test sp-gradient-test object-test) diff --git a/testfiles/src/svg-stringstream-test.cpp b/testfiles/src/svg-stringstream-test.cpp new file mode 100644 index 000000000..636b01857 --- /dev/null +++ b/testfiles/src/svg-stringstream-test.cpp @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** + * @file + * Test CSSOStringStream and SVGOStringStream + */ +/* + * Authors: + * Thomas Holder + * + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "2geom/point.h" +#include "svg/css-ostringstream.h" +#include "svg/stringstream.h" + +#include "gtest/gtest.h" +#include <glibmm/ustring.h> + +template <typename S, typename T> +static void assert_tostring_eq(T value, const char *expected) +{ + S os; + + // default of /options/svgoutput/numericprecision + os.precision(8); + + os << value; + ASSERT_EQ(os.str(), expected); +} + +#define TEST_STRING "Hello & <World>" + +template <typename S> +void test_tostring() +{ + assert_tostring_eq<S, char>('A', "A"); + assert_tostring_eq<S, signed char>('A', "A"); + assert_tostring_eq<S, unsigned char>('A', "A"); + + assert_tostring_eq<S, short>(0x7FFF, "32767"); + assert_tostring_eq<S, short>(-30000, "-30000"); + assert_tostring_eq<S, unsigned short>(0xFFFFu, "65535"); + assert_tostring_eq<S, int>(0x7FFFFFFF, "2147483647"); + assert_tostring_eq<S, int>(-2000000000, "-2000000000"); + assert_tostring_eq<S, unsigned int>(0xFFFFFFFFu, "4294967295"); + + // long is 32bit on Windows, 64bit on Linux + assert_tostring_eq<S, long>(0x7FFFFFFFL, "2147483647"); + assert_tostring_eq<S, long>(-2000000000L, "-2000000000"); + assert_tostring_eq<S, unsigned long>(0xFFFFFFFFuL, "4294967295"); + + assert_tostring_eq<S>((char const *)TEST_STRING, TEST_STRING); + assert_tostring_eq<S>((signed char const *)TEST_STRING, TEST_STRING); + assert_tostring_eq<S>((unsigned char const *)TEST_STRING, TEST_STRING); + assert_tostring_eq<S, std::string>(TEST_STRING, TEST_STRING); + assert_tostring_eq<S, Glib::ustring>(TEST_STRING, TEST_STRING); +} + +TEST(CSSOStringStreamTest, tostring) +{ + using S = Inkscape::CSSOStringStream; + + test_tostring<S>(); + + // float has 6 significant digits + assert_tostring_eq<S, float>(0.0, "0"); + assert_tostring_eq<S, float>(4.5, "4.5"); + assert_tostring_eq<S, float>(-4.0, "-4"); + assert_tostring_eq<S, float>(0.001, "0.001"); + assert_tostring_eq<S, float>(0.00123456, "0.00123456"); + assert_tostring_eq<S, float>(-0.00123456, "-0.00123456"); + assert_tostring_eq<S, float>(-1234560.0, "-1234560"); + + // double has 15 significant digits + assert_tostring_eq<S, double>(0.0, "0"); + assert_tostring_eq<S, double>(4.5, "4.5"); + assert_tostring_eq<S, double>(-4.0, "-4"); + assert_tostring_eq<S, double>(0.001, "0.001"); + + // 9 significant digits + assert_tostring_eq<S, double>(1.23456789, "1.23456789"); + assert_tostring_eq<S, double>(-1.23456789, "-1.23456789"); + assert_tostring_eq<S, double>(12345678.9, "12345678.9"); + assert_tostring_eq<S, double>(-12345678.9, "-12345678.9"); + + assert_tostring_eq<S, double>(1.234e-12, "0"); + assert_tostring_eq<S, double>(3e9, "3000000000"); + assert_tostring_eq<S, double>(-3.5e9, "-3500000000"); +} + +TEST(SVGOStringStreamTest, tostring) +{ + using S = Inkscape::SVGOStringStream; + + test_tostring<S>(); + + assert_tostring_eq<S>(Geom::Point(12, 3.4), "12,3.4"); + + // float has 6 significant digits + assert_tostring_eq<S, float>(0.0, "0"); + assert_tostring_eq<S, float>(4.5, "4.5"); + assert_tostring_eq<S, float>(-4.0, "-4"); + assert_tostring_eq<S, float>(0.001, "0.001"); + assert_tostring_eq<S, float>(0.00123456, "0.00123456"); + assert_tostring_eq<S, float>(-0.00123456, "-0.00123456"); + assert_tostring_eq<S, float>(-1234560.0, "-1234560"); + + // double has 15 significant digits + assert_tostring_eq<S, double>(0.0, "0"); + assert_tostring_eq<S, double>(4.5, "4.5"); + assert_tostring_eq<S, double>(-4.0, "-4"); + assert_tostring_eq<S, double>(0.001, "0.001"); + + // 8 significant digits + assert_tostring_eq<S, double>(1.23456789, "1.2345679"); + assert_tostring_eq<S, double>(-1.23456789, "-1.2345679"); + assert_tostring_eq<S, double>(12345678.9, "12345679"); + assert_tostring_eq<S, double>(-12345678.9, "-12345679"); + + assert_tostring_eq<S, double>(1.234e-12, "1.234e-12"); + assert_tostring_eq<S, double>(3e9, "3e+09"); + assert_tostring_eq<S, double>(-3.5e9, "-3.5e+09"); +} + +template <typename S> +void test_concat() +{ + S s; + s << "hello, "; + s << -53.5; + ASSERT_EQ(s.str(), std::string("hello, -53.5")); +} + +TEST(CSSOStringStreamTest, concat) +{ // + test_concat<Inkscape::CSSOStringStream>(); +} + +TEST(SVGOStringStreamTest, concat) +{ // + test_concat<Inkscape::SVGOStringStream>(); +} + +/* + 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:fileencoding=utf-8:textwidth=99 : |
