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