6 sys.path.append("python")
10 # the testsuite description
12 DIR="xinclude-test-suite"
14 LOG="check-xinclude-test-suite.log"
25 # Error and warning handlers
30 def errorHandler(ctx, str):
34 if string.find(str, "error:") >= 0:
35 error_nr = error_nr + 1
36 if len(error_msg) < 300:
37 if len(error_msg) == 0 or error_msg[-1] == '\n':
38 error_msg = error_msg + " >>" + str
40 error_msg = error_msg + str
42 libxml2.registerErrorHandler(errorHandler, None)
44 def testXInclude(filename, id):
52 print "testXInclude(%s, %s)" % (filename, id)
55 def runTest(test, basedir):
64 uri = test.prop('href')
66 type = test.prop('type')
68 print "Test without ID:", uri
71 print "Test without URI:", id
74 print "Test without URI:", id
77 URI = basedir + "/" + uri
80 if os.access(URI, os.R_OK) == 0:
81 print "Test %s missing: base %s uri %s" % (URI, basedir, uri)
86 output = test.xpathEval('string(output)')
87 if output == 'No output file.':
93 output = basedir + "/" + output
94 if os.access(output, os.R_OK) == 0:
95 print "Result for %s missing: %s" % (id, output)
102 print "Result for %s unreadable: %s" % (id, output)
105 # print "testing %s" % (URI)
106 doc = libxml2.parseFile(URI)
110 res = doc.xincludeProcess()
111 if res >= 0 and expected != None:
112 result = doc.serialize()
113 if result != expected:
114 print "Result for %s differs" % (id)
123 print "Failed to parse %s" % (URI)
128 test_nr = test_nr + 1
129 if type == 'success':
131 test_succeed = test_succeed + 1
133 test_failed = test_failed + 1
134 print "Test %s: no substitution done ???" % (id)
136 test_error = test_error + 1
137 print "Test %s: failed valid XInclude processing" % (id)
138 elif type == 'error':
140 test_error = test_error + 1
141 print "Test %s: failed to detect invalid XInclude processing" % (id)
143 test_failed = test_failed + 1
144 print "Test %s: Invalid but no substitution done" % (id)
146 test_succeed = test_succeed + 1
147 elif type == 'optional':
149 test_succeed = test_succeed + 1
151 print "Test %s: failed optional test" % (id)
155 log.write("Test ID %s\n" % (id))
156 log.write(" File: %s\n" % (URI))
157 content = string.strip(test.content)
158 while content[-1] == '\n':
159 content = content[0:-1]
160 log.write(" %s:%s\n\n" % (type, content))
162 log.write(" ----\n%s ----\n" % (error_msg))
169 def runTestCases(case):
170 creator = case.prop('creator')
173 base = case.getBase(None)
174 basedir = case.prop('basedir')
176 base = libxml2.buildURI(basedir, base)
179 if test.name == 'testcase':
181 if test.name == 'testcases':
185 conf = libxml2.parseFile(CONF)
187 print "Unable to load %s" % CONF
190 testsuite = conf.getRootElement()
191 if testsuite.name != 'testsuite':
192 print "Expecting TESTSUITE root element: aborting"
195 profile = testsuite.prop('PROFILE')
201 case = testsuite.children
203 if case.name == 'testcases':
204 old_test_nr = test_nr
205 old_test_succeed = test_succeed
206 old_test_failed = test_failed
207 old_test_error = test_error
209 print " Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
210 test_nr - old_test_nr, test_succeed - old_test_succeed,
211 test_failed - old_test_failed, test_error - old_test_error)
217 print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
218 test_nr, test_succeed, test_failed, test_error, time.time() - start)