Debian Codegraph @

net/sf/saxon/testdriver/TestReport.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.testdriver;
9
10 import net.sf.saxon.s9api.*;
11 import net.sf.saxon.value.DateTimeValue;
12
13 import javax.xml.stream.XMLStreamException;
14 import javax.xml.stream.XMLStreamWriter;
15 import java.io.*;
16
17 public abstract class TestReport {
18 protected TestDriver testDriver;
19 protected Spec spec;
20 protected XMLStreamWriter results;
21 protected Writer writer;
22
23 public TestReport(TestDriver testDriver, Spec sp) {
24 this.testDriver = testDriver;
25 this.spec = sp;
26 }
27
28 public void createWriter(Processor processor) throws IOException, SaxonApiException {
29 Writer resultWriter = new BufferedWriter(new FileWriter(new File(testDriver.getResultsDir() + "/results"
30 + "_" + spec.fullName + "_" + testDriver.getProductVersion() + ".xml")));
31 Serializer serializer = processor.newSerializer(resultWriter);
32 serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
33 serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
34 if (!processor.getSaxonEdition().equals("HE")) {
35 serializer.setOutputProperty(Serializer.Property.SAXON_LINE_LENGTH, "120");
36 }
37 this.writer = resultWriter;
38 this.results = serializer.getXMLStreamWriter();
39 }
40
41 public abstract void writeResultFilePreamble(Processor processor, XdmNode catalog) throws IOException, SaxonApiException, XMLStreamException;
42
43 public abstract String getReportNamespace();
44
45 public void writeResultFilePostamble() {
46 try {
47 this.results.writeEndElement();
48 this.results.close();
49 } catch (XMLStreamException e) {
50 throw new RuntimeException(e);
51 }
52 if (writer != null) {
53 try {
54 writer.close();
55 } catch (IOException e) {
56 throw new RuntimeException(e);
57 }
58 }
59 }
60
61 public void startTestSetElement(XdmNode funcSetNode) {
62 try {
63 results.writeStartElement(getReportNamespace(), "test-set");
64 results.writeAttribute("name", funcSetNode.attribute("name"));
65 } catch (XMLStreamException e) {
66 throw new RuntimeException(e);
67 }
68 }
69
70 public void endElement() {
71 try {
72 results.writeEndElement();
73 } catch (XMLStreamException e) {
74 throw new RuntimeException(e);
75 }
76 }
77
78 public void writeTestcaseElement(String name, String part, String result, String comment) {
79 try {
80 this.results.writeEmptyElement(getReportNamespace(), "test-case");
81 this.results.writeAttribute("name", name);
82 this.results.writeAttribute("part", part);
83 this.results.writeAttribute("result", result);
84 if (comment != null) {
85 this.results.writeAttribute("comment", comment);
86 }
87 } catch (XMLStreamException e) {
88 throw new RuntimeException(e);
89 }
90 }
91
92 public void writeTestcaseElement(String name, String result, String comment) {
93 try {
94 this.results.writeEmptyElement(getReportNamespace(), "test-case");
95 this.results.writeAttribute("name", name);
96 this.results.writeAttribute("result", result);
97 if (comment != null) {
98 this.results.writeAttribute("comment", comment);
99 }
100 } catch (XMLStreamException e) {
101 throw new RuntimeException(e);
102 }
103 }
104
105 public static String getDate() {
106 return DateTimeValue.getCurrentDateTime(null).getStringValue().substring(0, 10);
107 }
108 public static String getTime() {
109 return DateTimeValue.getCurrentDateTime(null).getStringValue().substring(11);
110 }
111
112
113 }