1 #include <cxxtest/TestSuite.h>
2 #include "svg/stringstream.h"
4 template<typename T>
5 static void
6 svg_test_datum(T const x, std::string const &exp_str)
7 {
8 Inkscape::SVGOStringStream s;
9 s << x;
10 TS_ASSERT_EQUALS(s.str(), exp_str);
11 }
13 static void
14 svg_test_float(float const x, std::string const &exp_str)
15 {
16 svg_test_datum(x, exp_str);
17 svg_test_datum((double) x, exp_str);
18 }
20 class StringStreamTest : public CxxTest::TestSuite
21 {
22 public:
23 void testFloats()
24 {
25 svg_test_float(4.5, "4.5");
26 svg_test_float(4.0, "4");
27 svg_test_float(0.0, "0");
28 svg_test_float(-3.75, "-3.75");
29 svg_test_float(-2.0625, "-2.0625");
30 svg_test_float(-0.0625, "-0.0625");
31 svg_test_float(30.0, "30");
32 svg_test_float(12345678.0, "12345678");
33 svg_test_float(3e9, "3e+09");
34 svg_test_float(-3.5e9, "-3.5e+09");
35 svg_test_float(32768e9, "3.2768e+13");
36 svg_test_float(-10.5, "-10.5");
37 }
39 void testOtherTypes()
40 {
41 svg_test_datum('3', "3");
42 svg_test_datum('x', "x");
43 svg_test_datum((unsigned char) '$', "$");
44 svg_test_datum((signed char) 'Z', "Z");
45 svg_test_datum(" my string ", " my string ");
46 svg_test_datum((signed char const *) "023", "023");
47 svg_test_datum((unsigned char const *) "023", "023");
48 }
50 void testConcat()
51 {
52 Inkscape::SVGOStringStream s;
53 s << "hello, ";
54 s << -53.5;
55 TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5"));
56 }
58 };
61 /*
62 Local Variables:
63 mode:c++
64 c-file-style:"stroustrup"
65 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
66 indent-tabs-mode:nil
67 fill-column:99
68 End:
69 */
70 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :