~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/attributes-test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-07-06 22:03:02 UTC
  • mto: (2.4.1 sid) (1.4.1 upstream) (45.1.3 maverick)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20060706220302-itgso3qgxdaxjmcy
Tags: upstream-0.44
ImportĀ upstreamĀ versionĀ 0.44

Show diffs side-by-side

added added

removed removed

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