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 {"feColorMatrix", false},
100 {"feComposite", false},
101 {"feGaussianBlur", false},
102 {"feMorphology", false},
103 {"feTile", false},
104 {"fill", true},
105 {"fill-opacity", true},
106 {"fill-rule", true},
107 {"filter", true},
108 {"filterRes", true},
109 {"filterUnits", true},
110 {"flood-color", true},
111 {"flood-opacity", true},
112 {"font-family", true},
113 {"font-size", true},
114 {"font-size-adjust", true},
115 {"font-stretch", true},
116 {"font-style", true},
117 {"font-variant", true},
118 {"font-weight", true},
119 {"format", false},
120 {"from", true},
121 {"fx", true},
122 {"fy", true},
123 {"g1", false},
124 {"g2", false},
125 {"glyph-name", false},
126 {"glyph-orientation-horizontal", true},
127 {"glyph-orientation-vertical", true},
128 {"glyphRef", false},
129 {"gradientTransform", true},
130 {"gradientUnits", true},
131 {"hanging", false},
132 {"height", true},
133 {"horiz-adv-x", false},
134 {"horiz-origin-x", false},
135 {"horiz-origin-y", false},
136 {"ideographic", false},
137 {"image-rendering", true},
138 {"in", false},
139 {"in2", false},
140 {"intercept", false},
141 {"k", false},
142 {"k1", false},
143 {"k2", false},
144 {"k3", false},
145 {"k4", false},
146 {"kernelMatrix", false},
147 {"kernelUnitLength", false},
148 {"kerning", true},
149 {"keyPoints", false},
150 {"keySplines", true},
151 {"keyTimes", true},
152 {"lang", false},
153 {"lengthAdjust", false},
154 {"letter-spacing", true},
155 {"lighting-color", true},
156 {"limitingConeAngle", false},
157 {"local", true},
158 {"marker-end", true},
159 {"marker-mid", true},
160 {"marker-start", true},
161 {"markerHeight", true},
162 {"markerUnits", true},
163 {"markerWidth", true},
164 {"mask", true},
165 {"maskContentUnits", true},
166 {"maskUnits", true},
167 {"mathematical", false},
168 {"max", true},
169 {"media", false},
170 {"method", false},
171 {"min", true},
172 {"mode", false},
173 {"name", true},
174 {"numOctaves", false},
175 {"offset", true},
176 {"onabort", false},
177 {"onactivate", false},
178 {"onbegin", false},
179 {"onclick", false},
180 {"onend", false},
181 {"onerror", false},
182 {"onfocusin", false},
183 {"onfocusout", false},
184 {"onload", false},
185 {"onmousedown", false},
186 {"onmousemove", false},
187 {"onmouseout", false},
188 {"onmouseover", false},
189 {"onmouseup", false},
190 {"onrepeat", false},
191 {"onresize", false},
192 {"onscroll", false},
193 {"onunload", false},
194 {"onzoom", false},
195 {"opacity", true},
196 {"operator", false},
197 {"order", false},
198 {"orient", true},
199 {"orientation", true},
200 {"origin", false},
201 {"overflow", true},
202 {"overline-position", false},
203 {"overline-thickness", false},
204 {"panose-1", false},
205 {"path", false},
206 {"pathLength", false},
207 {"patternContentUnits", true},
208 {"patternTransform", true},
209 {"patternUnits", true},
210 {"pointer-events", true},
211 {"points", true},
212 {"pointsAtX", false},
213 {"pointsAtY", false},
214 {"pointsAtZ", false},
215 {"preserveAlpha", false},
216 {"preserveAspectRatio", true},
217 {"primitiveUnits", true},
218 {"r", true},
219 {"radius", false},
220 {"refX", true},
221 {"refY", true},
222 {"rendering-intent", true},
223 {"repeatCount", true},
224 {"repeatDur", true},
225 {"requiredFeatures", true},
226 {"requiredExtensions", true},
227 {"restart", true},
228 {"result", false},
229 {"rotate", true},
230 {"rx", true},
231 {"ry", true},
232 {"scale", false},
233 {"seed", false},
234 {"shape-rendering", true},
235 {"slope", false},
236 {"spacing", false},
237 {"specularConstant", false},
238 {"specularExponent", false},
239 {"spreadMethod", true},
240 {"startOffset", true},
241 {"stdDeviation", true},
242 {"stemh", false},
243 {"stemv", false},
244 {"stitchTiles", false},
245 {"stop-color", true},
246 {"stop-opacity", true},
247 {"strikethrough-position", false},
248 {"strikethrough-thickness", false},
249 {"stroke", true},
250 {"stroke-dasharray", true},
251 {"stroke-dashoffset", true},
252 {"stroke-linecap", true},
253 {"stroke-linejoin", true},
254 {"stroke-miterlimit", true},
255 {"stroke-opacity", true},
256 {"stroke-width", true},
257 {"style", true},
258 {"surfaceScale", false},
259 {"systemLanguage", true},
260 {"tableValues", false},
261 {"target", true},
262 {"targetX", false},
263 {"targetY", false},
264 {"text-align", true},
265 {"text-anchor", true},
266 {"text-decoration", true},
267 {"text-indent", true},
268 {"text-rendering", true},
269 {"text-transform", true},
270 {"textLength", false},
271 {"title", false},
272 {"to", true},
273 {"transform", true},
274 {"type", true},
275 {"u1", false},
276 {"u2", false},
277 {"underline-position", false},
278 {"underline-thickness", false},
279 {"unicode", false},
280 {"unicode-bidi", true},
281 {"unicode-range", false},
282 {"units-per-em", false},
283 {"v-alphabetic", false},
284 {"v-hanging", false},
285 {"v-ideographic", false},
286 {"v-mathematical", false},
287 {"values", true},
288 {"version", true},
289 {"vert-adv-y", false},
290 {"vert-origin-x", false},
291 {"vert-origin-y", false},
292 {"viewBox", true},
293 {"viewTarget", false},
294 {"visibility", true},
295 {"width", true},
296 {"widths", false},
297 {"word-spacing", true},
298 {"writing-mode", true},
299 {"x", true},
300 {"x-height", false},
301 {"x1", true},
302 {"x2", true},
303 {"xChannelSelector", false},
304 {"xlink:actuate", true},
305 {"xlink:arcrole", true},
306 {"xlink:href", true},
307 {"xlink:role", true},
308 {"xlink:show", true},
309 {"xlink:title", true},
310 {"xlink:type", true},
311 {"xml:base", false},
312 {"xml:space", true},
313 {"xmlns", false},
314 {"xmlns:xlink", false},
315 {"y", true},
316 {"y1", true},
317 {"y2", true},
318 {"yChannelSelector", false},
319 {"z", false},
320 {"zoomAndPan", false},
322 /* Extra attributes. */
323 {"id", true},
324 {"inkscape:collect", true},
325 {"inkscape:document-units", true},
326 {"inkscape:label", true},
327 {"sodipodi:insensitive", true},
328 {"sodipodi:nonprintable", true},
329 {"inkscape:groupmode", true},
330 {"sodipodi:version", true},
331 {"inkscape:version", true},
332 {"inkscape:object-bbox", true},
333 {"inkscape:object-points", true},
334 {"inkscape:object-paths", true},
335 {"inkscape:object-nodes", true},
336 {"inkscape:pageopacity", true},
337 {"inkscape:pageshadow", true},
338 {"inkscape:transform-center-x", true},
339 {"inkscape:transform-center-y", true},
340 {"inkscape:zoom", true},
341 {"inkscape:cx", true},
342 {"inkscape:cy", true},
343 {"inkscape:window-width", true},
344 {"inkscape:window-height", true},
345 {"inkscape:window-x", true},
346 {"inkscape:window-y", true},
347 {"inkscape:grid-bbox", true},
348 {"inkscape:guide-bbox", true},
349 {"inkscape:grid-points", true},
350 {"inkscape:guide-points", true},
351 {"inkscape:current-layer", true},
352 {"inkscape:connector-type", true},
353 {"inkscape:connection-start", true},
354 {"inkscape:connection-end", true},
355 {"inkscape:connector-avoid", true},
356 {"inkscape:connector-spacing", true},
357 {"sodipodi:cx", true},
358 {"sodipodi:cy", true},
359 {"sodipodi:rx", true},
360 {"sodipodi:ry", true},
361 {"sodipodi:start", true},
362 {"sodipodi:end", true},
363 {"sodipodi:open", true},
364 {"sodipodi:sides", true},
365 {"sodipodi:r1", true},
366 {"sodipodi:r2", true},
367 {"sodipodi:arg1", true},
368 {"sodipodi:arg2", true},
369 {"inkscape:flatsided", true},
370 {"inkscape:rounded", true},
371 {"inkscape:randomized", true},
372 {"sodipodi:expansion", true},
373 {"sodipodi:revolution", true},
374 {"sodipodi:radius", true},
375 {"sodipodi:argument", true},
376 {"sodipodi:t0", true},
377 {"sodipodi:original", true},
378 {"inkscape:original", true},
379 {"inkscape:href", true},
380 {"inkscape:radius", true},
381 {"sodipodi:role", true},
382 {"sodipodi:linespacing", true},
383 {"inkscape:srcNoMarkup", true},
384 {"inkscape:srcPango", true},
385 {"inkscape:dstShape", true},
386 {"inkscape:dstPath", true},
387 {"inkscape:dstBox", true},
388 {"inkscape:dstColumn", true},
389 {"inkscape:excludeShape", true},
390 {"inkscape:layoutOptions", true},
392 /* SPNamedView */
393 {"viewonly", true},
394 {"showgrid", true},
395 {"showguides", true},
396 {"gridtolerance", true},
397 {"guidetolerance", true},
398 {"objecttolerance", true},
399 {"has_abs_tolerance", true},
400 {"gridoriginx", true},
401 {"gridoriginy", true},
402 {"gridspacingx", true},
403 {"gridspacingy", true},
404 {"gridcolor", true},
405 {"gridopacity", true},
406 {"gridempcolor", true},
407 {"gridempopacity", true},
408 {"gridempspacing", true},
409 {"guidecolor", true},
410 {"guideopacity", true},
411 {"guidehicolor", true},
412 {"guidehiopacity", true},
413 {"showborder", true},
414 {"inkscape:showpageshadow", true},
415 {"borderlayer", true},
416 {"bordercolor", true},
417 {"borderopacity", true},
418 {"pagecolor", true},
420 /* SPGuide */
421 {"position", true}
423 };
427 std::vector<bool> ids;
428 ids.reserve(256);
430 for (unsigned i = 0; i < G_N_ELEMENTS(all_attrs); ++i) {
431 char const *const attr_str = all_attrs[i].attr;
432 unsigned const id = sp_attribute_lookup(attr_str);
433 bool const recognized(id);
434 TSM_ASSERT_EQUALS( std::string(all_attrs[i].attr), recognized, all_attrs[i].supported );
435 if (recognized) {
436 if (ids.size() <= id) {
437 ids.resize(id + 1);
438 }
439 TS_ASSERT(!ids[id]);
440 ids[id] = true;
442 unsigned char const *reverse_ustr = sp_attribute_name(id);
443 char const *reverse_str = reinterpret_cast<char const *>(reverse_ustr);
444 TS_ASSERT(streq(reverse_str, attr_str));
445 }
446 }
448 /* Test for any attributes that this test program doesn't know about.
449 *
450 * If any are found, then:
451 *
452 * If it is in the `inkscape:' namespace then simply add it to all_attrs with
453 * `true' as the second field (`supported').
454 *
455 * If it is in the `sodipodi:' namespace then check the spelling against sodipodi
456 * sources. If you don't have sodipodi sources, then don't add it: leave to someone
457 * else.
458 *
459 * Otherwise, it's probably a bug: ~all SVG 1.1 attributes should already be
460 * in the all_attrs table. However, the comment above all_attrs does mention
461 * some things missing from attindex.html, so there may be more. Check the SVG
462 * spec. Another possibility is that the attribute is new in SVG 1.2. In this case,
463 * check the spelling against the [draft] SVG 1.2 spec before adding to all_attrs.
464 * (If you can't be bothered checking the spec, then don't update all_attrs.)
465 *
466 * If the attribute isn't in either SVG 1.1 or 1.2 then it's probably a mistake
467 * for it not to be in the inkscape namespace. (Not sure about attributes used only
468 * on elements in the inkscape namespace though.)
469 *
470 * In any case, make sure that the attribute's source is documented accordingly.
471 */
472 bool found = false;
473 unsigned const n_ids = ids.size();
474 for (unsigned id = 1; id < n_ids; ++id) {
475 if (!ids[id]) {
476 TS_WARN( std::string((const char*)sp_attribute_name(id)) );
477 found = true;
478 }
479 }
480 TS_ASSERT(!found);
481 }
482 };
484 #endif // SEEN_ATTRIBUTES_TEST_H
486 /*
487 Local Variables:
488 mode:c++
489 c-file-style:"stroustrup"
490 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
491 indent-tabs-mode:nil
492 fill-column:99
493 End:
494 */
495 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :