/
UserAgentTestCaseGenerator.py
3003 lines (2365 loc) · 76.7 KB
/
UserAgentTestCaseGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This script generates the User Agent test cases. It will create a directory
one level up from the directory containing this script called "UserAgent".
That directory will have the structure:
/UserAgent
README.txt - information about how the tests were generated and how they should be modified
/FontsToInstall
fonts that must be installed locally
/Tests
testcaseindex.xht - index of all test cases
test-case-name-number.xht - individual test case
test-case-name-number-ref - reference that uses locally installed fonts for rendering comparison
/resources
index.css - index CSS file
test-case-name-number.woff - individual WOFF test case
The individual test cases follow the CSS Test Format
(http://wiki.csswg.org/test/css2.1/format).
Within this script, each test case is generated with a call to the
writeFileStructureTest function or the writeMetadataSchemaValidityTest
function. In these, WOFF data must be passed along with details about
the data. This function will generate the WOFF and HTML files and
it will register the case in the suite index.
"""
import os
import shutil
import glob
from testCaseGeneratorLib.woff import packTestHeader, packTestDirectory, packTestTableData, packTestMetadata, packTestPrivateData
from testCaseGeneratorLib.defaultData import defaultTestData, testDataWOFFMetadata, testDataWOFFPrivateData
from testCaseGeneratorLib.html import generateSFNTDisplayTestHTML, generateSFNTDisplayRefHTML, generateSFNTDisplayIndexHTML
from testCaseGeneratorLib.paths import resourcesDirectory, userAgentDirectory, userAgentTestDirectory, userAgentTestResourcesDirectory, userAgentFontsToInstallDirectory
from testCaseGeneratorLib import sharedCases
from testCaseGeneratorLib.sharedCases import *
# ------------------------
# Specification URL
# This is used frequently.
# ------------------------
specificationURL = "http://dev.w3.org/webfonts/WOFF/spec/"
# ------------------
# Directory Creation
# (if needed)
# ------------------
if not os.path.exists(userAgentDirectory):
os.mkdir(userAgentDirectory)
if not os.path.exists(userAgentTestDirectory):
os.mkdir(userAgentTestDirectory)
if not os.path.exists(userAgentTestResourcesDirectory):
os.mkdir(userAgentTestResourcesDirectory)
# ---------------------
# Move Fonts To Install
# ---------------------
if not os.path.exists(userAgentFontsToInstallDirectory):
os.mkdir(userAgentFontsToInstallDirectory)
# CFF Reference
destPath = os.path.join(userAgentFontsToInstallDirectory, "SFNT-CFF-Reference.otf")
if os.path.exists(destPath):
os.remove(destPath)
shutil.copy(os.path.join(resourcesDirectory, "SFNT-CFF-Reference.otf"), os.path.join(destPath))
# CFF Fallback
destPath = os.path.join(userAgentFontsToInstallDirectory, "SFNT-CFF-Fallback.otf")
if os.path.exists(destPath):
os.remove(destPath)
shutil.copy(os.path.join(resourcesDirectory, "SFNT-CFF-Fallback.otf"), os.path.join(destPath))
# TTF Reference
destPath = os.path.join(userAgentFontsToInstallDirectory, "SFNT-TTF-Reference.ttf")
if os.path.exists(destPath):
os.remove(destPath)
shutil.copy(os.path.join(resourcesDirectory, "SFNT-TTF-Reference.ttf"), os.path.join(destPath))
# TTF Fallback
destPath = os.path.join(userAgentFontsToInstallDirectory, "SFNT-TTF-Fallback.ttf")
if os.path.exists(destPath):
os.remove(destPath)
shutil.copy(os.path.join(resourcesDirectory, "SFNT-TTF-Fallback.ttf"), os.path.join(destPath))
# -------------------
# Move HTML Resources
# -------------------
# index css
destPath = os.path.join(userAgentTestResourcesDirectory, "index.css")
if os.path.exists(destPath):
os.remove(destPath)
shutil.copy(os.path.join(resourcesDirectory, "index.css"), destPath)
# ---------------
# Test Case Index
# ---------------
# As the tests are generated a log will be kept.
# This log will be translated into an index after
# all of the tests have been written.
groupDefinitions = [
# identifier, title, spec section
("valid", "Valid WOFFs", specificationURL+"#OverallStructure"),
("header", "WOFF Header Tests", specificationURL+"#WOFFHeader"),
("blocks", "WOFF Data Block Tests", specificationURL+"#OverallStructure"),
("directory", "WOFF Table Directory Tests", specificationURL+"#TableDirectory"),
("tabledata", "WOFF Table Data Tests", specificationURL+"#DataTables"),
("metadata", "WOFF Metadata Tests", specificationURL+"#Metadata"),
("privatedata", "WOFF Private Data Tests", specificationURL+"#Private"),
("metadatadisplay", "WOFF Metadata Display Tests", specificationURL+"#Metadata"),
("available", "Availability", specificationURL+"#conform-css3font-available"),
]
testRegistry = {}
for group in groupDefinitions:
tag = group[0]
testRegistry[tag] = []
groupChapterURLs = {}
for tag, title, url in groupDefinitions:
groupChapterURLs[tag] = "#" + url.split("#")[-1]
# ---------------
# File Generators
# ---------------
registeredIdentifiers = set()
registeredTitles = set()
registeredAssertions = set()
def writeFileStructureTest(identifier, flavor="CFF",
title=None, assertion=None,
sfntDisplaySpecLink=None, metadataDisplaySpecLink=None,
credits=[], flags=[],
shouldDisplaySFNT=None, metadataIsValid=None,
data=None, metadataToDisplay=None,
extraSFNTNotes=[], extraMetadataNotes=[]
):
"""
This function generates all of the files needed by a test case and
registers the case with the suite. The arguments:
identifier: The identifier for the test case. The identifier must be
a - separated sequence of group name (from the groupDefinitions
listed above), test case description (arbitrary length) and a number
to make the name unique. The number should be zero padded to a length
of three characters (ie "001" instead of "1").
flavor: The flavor of the WOFF data. The options are CFF or TTF.
title: A thorough, but not too long, title for the test case.
assertion: A detailed statement about what the test case is proving.
sfntDisplaySpecLink: A space separated list of anchors in the WOFF spec
that the test case is testing. This anchor should only reference the
SFNT display conformance.
metadataDisplaySpecLink: The anchor in the WOFF spec that the test case
is testing. This anchor should only reference the metadata display conformance.
credits: A list of dictionaries defining the credits for the test case. The
dictionaries must have this form:
title="Name of the autor or reviewer",
role="author or reviewer",
link="mailto:email or http://contactpage"
flags: A list of requirement flags. The options are defined in the
CSS Test Format specification.
shouldDisplaySFNT: A boolean indicating if the SFNT should be used for display or not.
metadataIsValid: A boolean indicating if the metadata is valid.
data: The complete binary data for the WOFF.
metadataToDisplay: A string of metadata to display in the HTML. This should
be set when the metadata is valid.
extraSFNTNotes: Additional notes about the SFNT data that should be
displayed in the HTML.
extraMetadataNotes: Additional notes about the metadata that should be
displayed in the HTML.
"""
print "Compiling %s..." % identifier
assert identifier not in registeredIdentifiers, "Duplicate identifier! %s" % identifier
assert title not in registeredTitles, "Duplicate title! %s" % title
assert assertion not in registeredAssertions, "Duplicate assertion! %s" % assertion
registeredIdentifiers.add(identifier)
registeredTitles.add(title)
registeredAssertions.add(assertion)
if sfntDisplaySpecLink is None:
sfntDisplaySpecLink = ""
sfntDisplaySpecLink = [specificationURL + i for i in sfntDisplaySpecLink.split(" ")]
if metadataDisplaySpecLink is not None:
metadataDisplaySpecLink = specificationURL + metadataDisplaySpecLink
flags = list(flags)
flags += ["font"] # fonts must be installed for all of these tests
tag = identifier.split("-")[0]
# generate the WOFF
woffPath = os.path.join(userAgentTestResourcesDirectory, identifier) + ".woff"
f = open(woffPath, "wb")
f.write(data)
f.close()
# generate the test and ref html
kwargs = dict(
fileName=identifier,
directory=userAgentTestDirectory,
flavor=flavor,
title=title,
sfntDisplaySpecLink=sfntDisplaySpecLink,
metadataDisplaySpecLink=metadataDisplaySpecLink,
assertion=assertion,
credits=credits,
flags=flags,
shouldDisplay=shouldDisplaySFNT,
metadataIsValid=metadataIsValid,
metadataToDisplay=metadataToDisplay,
extraSFNTNotes=extraSFNTNotes,
extraMetadataNotes=extraMetadataNotes,
chapterURL=groupChapterURLs[tag]
)
generateSFNTDisplayTestHTML(**kwargs)
generateSFNTDisplayRefHTML(**kwargs)
# register the test
testRegistry[tag].append(
dict(
identifier=identifier,
flags=flags,
title=title,
assertion=assertion,
sfntExpectation=shouldDisplaySFNT,
sfntURL=sfntDisplaySpecLink,
metadataURL=metadataDisplaySpecLink,
metadataExpectation=metadataIsValid,
credits=credits,
hasReferenceRendering=True
)
)
def writeMetadataSchemaValidityTest(identifier,
title=None,
assertion=None,
credits=[],
sfntDisplaySpecLink=None,
metadataDisplaySpecLink=None,
metadataIsValid=None,
metadata=None):
"""
This is a convenience functon that eliminates the need to
make a complete WOFF when only the metadata is being tested.
Refer to the writeFileStructureTest documentation for
the meaning of the various arguments.
"""
# dynamically get some data from the shared cases as needed
if title is None:
assert assertion is None
assert metadata is None
parts = identifier.split("-")
assert parts[0] == "metadatadisplay"
number = int(parts[-1])
group = parts[1:-1]
group = [i.title() for i in group]
group = "".join(group)
importBase = "metadata" + group + str(number)
title = getattr(sharedCases, importBase + "Title")
assertion = getattr(sharedCases, importBase + "Description")
credits = getattr(sharedCases, importBase + "Credits")
metadata = getattr(sharedCases, importBase + "Metadata")
assert metadata is not None
assert metadataIsValid is not None
# compile the WOFF
data, metadata = makeMetadataTest(metadata)
# pass to the more verbose function
if metadataDisplaySpecLink is None:
if not metadataIsValid:
metadataDisplaySpecLink = "#conform-invalid-mustignore"
else:
metadataDisplaySpecLink = "#Metadata"
if sfntDisplaySpecLink is None:
sfntDisplaySpecLink = "#conform-metadata-noeffect"
kwargs = dict(
title=title,
assertion=assertion,
credits=credits,
sfntDisplaySpecLink=sfntDisplaySpecLink,
metadataDisplaySpecLink=metadataDisplaySpecLink,
shouldDisplaySFNT=True,
metadataIsValid=metadataIsValid,
data=data
)
if metadataIsValid:
kwargs["metadataToDisplay"] = metadata
writeFileStructureTest(
identifier,
**kwargs
)
# -----------
# Valid Files
# -----------
# CFF
writeFileStructureTest(
identifier="valid-001",
title=makeValidWOFF1Title,
assertion=makeValidWOFF1Description,
credits=makeValidWOFF1Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF1()
)
writeFileStructureTest(
identifier="valid-002",
title=makeValidWOFF2Title,
assertion=makeValidWOFF2Description,
credits=makeValidWOFF2Credits,
shouldDisplaySFNT=True,
metadataIsValid=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF2(),
metadataToDisplay=testDataWOFFMetadata,
metadataDisplaySpecLink="#conform-metadata-maydisplay"
)
writeFileStructureTest(
identifier="valid-003",
title=makeValidWOFF3Title,
assertion=makeValidWOFF3Description,
credits=makeValidWOFF3Credits,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
shouldDisplaySFNT=True,
data=makeValidWOFF3()
)
writeFileStructureTest(
identifier="valid-004",
title=makeValidWOFF4Title,
assertion=makeValidWOFF4Description,
credits=makeValidWOFF4Credits,
shouldDisplaySFNT=True,
metadataIsValid=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF4(),
metadataToDisplay=testDataWOFFMetadata,
metadataDisplaySpecLink="#conform-metadata-maydisplay"
)
# TTF
writeFileStructureTest(
identifier="valid-005",
flavor="TTF",
title=makeValidWOFF5Title,
assertion=makeValidWOFF5Description,
credits=makeValidWOFF5Credits,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
shouldDisplaySFNT=True,
data=makeValidWOFF5()
)
writeFileStructureTest(
identifier="valid-006",
flavor="TTF",
title=makeValidWOFF6Title,
assertion=makeValidWOFF6Description,
credits=makeValidWOFF6Credits,
shouldDisplaySFNT=True,
metadataIsValid=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF6(),
metadataToDisplay=testDataWOFFMetadata,
metadataDisplaySpecLink="#conform-metadata-maydisplay"
)
writeFileStructureTest(
identifier="valid-007",
flavor="TTF",
title=makeValidWOFF7Title,
assertion=makeValidWOFF7Description,
credits=makeValidWOFF7Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF7()
)
writeFileStructureTest(
identifier="valid-008",
flavor="TTF",
title=makeValidWOFF8Title,
assertion=makeValidWOFF8Description,
credits=makeValidWOFF8Credits,
shouldDisplaySFNT=True,
metadataIsValid=True,
sfntDisplaySpecLink="#conform-metadata-noeffect #conform-private-noeffect",
data=makeValidWOFF8(),
metadataToDisplay=testDataWOFFMetadata,
metadataDisplaySpecLink="#conform-metadata-maydisplay"
)
# ---------------------------------
# File Structure: Header: signature
# ---------------------------------
writeFileStructureTest(
identifier="header-signature-001",
title=makeHeaderInvalidSignature1Title,
assertion=makeHeaderInvalidSignature1Description,
credits=makeHeaderInvalidSignature1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-nomagicnumber-reject",
data=makeHeaderInvalidSignature1()
)
# ------------------------------
# File Structure: Header: length
# ------------------------------
writeFileStructureTest(
identifier="header-length-001",
title=makeHeaderInvalidLength1Title,
assertion=makeHeaderInvalidLength1Description,
credits=makeHeaderInvalidLength1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#WOFFHeader",
data=makeHeaderInvalidLength1()
)
writeFileStructureTest(
identifier="header-length-002",
title=makeHeaderInvalidLength2Title,
assertion=makeHeaderInvalidLength2Description,
credits=makeHeaderInvalidLength2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#WOFFHeader",
data=makeHeaderInvalidLength2()
)
# ---------------------------------
# File Structure: Header: numTables
# ---------------------------------
writeFileStructureTest(
identifier="header-numTables-001",
title=makeHeaderInvalidNumTables1Title,
assertion=makeHeaderInvalidNumTables1Description,
credits=makeHeaderInvalidNumTables1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#WOFFHeader",
data=makeHeaderInvalidNumTables1()
)
# -------------------------------------
# File Structure: Header: totalSfntSize
# -------------------------------------
writeFileStructureTest(
identifier="header-totalSfntSize-001",
title=makeHeaderInvalidTotalSfntSize1Title,
assertion=makeHeaderInvalidTotalSfntSize1Description,
credits=makeHeaderInvalidTotalSfntSize1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-totalsize-longword-reject",
data=makeHeaderInvalidTotalSfntSize1()
)
writeFileStructureTest(
identifier="header-totalSfntSize-002",
title=makeHeaderInvalidTotalSfntSize2Title,
assertion=makeHeaderInvalidTotalSfntSize2Description,
credits=makeHeaderInvalidTotalSfntSize2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-totalsize-longword-reject",
data=makeHeaderInvalidTotalSfntSize2()
)
writeFileStructureTest(
identifier="header-totalSfntSize-003",
title=makeHeaderInvalidTotalSfntSize3Title,
assertion=makeHeaderInvalidTotalSfntSize3Description,
credits=makeHeaderInvalidTotalSfntSize3Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-totalsize-longword-reject",
data=makeHeaderInvalidTotalSfntSize3()
)
# --------------------------------
# File Structure: Header: reserved
# --------------------------------
writeFileStructureTest(
identifier="header-reserved-001",
title=makeHeaderInvalidReserved1Title,
assertion=makeHeaderInvalidReserved1Description,
credits=makeHeaderInvalidReserved1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-reserved-reject",
data=makeHeaderInvalidReserved1()
)
# --------------------------------------------
# File Structure: Data Blocks: Extraneous Data
# --------------------------------------------
# between table directory and table data
writeFileStructureTest(
identifier="blocks-extraneous-data-001",
title=makeExtraneousData1Title,
assertion=makeExtraneousData1Description,
credits=makeExtraneousData1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData1()
)
# after table data with no metadata or private data
writeFileStructureTest(
identifier="blocks-extraneous-data-002",
title=makeExtraneousData2Title,
assertion=makeExtraneousData2Description,
credits=makeExtraneousData2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData2()
)
# between tabledata and metadata
writeFileStructureTest(
identifier="blocks-extraneous-data-003",
title=makeExtraneousData3Title,
assertion=makeExtraneousData3Description,
credits=makeExtraneousData3Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData3()
)
# between tabledata and private data
writeFileStructureTest(
identifier="blocks-extraneous-data-004",
title=makeExtraneousData4Title,
assertion=makeExtraneousData4Description,
credits=makeExtraneousData4Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData4()
)
# between metadata and private data
writeFileStructureTest(
identifier="blocks-extraneous-data-005",
title=makeExtraneousData5Title,
assertion=makeExtraneousData5Description,
credits=makeExtraneousData5Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData5()
)
# after metadata with no private data
writeFileStructureTest(
identifier="blocks-extraneous-data-006",
title=makeExtraneousData6Title,
assertion=makeExtraneousData6Description,
credits=makeExtraneousData6Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData6()
)
# after private data
writeFileStructureTest(
identifier="blocks-extraneous-data-007",
title=makeExtraneousData7Title,
assertion=makeExtraneousData7Description,
credits=makeExtraneousData7Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeExtraneousData7()
)
# -------------------------------------
# File Structure: Data Blocks: Overlaps
# -------------------------------------
# metadata overlaps the table data
writeFileStructureTest(
identifier="blocks-overlap-001",
title=makeOverlappingData1Title,
assertion=makeOverlappingData1Description,
credits=makeOverlappingData1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-overlap-reject",
data=makeOverlappingData1()
)
# private data overlaps the table data
writeFileStructureTest(
identifier="blocks-overlap-002",
title=makeOverlappingData2Title,
assertion=makeOverlappingData2Description,
credits=makeOverlappingData2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-overlap-reject",
data=makeOverlappingData2()
)
# private data overlaps the metadata
writeFileStructureTest(
identifier="blocks-overlap-003",
title=makeOverlappingData3Title,
assertion=makeOverlappingData3Description,
credits=makeOverlappingData3Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-overlap-reject",
data=makeOverlappingData3()
)
# ------------------------------------------------
# File Structure: Table Directory: 4-Byte Boundary
# ------------------------------------------------
writeFileStructureTest(
identifier="directory-4-byte-001",
title=makeTableData4Byte1Title,
assertion=makeTableData4Byte1Description,
credits=makeTableData4Byte1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-tablesize-longword",
data=makeTableData4Byte1()
)
# final table is not padded
writeFileStructureTest(
identifier="directory-4-byte-002",
title=makeTableData4Byte2Title,
assertion=makeTableData4Byte2Description,
credits=makeTableData4Byte2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-tablesize-longword",
data=makeTableData4Byte2()
)
# -----------------------------------------
# File Structure: Table Directory: Overlaps
# -----------------------------------------
# offset after end of file
writeFileStructureTest(
identifier="directory-overlaps-001",
title=makeTableDataByteRange1Title,
assertion=makeTableDataByteRange1Description,
credits=makeTableDataByteRange1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-diroverlap-reject",
data=makeTableDataByteRange1()
)
# offset + length goes past the end of the file
writeFileStructureTest(
identifier="directory-overlaps-002",
title=makeTableDataByteRange2Title,
assertion=makeTableDataByteRange2Description,
credits=makeTableDataByteRange2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-diroverlap-reject",
data=makeTableDataByteRange2()
)
# overlaps metadata
writeFileStructureTest(
identifier="directory-overlaps-003",
title=makeTableDataByteRange3Title,
assertion=makeTableDataByteRange3Description,
credits=makeTableDataByteRange3Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-diroverlap-reject",
data=makeTableDataByteRange3()
)
# overlaps private data
writeFileStructureTest(
identifier="directory-overlaps-004",
title=makeTableDataByteRange4Title,
assertion=makeTableDataByteRange4Description,
credits=makeTableDataByteRange4Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-diroverlap-reject",
data=makeTableDataByteRange4()
)
# two tables overlap
writeFileStructureTest(
identifier="directory-overlaps-005",
title=makeTableDataByteRange5Title,
assertion=makeTableDataByteRange5Description,
credits=makeTableDataByteRange5Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-diroverlap-reject",
data=makeTableDataByteRange5()
)
# ------------------------------------------------
# File Structure: Table Directory: Extraneous Data
# ------------------------------------------------
# between tables
writeFileStructureTest(
identifier="directory-extraneous-data-001",
title=makeTableDataExtraneousData1Title,
assertion=makeTableDataExtraneousData1Description,
credits=makeTableDataExtraneousData1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-extraneous-reject",
data=makeTableDataExtraneousData1()
)
# -------------------------------------------
# File Structure: Table Directory: compLength
# -------------------------------------------
# some tables have a compressed length that is longer than the original length
writeFileStructureTest(
identifier="directory-compLength-001",
title=makeTableDataCompressionLength1Title,
assertion=makeTableDataCompressionLength1Description,
credits=makeTableDataCompressionLength1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-compressedlarger",
data=makeTableDataCompressionLength1()
)
# -------------------------------------------
# File Structure: Table Directory: origLength
# -------------------------------------------
# one table has an origLength that is less than the decompressed length
writeFileStructureTest(
identifier="directory-origLength-001",
title=makeTableDataOriginalLength1Title,
assertion=makeTableDataOriginalLength1Description,
credits=makeTableDataOriginalLength1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-origLength",
data=makeTableDataOriginalLength1()
)
# one table has an origLength that is greater than the decompressed length
writeFileStructureTest(
identifier="directory-origLength-002",
title=makeTableDataOriginalLength2Title,
assertion=makeTableDataOriginalLength2Description,
credits=makeTableDataOriginalLength2Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-origLength",
data=makeTableDataOriginalLength2()
)
# ---------------------------------------
# File Structure: Table Data: Compression
# ---------------------------------------
# no tables compressed
writeFileStructureTest(
identifier="tabledata-compression-001",
title=makeTableCompressionTest1Title,
assertion=makeTableCompressionTest1Description,
credits=makeTableCompressionTest1Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-mustuncompress",
data=makeTableCompressionTest1()
)
# all possible tables are compressed
writeFileStructureTest(
identifier="tabledata-compression-002",
title=makeTableCompressionTest2Title,
assertion=makeTableCompressionTest2Description,
credits=makeTableCompressionTest2Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-mustuncompress",
data=makeTableCompressionTest2()
)
# not all possible tables are compressed
writeFileStructureTest(
identifier="tabledata-compression-003",
title=makeTableCompressionTest3Title,
assertion=makeTableCompressionTest3Description,
credits=makeTableCompressionTest3Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-mustuncompress",
data=makeTableCompressionTest3()
)
# varying compression levels
writeFileStructureTest(
identifier="tabledata-compression-004",
title=makeTableCompressionTest4Title,
assertion=makeTableCompressionTest4Description,
credits=makeTableCompressionTest4Credits,
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-mustuncompress",
data=makeTableCompressionTest4()
)
# ----------------------------------------------
# File Structure: Table Data: Compression Format
# ----------------------------------------------
# compression incompatible with zlib
writeFileStructureTest(
identifier="tabledata-zlib-001",
title=makeTableZlibCompressionTest1Title,
assertion=makeTableZlibCompressionTest1Description,
credits=makeTableZlibCompressionTest1Credits,
shouldDisplaySFNT=False,
sfntDisplaySpecLink="#conform-decompressfailure",
data=makeTableZlibCompressionTest1()
)
# -----------------------------------
# File Structure: Metadata: No Effect
# -----------------------------------
# have no metadata
def makeMetadataNoEffect1():
header, directory, tableData = defaultTestData()
data = packTestHeader(header) + packTestDirectory(directory) + packTestTableData(directory, tableData)
return data
writeFileStructureTest(
identifier="metadata-noeffect-001",
title="No Metadata Present",
assertion="The file has no metadata.",
credits=[dict(title="Tal Leming", role="author", link="http://typesupply.com")],
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-metadata-noeffect",
data=makeMetadataNoEffect1()
)
# have metadata
def makeMetadataNoEffect2():
header, directory, tableData, metadata = defaultTestData(metadata=testDataWOFFMetadata)
data = packTestHeader(header) + packTestDirectory(directory) + packTestTableData(directory, tableData) + packTestMetadata(metadata)
return data
writeFileStructureTest(
identifier="metadata-noeffect-002",
title="Metadata Present",
assertion="The file has metadata.",
credits=[dict(title="Tal Leming", role="author", link="http://typesupply.com")],
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-metadata-noeffect",
metadataIsValid=True,
metadataDisplaySpecLink="#conform-metadata-maydisplay",
data=makeMetadataNoEffect2()
)
# ---------------------------------------
# File Structure: Private Data: No Effect
# ---------------------------------------
# have no private data
def makePrivateDataNoEffect1():
header, directory, tableData = defaultTestData()
data = packTestHeader(header) + packTestDirectory(directory) + packTestTableData(directory, tableData)
return data
writeFileStructureTest(
identifier="privatedata-noeffect-001",
title="No Private Data Present",
assertion="The file has no private data.",
credits=[dict(title="Tal Leming", role="author", link="http://typesupply.com")],
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-private-noeffect",
data=makePrivateDataNoEffect1()
)
# have private data
def makePrivateDataNoEffect2():
header, directory, tableData, privateData = defaultTestData(privateData=testDataWOFFPrivateData)
data = packTestHeader(header) + packTestDirectory(directory) + packTestTableData(directory, tableData) + packTestPrivateData(privateData)
return data
writeFileStructureTest(
identifier="privatedata-noeffect-002",
title="Private Data Present",
assertion="The file has private data.",
credits=[dict(title="Tal Leming", role="author", link="http://typesupply.com")],
shouldDisplaySFNT=True,
sfntDisplaySpecLink="#conform-private-noeffect",
data=makePrivateDataNoEffect2()
)
# -------------------------------
# Metadata Display: Authoritative
# -------------------------------
metadataAuthoritativeXML = """
<?xml version="1.0" encoding="UTF-8"?>
<metadata version="1.0">
<uniqueid id="PASS" />
<description>
<text>
PASS
</text>
</description>
<copyright>
<text>
PASS
</text>
</copyright>
<trademark>
<text>
PASS
</text>
</trademark>
<vendor name="PASS" url="PASS" />
<credits>
<credit name="PASS" url="PASS" />
</credits>
<license url="PASS">
<text>
PASS
</text>
</license>
</metadata>
""".strip().replace(" ", "\t")
def makeMetadataAuthoritativeTest1():
from cStringIO import StringIO
from fontTools.ttLib import TTFont
from fontTools.ttLib.tables._n_a_m_e import NameRecord
from testCaseGeneratorLib.paths import sfntCFFSourcePath
from testCaseGeneratorLib.sfnt import getSFNTData
from testCaseGeneratorLib.defaultData import sfntCFFTableOrder
setToFAIL = [
0, # copyright
3, # unique id
7, # trademark
8, # manufacturer
9, # designer
10, # description
11, # vendor url
12, # designer url
13, # license
14 # license url
]
# open the SFNT
font = TTFont(sfntCFFSourcePath)
# overwrite parts of the name table that overlap the metadata
nameTable = font["name"]
newNames = []
for record in nameTable.names:
if record.nameID in setToFAIL:
continue
newNames.append(record)