1 #ifndef SEEN_STYLE_TEST_H
2 #define SEEN_STYLE_TEST_H
4 #include <cxxtest/TestSuite.h>
6 #include "test-helpers.h"
8 #include "style.h"
10 class StyleTest : public CxxTest::TestSuite
11 {
12 public:
13 SPDocument* _doc;
15 StyleTest() :
16 _doc(0)
17 {
18 }
20 virtual ~StyleTest()
21 {
22 if ( _doc )
23 {
24 _doc->doUnref();
25 _doc = 0;
26 }
27 }
29 static void createSuiteSubclass( StyleTest*& dst )
30 {
31 dst = new StyleTest();
32 }
34 // createSuite and destroySuite get us per-suite setup and teardown
35 // without us having to worry about static initialization order, etc.
36 static StyleTest *createSuite()
37 {
38 StyleTest* suite = Inkscape::createSuiteAndDocument<StyleTest>( createSuiteSubclass );
39 return suite;
40 }
42 static void destroySuite( StyleTest *suite )
43 {
44 delete suite;
45 }
47 // ---------------------------------------------------------------
48 // ---------------------------------------------------------------
49 // ---------------------------------------------------------------
51 void testOne()
52 {
53 struct TestCase {
54 TestCase(gchar const* src, gchar const* dst = 0, gchar const* uri = 0) : src(src), dst(dst), uri(uri) {}
55 gchar const* src;
56 gchar const* dst;
57 gchar const* uri;
58 };
60 TestCase cases[] = {
61 TestCase("fill:none"),
62 TestCase("fill:currentColor"),
63 TestCase("fill:#ff00ff"),
65 TestCase("fill:rgb(100%, 0%, 100%)", "fill:#ff00ff"),
66 // TODO - fix this to preserve the string
67 TestCase("fill:url(#painter) rgb(100%, 0%, 100%)",
68 "fill:url(#painter) #ff00ff", "#painter"),
70 TestCase("fill:rgb(255, 0, 255)", "fill:#ff00ff"),
71 // TODO - fix this to preserve the string
72 TestCase("fill:url(#painter) rgb(255, 0, 255)",
73 "fill:url(#painter) #ff00ff", "#painter"),
76 // TestCase("fill:#ff00ff icc-color(colorChange, 0.1, 0.5, 0.1)"),
78 TestCase("fill:url(#painter)", 0, "#painter"),
79 TestCase("fill:url(#painter) none", 0, "#painter"),
80 TestCase("fill:url(#painter) currentColor", 0, "#painter"),
81 TestCase("fill:url(#painter) #ff00ff", 0, "#painter"),
82 // TestCase("fill:url(#painter) rgb(100%, 0%, 100%)", 0, "#painter"),
83 // TestCase("fill:url(#painter) rgb(255, 0, 255)", 0, "#painter"),
85 TestCase("fill:url(#painter) #ff00ff icc-color(colorChange, 0.1, 0.5, 0.1)", 0, "#painter"),
87 // TestCase("fill:url(#painter) inherit", 0, "#painter"),
88 TestCase("fill:inherit"),
89 TestCase(0)
90 };
92 for ( gint i = 0; cases[i].src; i++ ) {
93 SPStyle *style = sp_style_new(_doc);
94 TS_ASSERT(style);
95 if ( style ) {
96 sp_style_merge_from_style_string( style, cases[i].src );
98 if ( cases[i].uri ) {
99 TSM_ASSERT( cases[i].src, style->fill.value.href );
100 if ( style->fill.value.href ) {
101 TS_ASSERT_EQUALS( style->fill.value.href->getURI()->toString(), std::string(cases[i].uri) );
102 }
103 } else {
104 TS_ASSERT( !style->fill.value.href || !style->fill.value.href->getObject() );
105 }
107 gchar *str0_set = sp_style_write_string( style, SP_STYLE_FLAG_IFSET );
108 //printf("<<%s>>\n", str0_set);
109 if ( cases[i].dst ) {
110 TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].dst) );
111 } else {
112 TS_ASSERT_EQUALS( std::string(str0_set), std::string(cases[i].src) );
113 }
115 g_free(str0_set);
116 sp_style_unref(style);
117 }
118 }
119 }
121 };
124 #endif // SEEN_STYLE_TEST_H
126 /*
127 Local Variables:
128 mode:c++
129 c-file-style:"stroustrup"
130 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131 indent-tabs-mode:nil
132 fill-column:99
133 End:
134 */
135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :