Code

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