1
2 '''
3 Currently contains W3C XML test suite
4
5 @author: Michael Eddington
6 @version: $Id: Peach.Generators.xmlstuff-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $
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 import re, struct, os
37 from Peach.generator import Generator
38 from Peach.Generators.dictionary import *
39 from Peach.Generators.static import *
40 import Peach.Generators.static
41
43 '''
44 This generator create XML elements N deep
45 '''
46
47 _startingDepth = 1
48 _increment = 1
49 _nodePrefix = Static('PeachFuzz')
50 _nodePostfix = None
51 _elementAttributs = None
52 _currentDepth = 1
53 _maxDepth = 1000
54
55 - def __init__(self, group, startingDepth = None, increment = None,
56 maxDepth = None, nodePrefix = None, nodePostfix = None,
57 elementAttributes = None):
58 '''
59 @type group: Group
60 @param group: Group to use
61 @type startingDepth: integer
62 @param startingDepth: How many deep to start at, default 1
63 @type increment: integer
64 @param increment: Incrementor, default 1
65 @type maxDepth: integer
66 @param maxDepth: Max depth, default 1000
67 @type nodePrefix: Generator
68 @param nodePrefix: Node prefix, default is Static('PeachFuzz')
69 @type nodePostfix: Generator
70 @param nodePostfix: Node postfix, default is None
71 @type elementAttributes: Generator
72 @param elementAttributes: Element attributes, default is None
73 '''
74 self.setGroup(group)
75 if startingDepth != None:
76 self._startingDepth = startingDepth
77 if increment != None:
78 self._increment = increment
79 if nodePrefix != None:
80 self._nodePrefix = nodePrefix
81 if nodePostfix != None:
82 self._nodePostfix = nodePostfix
83 if elementAttributes != None:
84 self._elementAttributes = elementAttributes
85 if maxDepth != None:
86 self._maxDepth = maxDepth
87
92
119
122
124 expected = '<PeachFuzz1><PeachFuzz2><PeachFuzz3></PeachFuzz3></PeachFuzz2></PeachFuzz1>'
125 g = XmlCreateNodes(1, 1)
126 g.next()
127 g.next()
128 g.next()
129 if g.getRawValue() != expected:
130 print "FAILURE!!! XmlCreateNodes"
131
132 unittest = staticmethod(unittest)
133
135 '''
136 This generator create XML nodes N deep
137 '''
138
139 _startingDepth = 1
140 _increment = 1
141 _nodePrefix = Static('PeachFuzz')
142 _currentDepth = 1
143 _maxDepth = 1000
144
145 - def __init__(self, group, startingDepth, increment, maxDepth, nodePrefix):
146 '''
147 @type group: Group
148 @param group: Group to use
149 @type startingDepth: integer
150 @param startingDepth: How many deep to start at, default 1
151 @type increment: integer
152 @param increment: Incrementor, default 1
153 @type maxDepth: integer
154 @param maxDepth: Max depth, default 1000
155 @type nodePrefix: Generator
156 @param nodePrefix: Node prefix, default is Static('PeachFuzz')
157 '''
158 self.setGroup(group)
159 if startingDepth != None:
160 self._startingDepth = startingDepth
161 if increment != None:
162 self._increment = increment
163 if nodePrefix != None:
164 self._nodePrefix = nodePrefix
165 if maxDepth != None:
166 self._maxDepth = maxDepth
167
172
183
186
188 expected = '<PeachFuzz1><PeachFuzz2><PeachFuzz3></PeachFuzz3></PeachFuzz2></PeachFuzz1>'
189 g = XmlCreateNodes(1, 1)
190 g.next()
191 g.next()
192 g.next()
193 if g.getRawValue() != expected:
194 print "FAILURE!!! XmlCreateNodes"
195
196 unittest = staticmethod(unittest)
197
199 '''
200 W3C XML Validation Tests. This includes
201 all sets of tests, invalid, non-well formed, valid and error.
202
203 NOTE: Test files are in samples/xmltests.zip these are the
204 latest test cases from W3C as of 02/23/06 for XML.
205 '''
206
207 - def __init__(self, group, testFiles = None):
222
225
227 self._generatorList.next()
228
231 unittest = staticmethod(unittest)
232
234 '''
235 Base class
236 '''
237
238 - def __init__(self, group, testsFolder, testsFile):
239 '''
240 @type group: Group
241 @param group: Group this Generator belongs to
242 @type testsFolder: string
243 @param testsFolder: Location of test files
244 @type testsFile: string
245 @param testsFile: File with listing of test files
246 '''
247 Generator.__init__(self)
248
249 self._testsFolder = 'xmltests'
250 self._testsFile = 'invalid.txt'
251 self._currentValue = None
252 self._currentTestNum = 1
253 self._currentFilename = None
254 self._fdTests = None
255 self._fd = None
256
257
258 self.setGroup(group)
259 if testsFile != None:
260 self._testsFile = testsFile
261 if testsFolder != None:
262 self._testsFolder = testsFolder
263
264
266 if self._fdTests == None:
267 self._fdTests = open(os.path.join(self._testsFolder, self._testsFile),
268 'rb')
269
270 self._currentFilename = os.path.join(self._testsFolder,
271 self._fdTests.readline())
272 self._currentFilename = self._currentFilename.strip("\r\n")
273 if len(self._currentFilename) <= len(self._testsFolder)+2:
274 raise generator.GeneratorCompleted(
275 "Peach.Generators.xml.XmlParserTestsInvalid")
276
277 if self._fd == None:
278 self._fd = open(self._currentFilename, 'rb')
279 if self._fd == None:
280 raise Exception('Unable to open', self._currentFilename)
281
282 self._currentValue = self._fd.read()
283 self._fd = None
284
290
295
298 unittest = staticmethod(unittest)
299
301 '''
302 W3C XML Validation Tests, invalid set only.
303
304 NOTE: Test files are in samples/xmltests.zip these are the
305 latest test cases from W3C as of 02/23/06 for XML.
306 '''
307
308 - def __init__(self, group, testsFolder):
309 '''
310 @type group: Group
311 @param group: Group this Generator belongs to
312 @type testsFolder: string
313 @param testsFolder: Location of test files
314 '''
315 XmlParserTestsGeneric.__init__(self, group, testsFolder, None)
316 self.setGroup(group)
317 self._testsFile = 'valid.txt'
318 if testsFolder != None:
319 self._testsFolder = testsFolder
320
322 '''
323 W3C XML Validation Tests, valid set only.
324
325 NOTE: Test files are in samples/xmltests.zip these are the
326 latest test cases from W3C as of 02/23/06 for XML.
327 '''
328
329 - def __init__(self, group, testsFolder):
330 '''
331 @type group: Group
332 @param group: Group this Generator belongs to
333 @type testsFolder: string
334 @param testsFolder: Location of test files
335 '''
336 XmlParserTestsGeneric.__init__(self, group, testsFolder, None)
337 self.setGroup(group)
338 self._testsFile = 'valid.txt'
339 if testsFolder != None:
340 self._testsFolder = testsFolder
341
343 '''
344 W3C XML Validation Tests, error set only.
345
346 NOTE: Test files are in samples/xmltests.zip these are the
347 latest test cases from W3C as of 02/23/06 for XML.
348 '''
349
350 - def __init__(self, group, testsFolder):
351 '''
352 @type group: Group
353 @param group: Group this Generator belongs to
354 @type testsFolder: string
355 @param testsFolder: Location of test files
356 '''
357 XmlParserTestsGeneric.__init__(self, group, testsFolder, None)
358 self.setGroup(group)
359 self._testsFile = 'error.txt'
360 if testsFolder != None:
361 self._testsFolder = testsFolder
362
383
384
385