Code

- Connectors with end-markers now constrained to point downwards in graph layout
[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             UTEST_ASSERT(!style_elem->is_css);
35             UTEST_ASSERT(style_elem->media.print);
36             UTEST_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         SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
77         SP_OBJECT(style_elem)->document = _doc;
79         sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
80         Inkscape::XML::Node *repr = sp_repr_new("svg:style");
81         SP_OBJECT(style_elem)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
82         {
83             gchar const *typ = repr->attribute("type");
84             TS_ASSERT( typ != NULL );
85             if ( typ )
86             {
87                 TS_ASSERT_EQUALS( std::string(typ), std::string("text/css") );
88             }
89         }
91         g_object_unref(style_elem);
92     }
94     void testBuild()
95     {
96         SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
97         Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
98         repr->setAttribute("type", "text/css");
99         sp_object_invoke_build(&style_elem, _doc, repr, false);
100         TS_ASSERT( style_elem.is_css );
101         TS_ASSERT( style_elem.media.print );
102         TS_ASSERT( style_elem.media.screen );
104         /* Some checks relevant to the read_content test below. */
105         {
106             g_assert(_doc->style_cascade);
107             CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
108             g_assert(stylesheet);
109             g_assert(stylesheet->statements == NULL);
110         }
112         g_object_unref(&style_elem);
113         Inkscape::GC::release(repr);
114     }
116     void testReadContent()
117     {
118         SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
119         Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
120         repr->setAttribute("type", "text/css");
121         Inkscape::XML::Node *const content_repr = sp_repr_new_text(".myclass { }");
122         repr->addChild(content_repr, NULL);
123         sp_object_invoke_build(&style_elem, _doc, repr, false);
124         TS_ASSERT( style_elem.is_css );
125         TS_ASSERT( _doc->style_cascade );
126         CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
127         TS_ASSERT(stylesheet != NULL);
128         TS_ASSERT(stylesheet->statements != NULL);
130         g_object_unref(&style_elem);
131         Inkscape::GC::release(repr);
132     }
134 };
137 #endif // SEEN_SP_STYLE_ELEM_TEST_H
139 /*
140   Local Variables:
141   mode:c++
142   c-file-style:"stroustrup"
143   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
144   indent-tabs-mode:nil
145   fill-column:99
146   End:
147 */
148 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :