1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include "attributes.h"
#include "document.h"
#include "inkscape-private.h"
#include "sp-style-elem.h"
#include "streq.h"
#include "utest/utest.h"
#include "xml/repr.h"
/// Dummy functions to keep linker happy
int sp_main_gui (int, char const**) { return 0; }
int sp_main_console (int, char const**) { return 0; }
static bool
test_style_elem()
{
utest_start("SPStyleElem");
//#if 0
UTEST_TEST("init") {
SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
UTEST_ASSERT(!style_elem->is_css);
UTEST_ASSERT(style_elem->media.print);
UTEST_ASSERT(style_elem->media.screen);
g_object_unref(style_elem);
}
//#endif
/* Create the global inkscape object. */
static_cast<void>(g_object_new(inkscape_get_type(), NULL));
//#if 0
SPDocument *doc = sp_document_new_dummy();
UTEST_TEST("sp_object_set(\"type\")") {
SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
SP_OBJECT(style_elem)->document = doc;
sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "something unrecognized");
UTEST_ASSERT(!style_elem->is_css);
sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
UTEST_ASSERT(style_elem->is_css);
sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "atext/css");
UTEST_ASSERT(!style_elem->is_css);
sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/cssx");
UTEST_ASSERT(!style_elem->is_css);
g_object_unref(style_elem);
}
UTEST_TEST("write") {
SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
SP_OBJECT(style_elem)->document = doc;
sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
Inkscape::XML::Node *repr = sp_repr_new("svg:style");
SP_OBJECT(style_elem)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
{
gchar const *typ = repr->attribute("type");
UTEST_ASSERT(streq(typ, "text/css"));
}
g_object_unref(style_elem);
}
UTEST_TEST("build") {
SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
repr->setAttribute("type", "text/css");
sp_object_invoke_build(&style_elem, doc, repr, false);
UTEST_ASSERT(style_elem.is_css);
UTEST_ASSERT(style_elem.media.print);
UTEST_ASSERT(style_elem.media.screen);
/* Some checks relevant to the read_content test below. */
{
g_assert(doc->style_cascade);
CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(doc->style_cascade, ORIGIN_AUTHOR);
g_assert(stylesheet);
g_assert(stylesheet->statements == NULL);
}
g_object_unref(&style_elem);
Inkscape::GC::release(repr);
}
UTEST_TEST("read_content") {
SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
repr->setAttribute("type", "text/css");
Inkscape::XML::Node *const content_repr = sp_repr_new_text(".myclass { }");
repr->addChild(content_repr, NULL);
sp_object_invoke_build(&style_elem, doc, repr, false);
UTEST_ASSERT(style_elem.is_css);
UTEST_ASSERT(doc->style_cascade);
CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(doc->style_cascade, ORIGIN_AUTHOR);
UTEST_ASSERT(stylesheet != NULL);
UTEST_ASSERT(stylesheet->statements != NULL);
g_object_unref(&style_elem);
Inkscape::GC::release(repr);
}
//#endif
return utest_end();
}
int main()
{
g_type_init();
Inkscape::GC::init();
return ( test_style_elem()
? EXIT_SUCCESS
: EXIT_FAILURE );
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|