Code

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