Code

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