/* * 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.layout; import com.android.SdkConstants; import com.android.ide.common.api.IAttributeInfo.Format; import com.android.ide.common.resources.platform.AttributeInfo; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.mock.MockXmlNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.resources.Density; import org.w3c.dom.Node; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.util.HashMap; import junit.framework.TestCase; public class UiElementPullParserTest extends TestCase { private UiElementNode ui; private HashMap button1Map; private HashMap button2Map; private HashMap textMap; private TextAttributeDescriptor createTextAttrDesc(String xmlName) { return new TextAttributeDescriptor( xmlName, // xmlLocalName SdkConstants.NS_RESOURCES, new AttributeInfo(xmlName, Format.STRING_SET) ); } @Override protected void setUp() throws Exception { // set up some basic descriptors. // We have button, textview, linear layout, relative layout. // only the layouts have children (all 4 descriptors possible) // Also add some dummy attributes. ElementDescriptor buttonDescriptor = new ElementDescriptor("Button", "Button", "", "", new AttributeDescriptor[] { createTextAttrDesc("name"), createTextAttrDesc("text"), }, new ElementDescriptor[] {}, false); ElementDescriptor textDescriptor = new ElementDescriptor("TextView", "TextView", "", "", new AttributeDescriptor[] { createTextAttrDesc("name"), createTextAttrDesc("text"), }, new ElementDescriptor[] {}, false); ElementDescriptor linearDescriptor = new ElementDescriptor("LinearLayout", "Linear Layout", "", "", new AttributeDescriptor[] { createTextAttrDesc("orientation"), }, new ElementDescriptor[] { }, false); ElementDescriptor relativeDescriptor = new ElementDescriptor("RelativeLayout", "Relative Layout", "", "", new AttributeDescriptor[] { createTextAttrDesc("orientation"), }, new ElementDescriptor[] { }, false); ElementDescriptor[] a = new ElementDescriptor[] { buttonDescriptor, textDescriptor, linearDescriptor, relativeDescriptor }; linearDescriptor.setChildren(a); relativeDescriptor.setChildren(a); // document descriptor ElementDescriptor rootDescriptor = new ElementDescriptor("root", "", "", "", new AttributeDescriptor[] { }, a, false); ui = new UiElementNode(rootDescriptor); /* create a dummy XML file. * *