aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock
diff options
context:
space:
mode:
authorBob Badour <bbadour@google.com>2020-05-06 15:09:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-06 15:09:12 +0000
commitf1a59c98333d28b04b74772f204bcc1df6e83634 (patch)
treefd845444b59dfc72656b7781596e0b1a0662c4c7 /eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock
parent14a008655dafe4ca1fc7d014a16a1c401761675c (diff)
parentd58f8ba3b1869530926bd5f167103dfa161787a1 (diff)
downloadsdk-f1a59c98333d28b04b74772f204bcc1df6e83634.tar.gz
Merge "Revert "Remove unused project."" am: fc7cda06f5 am: d3c69fa48e am: d58f8ba3b1
Change-Id: I297730ce4f9da2bf30dde696439ab825cd642b00
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNamedNodeMap.java112
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNodeList.java62
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockXmlNode.java319
3 files changed, 493 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNamedNodeMap.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNamedNodeMap.java
new file mode 100644
index 000000000..0330216d5
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNamedNodeMap.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.adt.internal.editors.mock;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+class MockNamedNodeMap implements NamedNodeMap {
+
+ /** map for access by namespace/name */
+ private final HashMap<String, HashMap<String, Node>> mNodeMap =
+ new HashMap<String, HashMap<String, Node>>();
+
+ /** list for access by index */
+ private final ArrayList<Node> mNodeList = new ArrayList<Node>();
+
+ public MockXmlNode addAttribute(String namespace, String localName, String value) {
+ MockXmlNode node = new MockXmlNode(namespace, localName, value);
+
+ if (namespace == null) {
+ namespace = ""; // no namespace
+ }
+
+ // get the map for the namespace
+ HashMap<String, Node> map = mNodeMap.get(namespace);
+ if (map == null) {
+ map = new HashMap<String, Node>();
+ mNodeMap.put(namespace, map);
+ }
+
+
+ map.put(localName, node);
+ mNodeList.add(node);
+
+ return node;
+ }
+
+ // --------- NamedNodeMap -------
+
+ @Override
+ public int getLength() {
+ return mNodeList.size();
+ }
+
+ @Override
+ public Node getNamedItem(String name) {
+ HashMap<String, Node> map = mNodeMap.get(""); // no namespace
+ if (map != null) {
+ return map.get(name);
+ }
+
+ return null;
+ }
+
+ @Override
+ public Node getNamedItemNS(String namespaceURI, String localName) throws DOMException {
+ if (namespaceURI == null) {
+ namespaceURI = ""; //no namespace
+ }
+
+ HashMap<String, Node> map = mNodeMap.get(namespaceURI);
+ if (map != null) {
+ return map.get(localName);
+ }
+
+ return null;
+ }
+
+ @Override
+ public Node item(int index) {
+ return mNodeList.get(index);
+ }
+
+ @Override
+ public Node removeNamedItem(String name) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node setNamedItem(Node arg) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node setNamedItemNS(Node arg) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNodeList.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNodeList.java
new file mode 100644
index 000000000..ff9df19a1
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockNodeList.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.adt.internal.editors.mock;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.ArrayList;
+
+
+/**
+ * A quick mock implementation of NodeList on top of ArrayList.
+ */
+public class MockNodeList implements NodeList {
+
+ ArrayList<MockXmlNode> mChildren;
+
+ /**
+ * Constructs a node list from a given children list.
+ *
+ * @param children The children list. Can be null.
+ */
+ public MockNodeList(MockXmlNode[] children) {
+ mChildren = new ArrayList<MockXmlNode>();
+ if (children != null) {
+ for (MockXmlNode n : children) {
+ mChildren.add(n);
+ }
+ }
+ }
+
+ @Override
+ public int getLength() {
+ return mChildren.size();
+ }
+
+ @Override
+ public Node item(int index) {
+ if (index >= 0 && index < mChildren.size()) {
+ return mChildren.get(index);
+ }
+ return null;
+ }
+
+ public ArrayList<MockXmlNode> getArrayList() {
+ return mChildren;
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockXmlNode.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockXmlNode.java
new file mode 100644
index 000000000..77de2c822
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/mock/MockXmlNode.java
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.adt.internal.editors.mock;
+
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.UserDataHandler;
+
+import java.util.HashMap;
+
+
+/**
+ * A mock XML node with only a minimal set of information.
+ */
+public class MockXmlNode implements Node {
+
+ MockNodeList mNodeList;
+ private String mLocalName;
+ private String mNamespace;
+ private short mNodeType;
+ private MockXmlNode mParent;
+ private MockXmlNode mPreviousSibling;
+ private MockXmlNode mNextSibling;
+ private String mAttrValue;
+ private MockNamedNodeMap mAttributes;
+
+ // namespace stuff only set in the root node
+ /** map from namespace to prefix. */
+ private HashMap<String, String> mNsMap = null;
+
+ /**
+ * Constructs a node from a given children list.
+ *
+ * @param namespace The namespace of the node or null if none
+ * @param localName The XML local node name.
+ * @param node_type One of Node.xxx_NODE constants, e.g. Node.ELEMENT_NODE
+ * @param children The children list. Can be null.
+ */
+ public MockXmlNode(String namespace, String localName, short node_type,
+ MockXmlNode[] children) {
+ mLocalName = localName;
+ mNamespace = namespace;
+ mNodeType = node_type;
+ mNodeList = new MockNodeList(children);
+ fixNavigation();
+ }
+
+ /**
+ * Constructs an attribute node
+ *
+ * @param namespace The namespace of the node or null if none
+ * @param localName The XML local node name.
+ * @param value the value of the attribute
+ */
+ public MockXmlNode(String namespace, String localName, String value) {
+ mLocalName = localName;
+ mNamespace = namespace;
+ mAttrValue = value;
+ mNodeType = Node.ATTRIBUTE_NODE;
+ mNodeList = new MockNodeList(new MockXmlNode[0]);
+ fixNavigation();
+ }
+
+ private void fixNavigation() {
+ MockXmlNode prev = null;
+ for (MockXmlNode n : mNodeList.getArrayList()) {
+ n.mParent = this;
+ n.mPreviousSibling = prev;
+ if (prev != null) {
+ prev.mNextSibling = n;
+ }
+ n.fixNavigation();
+ prev = n;
+ }
+ }
+
+ public void addAttributes(String namespaceURI, String localName, String value) {
+ if (mAttributes == null) {
+ mAttributes = new MockNamedNodeMap();
+ }
+
+ MockXmlNode node = mAttributes.addAttribute(namespaceURI, localName, value);
+ node.mParent = this;
+ }
+
+ public void setPrefix(String namespace, String prefix) {
+ if (mNsMap == null) {
+ mNsMap = new HashMap<String, String>();
+ }
+
+ mNsMap.put(namespace, prefix);
+ }
+
+ public String getPrefix(String namespace) {
+ if (mNsMap != null) {
+ return mNsMap.get(namespace);
+ }
+
+ return mParent.getPrefix(namespace);
+ }
+
+
+ // ----------- Node methods
+
+ @Override
+ public Node appendChild(Node newChild) throws DOMException {
+ mNodeList.getArrayList().add((MockXmlNode) newChild);
+ return newChild;
+ }
+
+ @Override
+ public NamedNodeMap getAttributes() {
+ return mAttributes;
+ }
+
+ @Override
+ public NodeList getChildNodes() {
+ return mNodeList;
+ }
+
+ @Override
+ public Node getFirstChild() {
+ if (mNodeList.getLength() > 0) {
+ return mNodeList.item(0);
+ }
+ return null;
+ }
+
+ @Override
+ public Node getLastChild() {
+ if (mNodeList.getLength() > 0) {
+ return mNodeList.item(mNodeList.getLength() - 1);
+ }
+ return null;
+ }
+
+ @Override
+ public Node getNextSibling() {
+ return mNextSibling;
+ }
+
+ @Override
+ public String getNodeName() {
+ return mLocalName;
+ }
+
+ @Override
+ public String getLocalName() {
+ return mLocalName;
+ }
+
+ @Override
+ public short getNodeType() {
+ return mNodeType;
+ }
+
+ @Override
+ public Node getParentNode() {
+ return mParent;
+ }
+
+ @Override
+ public Node getPreviousSibling() {
+ return mPreviousSibling;
+ }
+
+ @Override
+ public boolean hasChildNodes() {
+ return mNodeList.getLength() > 0;
+ }
+
+ @Override
+ public boolean hasAttributes() {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isSameNode(Node other) {
+ return this == other;
+ }
+
+ @Override
+ public String getNodeValue() throws DOMException {
+ return mAttrValue;
+ }
+
+ @Override
+ public String getPrefix() {
+ return getPrefix(getNamespaceURI());
+ }
+
+ @Override
+ public String getNamespaceURI() {
+ return mNamespace;
+ }
+
+
+ // --- methods not implemented ---
+
+ @Override
+ public Node cloneNode(boolean deep) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public short compareDocumentPosition(Node other) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getBaseURI() {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Object getFeature(String feature, String version) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Document getOwnerDocument() {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getTextContent() throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Object getUserData(String key) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node insertBefore(Node newChild, Node refChild)
+ throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isDefaultNamespace(String namespaceURI) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isEqualNode(Node arg) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean isSupported(String feature, String version) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public String lookupNamespaceURI(String prefix) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public String lookupPrefix(String namespaceURI) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public void normalize() {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node removeChild(Node oldChild) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Node replaceChild(Node newChild, Node oldChild)
+ throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setNodeValue(String nodeValue) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setPrefix(String prefix) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setTextContent(String textContent) throws DOMException {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+
+ @Override
+ public Object setUserData(String key, Object data,
+ UserDataHandler handler) {
+ throw new UnsupportedOperationException("Operation not implemented."); //$NON-NLS-1$
+ }
+}