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", false},
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", false},
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", false},
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", false},
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", false},
225 {"pointsAtY", false},
226 {"pointsAtZ", false},
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", false},
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", false},
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-bbox", true},
345 {"inkscape:object-points", true},*/
346 {"inkscape:object-paths", true},
347 {"inkscape:object-nodes", true},
348 {"inkscape:pageopacity", true},
349 {"inkscape:pageshadow", true},
350 {"inkscape:transform-center-x", true},
351 {"inkscape:transform-center-y", true},
352 {"inkscape:zoom", true},
353 {"inkscape:cx", true},
354 {"inkscape:cy", true},
355 {"inkscape:window-width", true},
356 {"inkscape:window-height", true},
357 {"inkscape:window-x", true},
358 {"inkscape:window-y", true},
359 /* {"inkscape:grid-bbox", true},
360 {"inkscape:guide-bbox", true},
361 {"inkscape:grid-points", true},
362 {"inkscape:guide-points", true},*/
363 {"inkscape:current-layer", true},
364 {"inkscape:connector-type", true},
365 {"inkscape:connection-start", true},
366 {"inkscape:connection-end", true},
367 {"inkscape:connector-avoid", true},
368 {"inkscape:connector-spacing", true},
369 {"sodipodi:cx", true},
370 {"sodipodi:cy", true},
371 {"sodipodi:rx", true},
372 {"sodipodi:ry", true},
373 {"sodipodi:start", true},
374 {"sodipodi:end", true},
375 {"sodipodi:open", true},
376 {"sodipodi:sides", true},
377 {"sodipodi:r1", true},
378 {"sodipodi:r2", true},
379 {"sodipodi:arg1", true},
380 {"sodipodi:arg2", true},
381 {"inkscape:flatsided", true},
382 {"inkscape:rounded", true},
383 {"inkscape:randomized", true},
384 {"sodipodi:expansion", true},
385 {"sodipodi:revolution", true},
386 {"sodipodi:radius", true},
387 {"sodipodi:argument", true},
388 {"sodipodi:t0", true},
389 {"sodipodi:original", true},
390 {"inkscape:original", true},
391 {"inkscape:href", true},
392 {"inkscape:radius", true},
393 {"sodipodi:role", true},
394 {"sodipodi:linespacing", true},
395 {"inkscape:srcNoMarkup", true},
396 {"inkscape:srcPango", true},
397 {"inkscape:dstShape", true},
398 {"inkscape:dstPath", true},
399 {"inkscape:dstBox", true},
400 {"inkscape:dstColumn", true},
401 {"inkscape:excludeShape", true},
402 {"inkscape:layoutOptions", true},
404 /* SPNamedView */
405 {"viewonly", true},
406 {"showgrid", true},
407 {"gridtype", true},
408 {"showguides", true},
409 {"gridtolerance", true},
410 {"guidetolerance", true},
411 {"objecttolerance", true},
412 {"gridoriginx", true},
413 {"gridoriginy", true},
414 {"gridspacingx", true},
415 {"gridspacingy", true},
416 {"gridanglex", true},
417 {"gridanglez", true},
418 {"gridcolor", true},
419 {"gridopacity", true},
420 {"gridempcolor", true},
421 {"gridempopacity", true},
422 {"gridempspacing", true},
423 {"guidecolor", true},
424 {"guideopacity", true},
425 {"guidehicolor", true},
426 {"guidehiopacity", true},
427 {"showborder", true},
428 {"inkscape:showpageshadow", true},
429 {"borderlayer", true},
430 {"bordercolor", true},
431 {"borderopacity", true},
432 {"pagecolor", true},
434 /* SPGuide */
435 {"position", true}
437 };
441 std::vector<bool> ids;
442 ids.reserve(256);
444 for (unsigned i = 0; i < G_N_ELEMENTS(all_attrs); ++i) {
445 char const *const attr_str = all_attrs[i].attr;
446 unsigned const id = sp_attribute_lookup(attr_str);
447 bool const recognized(id);
448 TSM_ASSERT_EQUALS( std::string(all_attrs[i].attr), recognized, all_attrs[i].supported );
449 if (recognized) {
450 if (ids.size() <= id) {
451 ids.resize(id + 1);
452 }
453 TS_ASSERT(!ids[id]);
454 ids[id] = true;
456 unsigned char const *reverse_ustr = sp_attribute_name(id);
457 char const *reverse_str = reinterpret_cast<char const *>(reverse_ustr);
458 TS_ASSERT(streq(reverse_str, attr_str));
459 }
460 }
462 /* Test for any attributes that this test program doesn't know about.
463 *
464 * If any are found, then:
465 *
466 * If it is in the `inkscape:' namespace then simply add it to all_attrs with
467 * `true' as the second field (`supported').
468 *
469 * If it is in the `sodipodi:' namespace then check the spelling against sodipodi
470 * sources. If you don't have sodipodi sources, then don't add it: leave to someone
471 * else.
472 *
473 * Otherwise, it's probably a bug: ~all SVG 1.1 attributes should already be
474 * in the all_attrs table. However, the comment above all_attrs does mention
475 * some things missing from attindex.html, so there may be more. Check the SVG
476 * spec. Another possibility is that the attribute is new in SVG 1.2. In this case,
477 * check the spelling against the [draft] SVG 1.2 spec before adding to all_attrs.
478 * (If you can't be bothered checking the spec, then don't update all_attrs.)
479 *
480 * If the attribute isn't in either SVG 1.1 or 1.2 then it's probably a mistake
481 * for it not to be in the inkscape namespace. (Not sure about attributes used only
482 * on elements in the inkscape namespace though.)
483 *
484 * In any case, make sure that the attribute's source is documented accordingly.
485 */
486 bool found = false;
487 unsigned const n_ids = ids.size();
488 for (unsigned id = 1; id < n_ids; ++id) {
489 if (!ids[id]) {
490 gchar* tmp = g_strdup_printf( "Attribute string with enum %d {%s} not handled", id, sp_attribute_name(id) );
491 TS_WARN( std::string((const char*)tmp) );
492 g_free( tmp );
493 found = true;
494 }
495 }
496 TS_ASSERT(!found);
498 for ( guint index = 1; index < n_ids; index++ ) {
499 guchar const* name = sp_attribute_name(index);
500 gint postLookup = sp_attribute_lookup( reinterpret_cast<gchar const*>(name) );
501 TSM_ASSERT_EQUALS( std::string("Enum round-trip through string {") + (char const*)name + "} failed.", index, postLookup );
502 }
504 }
505 };
507 #endif // SEEN_ATTRIBUTES_TEST_H
509 /*
510 Local Variables:
511 mode:c++
512 c-file-style:"stroustrup"
513 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
514 indent-tabs-mode:nil
515 fill-column:99
516 End:
517 */
518 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :