Code

Committed double code because of the hurry to let you use the axonom-snapping stuff.
[inkscape.git] / src / svg / css-ostringstream-test.h
1 #include <cxxtest/TestSuite.h>
2 #include "svg/css-ostringstream.h"
4 template<typename T>
5 static void
6 css_test_datum(T const x, std::string const &exp_str)
7 {
8     Inkscape::CSSOStringStream s;
9     s << x;
10     TS_ASSERT_EQUALS(s.str(), exp_str);
11 }
13 static void
14 css_test_float(float const x, std::string const &exp_str)
15 {
16     css_test_datum(x, exp_str);
17     css_test_datum((double) x, exp_str);
18 }
20 class CSSOStringStreamTest : public CxxTest::TestSuite
21 {
22 public:
23     void testFloats()
24     {
25         css_test_float(4.5, "4.5");
26         css_test_float(4.0, "4");
27         css_test_float(0.0, "0");
28         css_test_float(-3.75, "-3.75");
29         css_test_float(-2.0625, "-2.0625");
30         css_test_float(-0.0625, "-0.0625");
31         css_test_float(30.0, "30");
32         css_test_float(12345678.0, "12345678");
33         css_test_float(3e9, "3000000000");
34         css_test_float(-3.5e9, "-3500000000");
35         css_test_float(3e-7, "0.0000003");
36         css_test_float(3e-8, "0.00000003");
37         css_test_float(3e-9, "0");
38         css_test_float(32768e9, "32768000000000");
39         css_test_float(-10.5, "-10.5");
40     }
42     void testOtherTypes()
43     {
44         css_test_datum('3', "3");
45         css_test_datum('x', "x");
46         css_test_datum((unsigned char) '$', "$");
47         css_test_datum((signed char) 'Z', "Z");
48         css_test_datum("  my string  ", "  my string  ");
49         css_test_datum((signed char const *) "023", "023");
50         css_test_datum((unsigned char const *) "023", "023");
51     }
53     void testConcat()
54     {
55         Inkscape::CSSOStringStream s;
56         s << "hello, ";
57         s << -53.5;
58         TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5"));
59     }
61 };
64 /*
65   Local Variables:
66   mode:c++
67   c-file-style:"stroustrup"
68   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
69   indent-tabs-mode:nil
70   fill-column:99
71   End:
72 */
73 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :