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 {"requiredFeatures", true},
223 {"requiredExtensions", true},
224 {"restart", true},
225 {"result", false},
226 {"rotate", true},
227 {"rx", true},
228 {"ry", true},
229 {"scale", false},
230 {"seed", false},
231 {"shape-rendering", true},
232 {"slope", false},
233 {"spacing", false},
234 {"specularConstant", false},
235 {"specularExponent", false},
236 {"spreadMethod", true},
237 {"startOffset", true},
238 {"stdDeviation", false},
239 {"stemh", false},
240 {"stemv", false},
241 {"stitchTiles", false},
242 {"stop-color", true},
243 {"stop-opacity", true},
244 {"strikethrough-position", false},
245 {"strikethrough-thickness", false},
246 {"stroke", true},
247 {"stroke-dasharray", true},
248 {"stroke-dashoffset", true},
249 {"stroke-linecap", true},
250 {"stroke-linejoin", true},
251 {"stroke-miterlimit", true},
252 {"stroke-opacity", true},
253 {"stroke-width", true},
254 {"style", true},
255 {"surfaceScale", false},
256 {"systemLanguage", true},
257 {"tableValues", false},
258 {"target", true},
259 {"targetX", false},
260 {"targetY", false},
261 {"text-align", true},
262 {"text-anchor", true},
263 {"text-decoration", true},
264 {"text-indent", true},
265 {"text-rendering", true},
266 {"text-transform", true},
267 {"textLength", false},
268 {"title", false},
269 {"to", true},
270 {"transform", true},
271 {"type", true},
272 {"u1", false},
273 {"u2", false},
274 {"underline-position", false},
275 {"underline-thickness", false},
276 {"unicode", false},
277 {"unicode-bidi", true},
278 {"unicode-range", false},
279 {"units-per-em", false},
280 {"v-alphabetic", false},
281 {"v-hanging", false},
282 {"v-ideographic", false},
283 {"v-mathematical", false},
284 {"values", true},
285 {"version", true},
286 {"vert-adv-y", false},
287 {"vert-origin-x", false},
288 {"vert-origin-y", false},
289 {"viewBox", true},
290 {"viewTarget", false},
291 {"visibility", true},
292 {"width", true},
293 {"widths", false},
294 {"word-spacing", true},
295 {"writing-mode", true},
296 {"x", true},
297 {"x-height", false},
298 {"x1", true},
299 {"x2", true},
300 {"xChannelSelector", false},
301 {"xlink:actuate", true},
302 {"xlink:arcrole", true},
303 {"xlink:href", true},
304 {"xlink:role", true},
305 {"xlink:show", true},
306 {"xlink:title", true},
307 {"xlink:type", true},
308 {"xml:base", false},
309 {"xml:space", true},
310 {"xmlns", false},
311 {"xmlns:xlink", false},
312 {"y", true},
313 {"y1", true},
314 {"y2", true},
315 {"yChannelSelector", false},
316 {"z", false},
317 {"zoomAndPan", false},
319 /* Extra attributes. */
320 {"id", true},
321 {"inkscape:collect", true},
322 {"inkscape:document-units", true},
323 {"inkscape:label", true},
324 {"sodipodi:insensitive", true},
325 {"sodipodi:nonprintable", true},
326 {"inkscape:groupmode", true},
327 {"sodipodi:version", true},
328 {"inkscape:version", true},
329 {"inkscape:object-bbox", true},
330 {"inkscape:object-points", true},
331 {"inkscape:object-paths", true},
332 {"inkscape:object-nodes", true},
333 {"inkscape:pageopacity", true},
334 {"inkscape:pageshadow", true},
335 {"inkscape:transform-center-x", true},
336 {"inkscape:transform-center-y", true},
337 {"inkscape:zoom", true},
338 {"inkscape:cx", true},
339 {"inkscape:cy", true},
340 {"inkscape:window-width", true},
341 {"inkscape:window-height", true},
342 {"inkscape:window-x", true},
343 {"inkscape:window-y", true},
344 {"inkscape:grid-bbox", true},
345 {"inkscape:guide-bbox", true},
346 {"inkscape:grid-points", true},
347 {"inkscape:guide-points", true},
348 {"inkscape:current-layer", true},
349 {"inkscape:connector-type", true},
350 {"inkscape:connection-start", true},
351 {"inkscape:connection-end", true},
352 {"inkscape:connector-avoid", true},
353 {"inkscape:connector-spacing", true},
354 {"sodipodi:cx", true},
355 {"sodipodi:cy", true},
356 {"sodipodi:rx", true},
357 {"sodipodi:ry", true},
358 {"sodipodi:start", true},
359 {"sodipodi:end", true},
360 {"sodipodi:open", true},
361 {"sodipodi:sides", true},
362 {"sodipodi:r1", true},
363 {"sodipodi:r2", true},
364 {"sodipodi:arg1", true},
365 {"sodipodi:arg2", true},
366 {"inkscape:flatsided", true},
367 {"inkscape:rounded", true},
368 {"inkscape:randomized", true},
369 {"sodipodi:expansion", true},
370 {"sodipodi:revolution", true},
371 {"sodipodi:radius", true},
372 {"sodipodi:argument", true},
373 {"sodipodi:t0", true},
374 {"sodipodi:original", true},
375 {"inkscape:original", true},
376 {"inkscape:href", true},
377 {"inkscape:radius", true},
378 {"sodipodi:role", true},
379 {"sodipodi:linespacing", true},
380 {"inkscape:srcNoMarkup", true},
381 {"inkscape:srcPango", true},
382 {"inkscape:dstShape", true},
383 {"inkscape:dstPath", true},
384 {"inkscape:dstBox", true},
385 {"inkscape:dstColumn", true},
386 {"inkscape:excludeShape", true},
387 {"inkscape:layoutOptions", true},
389 /* SPNamedView */
390 {"viewonly", true},
391 {"showgrid", true},
392 {"showguides", true},
393 {"gridtolerance", true},
394 {"guidetolerance", true},
395 {"objecttolerance", true},
396 {"has_abs_tolerance", true},
397 {"gridoriginx", true},
398 {"gridoriginy", true},
399 {"gridspacingx", true},
400 {"gridspacingy", true},
401 {"gridcolor", true},
402 {"gridopacity", true},
403 {"gridempcolor", true},
404 {"gridempopacity", true},
405 {"gridempspacing", true},
406 {"guidecolor", true},
407 {"guideopacity", true},
408 {"guidehicolor", true},
409 {"guidehiopacity", true},
410 {"showborder", true},
411 {"inkscape:showpageshadow", true},
412 {"borderlayer", true},
413 {"bordercolor", true},
414 {"borderopacity", true},
415 {"pagecolor", true},
417 /* SPGuide */
418 {"position", true}
420 };
424 std::vector<bool> ids;
425 ids.reserve(256);
427 for (unsigned i = 0; i < G_N_ELEMENTS(all_attrs); ++i) {
428 char const *const attr_str = all_attrs[i].attr;
429 unsigned const id = sp_attribute_lookup(attr_str);
430 bool const recognized(id);
431 TSM_ASSERT_EQUALS( std::string(all_attrs[i].attr), recognized, all_attrs[i].supported );
432 if (recognized) {
433 if (ids.size() <= id) {
434 ids.resize(id + 1);
435 }
436 TS_ASSERT(!ids[id]);
437 ids[id] = true;
439 unsigned char const *reverse_ustr = sp_attribute_name(id);
440 char const *reverse_str = reinterpret_cast<char const *>(reverse_ustr);
441 TS_ASSERT(streq(reverse_str, attr_str));
442 }
443 }
445 /* Test for any attributes that this test program doesn't know about.
446 *
447 * If any are found, then:
448 *
449 * If it is in the `inkscape:' namespace then simply add it to all_attrs with
450 * `true' as the second field (`supported').
451 *
452 * If it is in the `sodipodi:' namespace then check the spelling against sodipodi
453 * sources. If you don't have sodipodi sources, then don't add it: leave to someone
454 * else.
455 *
456 * Otherwise, it's probably a bug: ~all SVG 1.1 attributes should already be
457 * in the all_attrs table. However, the comment above all_attrs does mention
458 * some things missing from attindex.html, so there may be more. Check the SVG
459 * spec. Another possibility is that the attribute is new in SVG 1.2. In this case,
460 * check the spelling against the [draft] SVG 1.2 spec before adding to all_attrs.
461 * (If you can't be bothered checking the spec, then don't update all_attrs.)
462 *
463 * If the attribute isn't in either SVG 1.1 or 1.2 then it's probably a mistake
464 * for it not to be in the inkscape namespace. (Not sure about attributes used only
465 * on elements in the inkscape namespace though.)
466 *
467 * In any case, make sure that the attribute's source is documented accordingly.
468 */
469 bool found = false;
470 unsigned const n_ids = ids.size();
471 for (unsigned id = 1; id < n_ids; ++id) {
472 if (!ids[id]) {
473 TS_WARN( std::string((const char*)sp_attribute_name(id)) );
474 found = true;
475 }
476 }
477 TS_ASSERT(!found);
478 }
479 };
481 /*
482 Local Variables:
483 mode:c++
484 c-file-style:"stroustrup"
485 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
486 indent-tabs-mode:nil
487 fill-column:99
488 End:
489 */
490 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :