Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / attributes-test.h
2 #ifndef SEEN_ATTRIBUTES_TEST_H
3 #define SEEN_ATTRIBUTES_TEST_H
5 #include <cxxtest/TestSuite.h>
7 #include <vector>
8 #include <glib.h>
9 #include <glib/gprintf.h>
10 #include "attributes.h"
11 #include "streq.h"
13 class AttributesTest : public CxxTest::TestSuite
14 {
15 public:
17     AttributesTest()
18     {
19     }
20     virtual ~AttributesTest() {}
22 // createSuite and destroySuite get us per-suite setup and teardown
23 // without us having to worry about static initialization order, etc.
24     static AttributesTest *createSuite() { return new AttributesTest(); }
25     static void destroySuite( AttributesTest *suite ) { delete suite; }
28     void testAttributes()
29     {
30 /* Extracted mechanically from http://www.w3.org/TR/SVG11/attindex.html:
32    tidy -wrap 999 -asxml < attindex.html 2>/dev/null |
33      tr -d \\n |
34      sed 's,<tr>,@,g' |
35      tr @ \\n |
36      sed 's,</td>.*,,;s,^<td>,,;1,/^%/d;/^%/d;s,^,    {",;s/$/", false},/' |
37      uniq
39    attindex.html lacks attributeName, begin, additive, font, marker;
40    I've added these manually.
41 */
42 struct {char const *attr; bool supported;} const all_attrs[] = {
43     {"attributeName", true},
44     {"begin", true},
45     {"additive", true},
46     {"font", true},
47     {"-inkscape-font-specification", true}, // TODO look into this attribute's name
48     {"marker", true},
49     {"line-height", true},
51     {"accent-height", true},
52     {"accumulate", true},
53     {"alignment-baseline", true},
54     {"alphabetic", true},
55     {"amplitude", true},
56     {"animate", false},
57     {"arabic-form", true},
58     {"ascent", true},
59     {"attributeType", true},
60     {"azimuth", true},
61     {"baseFrequency", true},
62     {"baseline-shift", true},
63     {"baseProfile", false},
64     {"bbox", true},
65     {"bias", true},
66     {"block-progression", true},
67     {"by", true},
68     {"calcMode", true},
69     {"cap-height", true},
70     {"class", false},
71     {"clip", true},
72     {"clip-path", true},
73     {"clip-rule", true},
74     {"clipPathUnits", true},
75     {"color", true},
76     {"color-interpolation", true},
77     {"color-interpolation-filters", true},
78     {"color-profile", true},
79     {"color-rendering", true},
80     {"contentScriptType", false},
81     {"contentStyleType", false},
82     {"cursor", true},
83     {"cx", true},
84     {"cy", true},
85     {"d", true},
86     {"descent", true},
87     {"diffuseConstant", true},
88     {"direction", true},
89     {"display", true},
90     {"divisor", true},
91     {"dominant-baseline", true},
92     {"dur", true},
93     {"dx", true},
94     {"dy", true},
95     {"edgeMode", true},
96     {"elevation", true},
97     {"enable-background", true},
98     {"end", true},
99     {"exponent", true},
100     {"externalResourcesRequired", false},
101     {"feBlend", false},
102     {"feColorMatrix", false},
103     {"feComponentTransfer", false},
104     {"feComposite", false},
105     {"feConvolveMatrix", false},
106     {"feDiffuseLighting", false},
107     {"feDisplacementMap", false},
108     {"feFlood", false},
109     {"feGaussianBlur", false},
110     {"feImage", false},
111     {"feMerge", false},
112     {"feMorphology", false},
113     {"feOffset", false},
114     {"feSpecularLighting", false},
115     {"feTile", false},
116     {"fill", true},
117     {"fill-opacity", true},
118     {"fill-rule", true},
119     {"filter", true},
120     {"filterRes", true},
121     {"filterUnits", true},
122     {"flood-color", true},
123     {"flood-opacity", true},
124     {"font-family", true},
125     {"font-size", true},
126     {"font-size-adjust", true},
127     {"font-stretch", true},
128     {"font-style", true},
129     {"font-variant", true},
130     {"font-weight", true},
131     {"format", false},
132     {"from", true},
133     {"fx", true},
134     {"fy", true},
135     {"g1", true},
136     {"g2", true},
137     {"glyph-name", true},
138     {"glyph-orientation-horizontal", true},
139     {"glyph-orientation-vertical", true},
140     {"glyphRef", false},
141     {"gradientTransform", true},
142     {"gradientUnits", true},
143     {"hanging", true},
144     {"height", true},
145     {"horiz-adv-x", true},
146     {"horiz-origin-x", true},
147     {"horiz-origin-y", true},
148     {"ideographic", true},
149     {"image-rendering", true},
150     {"in", true},
151     {"in2", true},
152     {"intercept", true},
153     {"k", true},
154     {"k1", true},
155     {"k2", true},
156     {"k3", true},
157     {"k4", true},
158     {"kernelMatrix", true},
159     {"kernelUnitLength", true},
160     {"kerning", true},
161     {"keyPoints", false},
162     {"keySplines", true},
163     {"keyTimes", true},
164     {"lang", true},
165     {"lengthAdjust", false},
166     {"letter-spacing", true},
167     {"lighting-color", true},
168     {"limitingConeAngle", true},
169     {"local", true},
170     {"marker-end", true},
171     {"marker-mid", true},
172     {"marker-start", true},
173     {"markerHeight", true},
174     {"markerUnits", true},
175     {"markerWidth", true},
176     {"mask", true},
177     {"maskContentUnits", true},
178     {"maskUnits", true},
179     {"mathematical", true},
180     {"max", true},
181     {"media", false},
182     {"method", false},
183     {"min", true},
184     {"mode", true},
185     {"name", true},
186     {"numOctaves", true},
187     {"offset", true},
188     {"onabort", false},
189     {"onactivate", false},
190     {"onbegin", false},
191     {"onclick", false},
192     {"onend", false},
193     {"onerror", false},
194     {"onfocusin", false},
195     {"onfocusout", false},
196     {"onload", true},
197     {"onmousedown", false},
198     {"onmousemove", false},
199     {"onmouseout", false},
200     {"onmouseover", false},
201     {"onmouseup", false},
202     {"onrepeat", false},
203     {"onresize", false},
204     {"onscroll", false},
205     {"onunload", false},
206     {"onzoom", false},
207     {"opacity", true},
208     {"operator", true},
209     {"order", true},
210     {"orient", true},
211     {"orientation", true},
212     {"origin", false},
213     {"overflow", true},
214     {"overline-position", true},
215     {"overline-thickness", true},
216     {"panose-1", true},
217     {"path", false},
218     {"pathLength", false},
219     {"patternContentUnits", true},
220     {"patternTransform", true},
221     {"patternUnits", true},
222     {"pointer-events", true},
223     {"points", true},
224     {"pointsAtX", true},
225     {"pointsAtY", true},
226     {"pointsAtZ", true},
227     {"preserveAlpha", true},
228     {"preserveAspectRatio", true},
229     {"primitiveUnits", true},
230     {"r", true},
231     {"radius", true},
232     {"refX", true},
233     {"refY", true},
234     {"rendering-intent", true},
235     {"repeatCount", true},
236     {"repeatDur", true},
237     {"requiredFeatures", true},
238     {"requiredExtensions", true},
239     {"restart", true},
240     {"result", true},
241     {"rotate", true},
242     {"rx", true},
243     {"ry", true},
244     {"scale", true},
245     {"seed", true},
246     {"shape-rendering", true},
247     {"slope", true},
248     {"spacing", false},
249     {"specularConstant", true},
250     {"specularExponent", true},
251     {"spreadMethod", true},
252     {"startOffset", true},
253     {"stdDeviation", true},
254     {"stemh", true},
255     {"stemv", true},
256     {"stitchTiles", true},
257     {"stop-color", true},
258     {"stop-opacity", true},
259     {"strikethrough-position", true},
260     {"strikethrough-thickness", true},
261     {"stroke", true},
262     {"stroke-dasharray", true},
263     {"stroke-dashoffset", true},
264     {"stroke-linecap", true},
265     {"stroke-linejoin", true},
266     {"stroke-miterlimit", true},
267     {"stroke-opacity", true},
268     {"stroke-width", true},
269     {"style", true},
270     {"surfaceScale", true},
271     {"systemLanguage", true},
272     {"tableValues", true},
273     {"target", true},
274     {"targetX", true},
275     {"targetY", true},
276     {"text-align", true},
277     {"text-anchor", true},
278     {"text-decoration", true},
279     {"text-indent", true},
280     {"text-rendering", true},
281     {"text-transform", true},
282     {"textLength", false},
283     {"title", false},
284     {"to", true},
285     {"transform", true},
286     {"type", true},
287     {"u1", true},
288     {"u2", true},
289     {"underline-position", true},
290     {"underline-thickness", true},
291     {"unicode", true},
292     {"unicode-bidi", true},
293     {"unicode-range", true},
294     {"units-per-em", true},
295     {"v-alphabetic", true},
296     {"v-hanging", true},
297     {"v-ideographic", true},
298     {"v-mathematical", true},
299     {"values", true},
300     {"version", true},
301     {"vert-adv-y", true},
302     {"vert-origin-x", true},
303     {"vert-origin-y", true},
304     {"viewBox", true},
305     {"viewTarget", false},
306     {"visibility", true},
307     {"width", true},
308     {"widths", true},
309     {"word-spacing", true},
310     {"writing-mode", true},
311     {"x", true},
312     {"x-height", true},
313     {"x1", true},
314     {"x2", true},
315     {"xChannelSelector", true},
316     {"xlink:actuate", true},
317     {"xlink:arcrole", true},
318     {"xlink:href", true},
319     {"xlink:role", true},
320     {"xlink:show", true},
321     {"xlink:title", true},
322     {"xlink:type", true},
323     {"xml:base", false},
324     {"xml:space", true},
325     {"xmlns", false},
326     {"xmlns:xlink", false},
327     {"y", true},
328     {"y1", true},
329     {"y2", true},
330     {"yChannelSelector", true},
331     {"z", true},
332     {"zoomAndPan", false},
334     /* Extra attributes. */
335     {"id", true},
336     {"inkscape:collect", true},
337     {"inkscape:document-units", true},
338     {"inkscape:label", true},
339     {"sodipodi:insensitive", true},
340     {"sodipodi:nonprintable", true},
341     {"inkscape:groupmode", true},
342     {"sodipodi:version", false},
343     {"inkscape:version", true},
344     {"inkscape:object-paths", true},
345     {"inkscape:object-nodes", true},
346     {"inkscape:bbox-paths", true},
347     {"inkscape:bbox-nodes", true},
348     {"inkscape:snap-page", true},
349     {"inkscape:snap-global", true},
350     {"inkscape:snap-bbox", true},
351     {"inkscape:snap-nodes", true},
352     {"inkscape:snap-from-guide", true},
353     {"inkscape:snap-center", true},
354     {"inkscape:snap-smooth-nodes", true},
355     {"inkscape:snap-midpoints", true},
356     {"inkscape:snap-object-midpoints", true},
357     {"inkscape:snap-bbox-edge-midpoints", true},
358     {"inkscape:snap-bbox-midpoints", true},
359     //{"inkscape:snap-intersection-grid-guide", true},
360     {"inkscape:snap-grids", true},
361     {"inkscape:snap-to-guides", true},
362     {"inkscape:snap-intersection-paths", true},
363     {"inkscape:original-d", true},
364     {"inkscape:pageopacity", true},
365     {"inkscape:pageshadow", true},
366     {"inkscape:path-effect", true},
367     {"inkscape:transform-center-x", true},
368     {"inkscape:transform-center-y", true},
369     {"inkscape:zoom", true},
370     {"inkscape:cx", true},
371     {"inkscape:cy", true},
372     {"inkscape:window-width", true},
373     {"inkscape:window-height", true},
374     {"inkscape:window-x", true},
375     {"inkscape:window-y", true},
376     {"inkscape:window-maximized", true},
377     {"inkscape:current-layer", true},
378     {"inkscape:connector-type", true},
379     {"inkscape:connection-start", true},
380     {"inkscape:connection-end", true},
381     {"inkscape:connection-points", true},
382     {"inkscape:connector-curvature", true},
383     {"inkscape:connector-avoid", true},
384     {"inkscape:connector-spacing", true},
385     {"sodipodi:cx", true},
386     {"sodipodi:cy", true},
387     {"sodipodi:rx", true},
388     {"sodipodi:ry", true},
389     {"inkscape:perspectiveID", true},
390     {"inkscape:corner0", true},
391     {"inkscape:corner7", true},
392     {"inkscape:box3dsidetype", true},
393     {"inkscape:persp3d", true},
394     {"inkscape:vp_x", true},
395     {"inkscape:vp_y", true},
396     {"inkscape:vp_z", true},
397     {"inkscape:persp3d-origin", true},
398     {"sodipodi:start", true},
399     {"sodipodi:end", true},
400     {"sodipodi:open", true},
401     {"sodipodi:sides", true},
402     {"sodipodi:r1", true},
403     {"sodipodi:r2", true},
404     {"sodipodi:arg1", true},
405     {"sodipodi:arg2", true},
406     {"inkscape:flatsided", true},
407     {"inkscape:rounded", true},
408     {"inkscape:randomized", true},
409     {"sodipodi:expansion", true},
410     {"sodipodi:revolution", true},
411     {"sodipodi:radius", true},
412     {"sodipodi:argument", true},
413     {"sodipodi:t0", true},
414     {"sodipodi:original", true},
415     {"inkscape:original", true},
416     {"inkscape:href", true},
417     {"inkscape:radius", true},
418     {"sodipodi:role", true},
419     {"sodipodi:linespacing", true},
420     {"inkscape:srcNoMarkup", true},
421     {"inkscape:srcPango", true},
422     {"inkscape:dstShape", true},
423     {"inkscape:dstPath", true},
424     {"inkscape:dstBox", true},
425     {"inkscape:dstColumn", true},
426     {"inkscape:excludeShape", true},
427     {"inkscape:layoutOptions", true},
429     /* SPNamedView */
430     {"viewonly", true},
431     {"showgrid", true},
432 //    {"gridtype", true},
433     {"showguides", true},
434     {"gridtolerance", true},
435     {"guidetolerance", true},
436     {"objecttolerance", true},
437 /*    {"gridoriginx", true},
438     {"gridoriginy", true},
439     {"gridspacingx", true},
440     {"gridspacingy", true},
441     {"gridanglex", true},
442     {"gridanglez", true},
443     {"gridcolor", true},
444     {"gridopacity", true},
445     {"gridempcolor", true},
446     {"gridempopacity", true},
447     {"gridempspacing", true}, */
448     {"guidecolor", true},
449     {"guideopacity", true},
450     {"guidehicolor", true},
451     {"guidehiopacity", true},
452     {"showborder", true},
453     {"inkscape:showpageshadow", true},
454     {"borderlayer", true},
455     {"bordercolor", true},
456     {"borderopacity", true},
457     {"pagecolor", true},
459     /* SPGuide */
460     {"position", true}
462 };
466         std::vector<bool> ids;
467         ids.reserve(256);
469         for (unsigned i = 0; i < G_N_ELEMENTS(all_attrs); ++i) {
470             char const *const attr_str = all_attrs[i].attr;
471             unsigned const id = sp_attribute_lookup(attr_str);
472             bool const recognized(id);
473             TSM_ASSERT_EQUALS( std::string(all_attrs[i].attr), recognized, all_attrs[i].supported );
474             if (recognized) {
475                 if (ids.size() <= id) {
476                     ids.resize(id + 1);
477                 }
478                 TS_ASSERT(!ids[id]);
479                 ids[id] = true;
481                 unsigned char const *reverse_ustr = sp_attribute_name(id);
482                 char const *reverse_str = reinterpret_cast<char const *>(reverse_ustr);
483                 TS_ASSERT(streq(reverse_str, attr_str));
484             }
485         }
487         /* Test for any attributes that this test program doesn't know about.
488          *
489          * If any are found, then:
490          *
491          *   If it is in the `inkscape:' namespace then simply add it to all_attrs with
492          *   `true' as the second field (`supported').
493          *
494          *   If it is in the `sodipodi:' namespace then check the spelling against sodipodi
495          *   sources.  If you don't have sodipodi sources, then don't add it: leave to someone
496          *   else.
497          *
498          *   Otherwise, it's probably a bug: ~all SVG 1.1 attributes should already be
499          *   in the all_attrs table.  However, the comment above all_attrs does mention
500          *   some things missing from attindex.html, so there may be more.  Check the SVG
501          *   spec.  Another possibility is that the attribute is new in SVG 1.2.  In this case,
502          *   check the spelling against the [draft] SVG 1.2 spec before adding to all_attrs.
503          *   (If you can't be bothered checking the spec, then don't update all_attrs.)
504          *
505          *   If the attribute isn't in either SVG 1.1 or 1.2 then it's probably a mistake
506          *   for it not to be in the inkscape namespace.  (Not sure about attributes used only
507          *   on elements in the inkscape namespace though.)
508          *
509          *   In any case, make sure that the attribute's source is documented accordingly.
510          */
511         bool found = false;
512         unsigned const n_ids = ids.size();
513         for (unsigned id = 1; id < n_ids; ++id) {
514             if (!ids[id]) {
515                 gchar* tmp = g_strdup_printf( "Attribute string with enum %d {%s} not handled", id, sp_attribute_name(id) );
516                 TS_WARN( std::string((const char*)tmp) );
517                 g_free( tmp );
518                 found = true;
519             }
520         }
521         TS_ASSERT(!found);
523         for ( unsigned int index = 1; index < n_ids; index++ ) {
524             guchar const* name = sp_attribute_name(index);
525             unsigned int postLookup = sp_attribute_lookup( reinterpret_cast<gchar const*>(name) );
526             TSM_ASSERT_EQUALS( std::string("Enum round-trip through string {") + (char const*)name + "} failed.", index, postLookup );
527         }
529     }
530 };
532 #endif // SEEN_ATTRIBUTES_TEST_H
534 /*
535   Local Variables:
536   mode:c++
537   c-file-style:"stroustrup"
538   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
539   indent-tabs-mode:nil
540   fill-column:99
541   End:
542 */
543 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :