Code

Merge from trunk.
[inkscape.git] / src / svg / stringstream-test.h
1 #include <cxxtest/TestSuite.h>
2 #include "svg/stringstream.h"
3 #include <2geom/point.h>
5 template<typename T>
6 static void
7 svg_test_datum(T const x, std::string const &exp_str)
8 {
9     Inkscape::SVGOStringStream s;
10     s << x;
11     TS_ASSERT_EQUALS(s.str(), exp_str);
12 }
14 static void
15 svg_test_float(float const x, std::string const &exp_str)
16 {
17     svg_test_datum(x, exp_str);
18     svg_test_datum((double) x, exp_str);
19 }
21 class StringStreamTest : public CxxTest::TestSuite
22 {
23 public:
25 // createSuite and destroySuite get us per-suite setup and teardown
26 // without us having to worry about static initialization order, etc.
27     static StringStreamTest *createSuite() { return new StringStreamTest(); }
28     static void destroySuite( StringStreamTest *suite ) { delete suite; }
30     void testFloats()
31     {
32         svg_test_float(4.5, "4.5");
33         svg_test_float(4.0, "4");
34         svg_test_float(0.0, "0");
35         svg_test_float(-3.75, "-3.75");
36         svg_test_float(-2.0625, "-2.0625");
37         svg_test_float(-0.0625, "-0.0625");
38         svg_test_float(30.0, "30");
39         svg_test_float(12345678.0, "12345678");
40         svg_test_float(3e9, "3e+09");
41         svg_test_float(-3.5e9, "-3.5e+09");
42         svg_test_float(32768e9, "3.2768e+13");
43         svg_test_float(-10.5, "-10.5");
44     }
46     void testOtherTypes()
47     {
48         svg_test_datum('3', "3");
49         svg_test_datum('x', "x");
50         svg_test_datum((unsigned char) '$', "$");
51         svg_test_datum((signed char) 'Z', "Z");
52         svg_test_datum("  my string  ", "  my string  ");
53         svg_test_datum((signed char const *) "023", "023");
54         svg_test_datum((unsigned char const *) "023", "023");
55         svg_test_datum(Geom::Point(1.23, 3.45), "1.23,3.45");
56     }
58     void testConcat()
59     {
60         Inkscape::SVGOStringStream s;
61         s << "hello, ";
62         s << -53.5;
63         TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5"));
64     }
66 };
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :