1 #include <cxxtest/TestSuite.h>
2 #include "svg/css-ostringstream.h"
4 // dummy functions to prevent link errors
5 int sp_main_gui(int argc, char const **argv) { return 0; }
6 int sp_main_console(int argc, char const **argv) { return 0; }
8 template<typename T>
9 static void
10 css_test_datum(T const x, std::string const &exp_str)
11 {
12 Inkscape::CSSOStringStream s;
13 s << x;
14 TS_ASSERT_EQUALS(s.str(), exp_str);
15 }
17 static void
18 css_test_float(float const x, std::string const &exp_str)
19 {
20 css_test_datum(x, exp_str);
21 css_test_datum((double) x, exp_str);
22 }
24 class CSSOStringStreamTest : public CxxTest::TestSuite
25 {
26 public:
28 // createSuite and destroySuite get us per-suite setup and teardown
29 // without us having to worry about static initialization order, etc.
30 static CSSOStringStreamTest *createSuite() { return new CSSOStringStreamTest(); }
31 static void destroySuite( CSSOStringStreamTest *suite ) { delete suite; }
33 void testFloats()
34 {
35 css_test_float(4.5, "4.5");
36 css_test_float(4.0, "4");
37 css_test_float(0.0, "0");
38 css_test_float(-3.75, "-3.75");
39 css_test_float(-2.0625, "-2.0625");
40 css_test_float(-0.0625, "-0.0625");
41 css_test_float(30.0, "30");
42 css_test_float(12345678.0, "12345678");
43 css_test_float(3e9, "3000000000");
44 css_test_float(-3.5e9, "-3500000000");
45 css_test_float(3e-7, "0.0000003");
46 css_test_float(3e-8, "0.00000003");
47 css_test_float(3e-9, "0");
48 css_test_float(32768e9, "32768000000000");
49 css_test_float(-10.5, "-10.5");
50 }
52 void testOtherTypes()
53 {
54 css_test_datum('3', "3");
55 css_test_datum('x', "x");
56 css_test_datum((unsigned char) '$', "$");
57 css_test_datum((signed char) 'Z', "Z");
58 css_test_datum(" my string ", " my string ");
59 css_test_datum((signed char const *) "023", "023");
60 css_test_datum((unsigned char const *) "023", "023");
61 }
63 void testConcat()
64 {
65 Inkscape::CSSOStringStream s;
66 s << "hello, ";
67 s << -53.5;
68 TS_ASSERT_EQUALS(s.str(), std::string("hello, -53.5"));
69 }
71 };
74 /*
75 Local Variables:
76 mode:c++
77 c-file-style:"stroustrup"
78 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79 indent-tabs-mode:nil
80 fill-column:99
81 End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :