diff options
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
4 files changed, 94 insertions, 91 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar Binary files differindex 1656222a1c..6df4a1f3da 100644 --- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar +++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLComparer.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLComparer.java index 0c427e7be9..3c0e80bfdb 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLComparer.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLComparer.java @@ -12,9 +12,11 @@ package org.eclipse.jdt.compiler.apt.tests.processors.base; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.io.StringReader; import java.util.HashSet; import java.util.Iterator; import java.util.Map; @@ -22,10 +24,13 @@ import java.util.Set; import java.util.TreeMap; import java.util.Map.Entry; +import javax.xml.parsers.DocumentBuilderFactory; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; +import org.xml.sax.InputSource; /** * Utility to compare two XML DOM trees that represent JSR269 (javax.lang.model) language models. @@ -127,6 +132,88 @@ public class XMLComparer implements IXMLNames { _out = new PrintStream(os, true); _summary = summary; } + + /** + * Test this class by creating a known XML language model and using + * this class to compare it to a known reference model. The models + * should match. + * @return true if the models matched, i.e., if the test passed + * @throws Exception + */ + public static boolean test() throws Exception { + final String XML_FRAMEWORK_TEST_MODEL = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + + "<model>\n" + + " <type-element kind=\"CLASS\" qname=\"pa.A\" sname=\"A\">\n" + + " <superclass>\n" + + " <type-mirror kind=\"DECLARED\" to-string=\"java.lang.Object\"/>\n" + + " </superclass>\n" + + " <variable-element kind=\"FIELD\" sname=\"f\" type=\"java.lang.String\">\n" + + " <annotations>\n" + + " <annotation sname=\"Anno1\">\n" + + " <annotation-values>\n" + + " <annotation-value member=\"value\" type=\"java.lang.String\" value=\"spud\"/>\n" + + " </annotation-values>\n" + + " </annotation>\n" + + " </annotations>\n" + + " </variable-element>\n" + + " </type-element>\n" + + "</model>\n"; + + // create "actual" model + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + Document actualModel = factory.newDocumentBuilder().newDocument(); + Element modelNode = actualModel.createElement(MODEL_TAG); + // primary type + Element typeNode = actualModel.createElement(TYPE_ELEMENT_TAG); + typeNode.setAttribute(KIND_TAG, "CLASS"); + typeNode.setAttribute(SNAME_TAG, "A"); + typeNode.setAttribute(QNAME_TAG, "pa.A"); + // superclass + Element scNode = actualModel.createElement(SUPERCLASS_TAG); + Element tmNode = actualModel.createElement(TYPE_MIRROR_TAG); + tmNode.setAttribute(KIND_TAG, "DECLARED"); + tmNode.setAttribute(TO_STRING_TAG, "java.lang.Object"); + scNode.appendChild(tmNode); + typeNode.appendChild(scNode); + // field + Element variableNode = actualModel.createElement(VARIABLE_ELEMENT_TAG); + variableNode.setAttribute(KIND_TAG, "FIELD"); + variableNode.setAttribute(SNAME_TAG, "f"); + variableNode.setAttribute(TYPE_TAG, "java.lang.String"); + // annotation on field + Element annotationsNode = actualModel.createElement(ANNOTATIONS_TAG); + Element annoNode = actualModel.createElement(ANNOTATION_TAG); + annoNode.setAttribute(SNAME_TAG, "Anno1"); + Element valuesNode = actualModel.createElement(ANNOTATION_VALUES_TAG); + Element valueNode = actualModel.createElement(ANNOTATION_VALUE_TAG); + valueNode.setAttribute(MEMBER_TAG, "value"); + valueNode.setAttribute(TYPE_TAG, "java.lang.String"); + valueNode.setAttribute(VALUE_TAG, "spud"); + valuesNode.appendChild(valueNode); + annoNode.appendChild(valuesNode); + annotationsNode.appendChild(annoNode); + variableNode.appendChild(annotationsNode); + typeNode.appendChild(variableNode); + modelNode.appendChild(typeNode); + actualModel.appendChild(modelNode); + + // load reference model + InputSource source = new InputSource(new StringReader(XML_FRAMEWORK_TEST_MODEL)); + Document expectedModel = factory.newDocumentBuilder().parse(source); + + // compare actual and reference + ByteArrayOutputStream out = new ByteArrayOutputStream(); + StringBuilder summary = new StringBuilder(); + summary.append("testXMLFramework failed; see console for details. "); + boolean success = compare(actualModel, expectedModel, out, summary, false /* ignoreJavacBugs */); + if (!success) { + System.out.println("testXMLFramework failed. Detailed output follows:"); + System.out.print(out.toString()); + System.out.println("=============== end output ==============="); + } + return success; + } /** * Non-static internal comparison routine called from diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/negative/NegativeModelProc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/negative/NegativeModelProc.java index e136d41053..798faa133a 100644 --- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/negative/NegativeModelProc.java +++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/negative/NegativeModelProc.java @@ -431,13 +431,19 @@ public class NegativeModelProc extends AbstractProcessor reportSuccess(); return false; } - + /** * Check the model of resources/targets.negative.pa.Negative6 * @return true if all tests passed */ public boolean checkNegative1() throws Exception { + // Self-test of XML framework. Here for now to debug https://bugs.eclipse.org/bugs/show_bug.cgi?id=224424. + if (!XMLComparer.test()) { + reportError("XML language model comparison framework failed self-test"); + return false; + } + // Test is failing on Linux - https://bugs.eclipse.org/bugs/show_bug.cgi?id=224424 if (System.getProperty("os.name").indexOf("Windows") == -1) return true; diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java index 2e9b9efb3a..268701fa66 100644 --- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java +++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java @@ -11,12 +11,8 @@ package org.eclipse.jdt.compiler.apt.tests; -import static org.eclipse.jdt.compiler.apt.tests.processors.base.IXMLNames.*; - -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; @@ -25,15 +21,9 @@ import java.util.List; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; -import javax.xml.parsers.DocumentBuilderFactory; import junit.framework.TestCase; -import org.eclipse.jdt.compiler.apt.tests.processors.base.XMLComparer; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.InputSource; - /** * Test cases for annotation processing behavior when code contains semantic errors */ @@ -50,86 +40,6 @@ public class NegativeTests extends TestCase } /** - * Test that generation and reading of XML language models works - * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=224424) - * @throws Exception - */ - public void testXMLFramework() throws Exception { - final String XML_FRAMEWORK_TEST_MODEL = - "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + - "<model>\n" + - " <type-element kind=\"CLASS\" qname=\"pa.A\" sname=\"A\">\n" + - " <superclass>\n" + - " <type-mirror kind=\"DECLARED\" to-string=\"java.lang.Object\"/>\n" + - " </superclass>\n" + - " <variable-element kind=\"FIELD\" sname=\"f\" type=\"java.lang.String\">\n" + - " <annotations>\n" + - " <annotation sname=\"Anno1\">\n" + - " <annotation-values>\n" + - " <annotation-value member=\"value\" type=\"java.lang.String\" value=\"spud\"/>\n" + - " </annotation-values>\n" + - " </annotation>\n" + - " </annotations>\n" + - " </variable-element>\n" + - " </type-element>\n" + - "</model>\n"; - - // create "actual" model - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - Document actualModel = factory.newDocumentBuilder().newDocument(); - Element modelNode = actualModel.createElement(MODEL_TAG); - // primary type - Element typeNode = actualModel.createElement(TYPE_ELEMENT_TAG); - typeNode.setAttribute(KIND_TAG, "CLASS"); - typeNode.setAttribute(SNAME_TAG, "A"); - typeNode.setAttribute(QNAME_TAG, "pa.A"); - // superclass - Element scNode = actualModel.createElement(SUPERCLASS_TAG); - Element tmNode = actualModel.createElement(TYPE_MIRROR_TAG); - tmNode.setAttribute(KIND_TAG, "DECLARED"); - tmNode.setAttribute(TO_STRING_TAG, "java.lang.Object"); - scNode.appendChild(tmNode); - typeNode.appendChild(scNode); - // field - Element variableNode = actualModel.createElement(VARIABLE_ELEMENT_TAG); - variableNode.setAttribute(KIND_TAG, "FIELD"); - variableNode.setAttribute(SNAME_TAG, "f"); - variableNode.setAttribute(TYPE_TAG, "java.lang.String"); - // annotation on field - Element annotationsNode = actualModel.createElement(ANNOTATIONS_TAG); - Element annoNode = actualModel.createElement(ANNOTATION_TAG); - annoNode.setAttribute(SNAME_TAG, "Anno1"); - Element valuesNode = actualModel.createElement(ANNOTATION_VALUES_TAG); - Element valueNode = actualModel.createElement(ANNOTATION_VALUE_TAG); - valueNode.setAttribute(MEMBER_TAG, "value"); - valueNode.setAttribute(TYPE_TAG, "java.lang.String"); - valueNode.setAttribute(VALUE_TAG, "spud"); - valuesNode.appendChild(valueNode); - annoNode.appendChild(valuesNode); - annotationsNode.appendChild(annoNode); - variableNode.appendChild(annotationsNode); - typeNode.appendChild(variableNode); - modelNode.appendChild(typeNode); - actualModel.appendChild(modelNode); - - // load reference model - InputSource source = new InputSource(new StringReader(XML_FRAMEWORK_TEST_MODEL)); - Document expectedModel = factory.newDocumentBuilder().parse(source); - - // compare actual and reference - ByteArrayOutputStream out = new ByteArrayOutputStream(); - StringBuilder summary = new StringBuilder(); - summary.append("testXMLFramework failed; see console for details. "); - boolean success = XMLComparer.compare(actualModel, expectedModel, out, summary, false /* ignoreJavacBugs */); - if (!success) { - System.out.println("testXMLFramework failed. Detailed output follows:"); - System.out.print(out.toString()); - System.out.println("=============== end output ==============="); - } - assertTrue(success); - } - - /** * Validate the testNegativeModel test against the javac compiler. * All test routines are executed. * @throws IOException |