6 sys.path.insert(0, "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)
88 output = test.xpathEval('string(output)')
89 if output == 'No output file.':
95 output = basedir + "/" + output
96 if os.access(output, os.R_OK) == 0:
97 print "Result for %s missing: %s" % (id, output)
105 print "Result for %s unreadable: %s" % (id, output)
108 # print "testing %s" % (URI)
109 doc = libxml2.parseFile(URI)
113 res = doc.xincludeProcess()
114 if res >= 0 and expected != None:
115 result = doc.serialize()
116 if result != expected:
117 print "Result for %s differs" % (id)
118 open("xinclude.res", "w").write(result)
119 diff = os.popen("diff %s xinclude.res" % outputfile).read()
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))
166 log.write("diff from test %s:\n" %(id))
167 log.write(" -----------\n%s\n -----------\n" % (diff));
172 def runTestCases(case):
173 creator = case.prop('creator')
176 base = case.getBase(None)
177 basedir = case.prop('basedir')
179 base = libxml2.buildURI(basedir, base)
182 if test.name == 'testcase':
184 if test.name == 'testcases':
188 conf = libxml2.parseFile(CONF)
190 print "Unable to load %s" % CONF
193 testsuite = conf.getRootElement()
194 if testsuite.name != 'testsuite':
195 print "Expecting TESTSUITE root element: aborting"
198 profile = testsuite.prop('PROFILE')
204 case = testsuite.children
206 if case.name == 'testcases':
207 old_test_nr = test_nr
208 old_test_succeed = test_succeed
209 old_test_failed = test_failed
210 old_test_error = test_error
212 print " Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
213 test_nr - old_test_nr, test_succeed - old_test_succeed,
214 test_failed - old_test_failed, test_error - old_test_error)
220 print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
221 test_nr, test_succeed, test_failed, test_error, time.time() - start)