Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Harley2008-03-28 22:26:58 +0000
committerWalter Harley2008-03-28 22:26:58 +0000
commitdf3cea4fdd0029cef4a2ae74c3fb4d2e089b02e7 (patch)
treeed392864af6fefbc903cc5e1ec4cc889311692cb /org.eclipse.jdt.compiler.apt.tests
parentfaccf65c339a14005fa4d1de375a538b2b72d868 (diff)
downloadeclipse.jdt.core-df3cea4fdd0029cef4a2ae74c3fb4d2e089b02e7.tar.gz
eclipse.jdt.core-df3cea4fdd0029cef4a2ae74c3fb4d2e089b02e7.tar.xz
eclipse.jdt.core-df3cea4fdd0029cef4a2ae74c3fb4d2e089b02e7.zip
Another attempt at debugging bug 224424. The last one fell afoul of classpath differences in the test environment.
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jarbin142841 -> 145342 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/base/XMLComparer.java87
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/negative/NegativeModelProc.java8
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java90
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
index 1656222a1c..6df4a1f3da 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
Binary files differ
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

Back to the top