Debian Codegraph @

tests/test_py_invalid_objs.py

raw symbols SCIP
1 #Needs: fonts/Ambrosia.sfd
2
3 import sys, fontforge
4
5 #### Invalid Glyph Pen ####
6 font=fontforge.open(sys.argv[1])
7 pen = font["A"].glyphPen()
8 font.close()
9
10 # Try to access object after the font was deleted
11 exception_occured = False
12 try:
13 pen.moveTo((100,100))
14 pen.lineTo((100,200))
15 pen = None
16 # The execution shall not reach this line
17 assert(False)
18 except RuntimeError:
19 exception_occured = True
20
21 assert(exception_occured)
22
23 #### Invalid Layer Array ####
24 font2=fontforge.open(sys.argv[1])
25 layers = font2["B"].layers
26 font2.close()
27
28 # Try to access object after the font was deleted
29 exception_occured = False
30 try:
31 new_l = layers[0].dup()
32 # The execution shall not reach this line
33 assert(False)
34 except RuntimeError:
35 exception_occured = True
36
37 assert(exception_occured)
38
39 #### Invalid Layer References Dictionary ####
40 font3 = fontforge.open(sys.argv[1])
41 l_refs = font3["C"].layerrefs
42 font3.close()
43
44 # Try to access object after the font was deleted
45 exception_occured = False
46 try:
47 refs = l_refs["Fore"]
48 # The execution shall not reach this line
49 assert(False)
50 except RuntimeError:
51 exception_occured = True
52
53 assert(exception_occured)
54
55 #### Invalid Math Kerning Data ####
56 font4 = fontforge.open(sys.argv[1])
57 mk_data = font4["D"].mathKern
58 font4.close()
59
60 # Try to access object after the font was deleted
61 exception_occured = False
62 try:
63 bl = mk_data.bottomLeft
64 # The execution shall not reach this line
65 assert(False)
66 except RuntimeError:
67 exception_occured = True
68
69 assert(exception_occured)
70
71 #### Invalid Glyph Object ####
72 font5 = fontforge.open(sys.argv[1])
73 glyph_E = font5["E"]
74 glyph_F = font5["F"]
75 font5.close()
76
77 # Try to access object getter after the font was deleted
78 exception_occured = False
79 try:
80 tti = glyph_E.ttinstrs
81 # The execution shall not reach this line
82 assert(False)
83 except RuntimeError:
84 exception_occured = True
85
86 assert(exception_occured)
87
88 # Try to access object function after the font was deleted
89 exception_occured = False
90 try:
91 glyph_F.correctDirection()
92 # The execution shall not reach this line
93 assert(False)
94 except RuntimeError:
95 exception_occured = True
96
97 assert(exception_occured)
98
99 #### Invalid Layer Info Array ####
100 font6 = fontforge.open(sys.argv[1])
101 layers = font6.layers
102 font6.close()
103
104 # Try to access object after the font was deleted
105 exception_occured = False
106 try:
107 layers.add("new-layer", False)
108 # The execution shall not reach this line
109 assert(False)
110 except RuntimeError:
111 exception_occured = True
112
113 assert(exception_occured)
114
115 #### Invalid Layer Info ####
116 font7 = fontforge.open(sys.argv[1])
117 fore_info = font7.layers["Fore"]
118 font7.close()
119
120 # Try to access object after the font was deleted
121 exception_occured = False
122 try:
123 is_q = fore_info.is_quadratic
124 # The execution shall not reach this line
125 assert(False)
126 except RuntimeError:
127 exception_occured = True
128
129 assert(exception_occured)
130
131 #### Invalid Private Dictionary ####
132 font8 = fontforge.open(sys.argv[1])
133 private = font8.private
134 font8.close()
135
136 # Try to access object after the font was deleted
137 exception_occured = False
138 try:
139 private["BlueValues"] = None
140 # The execution shall not reach this line
141 assert(False)
142 except RuntimeError:
143 exception_occured = True
144
145 assert(exception_occured)
146
147 #### Invalid Selection ####
148 font9 = fontforge.open(sys.argv[1])
149 sel_ref = font9.selection
150 font9.close()
151
152 # Try to access object after the font was deleted
153 exception_occured = False
154 try:
155 sel_ref.select("A", "C", "Z")
156 # The execution shall not reach this line
157 assert(False)
158 except RuntimeError:
159 exception_occured = True
160
161 assert(exception_occured)
162
163 #### Invalid Cvt table ####
164 font10 = fontforge.open(sys.argv[1])
165 cvt = font10.cvt
166 font10.close()
167
168 # Try to access object after the font was deleted
169 exception_occured = False
170 try:
171 cvt += [10, 12]
172 # The execution shall not reach this line
173 assert(False)
174 except RuntimeError:
175 exception_occured = True
176
177 assert(exception_occured)
178
179 #### Invalid Math table ####
180 font11 = fontforge.open(sys.argv[1])
181 math = font11.math
182 font11.close()
183
184 # Try to access object after the font was deleted
185 exception_occured = False
186 try:
187 has = math.exists()
188 # The execution shall not reach this line
189 assert(False)
190 except RuntimeError:
191 exception_occured = True
192
193 assert(exception_occured)
194
195 #### Invalid Math Device table ####
196 font12 = fontforge.open(sys.argv[1])
197 devtable = font12.math.AxisHeightDeviceTable
198 font12.close()
199
200 # Try to access object after the font was deleted
201 exception_occured = False
202 try:
203 devtable[10] = 2
204 # The execution shall not reach this line
205 assert(False)
206 except RuntimeError:
207 exception_occured = True
208
209 assert(exception_occured)