6 sys.path.insert(0, "python")
15 # the testsuite description
17 CONF="xml-test-suite/xmlconf/xmlconf.xml"
18 LOG="check-xml-test-suite.log"
23 # Error and warning handlers
27 def errorHandler(ctx, str):
31 error_nr = error_nr + 1
32 if len(error_msg) < 300:
33 if len(error_msg) == 0 or error_msg[-1] == '\n':
34 error_msg = error_msg + " >>" + str
36 error_msg = error_msg + str
38 libxml2.registerErrorHandler(errorHandler, None)
42 #def warningHandler(ctx, str):
46 # warning_nr = warning_nr + 1
47 # warning = warning + str
49 #libxml2.registerWarningHandler(warningHandler, None)
52 # Used to load the XML testsuite description
54 def loadNoentDoc(filename):
55 ctxt = libxml2.createFileParserCtxt(filename)
58 ctxt.replaceEntities(1)
64 if ctxt.wellFormed() != 1:
70 # The conformance testing routines
73 def testNotWf(filename, id):
81 ctxt = libxml2.createFileParserCtxt(filename)
84 ret = ctxt.parseDocument()
92 if ret == 0 or ctxt.wellFormed() != 0:
93 print "%s: error: Well Formedness error not detected" % (id)
94 log.write("%s: error: Well Formedness error not detected\n" % (id))
98 def testNotWfEnt(filename, id):
106 ctxt = libxml2.createFileParserCtxt(filename)
109 ctxt.replaceEntities(1)
110 ret = ctxt.parseDocument()
118 if ret == 0 or ctxt.wellFormed() != 0:
119 print "%s: error: Well Formedness error not detected" % (id)
120 log.write("%s: error: Well Formedness error not detected\n" % (id))
124 def testNotWfEntDtd(filename, id):
132 ctxt = libxml2.createFileParserCtxt(filename)
135 ctxt.replaceEntities(1)
137 ret = ctxt.parseDocument()
145 if ret == 0 or ctxt.wellFormed() != 0:
146 print "%s: error: Well Formedness error not detected" % (id)
147 log.write("%s: error: Well Formedness error not detected\n" % (id))
151 def testWfEntDtd(filename, id):
159 ctxt = libxml2.createFileParserCtxt(filename)
162 ctxt.replaceEntities(1)
164 ret = ctxt.parseDocument()
170 if doc == None or ret != 0 or ctxt.wellFormed() == 0:
171 print "%s: error: wrongly failed to parse the document" % (id)
172 log.write("%s: error: wrongly failed to parse the document\n" % (id))
177 print "%s: warning: WF document generated an error msg" % (id)
178 log.write("%s: error: WF document generated an error msg\n" % (id))
184 def testError(filename, id):
192 ctxt = libxml2.createFileParserCtxt(filename)
195 ctxt.replaceEntities(1)
197 ret = ctxt.parseDocument()
205 if ctxt.wellFormed() == 0:
206 print "%s: warning: failed to parse the document but accepted" % (id)
207 log.write("%s: warning: failed to parse the document but accepte\n" % (id))
210 print "%s: warning: WF document generated an error msg" % (id)
211 log.write("%s: error: WF document generated an error msg\n" % (id))
215 def testInvalid(filename, id):
223 ctxt = libxml2.createFileParserCtxt(filename)
227 ret = ctxt.parseDocument()
233 valid = ctxt.isValid()
235 print "%s: error: wrongly failed to parse the document" % (id)
236 log.write("%s: error: wrongly failed to parse the document\n" % (id))
239 print "%s: error: Validity error not detected" % (id)
240 log.write("%s: error: Validity error not detected\n" % (id))
244 print "%s: warning: Validity error not reported" % (id)
245 log.write("%s: warning: Validity error not reported\n" % (id))
252 def testValid(filename, id):
259 ctxt = libxml2.createFileParserCtxt(filename)
269 valid = ctxt.isValid()
271 print "%s: error: wrongly failed to parse the document" % (id)
272 log.write("%s: error: wrongly failed to parse the document\n" % (id))
275 print "%s: error: Validity check failed" % (id)
276 log.write("%s: error: Validity check failed\n" % (id))
279 if error_nr != 0 or valid != 1:
280 print "%s: warning: valid document reported an error" % (id)
281 log.write("%s: warning: valid document reported an error\n" % (id))
294 uri = test.prop('URI')
297 print "Test without ID:", uri
300 print "Test without URI:", id
302 base = test.getBase(None)
303 URI = libxml2.buildURI(uri, base)
304 if os.access(URI, os.R_OK) == 0:
305 print "Test %s missing: base %s uri %s" % (URI, base, uri)
307 type = test.prop('TYPE')
309 print "Test %s missing TYPE" % (id)
313 if type == "invalid":
314 res = testInvalid(URI, id)
315 elif type == "valid":
316 res = testValid(URI, id)
317 elif type == "not-wf":
318 extra = test.prop('ENTITIES')
321 # res = testNotWfEntDtd(URI, id)
322 #elif extra == 'none':
323 # res = testNotWf(URI, id)
324 #elif extra == 'general':
325 # res = testNotWfEnt(URI, id)
326 #elif extra == 'both' or extra == 'parameter':
327 res = testNotWfEntDtd(URI, id)
329 # print "Unknow value %s for an ENTITIES test value" % (extra)
331 elif type == "error":
332 res = testError(URI, id)
334 # TODO skipped for now
337 test_nr = test_nr + 1
339 test_succeed = test_succeed + 1
341 test_failed = test_failed + 1
343 test_error = test_error + 1
347 log.write(" File: %s\n" % (URI))
348 content = string.strip(test.content)
349 while content[-1] == '\n':
350 content = content[0:-1]
352 log.write(" %s:%s:%s\n" % (type, extra, content))
354 log.write(" %s:%s\n\n" % (type, content))
356 log.write(" ----\n%s ----\n" % (error_msg))
363 def runTestCases(case):
364 profile = case.prop('PROFILE')
365 if profile != None and \
366 string.find(profile, "IBM XML Conformance Test Suite - Production") < 0:
370 if test.name == 'TEST':
372 if test.name == 'TESTCASES':
376 conf = loadNoentDoc(CONF)
378 print "Unable to load %s" % CONF
381 testsuite = conf.getRootElement()
382 if testsuite.name != 'TESTSUITE':
383 print "Expecting TESTSUITE root element: aborting"
386 profile = testsuite.prop('PROFILE')
392 case = testsuite.children
394 if case.name == 'TESTCASES':
395 old_test_nr = test_nr
396 old_test_succeed = test_succeed
397 old_test_failed = test_failed
398 old_test_error = test_error
400 print " Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
401 test_nr - old_test_nr, test_succeed - old_test_succeed,
402 test_failed - old_test_failed, test_error - old_test_error)
408 print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
409 test_nr, test_succeed, test_failed, test_error, time.time() - start)