summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-03-07 12:57:00 (EST)
committer pelder2006-03-07 12:57:00 (EST)
commitcc967bd70da1501fef5662413f0595c3f7ff1400 (patch)
tree3f218220aaf3eebffde285a37ff023409860e9d4
parentbdd7661641a9ae84df16c5af1ec3410d9db3ea2e (diff)
downloadorg.eclipse.jet-cc967bd70da1501fef5662413f0595c3f7ff1400.zip
org.eclipse.jet-cc967bd70da1501fef5662413f0595c3f7ff1400.tar.gz
org.eclipse.jet-cc967bd70da1501fef5662413f0595c3f7ff1400.tar.bz2
[130546] Code work arounds for bugzilla 130547.
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/Bug130552Workaround.java78
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java68
2 files changed, 126 insertions, 20 deletions
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/Bug130552Workaround.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/Bug130552Workaround.java
new file mode 100644
index 0000000..9e67977
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/Bug130552Workaround.java
@@ -0,0 +1,78 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.tests.xpath;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
+
+/**
+ * Utility class to work around Bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=130552">130552</a> in EMF.
+ *
+ */
+public class Bug130552Workaround {
+
+ private Bug130552Workaround() {
+ // prevent intantiation
+ }
+
+ public static FeatureMap.Entry getEntry(FeatureMap fm, int index) {
+
+ // this should work, but doesn't:
+// return (FeatureMap.Entry)fm.get(index);
+
+ int iWithoutCommentsOrText = 0;
+ for (int i = 0; i < fm.size(); i++) {
+ FeatureMap.Entry entry = (FeatureMap.Entry) fm.get(i);
+ if(entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_CDATA()
+ || entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Comment()
+ || entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text()) {
+ continue;
+ }
+ if( iWithoutCommentsOrText++ == index) {
+ return entry;
+ }
+
+ }
+ throw new IndexOutOfBoundsException();
+ }
+
+ public static Object getValue(FeatureMap fm, int index) {
+ return getEntry(fm, index).getValue();
+ }
+
+ public static EStructuralFeature getEStructuralFeature(FeatureMap fm, int index) {
+ return getEntry(fm, index).getEStructuralFeature();
+ }
+
+ public static int size(FeatureMap fm) {
+ int sizeWithoutCommentsOrText = 0;
+ for (int i = 0; i < fm.size(); i++) {
+ FeatureMap.Entry entry = (FeatureMap.Entry) fm.get(i);
+ if(entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_CDATA()
+ || entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Comment()
+ || entry.getEStructuralFeature() == XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text()) {
+ continue;
+ } else {
+ ++sizeWithoutCommentsOrText;
+ }
+
+ }
+ return sizeWithoutCommentsOrText;
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
index 958cf61..f462be8 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
@@ -218,7 +218,9 @@ public class EObjectInspectorTests extends TestCase {
Object failAttr = inspector.getNamedAttribute(xmlRootElement, new ExpandedName("fail"));
assertNull(failAttr);
- Object elementA1 = xmlRootElement.getAny().getValue(0);
+// Object elementA1 = xmlRootElement.getAny().getValue(0);
+ Object elementA1 = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+
Object a1Name = inspector.getNamedAttribute(elementA1, new ExpandedName("name"));
assertNotNull(a1Name);
assertTrue("instanceof EStructuralFeature.Setting", a1Name instanceof EStructuralFeature.Setting);
@@ -362,7 +364,10 @@ public class EObjectInspectorTests extends TestCase {
ExpandedName enEmfRoot = inspector.expandedNameOf(xmlRootElement);
assertEquals("root", enEmfRoot.toString());
- ExpandedName enCustomer = inspector.expandedNameOf(xmlRootElement.getAny().getValue(0));
+// final Object value = xmlRootElement.getAny().getValue(0);
+ final Object value = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+
+ ExpandedName enCustomer = inspector.expandedNameOf(value);
assertEquals("a", enCustomer.toString());
}
@@ -392,7 +397,10 @@ public class EObjectInspectorTests extends TestCase {
public void testGetDocumentRoot_xml() {
assertEquals(xmlDocumentRoot, inspector.getDocumentRoot(xmlRootElement));
- assertEquals(xmlDocumentRoot, inspector.getDocumentRoot(xmlRootElement.getAny().getValue(0)));
+// final Object value = xmlRootElement.getAny().getValue(0);
+ final Object value = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+
+ assertEquals(xmlDocumentRoot, inspector.getDocumentRoot(value));
}
/*
@@ -486,8 +494,10 @@ public class EObjectInspectorTests extends TestCase {
*/
public void testNameOf_xml() {
assertEquals("root", inspector.nameOf(xmlRootElement));
- for (Iterator i = xmlRootElement.getAny().iterator(); i.hasNext();) {
- FeatureMap.Entry obj = (FeatureMap.Entry) i.next();
+// for (Iterator i = xmlRootElement.getAny().iterator(); i.hasNext();) {
+ for(int i = 0; i < Bug130552Workaround.size(xmlRootElement.getAny()); i++) {
+// FeatureMap.Entry obj = (FeatureMap.Entry) i.next();
+ FeatureMap.Entry obj = Bug130552Workaround.getEntry(xmlRootElement.getAny(), i);
String result = inspector.nameOf(obj.getValue());
assertEquals(obj.getEStructuralFeature().getName(), result);
}
@@ -625,16 +635,20 @@ public class EObjectInspectorTests extends TestCase {
}
public void testAddElement_xml_before() throws Exception {
- Object fildChild = xmlRootElement.getAny().getValue(0);
- int childCount = xmlRootElement.getAny().size();
+// Object firstChild = xmlRootElement.getAny().getValue(0);
+ Object firstChild = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+// int childCount = xmlRootElement.getAny().size();
+ int childCount = Bug130552Workaround.size(xmlRootElement.getAny());
- final Object newElement = inspector.addElement(xmlRootElement, new ExpandedName("a"), fildChild);
+ final Object newElement = inspector.addElement(xmlRootElement, new ExpandedName("a"), firstChild);
assertNotNull(newElement);
assertEquals("org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl", newElement.getClass().getName());
- assertEquals(childCount + 1, xmlRootElement.getAny().size());
- assertEquals(newElement, xmlRootElement.getAny().getValue(0));
+// assertEquals(childCount + 1, xmlRootElement.getAny().size());
+ assertEquals(childCount + 1, Bug130552Workaround.size(xmlRootElement.getAny()));
+// assertEquals(newElement, xmlRootElement.getAny().getValue(0));
+ assertEquals(newElement, Bug130552Workaround.getValue(xmlRootElement.getAny(), 0));
}
public void testAddElement_xml_before_fail() throws Exception {
@@ -686,8 +700,11 @@ public class EObjectInspectorTests extends TestCase {
}
public void testRemoveElement_xml() {
- EStructuralFeature feature = xmlRootElement.getAny().getEStructuralFeature(0);
- Object elementA = xmlRootElement.getAny().getValue(0);
+// EStructuralFeature feature = xmlRootElement.getAny().getEStructuralFeature(0);
+ EStructuralFeature feature = Bug130552Workaround.getEStructuralFeature(xmlRootElement.getAny(), 0);
+// Object elementA = xmlRootElement.getAny().getValue(0);
+ Object elementA = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+
int beforeSize = xmlRootElement.getAny().list(feature).size();
inspector.removeElement(elementA);
@@ -739,25 +756,36 @@ public class EObjectInspectorTests extends TestCase {
}
public void testCopyElement_xml() throws CopyElementException {
- AnyType elementA = (AnyType) xmlRootElement.getAny().getValue(0);
- int initialSize = xmlRootElement.getAny().size();
+// AnyType elementA = (AnyType) xmlRootElement.getAny().getValue(0);
+ AnyType elementA = (AnyType) Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+
+// int initialSize = xmlRootElement.getAny().size();
+ int initialSize = Bug130552Workaround.size(xmlRootElement.getAny());
+
final Object elementACopy = inspector.copyElement(xmlRootElement, elementA, "a", true);
assertNotNull(elementACopy);
assertTrue("copy != original", elementA != elementACopy);
assertEquals(inspector.stringValueOf(elementA), inspector.stringValueOf(elementACopy));
- assertEquals(initialSize + 1, xmlRootElement.getAny().size());
- assertEquals(elementACopy ,xmlRootElement.getAny().getValue(initialSize));
+// assertEquals(initialSize + 1, xmlRootElement.getAny().size());
+ assertEquals(initialSize + 1, Bug130552Workaround.size(xmlRootElement.getAny()));
+// assertEquals(elementACopy ,xmlRootElement.getAny().getValue(initialSize));
+ assertEquals(elementACopy ,Bug130552Workaround.getValue(xmlRootElement.getAny(), initialSize));
}
public void testCopyElement_xml_shallow() throws CopyElementException {
- AnyType elementA = (AnyType) xmlRootElement.getAny().getValue(0);
- int initialSize = xmlRootElement.getAny().size();
+// AnyType elementA = (AnyType) xmlRootElement.getAny().getValue(0);
+ AnyType elementA = (AnyType) Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+// int initialSize = xmlRootElement.getAny().size();
+ int initialSize = Bug130552Workaround.size(xmlRootElement.getAny());
+
final Object elementACopy = inspector.copyElement(xmlRootElement, elementA, "a", false);
assertNotNull(elementACopy);
assertTrue("copy != original", elementA != elementACopy);
- assertEquals(initialSize + 1, xmlRootElement.getAny().size());
- assertEquals(elementACopy ,xmlRootElement.getAny().getValue(initialSize));
+// assertEquals(initialSize + 1, xmlRootElement.getAny().size());
+ assertEquals(initialSize + 1, Bug130552Workaround.size(xmlRootElement.getAny()));
+// assertEquals(elementACopy ,xmlRootElement.getAny().getValue(initialSize));
+ assertEquals(elementACopy ,Bug130552Workaround.getValue(xmlRootElement.getAny(), initialSize));
assertEquals(0, inspector.getChildren(elementACopy).length);
}