1 #ifndef SEEN_SP_STYLE_ELEM_TEST_H
2 #define SEEN_SP_STYLE_ELEM_TEST_H
4 #include <cxxtest/TestSuite.h>
6 #include "test-helpers.h"
8 #include "sp-style-elem.h"
9 #include "xml/repr.h"
11 class SPStyleElemTest : public CxxTest::TestSuite
12 {
13 public:
14 SPDocument* _doc;
16 SPStyleElemTest() :
17 _doc(0)
18 {
19 }
21 virtual ~SPStyleElemTest()
22 {
23 if ( _doc )
24 {
25 _doc->doUnref();
26 }
27 }
29 static void createSuiteSubclass( SPStyleElemTest *& dst )
30 {
31 SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
32 if ( style_elem ) {
33 TS_ASSERT(!style_elem->is_css);
34 TS_ASSERT(style_elem->media.print);
35 TS_ASSERT(style_elem->media.screen);
36 g_object_unref(style_elem);
38 dst = new SPStyleElemTest();
39 }
40 }
42 static SPStyleElemTest *createSuite()
43 {
44 return Inkscape::createSuiteAndDocument<SPStyleElemTest>( createSuiteSubclass );
45 }
47 static void destroySuite( SPStyleElemTest *suite ) { delete suite; }
49 // -------------------------------------------------------------------------
50 // -------------------------------------------------------------------------
53 void testSetType()
54 {
55 SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
56 SP_OBJECT(style_elem)->document = _doc;
58 SP_OBJECT(style_elem)->setKeyValue( SP_ATTR_TYPE, "something unrecognized");
59 TS_ASSERT( !style_elem->is_css );
61 SP_OBJECT(style_elem)->setKeyValue( SP_ATTR_TYPE, "text/css");
62 TS_ASSERT( style_elem->is_css );
64 SP_OBJECT(style_elem)->setKeyValue( SP_ATTR_TYPE, "atext/css");
65 TS_ASSERT( !style_elem->is_css );
67 SP_OBJECT(style_elem)->setKeyValue( SP_ATTR_TYPE, "text/cssx");
68 TS_ASSERT( !style_elem->is_css );
70 g_object_unref(style_elem);
71 }
73 void testWrite()
74 {
75 TS_ASSERT( _doc );
76 TS_ASSERT( sp_document_repr_doc(_doc) );
77 if ( !sp_document_repr_doc(_doc) ) {
78 return; // evil early return
79 }
81 SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
82 SP_OBJECT(style_elem)->document = _doc;
84 SP_OBJECT(style_elem)->setKeyValue( SP_ATTR_TYPE, "text/css");
85 Inkscape::XML::Node *repr = sp_document_repr_doc(_doc)->createElement("svg:style");
86 SP_OBJECT(style_elem)->updateRepr(sp_document_repr_doc(_doc), repr, SP_OBJECT_WRITE_ALL);
87 {
88 gchar const *typ = repr->attribute("type");
89 TS_ASSERT( typ != NULL );
90 if ( typ )
91 {
92 TS_ASSERT_EQUALS( std::string(typ), std::string("text/css") );
93 }
94 }
96 g_object_unref(style_elem);
97 }
99 void testBuild()
100 {
101 TS_ASSERT( _doc );
102 TS_ASSERT( sp_document_repr_doc(_doc) );
103 if ( !sp_document_repr_doc(_doc) ) {
104 return; // evil early return
105 }
107 SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
108 Inkscape::XML::Node *const repr = sp_document_repr_doc(_doc)->createElement("svg:style");
109 repr->setAttribute("type", "text/css");
110 (&style_elem)->invoke_build( _doc, repr, false);
111 TS_ASSERT( style_elem.is_css );
112 TS_ASSERT( style_elem.media.print );
113 TS_ASSERT( style_elem.media.screen );
115 /* Some checks relevant to the read_content test below. */
116 {
117 g_assert(_doc->style_cascade);
118 CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
119 g_assert(stylesheet);
120 g_assert(stylesheet->statements == NULL);
121 }
123 g_object_unref(&style_elem);
124 Inkscape::GC::release(repr);
125 }
127 void testReadContent()
128 {
129 TS_ASSERT( _doc );
130 TS_ASSERT( sp_document_repr_doc(_doc) );
131 if ( !sp_document_repr_doc(_doc) ) {
132 return; // evil early return
133 }
135 SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
136 Inkscape::XML::Node *const repr = sp_document_repr_doc(_doc)->createElement("svg:style");
137 repr->setAttribute("type", "text/css");
138 Inkscape::XML::Node *const content_repr = sp_document_repr_doc(_doc)->createTextNode(".myclass { }");
139 repr->addChild(content_repr, NULL);
140 (&style_elem)->invoke_build(_doc, repr, false);
141 TS_ASSERT( style_elem.is_css );
142 TS_ASSERT( _doc->style_cascade );
143 CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
144 TS_ASSERT(stylesheet != NULL);
145 TS_ASSERT(stylesheet->statements != NULL);
147 g_object_unref(&style_elem);
148 Inkscape::GC::release(repr);
149 }
151 };
154 #endif // SEEN_SP_STYLE_ELEM_TEST_H
156 /*
157 Local Variables:
158 mode:c++
159 c-file-style:"stroustrup"
160 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
161 indent-tabs-mode:nil
162 fill-column:99
163 End:
164 */
165 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :