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