Code

Extensions. Fix for bug #647744 ([inx] min/max float values ignored with locale using...
[inkscape.git] / src / sp-style-elem-test.h
2 #ifndef SEEN_SP_STYLE_ELEM_TEST_H
3 #define SEEN_SP_STYLE_ELEM_TEST_H
5 #include <cxxtest/TestSuite.h>
7 #include "test-helpers.h"
9 #include "sp-style-elem.h"
10 #include "xml/repr.h"
12 class SPStyleElemTest : public CxxTest::TestSuite
13 {
14 public:
15     SPDocument* _doc;
17     SPStyleElemTest() :
18         _doc(0)
19     {
20     }
22     virtual ~SPStyleElemTest()
23     {
24         if ( _doc )
25         {
26             sp_document_unref( _doc );
27         }
28     }
30     static void createSuiteSubclass( SPStyleElemTest *& dst )
31     {
32         SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
33         if ( style_elem ) {
34             TS_ASSERT(!style_elem->is_css);
35             TS_ASSERT(style_elem->media.print);
36             TS_ASSERT(style_elem->media.screen);
37             g_object_unref(style_elem);
39             dst = new SPStyleElemTest();
40         }
41     }
43     static SPStyleElemTest *createSuite()
44     {
45         return Inkscape::createSuiteAndDocument<SPStyleElemTest>( createSuiteSubclass );
46     }
48     static void destroySuite( SPStyleElemTest *suite ) { delete suite; }
50 // -------------------------------------------------------------------------
51 // -------------------------------------------------------------------------
54     void testSetType()
55     {
56         SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
57         SP_OBJECT(style_elem)->document = _doc;
59         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "something unrecognized");
60         TS_ASSERT( !style_elem->is_css );
62         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
63         TS_ASSERT( style_elem->is_css );
65         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "atext/css");
66         TS_ASSERT( !style_elem->is_css );
68         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/cssx");
69         TS_ASSERT( !style_elem->is_css );
71         g_object_unref(style_elem);
72     }
74     void testWrite()
75     {
76         TS_ASSERT( _doc );
77         TS_ASSERT( sp_document_repr_doc(_doc) );
78         if ( !sp_document_repr_doc(_doc) ) {
79             return; // evil early return
80         }
82         SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
83         SP_OBJECT(style_elem)->document = _doc;
85         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
86         Inkscape::XML::Node *repr = sp_document_repr_doc(_doc)->createElement("svg:style");
87         SP_OBJECT(style_elem)->updateRepr(sp_document_repr_doc(_doc), repr, SP_OBJECT_WRITE_ALL);
88         {
89             gchar const *typ = repr->attribute("type");
90             TS_ASSERT( typ != NULL );
91             if ( typ )
92             {
93                 TS_ASSERT_EQUALS( std::string(typ), std::string("text/css") );
94             }
95         }
97         g_object_unref(style_elem);
98     }
100     void testBuild()
101     {
102         TS_ASSERT( _doc );
103         TS_ASSERT( sp_document_repr_doc(_doc) );
104         if ( !sp_document_repr_doc(_doc) ) {
105             return; // evil early return
106         }
108         SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
109         Inkscape::XML::Node *const repr = sp_document_repr_doc(_doc)->createElement("svg:style");
110         repr->setAttribute("type", "text/css");
111         sp_object_invoke_build(&style_elem, _doc, repr, false);
112         TS_ASSERT( style_elem.is_css );
113         TS_ASSERT( style_elem.media.print );
114         TS_ASSERT( style_elem.media.screen );
116         /* Some checks relevant to the read_content test below. */
117         {
118             g_assert(_doc->style_cascade);
119             CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
120             g_assert(stylesheet);
121             g_assert(stylesheet->statements == NULL);
122         }
124         g_object_unref(&style_elem);
125         Inkscape::GC::release(repr);
126     }
128     void testReadContent()
129     {
130         TS_ASSERT( _doc );
131         TS_ASSERT( sp_document_repr_doc(_doc) );
132         if ( !sp_document_repr_doc(_doc) ) {
133             return; // evil early return
134         }
136         SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
137         Inkscape::XML::Node *const repr = sp_document_repr_doc(_doc)->createElement("svg:style");
138         repr->setAttribute("type", "text/css");
139         Inkscape::XML::Node *const content_repr = sp_document_repr_doc(_doc)->createTextNode(".myclass { }");
140         repr->addChild(content_repr, NULL);
141         sp_object_invoke_build(&style_elem, _doc, repr, false);
142         TS_ASSERT( style_elem.is_css );
143         TS_ASSERT( _doc->style_cascade );
144         CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
145         TS_ASSERT(stylesheet != NULL);
146         TS_ASSERT(stylesheet->statements != NULL);
148         g_object_unref(&style_elem);
149         Inkscape::GC::release(repr);
150     }
152 };
155 #endif // SEEN_SP_STYLE_ELEM_TEST_H
157 /*
158   Local Variables:
159   mode:c++
160   c-file-style:"stroustrup"
161   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
162   indent-tabs-mode:nil
163   fill-column:99
164   End:
165 */
166 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :